From: Lars Ingebrigtsen Date: Wed, 24 Aug 2022 11:33:02 +0000 (+0200) Subject: When reverting, preserve the readedness state set by `C-x C-q' X-Git-Tag: emacs-29.0.90~1893^2~62 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fd74c6f4b81ffb6b373993ef2a5d80f888842397;p=emacs.git 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. --- diff --git a/lisp/files.el b/lisp/files.el index cf2a5221930..8596d9a8390 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 460aff8bd82..13d0d3b2414 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)