branch: elpa/projectile
commit 81fd74f17e7e2a6082c905947a603f76f04ff730
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Fix mode-line in non-file buffers and nil project root crash
- Update the mode-line via window-configuration-change-hook so
non-file buffers like Magit display correct project info (#1823)
- Use projectile-acquire-root instead of projectile-project-root in
projectile--run-project-cmd to prevent wrong-type-argument error
when running commands in newly created projects (#1886)
---
CHANGELOG.md | 2 ++
projectile.el | 16 +++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 930f5a1967..7cf4b6997b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@
### Bugs fixed
+* [#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.
+* [#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`.
* [#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.
* [#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+.
* [#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.
diff --git a/projectile.el b/projectile.el
index 0098b2c656..6692cff5d5 100644
--- a/projectile.el
+++ b/projectile.el
@@ -569,8 +569,8 @@ Any function that does not take arguments will do."
(defcustom projectile-dynamic-mode-line t
"If true, update the mode-line dynamically.
-Only file buffers are affected by this, as the update happens via
-`find-file-hook'.
+The mode-line is updated when files are opened via `find-file-hook'
+and when the window configuration changes.
See also `projectile-mode-line-function' and `projectile-update-mode-line'."
:group 'projectile
@@ -5463,7 +5463,7 @@ If SAVE-BUFFERS is non-nil save all projectile buffers
before
running the command.
The command actually run is returned."
- (let* ((project-root (projectile-project-root))
+ (let* ((project-root (projectile-acquire-root))
(default-directory (projectile-compilation-dir))
(command (projectile-maybe-read-command show-prompt
command
@@ -6286,6 +6286,14 @@ thing shown in the mode line otherwise."
(setq projectile--mode-line mode-line))
(force-mode-line-update))
+(defun projectile-update-mode-line-on-window-change ()
+ "Update the mode-line when the window configuration changes.
+This ensures the mode-line is correct in non-file buffers like
+Magit that don't trigger `find-file-hook'."
+ (when projectile-dynamic-mode-line
+ (unless (file-remote-p default-directory)
+ (projectile-update-mode-line))))
+
(defvar projectile-command-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "4 a") #'projectile-find-other-file-other-window)
@@ -6542,12 +6550,14 @@ Otherwise behave as if called interactively.
(add-hook 'find-file-hook 'projectile-find-file-hook-function)
(add-hook 'projectile-find-dir-hook
#'projectile-track-known-projects-find-file-hook t)
(add-hook 'dired-before-readin-hook
#'projectile-track-known-projects-find-file-hook t t)
+ (add-hook 'window-configuration-change-hook
#'projectile-update-mode-line-on-window-change)
(advice-add 'compilation-find-file :around
#'compilation-find-file-projectile-find-compilation-buffer)
(advice-add 'delete-file :before
#'delete-file-projectile-remove-from-cache))
(t
(remove-hook 'project-find-functions #'project-projectile)
(remove-hook 'find-file-hook #'projectile-find-file-hook-function)
(remove-hook 'dired-before-readin-hook
#'projectile-track-known-projects-find-file-hook t)
+ (remove-hook 'window-configuration-change-hook
#'projectile-update-mode-line-on-window-change)
(advice-remove 'compilation-find-file
#'compilation-find-file-projectile-find-compilation-buffer)
(advice-remove 'delete-file #'delete-file-projectile-remove-from-cache))))