aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.dev>2026-03-04 21:34:41 +0200
committerBozhidar Batsov <bozhidar@batsov.dev>2026-03-04 21:43:10 +0200
commit490067591660e0901358656152066a5c5221ff5c (patch)
tree50ad2a2018d4b349450b7e4fc83582b820bf8118
parentd29b5b3526b4ee0335e92f93997cb4ac12f14fef (diff)
Wrap add-dir-local-variable in save-selected-window in toggle-read-only
add-dir-local-variable switches to the .dir-locals.el buffer. Without save-selected-window, kill-buffer and the subsequent buffer-file-name check operated on unpredictable buffers. This matches the pattern already used in projectile-add-dir-local-variable.
-rw-r--r--projectile.el7
1 files changed, 4 insertions, 3 deletions
diff --git a/projectile.el b/projectile.el
index 65b38ee..7c2b0f7 100644
--- a/projectile.el
+++ b/projectile.el
@@ -2671,9 +2671,10 @@ With a prefix arg INVALIDATE-CACHE invalidates the cache first."
(let ((inhibit-read-only t)
(val (not buffer-read-only))
(default-directory (projectile-acquire-root)))
- (add-dir-local-variable nil 'buffer-read-only val)
- (save-buffer)
- (kill-buffer)
+ (save-selected-window
+ (add-dir-local-variable nil 'buffer-read-only val)
+ (save-buffer)
+ (kill-buffer))
(when buffer-file-name
(read-only-mode (if val +1 -1))
(message "[%s] read-only-mode is %s" (projectile-project-name) (if val "on" "off")))))