diff options
| author | Tassilo Horn | 2025-02-23 09:46:54 +0100 |
|---|---|---|
| committer | Tassilo Horn | 2025-03-01 13:47:19 +0100 |
| commit | 34362a2a1ccd229b486d87cbf4de2eed66e0010d (patch) | |
| tree | 2fe4a0bb98a0496946fd428afc842fd4f286dd64 | |
| parent | b6efedd66a08103e547266279419e646fc659339 (diff) | |
| download | emacs-34362a2a1ccd229b486d87cbf4de2eed66e0010d.tar.gz emacs-34362a2a1ccd229b486d87cbf4de2eed66e0010d.zip | |
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'.
| -rw-r--r-- | lisp/doc-view.el | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 2fdcc111cab..9cc55529440 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -591,11 +591,15 @@ Typically \"page-%s.png\".") | |||
| 591 | (cl-labels ((revert () | 591 | (cl-labels ((revert () |
| 592 | (let ((revert-buffer-preserve-modes t)) | 592 | (let ((revert-buffer-preserve-modes t)) |
| 593 | (apply orig-fun args) | 593 | (apply orig-fun args) |
| 594 | ;; Update the cached version of the pdf file, | 594 | ;; Update the cached version of the pdf file, too. |
| 595 | ;; too. This is the one that's used when | 595 | ;; This is the one that's used when rendering |
| 596 | ;; rendering (bug#26996). | 596 | ;; (bug#26996). doc-view--buffer-file-name is nil in |
| 597 | (unless (equal buffer-file-name | 597 | ;; the case where we've switched to the editing mode |
| 598 | doc-view--buffer-file-name) | 598 | ;; (bug#76478). In that case, we'll update the cached |
| 599 | ;; version when switching back to doc-view-mode. | ||
| 600 | (when (and doc-view--buffer-file-name | ||
| 601 | (not (equal buffer-file-name | ||
| 602 | doc-view--buffer-file-name))) | ||
| 599 | ;; FIXME: Lars says he needed to recreate | 603 | ;; FIXME: Lars says he needed to recreate |
| 600 | ;; the dir, we should figure out why. | 604 | ;; the dir, we should figure out why. |
| 601 | (doc-view-make-safe-dir doc-view-cache-directory) | 605 | (doc-view-make-safe-dir doc-view-cache-directory) |
| @@ -2443,7 +2447,20 @@ to the next best mode." | |||
| 2443 | See the command `doc-view-mode' for more information on this mode." | 2447 | See the command `doc-view-mode' for more information on this mode." |
| 2444 | :lighter " DocView" | 2448 | :lighter " DocView" |
| 2445 | (when doc-view-minor-mode | 2449 | (when doc-view-minor-mode |
| 2446 | (add-hook 'change-major-mode-hook (lambda () (doc-view-minor-mode -1)) nil t) | 2450 | (add-hook 'change-major-mode-hook |
| 2451 | (lambda () | ||
| 2452 | (doc-view-minor-mode -1)) | ||
| 2453 | nil t) | ||
| 2454 | ;; OpenDocuments are archive files, so their editing mode is | ||
| 2455 | ;; archive-mode. When editing and saving a file in that archive, | ||
| 2456 | ;; it'll automatically revert the archive buffer. Take care to | ||
| 2457 | ;; re-enable `doc-view-minor-mode' in that case. | ||
| 2458 | (add-hook 'revert-buffer-restore-functions | ||
| 2459 | (lambda () | ||
| 2460 | (lambda () | ||
| 2461 | (unless (derived-mode-p 'doc-view-mode) | ||
| 2462 | (doc-view-minor-mode 1)))) | ||
| 2463 | nil t) | ||
| 2447 | (message | 2464 | (message |
| 2448 | "%s" | 2465 | "%s" |
| 2449 | (substitute-command-keys | 2466 | (substitute-command-keys |