Function: projectile-parse-dirconfig-file

projectile-parse-dirconfig-file is a byte-compiled function defined in projectile.el.

Signature

(projectile-parse-dirconfig-file &optional ROOT)

Documentation

Parse ROOT's ignore file and return its rules.

ROOT defaults to the current project; pass it to read the rules of a project you are not visiting, which is what listing the files of several projects at once needs.

The return value is a projectile-dirconfig struct with three slots: KEEP (subdirectories to restrict the project to), IGNORE
(files or directories to skip), and ENSURE (files or directories
to forcibly include even when otherwise ignored). When the file does not exist, the return value is nil.

Lines are dispatched on their first non-whitespace character:

  + add to the keep list
  - add to the ignore list
  ! add to the ensure list

Without a prefix, the line is assumed to be an ignore pattern, for backward compatibility. When projectile-dirconfig-comment-prefix is non-nil, lines whose first non-whitespace character matches it are treated as comments.

Results are cached per project root and invalidated when the dirconfig file's modification time changes.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile-parse-dirconfig-file (&optional root)
  "Parse ROOT's ignore file and return its rules.
ROOT defaults to the current project; pass it to read the rules of a
project you are not visiting, which is what listing the files of several
projects at once needs.

The return value is a `projectile-dirconfig' struct with three
slots: KEEP (subdirectories to restrict the project to), IGNORE
(files or directories to skip), and ENSURE (files or directories
to forcibly include even when otherwise ignored).  When the file
does not exist, the return value is nil.

Lines are dispatched on their first non-whitespace character:

  +  add to the keep list
  -  add to the ignore list
  !  add to the ensure list

Without a prefix, the line is assumed to be an ignore pattern, for
backward compatibility.  When `projectile-dirconfig-comment-prefix'
is non-nil, lines whose first non-whitespace character matches it
are treated as comments.

Results are cached per project root and invalidated when the
dirconfig file's modification time changes."
  (let* ((project-root (or root (projectile-project-root)))
         (dirconfig (projectile-dirconfig-file project-root))
         (cached (gethash project-root projectile--dirconfig-cache))
         (attrs (file-attributes dirconfig))
         (mtime (when attrs (file-attribute-modification-time attrs)))
         (result (pcase-let ((`(,cached-dirconfig ,cached-mtime ,cached-result) cached))
                   (if (and cached mtime
                            (equal cached-dirconfig dirconfig)
                            (equal cached-mtime mtime))
                       cached-result
                     (let ((parsed (projectile--parse-dirconfig-file-uncached project-root)))
                       (when mtime
                         (puthash project-root
                                  (list dirconfig mtime parsed)
                                  projectile--dirconfig-cache))
                       parsed)))))
    (projectile--maybe-warn-prefixless-entries project-root result)
    (projectile--maybe-warn-glob-keep-entries project-root result)
    result))