fix(org): epdfinfo error when storing/exporting links
Here's the problem: 1. Org's link system unconditionally calls *all* link :store handlers when you call `org-store-link`, and all :export handlers when you export an Org file. 2. The org-pdftools package works by defining a custom pdf: link with custom :store and :export handlers. 3. Those handlers do not perform error handling before using pdftool's API. 4. pdf-tools fails loudly and ungracefully with a "pdf-info-epdfinfo-program is not executable" error when its API is used and epdfinfo isn't installed. TL;DR org-pdftools effectively breaks storing/exporting in org-mode until pdf-tools-install is executed to install epdfinfo. This is awful UX, so let's suppress the error.
This commit is contained in:
parent
265e19a405
commit
bf8495b412
1 changed files with 15 additions and 4 deletions
|
@ -1074,11 +1074,22 @@ compelling reason, so..."
|
|||
:commands org-pdftools-export
|
||||
:init
|
||||
(after! org
|
||||
;; HACK Fixes an issue where org-pdftools link handlers will throw a
|
||||
;; 'pdf-info-epdfinfo-program is not executable' error whenever any
|
||||
;; link is stored or exported (whether or not they're a pdf link). This
|
||||
;; error gimps org until `pdf-tools-install' is run, but this is poor
|
||||
;; UX, so we suppress it.
|
||||
(defun +org--pdftools-link-handler (fn &rest args)
|
||||
"Produces a link handler for org-pdftools that suppresses missing-epdfinfo errors whenever storing or exporting links."
|
||||
(lambda (&rest args)
|
||||
(and (ignore-errors (require 'org-pdftools nil t))
|
||||
(file-executable-p pdf-info-epdfinfo-program)
|
||||
(apply fn args))))
|
||||
(org-link-set-parameters (or (bound-and-true-p org-pdftools-link-prefix) "pdf")
|
||||
:follow #'org-pdftools-open
|
||||
:complete #'org-pdftools-complete-link
|
||||
:store #'org-pdftools-store-link
|
||||
:export #'org-pdftools-export)
|
||||
:follow (+org--pdftools-link-handler #'org-pdftools-open)
|
||||
:complete (+org--pdftools-link-handler #'org-pdftools-complete-link)
|
||||
:store (+org--pdftools-link-handler #'org-pdftools-store-link)
|
||||
:export (+org--pdftools-link-handler #'org-pdftools-export))
|
||||
(add-hook! 'org-open-link-functions
|
||||
(defun +org-open-legacy-pdf-links-fn (link)
|
||||
"Open pdftools:* and pdfviews:* links as if they were pdf:* links."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue