emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master fd74c6f4b8 1/2: When reverting, preserve the readedness state set


From: Lars Ingebrigtsen
Subject: master fd74c6f4b8 1/2: When reverting, preserve the readedness state set by `C-x C-q'
Date: Wed, 24 Aug 2022 07:39:49 -0400 (EDT)

branch: master
commit fd74c6f4b81ffb6b373993ef2a5d80f888842397
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    When reverting, preserve the readedness state set by `C-x C-q'
    
    * lisp/files.el (revert-buffer): Save the user's intention in a
    variable (bug#50431).
    
    * lisp/simple.el (read-only-mode): Use it.
---
 lisp/files.el  | 9 +++++++--
 lisp/simple.el | 9 ++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index cf2a522193..8596d9a839 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6627,9 +6627,14 @@ preserve markers and overlays, at the price of being 
slower."
   ;; interface, but leaving the programmatic interface the same.
   (interactive (list (not current-prefix-arg)))
   (let ((revert-buffer-in-progress-p t)
-        (revert-buffer-preserve-modes preserve-modes))
+        (revert-buffer-preserve-modes preserve-modes)
+        (state (and (boundp 'read-only-mode--state)
+                    (list read-only-mode--state))))
     (funcall (or revert-buffer-function #'revert-buffer--default)
-             ignore-auto noconfirm)))
+             ignore-auto noconfirm)
+    (when state
+      (setq buffer-read-only (car state))
+      (setq-local read-only-mode--state (car state)))))
 
 (defun revert-buffer--default (ignore-auto noconfirm)
   "Default function for `revert-buffer'.
diff --git a/lisp/simple.el b/lisp/simple.el
index 460aff8bd8..13d0d3b241 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10400,8 +10400,15 @@ command works by setting the variable 
`buffer-read-only', which
 does not affect read-only regions caused by text properties.  To
 ignore read-only status in a Lisp program (whether due to text
 properties or buffer state), bind `inhibit-read-only' temporarily
-to a non-nil value."
+to a non-nil value.
+
+Reverting a buffer will keep the readedness state set by using
+this command."
   :variable buffer-read-only
+  ;; We're saving this value here so that we can restore the
+  ;; readedness state after reverting the buffer to the value that's
+  ;; been explicitly set by the user.
+  (setq-local read-only-mode--state buffer-read-only)
   (cond
    ((and (not buffer-read-only) view-mode)
     (View-exit-and-edit)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]