Skip to content

Commit 81fd74f

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

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs fixed
1010

11+
* [#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.
12+
* [#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`.
1113
* [#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.
1214
* [#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+.
1315
* [#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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,8 @@ Any function that does not take arguments will do."
569569

570570
(defcustom projectile-dynamic-mode-line t
571571
"If true, update the mode-line dynamically.
572-
Only file buffers are affected by this, as the update happens via
573-
`find-file-hook'.
572+
The mode-line is updated when files are opened via `find-file-hook'
573+
and when the window configuration changes.
574574
575575
See also `projectile-mode-line-function' and `projectile-update-mode-line'."
576576
:group 'projectile
@@ -5463,7 +5463,7 @@ If SAVE-BUFFERS is non-nil save all projectile buffers before
54635463
running the command.
54645464
54655465
The command actually run is returned."
5466-
(let* ((project-root (projectile-project-root))
5466+
(let* ((project-root (projectile-acquire-root))
54675467
(default-directory (projectile-compilation-dir))
54685468
(command (projectile-maybe-read-command show-prompt
54695469
command
@@ -6286,6 +6286,14 @@ thing shown in the mode line otherwise."
62866286
(setq projectile--mode-line mode-line))
62876287
(force-mode-line-update))
62886288

6289+
(defun projectile-update-mode-line-on-window-change ()
6290+
"Update the mode-line when the window configuration changes.
6291+
This ensures the mode-line is correct in non-file buffers like
6292+
Magit that don't trigger `find-file-hook'."
6293+
(when projectile-dynamic-mode-line
6294+
(unless (file-remote-p default-directory)
6295+
(projectile-update-mode-line))))
6296+
62896297
(defvar projectile-command-map
62906298
(let ((map (make-sparse-keymap)))
62916299
(define-key map (kbd "4 a") #'projectile-find-other-file-other-window)
@@ -6542,12 +6550,14 @@ Otherwise behave as if called interactively.
65426550
(add-hook 'find-file-hook 'projectile-find-file-hook-function)
65436551
(add-hook 'projectile-find-dir-hook #'projectile-track-known-projects-find-file-hook t)
65446552
(add-hook 'dired-before-readin-hook #'projectile-track-known-projects-find-file-hook t t)
6553+
(add-hook 'window-configuration-change-hook #'projectile-update-mode-line-on-window-change)
65456554
(advice-add 'compilation-find-file :around #'compilation-find-file-projectile-find-compilation-buffer)
65466555
(advice-add 'delete-file :before #'delete-file-projectile-remove-from-cache))
65476556
(t
65486557
(remove-hook 'project-find-functions #'project-projectile)
65496558
(remove-hook 'find-file-hook #'projectile-find-file-hook-function)
65506559
(remove-hook 'dired-before-readin-hook #'projectile-track-known-projects-find-file-hook t)
6560+
(remove-hook 'window-configuration-change-hook #'projectile-update-mode-line-on-window-change)
65516561
(advice-remove 'compilation-find-file #'compilation-find-file-projectile-find-compilation-buffer)
65526562
(advice-remove 'delete-file #'delete-file-projectile-remove-from-cache))))
65536563

0 commit comments

Comments
 (0)