From: Tassilo Horn Date: Sun, 23 Feb 2025 08:46:54 +0000 (+0100) Subject: doc-view: Fix error during revert in editing mode X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f6b693dd1a979efa7bffadf7d3be7e44cf0a8d5f;p=emacs.git doc-view: Fix error during revert in editing mode When in editing mode in a doc-view buffer and then reverting (which can happen automatically when editing OpenDocument contents), we errored in the advide function doc-view--revert-buffer because the local doc-view--buffer-file-name has been killed when switching to the editing mode. Also restore doc-view-minor-mode after reverting during being in the editing mode. * lisp/doc-view.el (doc-view--revert-buffer): Check that 'doc-view--buffer-file-name' is non-nil. (doc-view-minor-mode): Add re-enabling function to 'revert-buffer-restore-functions'. (cherry picked from commit 34362a2a1ccd229b486d87cbf4de2eed66e0010d) --- diff --git a/lisp/doc-view.el b/lisp/doc-view.el index e836c212356..44b81706033 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -588,11 +588,15 @@ Typically \"page-%s.png\".") (cl-labels ((revert () (let ((revert-buffer-preserve-modes t)) (apply orig-fun args) - ;; Update the cached version of the pdf file, - ;; too. This is the one that's used when - ;; rendering (bug#26996). - (unless (equal buffer-file-name - doc-view--buffer-file-name) + ;; Update the cached version of the pdf file, too. + ;; This is the one that's used when rendering + ;; (bug#26996). doc-view--buffer-file-name is nil in + ;; the case where we've switched to the editing mode + ;; (bug#76478). In that case, we'll update the cached + ;; version when switching back to doc-view-mode. + (when (and doc-view--buffer-file-name + (not (equal buffer-file-name + doc-view--buffer-file-name))) ;; FIXME: Lars says he needed to recreate ;; the dir, we should figure out why. (doc-view-make-safe-dir doc-view-cache-directory) @@ -2440,7 +2444,20 @@ to the next best mode." See the command `doc-view-mode' for more information on this mode." :lighter " DocView" (when doc-view-minor-mode - (add-hook 'change-major-mode-hook (lambda () (doc-view-minor-mode -1)) nil t) + (add-hook 'change-major-mode-hook + (lambda () + (doc-view-minor-mode -1)) + nil t) + ;; OpenDocuments are archive files, so their editing mode is + ;; archive-mode. When editing and saving a file in that archive, + ;; it'll automatically revert the archive buffer. Take care to + ;; re-enable `doc-view-minor-mode' in that case. + (add-hook 'revert-buffer-restore-functions + (lambda () + (lambda () + (unless (derived-mode-p 'doc-view-mode) + (doc-view-minor-mode 1)))) + nil t) (message "%s" (substitute-command-keys