aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2026-04-09 10:57:24 +0200
committerJonas Bernoulli <jonas@bernoul.li>2026-04-09 10:57:24 +0200
commit609996dc819cd54d4bcf7bfdd89d573475f16046 (patch)
treee93049537ee7cc29c0431b7d6c879b56d075b9df /lisp
parent073b01e83405031da1ed55b45cb6b649a3cfb228 (diff)
Preserve read-only-mode in blob-visiting buffers
Only make blob-visiting buffers read-only when they are first visited. Previously `buffer-read-only' was set to t whenever such a buffer was reverted (via `magit--blob-normal-mode'). Additionally set `read-only-mode--state' to the same value; otherwise `revert-buffer' would not actually restore `buffer-read-only' (via `revert-buffer-restore-read-only' on `revert-buffer-restore-functions'). Set `read-only-mode--state' manually because calling `read-only-mode' does not only set these two variables, it could also enable `view-mode', which would shadow all the bindings in `magit-blob-mode-map'. Beside `magit-find-file-noselect', `magit-ediff-stage' also has to set both variables if it needs to make the buffer temporarily editable.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/magit-ediff.el8
-rw-r--r--lisp/magit-files.el3
2 files changed, 8 insertions, 3 deletions
diff --git a/lisp/magit-ediff.el b/lisp/magit-ediff.el
index 6846c55..560edfb 100644
--- a/lisp/magit-ediff.el
+++ b/lisp/magit-ediff.el
@@ -244,13 +244,17 @@ FILE has to be relative to the top directory of the repository."
(bufA (magit-ediff--find-file "HEAD" file))
(bufB (magit-ediff--find-file "{index}" file))
(lockB (buffer-local-value 'buffer-read-only bufB)))
- (with-current-buffer bufB (setq buffer-read-only nil))
+ (with-current-buffer bufB
+ (setq-local buffer-read-only nil)
+ (setq-local read-only-mode--state nil))
(magit-ediff-buffers
bufA bufB bufC nil
(lambda ()
(when (buffer-live-p ediff-buffer-B)
(when lockB
- (with-current-buffer bufB (setq buffer-read-only t)))
+ (with-current-buffer bufB
+ (setq-local buffer-read-only t)
+ (setq-local read-only-mode--state t)))
(when (buffer-modified-p ediff-buffer-B)
(with-current-buffer ediff-buffer-B
(magit-update-index))))
diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index 6ad6b19..3213dd9 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -126,6 +126,8 @@ Non-interactively REV can also be a blob object."
(setq default-directory
(if (file-exists-p defdir) defdir topdir))
(setq-local revert-buffer-function #'magit--revert-blob-buffer)
+ (setq-local buffer-read-only t)
+ (setq-local read-only-mode--state t)
(magit--refresh-blob-buffer)
(current-buffer)))
((error "Unexpected error")))))
@@ -215,7 +217,6 @@ Non-interactively REV can also be a blob object."
;; The FIND-FILE argument wasn't designed for our use case,
;; so we have to use this strange invocation to achieve that.
(normal-mode (not enable-local-variables)))
- (setq buffer-read-only t)
(set-buffer-modified-p nil)
(run-hooks 'magit-find-blob-hook)))