diff options
| author | Tassilo Horn | 2015-10-22 17:01:57 +0200 |
|---|---|---|
| committer | Tassilo Horn | 2015-10-22 17:04:35 +0200 |
| commit | 11d14229dc96d8b44b78a2f35ac0011fbd0f527f (patch) | |
| tree | 746de37795ea79018d6c7086c3eb8b1cff94d769 | |
| parent | 717e7a4e8f2f6aa6ae0be33783d208394eef4a0f (diff) | |
| download | emacs-11d14229dc96d8b44b78a2f35ac0011fbd0f527f.tar.gz emacs-11d14229dc96d8b44b78a2f35ac0011fbd0f527f.zip | |
Improve doc-view wrt. auto-revert-mode
* lisp/doc-view.el (doc-view-revert-buffer): Don't revert when file is
corrupted (bug#21729).
(doc-view-mode): Set doc-view-revert-buffer as revert-buffer-function.
| -rw-r--r-- | lisp/doc-view.el | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 9227b82a975..edc001455c9 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -440,10 +440,23 @@ Typically \"page-%s.png\".") | |||
| 440 | 440 | ||
| 441 | (defun doc-view-revert-buffer (&optional ignore-auto noconfirm) | 441 | (defun doc-view-revert-buffer (&optional ignore-auto noconfirm) |
| 442 | "Like `revert-buffer', but preserves the buffer's current modes." | 442 | "Like `revert-buffer', but preserves the buffer's current modes." |
| 443 | ;; FIXME: this should probably be moved to files.el and used for | ||
| 444 | ;; most/all "g" bindings to revert-buffer. | ||
| 445 | (interactive (list (not current-prefix-arg))) | 443 | (interactive (list (not current-prefix-arg))) |
| 446 | (revert-buffer ignore-auto noconfirm 'preserve-modes)) | 444 | (cl-labels ((revert () |
| 445 | (let (revert-buffer-function) | ||
| 446 | (revert-buffer ignore-auto noconfirm 'preserve-modes)))) | ||
| 447 | (if (and (eq 'pdf doc-view-doc-type) | ||
| 448 | (executable-find "pdfinfo")) | ||
| 449 | ;; We don't want to revert if the PDF file is corrupted which | ||
| 450 | ;; might happen when it it currently recompiled from a tex | ||
| 451 | ;; file. (TODO: We'd like to have something like that also | ||
| 452 | ;; for other types, at least PS, but I don't know a good way | ||
| 453 | ;; to test if a PS file is complete.) | ||
| 454 | (if (= 0 (call-process (executable-find "pdfinfo") nil nil nil | ||
| 455 | doc-view--buffer-file-name)) | ||
| 456 | (revert) | ||
| 457 | (when (called-interactively-p 'interactive) | ||
| 458 | (message "Can't revert right now because the file is corrupted."))) | ||
| 459 | (revert)))) | ||
| 447 | 460 | ||
| 448 | 461 | ||
| 449 | (easy-menu-define doc-view-menu doc-view-mode-map | 462 | (easy-menu-define doc-view-menu doc-view-mode-map |
| @@ -1766,6 +1779,8 @@ toggle between displaying the document or editing it as text. | |||
| 1766 | (when (not (string= doc-view--buffer-file-name buffer-file-name)) | 1779 | (when (not (string= doc-view--buffer-file-name buffer-file-name)) |
| 1767 | (write-region nil nil doc-view--buffer-file-name)) | 1780 | (write-region nil nil doc-view--buffer-file-name)) |
| 1768 | 1781 | ||
| 1782 | (setq-local revert-buffer-function #'doc-view-revert-buffer) | ||
| 1783 | |||
| 1769 | (add-hook 'change-major-mode-hook | 1784 | (add-hook 'change-major-mode-hook |
| 1770 | (lambda () | 1785 | (lambda () |
| 1771 | (doc-view-kill-proc) | 1786 | (doc-view-kill-proc) |