Skip to content

Commit a28bf9c

Browse files
committed
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)
1 parent 81fd74f commit a28bf9c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
* [#1823](https://github.com/bbatsov/projectile/issues/1823): Update the mode-line via `window-configuration-change-hook` so non-file buffers (e.g. Magit) display the correct project info.
1212
* [#1886](https://github.com/bbatsov/projectile/issues/1886): Fix `(wrong-type-argument stringp nil)` error when running project commands in a newly created project by using `projectile-acquire-root` instead of `projectile-project-root` in `projectile--run-project-cmd`.
13+
* [#1456](https://github.com/bbatsov/projectile/issues/1456): Fix `projectile-replace-regexp` stopping when encountering a missing file by filtering nonexistent files from the replacement file list.
14+
* [#1687](https://github.com/bbatsov/projectile/issues/1687): Fix `projectile-grep-finished-hook` not running on subsequent grep calls due to buffer rename collision.
15+
* [#1939](https://github.com/bbatsov/projectile/issues/1939): Handle corrupted `projectile-known-projects-file` gracefully instead of crashing with `(wrong-type-argument listp ...)`.
1316
* [#1748](https://github.com/bbatsov/projectile/issues/1748): Fix `projectile-replace` falling back to the legacy Emacs 25/26 code path on Emacs 27+ because `fileloop` was not loaded.
1417
* [#1741](https://github.com/bbatsov/projectile/issues/1741): Fix `projectile-replace` treating the search string as a regexp instead of a literal string on Emacs 27+.
1518
* [#1729](https://github.com/bbatsov/projectile/issues/1729): Fix `projectile-root-top-down` to actually return the topmost matching project root instead of the bottommost.

projectile.el

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4513,7 +4513,7 @@ With REGEXP given, don't query the user for a regexp."
45134513
;; scoped to the current root to allow multiple concurrent grep
45144514
;; operations, one per root
45154515
(with-current-buffer "*grep*"
4516-
(rename-buffer (concat "*grep <" root-dir ">*"))))))))
4516+
(rename-buffer (concat "*grep <" root-dir ">*") t)))))))
45174517
(run-hooks 'projectile-grep-finished-hook)))
45184518

45194519
;;;###autoload
@@ -5036,12 +5036,13 @@ to run the replacement."
50365036
(format "Replace regexp %s with: " old-text))))
50375037
(files
50385038
;; We have to reject directories as a workaround to work with git submodules.
5039+
;; We also reject nonexistent files to avoid errors during replacement.
50395040
;;
50405041
;; We can't narrow the list of files with
50415042
;; `projectile-files-with-string' because those regexp tools
50425043
;; don't support Emacs regular expressions.
50435044
(cl-remove-if
5044-
#'file-directory-p
5045+
(lambda (f) (or (file-directory-p f) (not (file-exists-p f))))
50455046
(mapcar #'(lambda (file) (expand-file-name file directory))
50465047
(projectile-dir-files directory)))))
50475048
;; FIXME: Probably would fail on Emacs 27+, fourth argument is gone.
@@ -5930,11 +5931,14 @@ Return a list of projects removed."
59305931
(defun projectile-load-known-projects ()
59315932
"Load saved projects from `projectile-known-projects-file'.
59325933
Also set `projectile-known-projects'."
5933-
(setq projectile-known-projects
5934-
(projectile-unserialize projectile-known-projects-file))
5935-
(setq projectile-known-projects-on-file
5936-
(and (sequencep projectile-known-projects)
5937-
(copy-sequence projectile-known-projects))))
5934+
(let ((data (projectile-unserialize projectile-known-projects-file)))
5935+
(setq projectile-known-projects
5936+
(if (and (listp data) (null (cdr (last data)))) data nil))
5937+
(unless (equal data projectile-known-projects)
5938+
(message "Warning: Projectile known projects file was corrupted, ignoring saved data"))
5939+
(setq projectile-known-projects-on-file
5940+
(and (sequencep projectile-known-projects)
5941+
(copy-sequence projectile-known-projects)))))
59385942

59395943
(defun projectile-save-known-projects ()
59405944
"Save PROJECTILE-KNOWN-PROJECTS to PROJECTILE-KNOWN-PROJECTS-FILE."
@@ -5952,7 +5956,8 @@ overwriting each other's changes."
59525956
(let* ((known-now projectile-known-projects)
59535957
(known-on-last-sync projectile-known-projects-on-file)
59545958
(known-on-file
5955-
(projectile-unserialize projectile-known-projects-file))
5959+
(let ((data (projectile-unserialize projectile-known-projects-file)))
5960+
(if (and (listp data) (null (cdr (last data)))) data nil)))
59565961
(removed-after-sync (projectile-difference known-on-last-sync known-now))
59575962
(removed-in-other-process
59585963
(projectile-difference known-on-last-sync known-on-file))

0 commit comments

Comments
 (0)