]> code.delx.au - gnu-emacs/commitdiff
Improve doc-view wrt. auto-revert-mode
authorTassilo Horn <tsdh@gnu.org>
Thu, 22 Oct 2015 15:01:57 +0000 (17:01 +0200)
committerTassilo Horn <tsdh@gnu.org>
Thu, 22 Oct 2015 15:04:35 +0000 (17:04 +0200)
* 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.

lisp/doc-view.el

index 9227b82a9755997a9ae36288a2a25a626fc3432e..edc001455c95f703f8553edbd30501ab13630ef0 100644 (file)
@@ -440,10 +440,23 @@ Typically \"page-%s.png\".")
 
 (defun doc-view-revert-buffer (&optional ignore-auto noconfirm)
   "Like `revert-buffer', but preserves the buffer's current modes."
-  ;; FIXME: this should probably be moved to files.el and used for
-  ;; most/all "g" bindings to revert-buffer.
   (interactive (list (not current-prefix-arg)))
-  (revert-buffer ignore-auto noconfirm 'preserve-modes))
+  (cl-labels ((revert ()
+                      (let (revert-buffer-function)
+                        (revert-buffer ignore-auto noconfirm 'preserve-modes))))
+    (if (and (eq 'pdf doc-view-doc-type)
+             (executable-find "pdfinfo"))
+        ;; We don't want to revert if the PDF file is corrupted which
+        ;; might happen when it it currently recompiled from a tex
+        ;; file.  (TODO: We'd like to have something like that also
+        ;; for other types, at least PS, but I don't know a good way
+        ;; to test if a PS file is complete.)
+        (if (= 0 (call-process (executable-find "pdfinfo") nil nil nil
+                               doc-view--buffer-file-name))
+            (revert)
+          (when (called-interactively-p 'interactive)
+            (message "Can't revert right now because the file is corrupted.")))
+      (revert))))
 
 
 (easy-menu-define doc-view-menu doc-view-mode-map
@@ -1766,6 +1779,8 @@ toggle between displaying the document or editing it as text.
     (when (not (string= doc-view--buffer-file-name buffer-file-name))
       (write-region nil nil doc-view--buffer-file-name))
 
+    (setq-local revert-buffer-function #'doc-view-revert-buffer)
+
     (add-hook 'change-major-mode-hook
              (lambda ()
                (doc-view-kill-proc)