From eb9b7b0bbcfac2097c10b609ccbad553a686e2b9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 24 May 2021 01:36:42 -0400 Subject: [PATCH] tools/pdf: build epdfinfo when pdf-tools is built This fixes a number of UX issues with pdf-tools trying to eagerly build epdfinfo at the least appropriate times, e.g. when org-mode processes org-pdf-tools links. Mentioned in #5086 --- modules/tools/pdf/config.el | 33 --------------------------------- modules/tools/pdf/packages.el | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/modules/tools/pdf/config.el b/modules/tools/pdf/config.el index 022b247ed9c..84f52040a1f 100644 --- a/modules/tools/pdf/config.el +++ b/modules/tools/pdf/config.el @@ -27,39 +27,6 @@ (letf! ((#'pdf-tools-pdf-buffer-p #'ignore)) (apply orig-fn args))) - (defadvice! +pdf--install-epdfinfo-a (orig-fn &rest args) - "Install epdfinfo after the first PDF file, if needed." - :around #'pdf-view-mode - ;; Prevent "epdfinfo not an executable" error short-circuiting this advice - (prog1 (with-demoted-errors "%s" (apply orig-fn args)) - ;; ...so we can go ahead and install it afterwards. - (cond ((file-executable-p pdf-info-epdfinfo-program)) - ((y-or-n-p "To read PDFs in Emacs the epdfinfo program must be built. Build it now?") - (message nil) ; flush lingering prompt in echo-area - ;; Make sure this doesn't run more than once - (advice-remove #'pdf-view-mode #'+pdf--install-epdfinfo-a) - (unless (or (pdf-info-running-p) - (ignore-errors (pdf-info-check-epdfinfo) t)) - ;; HACK On the first pdf you open (before pdf-tools loaded) - ;; `pdf-tools-install' throws errors because it has hardcoded - ;; opinions about what buffer should be focused when it is run. - ;; These errors cause `compile' to position the compilation - ;; window incorrectly or can interfere with the opening of the - ;; original pdf--sometimes aborting/burying it altogether. A - ;; timer works around this. - (run-at-time - 0.1 nil - (lambda () - (with-current-buffer (pdf-tools-install t) - (add-hook! 'compilation-finish-functions :local - (dolist (buf (buffer-list)) - (with-current-buffer buf - (and (buffer-file-name) - (or (pdf-tools-pdf-buffer-p) - (derived-mode-p 'pdf-view-mode)) - (revert-buffer t t)))))))))) - ((message "Aborted"))))) - (pdf-tools-install-noverify) ;; For consistency with other special modes diff --git a/modules/tools/pdf/packages.el b/modules/tools/pdf/packages.el index 3496401b347..106d07b8edc 100644 --- a/modules/tools/pdf/packages.el +++ b/modules/tools/pdf/packages.el @@ -2,7 +2,20 @@ ;;; tools/pdf/packages.el (package! pdf-tools - :recipe (:host github :repo "vedang/pdf-tools") ; active fork + :recipe (:host github + :repo "vedang/pdf-tools" + :post-build + (let ((warning-minimum-log-level :error)) + (require 'pdf-tools) + (unless (file-exists-p pdf-info-epdfinfo-program) + (require 'pdf-occur) + (print-group! + (print! (start "Building epdfinfo for pdf-tools")) + (with-current-buffer (pdf-tools-install 'no-query) + (while compilation-in-progress + (sleep-for 1)) + (when (> compilation-num-errors-found 0) + (print! (warn "Failed to build epdfinfo because: %s" (buffer-string))))))))) :pin "d262cf9e19d57c6567e06e51d109150c20753839") (package! saveplace-pdf-view :pin "54ed966b842501c3c092dbf57b372e37b033c578")