From daa50557a4f2b2c5f712e17fbe146ade973ee5aa Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 25 May 2021 00:10:45 -0400 Subject: [PATCH] tools/pdf: leave it to user to build epdfinfo Trying to do this automatically is buggy to the point of insanity. It's not reliable enough to use as a :post-build target for the pdf-tools package. Better to fail gracefully, let the user know what they must do, and let them do it at their own discretion. --- modules/tools/pdf/config.el | 25 +++++++++++++++---------- modules/tools/pdf/packages.el | 14 +------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/modules/tools/pdf/config.el b/modules/tools/pdf/config.el index 84f52040a1f..61b3c97d10e 100644 --- a/modules/tools/pdf/config.el +++ b/modules/tools/pdf/config.el @@ -18,16 +18,21 @@ (add-hook 'kill-buffer-hook #'+pdf-cleanup-windows-h nil t))) :config - ;; HACK `pdf-tools-install-noverify' tries to "reset" open pdf-view-mode - ;; buffers, but does so incorrectly, causing errors when pdf-tools is - ;; loaded after opening a pdf file. We've done its job ourselves in - ;; `+pdf--install-epdfinfo-a' instead. - (defadvice! +pdf--inhibit-pdf-view-mode-resets-a (orig-fn &rest args) - :around #'pdf-tools-install-noverify - (letf! ((#'pdf-tools-pdf-buffer-p #'ignore)) - (apply orig-fn args))) - - (pdf-tools-install-noverify) + (defadvice! +pdf--install-epdfinfo-a (orig-fn &rest args) + "Install epdfinfo after the first PDF file, if needed." + :around #'pdf-view-mode + (if (file-executable-p pdf-info-epdfinfo-program) + (apply orig-fn args) + ;; If we remain in pdf-view-mode, it'll spit out cryptic errors. This + ;; graceful failure is better UX. + (fundamental-mode) + (message "Viewing PDFs in Emacs requires epdfinfo. Use `M-x pdf-tools-install' to build it"))) + + (when (memq 'pdf-occur-global-minor-mode pdf-tools-enabled-modes) + (pdf-occur-global-minor-mode 1)) + (when (memq 'pdf-virtual-global-minor-mode pdf-tools-enabled-modes) + (pdf-virtual-global-minor-mode 1)) + (add-hook 'pdf-view-mode-hook 'pdf-tools-enable-minor-modes) ;; For consistency with other special modes (map! :map pdf-view-mode-map :gn "q" #'kill-current-buffer) diff --git a/modules/tools/pdf/packages.el b/modules/tools/pdf/packages.el index 106d07b8edc..f350264921f 100644 --- a/modules/tools/pdf/packages.el +++ b/modules/tools/pdf/packages.el @@ -3,19 +3,7 @@ (package! pdf-tools :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))))))))) + :repo "vedang/pdf-tools") :pin "d262cf9e19d57c6567e06e51d109150c20753839") (package! saveplace-pdf-view :pin "54ed966b842501c3c092dbf57b372e37b033c578")