Fix pdf(view|tools)?: org links

org-pdftools now uses a more generic "pdf:*" for its links, so that
users don't have to worry about the backend.

Also, pdf(view|tools) links should now work for backward compatibility.
This commit is contained in:
Henrik Lissner 2020-04-15 23:46:58 -04:00
parent 07350731ad
commit 582fb285bc
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -811,12 +811,38 @@ compelling reason, so..."
:commands org-pdftools-export :commands org-pdftools-export
:init :init
(after! org (after! org
(org-link-set-parameters "pdftools" (add-hook 'org-store-link-functions #'org-pdftools-store-link)
;; HACK `org-pdftools' hard-codes "pdftools:" for its links. We want to use
;; a generic link so that the backend doesn't matter. These hacks are
;; in place so that the old pdf(view|tools) links still work, but that
;; org-pdftools will only generate pdf: links.
(org-link-set-parameters "pdf"
:follow #'org-pdftools-open :follow #'org-pdftools-open
:complete #'org-pdftools-complete-link :complete #'org-pdftools-complete-link
:store #'org-pdftools-store-link :store #'org-pdftools-store-link
:export #'org-pdftools-export) :export #'org-pdftools-export)
(add-hook 'org-store-link-functions #'org-pdftools-store-link)))
(add-hook! 'org-open-link-functions
(defun +org-open-old-pdf-links-fn (path)
(let ((regexp "^pdf\\(?:tools\\|view\\):"))
(when (string-match-p regexp)
(org-link-open (replace-regexp-in-string regexp "pdf:" link))
t))))
;; TODO Perhaps PR a variable for changing the link upstream?
(defadvice! +org--use-generic-link-a (link)
:filter-return '(org-pdftools-complete-link
org-pdftools-get-link)
(replace-regexp-in-string "^pdftools:" "pdf:" link))
(defadvice! +org--store-generic-link-a (orig-fn &rest args)
:around #'org-pdftools-store-link
(cl-letf* ((old-store-props (symbol-function #'org-link-store-props))
((symbol-function #'org-link-store-props)
(lambda (&rest plist)
(apply old-store-props (plist-put plist :type "pdf")))))
(apply orig-fn args)))))
(use-package! evil-org (use-package! evil-org