Function: doc-view--revert-buffer

doc-view--revert-buffer is a byte-compiled function defined in doc-view.el.gz.

Signature

(doc-view--revert-buffer ORIG-FUN &rest ARGS)

Documentation

Preserve the buffer's current mode and check PDF sanity.

Source Code

;; Defined in /usr/src/emacs/lisp/doc-view.el.gz
(defun doc-view--revert-buffer (orig-fun &rest args)
  "Preserve the buffer's current mode and check PDF sanity."
  (if (< undo-outer-limit (* 2 (buffer-size)))
      ;; It's normal for this operation to result in a very large undo entry.
      (setq-local undo-outer-limit (* 2 (buffer-size))))
  (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)
                    ;; FIXME: Lars says he needed to recreate
                    ;; the dir, we should figure out why.
                    (doc-view-make-safe-dir doc-view-cache-directory)
                    (write-region nil nil doc-view--buffer-file-name)))))
    (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 is 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 "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))))