refactor(pdf): better epdfinfo check on pdf-view-mode
Also adds a comment to explain why I don't directly call pdf-tools-install, instead of pdf-tools-install-noverify. Ref: #6589
This commit is contained in:
parent
924d78443a
commit
efb46c77be
1 changed files with 13 additions and 1 deletions
|
@ -21,13 +21,25 @@
|
||||||
(defadvice! +pdf--install-epdfinfo-a (fn &rest args)
|
(defadvice! +pdf--install-epdfinfo-a (fn &rest args)
|
||||||
"Install epdfinfo after the first PDF file, if needed."
|
"Install epdfinfo after the first PDF file, if needed."
|
||||||
:around #'pdf-view-mode
|
:around #'pdf-view-mode
|
||||||
(if (file-executable-p pdf-info-epdfinfo-program)
|
(if (and (require 'pdf-info nil t)
|
||||||
|
(or (pdf-info-running-p)
|
||||||
|
(ignore-errors (pdf-info-check-epdfinfo) t)))
|
||||||
(apply fn args)
|
(apply fn args)
|
||||||
;; If we remain in pdf-view-mode, it'll spit out cryptic errors. This
|
;; If we remain in pdf-view-mode, it'll spit out cryptic errors. This
|
||||||
;; graceful failure is better UX.
|
;; graceful failure is better UX.
|
||||||
(fundamental-mode)
|
(fundamental-mode)
|
||||||
(message "Viewing PDFs in Emacs requires epdfinfo. Use `M-x pdf-tools-install' to build it")))
|
(message "Viewing PDFs in Emacs requires epdfinfo. Use `M-x pdf-tools-install' to build it")))
|
||||||
|
|
||||||
|
;; Despite its namesake, this does not call `pdf-tools-install', it only sets
|
||||||
|
;; up hooks, auto-mode-alist/magic-mode-alist entries, global modes, and
|
||||||
|
;; refreshes pdf-view-mode buffers, if any.
|
||||||
|
;;
|
||||||
|
;; I avoid calling `pdf-tools-install' directly because `pdf-tools' is easy to
|
||||||
|
;; prematurely load in the background (e.g. when exporting an org file or by
|
||||||
|
;; packages like org-pdftools). And I don't want pdf-tools to suddenly block
|
||||||
|
;; Emacs and spew out compiler output for a few minutes in those cases. It's
|
||||||
|
;; abysmal UX. The `pdf-view-mode' advice above works around this with a less
|
||||||
|
;; cryptic failure message, at least.
|
||||||
(pdf-tools-install-noverify)
|
(pdf-tools-install-noverify)
|
||||||
|
|
||||||
;; For consistency with other special modes
|
;; For consistency with other special modes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue