aboutsummaryrefslogtreecommitdiff
path: root/projectile.el
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.dev>2026-02-14 17:06:31 +0200
committerBozhidar Batsov <bozhidar@batsov.dev>2026-02-14 17:06:31 +0200
commita28bf9c778dadab1b3f93e90b0706a6e6f2da657 (patch)
treedb21c015c891db2b28fa5132d5cf4f733ddf668e /projectile.el
parent81fd74f17e7e2a6082c905947a603f76f04ff730 (diff)
Fix grep hook, replace-regexp on missing files, and corrupt bookmarks
- Pass unique=t to rename-buffer in projectile-grep so subsequent greps don't fail with "buffer name in use", which prevented projectile-grep-finished-hook from running (#1687) - Filter nonexistent files from projectile-replace-regexp file list to avoid stopping on deleted files (#1456) - Validate that deserialized known-projects data is a proper list, gracefully handling corrupted bookmarks files (#1939)
Diffstat (limited to 'projectile.el')
-rw-r--r--projectile.el21
1 files changed, 13 insertions, 8 deletions
diff --git a/projectile.el b/projectile.el
index 6692cff..5791b51 100644
--- a/projectile.el
+++ b/projectile.el
@@ -4513,7 +4513,7 @@ With REGEXP given, don't query the user for a regexp."
;; scoped to the current root to allow multiple concurrent grep
;; operations, one per root
(with-current-buffer "*grep*"
- (rename-buffer (concat "*grep <" root-dir ">*"))))))))
+ (rename-buffer (concat "*grep <" root-dir ">*") t)))))))
(run-hooks 'projectile-grep-finished-hook)))
;;;###autoload
@@ -5036,12 +5036,13 @@ to run the replacement."
(format "Replace regexp %s with: " old-text))))
(files
;; We have to reject directories as a workaround to work with git submodules.
+ ;; We also reject nonexistent files to avoid errors during replacement.
;;
;; We can't narrow the list of files with
;; `projectile-files-with-string' because those regexp tools
;; don't support Emacs regular expressions.
(cl-remove-if
- #'file-directory-p
+ (lambda (f) (or (file-directory-p f) (not (file-exists-p f))))
(mapcar #'(lambda (file) (expand-file-name file directory))
(projectile-dir-files directory)))))
;; FIXME: Probably would fail on Emacs 27+, fourth argument is gone.
@@ -5930,11 +5931,14 @@ Return a list of projects removed."
(defun projectile-load-known-projects ()
"Load saved projects from `projectile-known-projects-file'.
Also set `projectile-known-projects'."
- (setq projectile-known-projects
- (projectile-unserialize projectile-known-projects-file))
- (setq projectile-known-projects-on-file
- (and (sequencep projectile-known-projects)
- (copy-sequence projectile-known-projects))))
+ (let ((data (projectile-unserialize projectile-known-projects-file)))
+ (setq projectile-known-projects
+ (if (and (listp data) (null (cdr (last data)))) data nil))
+ (unless (equal data projectile-known-projects)
+ (message "Warning: Projectile known projects file was corrupted, ignoring saved data"))
+ (setq projectile-known-projects-on-file
+ (and (sequencep projectile-known-projects)
+ (copy-sequence projectile-known-projects)))))
(defun projectile-save-known-projects ()
"Save PROJECTILE-KNOWN-PROJECTS to PROJECTILE-KNOWN-PROJECTS-FILE."
@@ -5952,7 +5956,8 @@ overwriting each other's changes."
(let* ((known-now projectile-known-projects)
(known-on-last-sync projectile-known-projects-on-file)
(known-on-file
- (projectile-unserialize projectile-known-projects-file))
+ (let ((data (projectile-unserialize projectile-known-projects-file)))
+ (if (and (listp data) (null (cdr (last data)))) data nil)))
(removed-after-sync (projectile-difference known-on-last-sync known-now))
(removed-in-other-process
(projectile-difference known-on-last-sync known-on-file))