From: Sean Whitton Date: Wed, 16 Jul 2025 09:49:26 +0000 (+0100) Subject: view-mode-exit: Respect view-read-only X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5c111ef4295eb9328c577c94ef5d905d4c11d775;p=emacs.git view-mode-exit: Respect view-read-only * lisp/view.el (view-mode-exit): When view-read-only is non-nil, don't exit View mode if doing so would leave behind a read-only buffer not in View mode. (View-exit): Bind view-read-only to nil to override the above. (cherry picked from commit 3d04506cf3d0f020f40043d2b8e8be604ba1c2c5) --- diff --git a/lisp/view.el b/lisp/view.el index 3db7d6038bd..79c3a0c28c6 100644 --- a/lisp/view.el +++ b/lisp/view.el @@ -511,7 +511,10 @@ with the current buffer as argument and is called after disabling current buffer." (when view-mode (let ((buffer (window-buffer))) - (unless view-no-disable-on-exit + (unless (or view-no-disable-on-exit + ;; When `view-read-only' is non-nil, we don't want to + ;; leave a buffer read-only but not in `view-mode'. + (and view-read-only view-old-buffer-read-only)) (view-mode -1)) (unless exit-only @@ -528,7 +531,9 @@ current buffer." (defun View-exit () "Exit View mode but stay in current buffer." (interactive) - (view-mode-exit t)) + (let ((view-read-only nil) + (view-no-disable-on-exit nil)) + (view-mode-exit t))) ;;;###autoload (defun View-exit-and-edit ()