aboutsummaryrefslogtreecommitdiff
path: root/projectile.el
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.dev>2026-02-14 15:00:51 +0200
committerBozhidar Batsov <bozhidar@batsov.dev>2026-02-14 15:00:51 +0200
commit7a3708f146fdc4c483b276fa1bc749278cfdb82b (patch)
treed1eb4089c7541195b94a62a6092226d83afa2d6c /projectile.el
parent20228dd981f4467be1033dfad1cfe13d2aa9be9b (diff)
Don't cache nonexistent files & fix grep/git-grep with special chars (#1551, #1554)
Two unrelated small fixes: 1. projectile-cache-current-file now checks file-exists-p before adding a file to the cache. This prevents ghost entries when visiting a new file with find-file and abandoning the buffer without saving. 2. Add -F (fixed-string) flag to the grep and git-grep commands used by projectile-files-with-string, matching what rg, ag, and ack already do. This fixes errors when the search string contains regex special characters like [ ] and @.
Diffstat (limited to 'projectile.el')
-rw-r--r--projectile.el9
1 files changed, 6 insertions, 3 deletions
diff --git a/projectile.el b/projectile.el
index ed78865..6a342da 100644
--- a/projectile.el
+++ b/projectile.el
@@ -1187,7 +1187,9 @@ The cache is created both in memory and on the hard drive."
"Add the currently visited file to the cache."
(interactive)
(let ((current-project (projectile-project-root)))
- (when (and (buffer-file-name) (gethash (projectile-project-root) projectile-projects-cache))
+ (when (and (buffer-file-name)
+ (file-exists-p (buffer-file-name))
+ (gethash (projectile-project-root) projectile-projects-cache))
(let* ((abs-current-file (file-truename (buffer-file-name)))
(current-file (file-relative-name abs-current-file current-project)))
(unless (or (projectile-file-cached-p current-file current-project)
@@ -4842,12 +4844,13 @@ Returns a list of expanded filenames."
'((rg . "rg -lF --no-heading --color never ")
(ag . "ag --literal --nocolor --noheading -l ")
(ack . "ack --literal --nocolor -l ")
- (git . "git grep -HlI ")
+ (git . "git grep -HlIF ")
;; -r: recursive
;; -H: show filename for each match
;; -l: show only file names with matches
;; -I: no binary files
- (grep . "grep -rHlI %s .")))
+ ;; -F: interpret pattern as fixed string, not regexp
+ (grep . "grep -rHlIF %s .")))
(defun projectile--rg-construct-command (search-term &optional file-ext)
"Construct Rg option to search files by the extension FILE-EXT."