@@ -3174,7 +3174,7 @@ To enable, set `uniquify-dirname-transform' to this function:
31743174 "Get the list of PROJECT-DIR directories that are of interest to the user.
31753175When the dirconfig file has no `+' keep entries, return a single-
31763176element list with PROJECT-DIR itself."
3177- (let* ((cfg (projectile-parse-dirconfig-file))
3177+ (let* ((cfg (projectile-parse-dirconfig-file (expand-file-name project-dir) ))
31783178 (keep (and cfg (projectile-dirconfig-keep cfg))))
31793179 (if keep
31803180 (mapcar (lambda (subdir) (concat project-dir subdir)) keep)
@@ -3184,9 +3184,12 @@ element list with PROJECT-DIR itself."
31843184 "Checks if DIRECTORY is a string designating a valid directory."
31853185 (and (stringp directory) (file-directory-p directory)))
31863186
3187- (defun projectile-dir-files (directory)
3187+ (defun projectile-dir-files (directory &optional root )
31883188 "List the files in DIRECTORY and in its sub-directories.
3189- Files are returned as relative paths to DIRECTORY."
3189+ Files are returned as relative paths to DIRECTORY.
3190+ ROOT names the project whose ignore rules apply, defaulting to
3191+ DIRECTORY itself - pass it when DIRECTORY is a subdirectory of the
3192+ project being listed."
31903193 (unless (projectile--directory-p directory)
31913194 (user-error "Directory %S does not exist" directory))
31923195 ;; check for a cache hit first if caching is enabled
@@ -3195,19 +3198,21 @@ Files are returned as relative paths to DIRECTORY."
31953198 ;; cache disabled or cache miss
31963199 (or files-list
31973200 (pcase projectile-indexing-method
3198- ('native (projectile-dir-files-native directory))
3201+ ('native (projectile-dir-files-native directory root ))
31993202 ;; use external tools to get the project files
32003203 ('hybrid (let ((vcs (projectile-project-vcs directory)))
3201- (projectile-adjust-files directory vcs
3204+ (projectile-adjust-files (or root directory) vcs
32023205 (projectile-dir-files-alien directory vcs))))
32033206 ('alien (projectile-dir-files-alien directory))
32043207 (_ (user-error "Unsupported indexing method `%S'" projectile-indexing-method))))))
32053208
32063209;;; Native Project Indexing
32073210;;
32083211;; This corresponds to `projectile-indexing-method' being set to native.
3209- (defun projectile-dir-files-native (directory)
3210- "Get the files under DIRECTORY using just Emacs Lisp."
3212+ (defun projectile-dir-files-native (directory &optional root)
3213+ "Get the files under DIRECTORY using just Emacs Lisp.
3214+ ROOT names the project whose ignore rules apply, defaulting to
3215+ DIRECTORY itself."
32113216 (let ((progress-reporter
32123217 (make-progress-reporter
32133218 (format "Projectile is indexing %s"
@@ -3221,7 +3226,9 @@ Files are returned as relative paths to DIRECTORY."
32213226 (prefix-len (length (file-name-as-directory (expand-file-name directory)))))
32223227 ;; we need the files with paths relative to the project root
32233228 (mapcar (lambda (file) (substring file prefix-len))
3224- (projectile-index-directory directory (projectile-filtering-patterns)
3229+ (projectile-index-directory directory
3230+ (projectile-filtering-patterns
3231+ (expand-file-name (or root directory)))
32253232 progress-reporter))))
32263233
32273234(defun projectile--global-ignore-regexp-p (path)
@@ -4297,19 +4304,25 @@ PROJECT-ROOT defaults to the current project."
42974304
42984305(defun projectile-adjust-files (project vcs files)
42994306 "First remove ignored files from FILES, then add back unignored files."
4300- (projectile-add-unignored project vcs (projectile-remove-ignored files)))
4307+ (projectile-add-unignored project vcs (projectile-remove-ignored files project )))
43014308
4302- (defun projectile-remove-ignored (files)
4309+ (defun projectile-remove-ignored (files &optional root )
43034310 "Remove ignored files and folders from FILES.
43044311
43054312FILES are paths relative to the project root. They are matched against
43064313the project's ignore patterns (see `projectile--ignore-patterns'), the
43074314same gitignore-style rules the native indexer and the alien push-down
4308- apply; `!' ensure patterns rescue files from them."
4315+ apply; `!' ensure patterns rescue files from them.
4316+
4317+ ROOT names the project whose rules apply, defaulting to the current one.
4318+ Pass it whenever the files being filtered belong to a project other than
4319+ the one you are visiting - listing another project's files otherwise
4320+ filters them by the rules of the project you happen to be in, and with
4321+ caching on stores that wrong answer under the other project's key."
43094322 (let* (;; Ignore matching is case-sensitive; `string-match-p' would
43104323 ;; otherwise fold case, since `case-fold-search' defaults to t.
43114324 (case-fold-search nil)
4312- (filtering-patterns (projectile-filtering-patterns))
4325+ (filtering-patterns (projectile-filtering-patterns root ))
43134326 (ignore-re (projectile--compile-ignore-patterns
43144327 (car filtering-patterns)))
43154328 (ensure-re (projectile--compile-ignore-patterns
@@ -4352,7 +4365,8 @@ this case unignored files will be absent from FILES."
43524365 (projectile-keep-ignored-directories
43534366 project
43544367 vcs
4355- (projectile-unignored-directories-rel)))))
4368+ (projectile-unignored-directories-rel))
4369+ project)))
43564370 (append files unignored-files unignored-paths)))
43574371
43584372(defun projectile-buffers-with-file (buffers)
@@ -4682,14 +4696,14 @@ directory counts as ignored."
46824696 projectile-globally-ignored-directories
46834697 projectile-globally-unignored-directories))
46844698
4685- (defun projectile--dirconfig-ignore ()
4686- "Return the IGNORE entries from the project 's dirconfig, or nil."
4687- (when-let* ((cfg (projectile-parse-dirconfig-file)))
4699+ (defun projectile--dirconfig-ignore (&optional root )
4700+ "Return the IGNORE entries from ROOT 's dirconfig, or nil."
4701+ (when-let* ((cfg (projectile-parse-dirconfig-file root )))
46884702 (projectile-dirconfig-ignore cfg)))
46894703
4690- (defun projectile--dirconfig-ensure ()
4691- "Return the ENSURE entries from the project 's dirconfig, or nil."
4692- (when-let* ((cfg (projectile-parse-dirconfig-file)))
4704+ (defun projectile--dirconfig-ensure (&optional root )
4705+ "Return the ENSURE entries from ROOT 's dirconfig, or nil."
4706+ (when-let* ((cfg (projectile-parse-dirconfig-file root )))
46934707 (projectile-dirconfig-ensure cfg)))
46944708
46954709(defun projectile-unignored-files ()
@@ -4762,21 +4776,19 @@ ROOT defaults to the current project's root and only matters for the
47624776dirconfig entries; outside a project the global patterns are returned on
47634777their own. See `projectile--ignore-pattern-to-regexp' for the matching
47644778rules."
4765- (let ((default-directory (or root default-directory)))
4766- (append
4767- (mapcar (lambda (name) (concat (directory-file-name name) "/"))
4768- (projectile-globally-ignored-directory-names))
4769- (seq-difference projectile-globally-ignored-files
4770- projectile-globally-unignored-files)
4771- (projectile--globally-ignored-file-suffixes-glob)
4772- (projectile--dirconfig-ignore))))
4779+ (append
4780+ (mapcar (lambda (name) (concat (directory-file-name name) "/"))
4781+ (projectile-globally-ignored-directory-names))
4782+ (seq-difference projectile-globally-ignored-files
4783+ projectile-globally-unignored-files)
4784+ (projectile--globally-ignored-file-suffixes-glob)
4785+ (projectile--dirconfig-ignore root)))
47734786
47744787(defun projectile--ensure-patterns (&optional root)
47754788 "Return ROOT's ensure rules as a list of gitignore-style patterns.
47764789These are the `!' entries of the project's dirconfig; a path they match
47774790is kept even when `projectile--ignore-patterns' also matches it."
4778- (let ((default-directory (or root default-directory)))
4779- (projectile--dirconfig-ensure)))
4791+ (projectile--dirconfig-ensure root))
47804792
47814793(defun projectile-filtering-patterns (&optional root)
47824794 "Return ROOT's ignore and ensure patterns as a cons cell."
@@ -4789,9 +4801,11 @@ is kept even when `projectile--ignore-patterns' also matches it."
47894801 (projectile-expand-paths (projectile-files-to-ensure)))))
47904802
47914803
4792- (defun projectile-dirconfig-file ()
4793- "Return the absolute path to the project's dirconfig file."
4794- (expand-file-name projectile-dirconfig-file (projectile-project-root)))
4804+ (defun projectile-dirconfig-file (&optional root)
4805+ "Return the absolute path to ROOT's dirconfig file.
4806+ ROOT defaults to the current project's root."
4807+ (expand-file-name projectile-dirconfig-file
4808+ (or root (projectile-project-root))))
47954809
47964810(cl-defstruct projectile-dirconfig
47974811 "Parsed contents of a project's dirconfig file.
@@ -4864,10 +4878,11 @@ compatibility but are tracked separately so callers can warn."
48644878 :ensure (nreverse ensure)
48654879 :prefixless-ignore (nreverse prefixless))))
48664880
4867- (defun projectile--parse-dirconfig-file-uncached ()
4868- "Parse the dirconfig file without caching.
4869- Return a `projectile-dirconfig' or nil if the file doesn't exist."
4870- (let ((dirconfig (projectile-dirconfig-file)))
4881+ (defun projectile--parse-dirconfig-file-uncached (&optional root)
4882+ "Parse ROOT's dirconfig file without caching.
4883+ Return a `projectile-dirconfig' or nil if the file doesn't exist.
4884+ ROOT defaults to the current project."
4885+ (let ((dirconfig (projectile-dirconfig-file root)))
48714886 (when (projectile-file-exists-p dirconfig)
48724887 (projectile--parse-dirconfig-string
48734888 (with-temp-buffer
@@ -4896,8 +4911,11 @@ to nil to silence this warning."
48964911 ", "))
48974912 :warning)))
48984913
4899- (defun projectile-parse-dirconfig-file ()
4900- "Parse project ignore file and return its rules.
4914+ (defun projectile-parse-dirconfig-file (&optional root)
4915+ "Parse ROOT's ignore file and return its rules.
4916+ ROOT defaults to the current project; pass it to read the rules of a
4917+ project you are not visiting, which is what listing the files of several
4918+ projects at once needs.
49014919
49024920The return value is a `projectile-dirconfig' struct with three
49034921slots: KEEP (subdirectories to restrict the project to), IGNORE
@@ -4918,8 +4936,8 @@ are treated as comments.
49184936
49194937Results are cached per project root and invalidated when the
49204938dirconfig file's modification time changes."
4921- (let* ((dirconfig ( projectile-dirconfig-file ))
4922- (project-root (projectile-project-root))
4939+ (let* ((project-root (or root ( projectile-project-root) ))
4940+ (dirconfig (projectile-dirconfig-file project-root))
49234941 (cached (gethash project-root projectile--dirconfig-cache))
49244942 (attrs (file-attributes dirconfig))
49254943 (mtime (when attrs (file-attribute-modification-time attrs)))
@@ -4928,7 +4946,7 @@ dirconfig file's modification time changes."
49284946 (equal cached-dirconfig dirconfig)
49294947 (equal cached-mtime mtime))
49304948 cached-result
4931- (let ((parsed (projectile--parse-dirconfig-file-uncached)))
4949+ (let ((parsed (projectile--parse-dirconfig-file-uncached project-root )))
49324950 (when mtime
49334951 (puthash project-root
49344952 (list dirconfig mtime parsed)
@@ -5056,7 +5074,7 @@ CALLER is accepted for backward compatibility but no longer used."
50565074 ;; equivalent to the batched call above.
50575075 (mapcan
50585076 (lambda (dir)
5059- (let ((files (projectile-dir-files dir)))
5077+ (let ((files (projectile-dir-files dir project-root )))
50605078 ;; `projectile-dir-files' already returns paths
50615079 ;; relative to DIR, so when DIR is the project root
50625080 ;; itself (the single-directory case - native, or
@@ -14674,12 +14692,8 @@ re-search, the hand-off to the replace reviewer - then covers the whole
1467414692group.
1467514693
1467614694Searching more than one project skips the ripgrep fast-path, which runs
14677- one `rg' over one directory tree. Note also that a project's own
14678- dirconfig ignores are only applied while you are inside it -
14679- `projectile-project-files' resolves them against the current project
14680- rather than the one it was handed - so the other members of a group are
14681- filtered by the global ignore rules alone. That is long-standing
14682- behaviour, shared with `projectile-find-file-in-known-projects'."
14695+ one `rg' over one directory tree. Each member of the group is filtered
14696+ by its own ignore rules, wherever you happen to be sitting."
1468314697 (let* ((projects (projectile--project-group projects "projects"))
1468414698 (term (projectile--read-search-string-with-default
1468514699 (or prompt (format "Search %d project%s%s for"
0 commit comments