Tidy =org-link= type code and section

This commit is contained in:
Gerard Vermeulen 2022-09-25 20:37:08 +02:00
parent dc3e729fa2
commit d956948796

View File

@ -2486,12 +2486,17 @@ capable of handling this [[file:README.org]] file:*
:CUSTOM_ID: sec:making-org-hyperlink-types
:END:
Listing [[lst:org-ref-like-org-link-types]] defines =org-link= types for backwards
compatibility with [[https://github.com/jkitchin/org-ref][org-ref]]. Listing [[lst:define-org-pdfview-link-type]] uses ideas
from the definition of =docview-org-link= and =doi-org-link= types to define an
=pdfview-org-link= type for use with [[https://github.com/vedang/pdf-tools][pdf-tools]]. Finally, listing
[[lst:patch-org-info-link-type]] patches the function =org-info-export= and
listing [[lst:emacs-lisp-setup-buffer-local-ol-info]] sets the constants
The listings below implement four groups of =org-link= types:
1. Listing [[lst:org-ref-like-org-link-types]] defines =org-link= types for
backwards compatibility with [[https://github.com/jkitchin/org-ref][org-ref]].
2. Listing [[lst:define-org-pdfview-link-type]] uses ideas from the definition of
=docview-org-link= and =doi-org-link= types to define an =pdfview-org-link=
type for use with [[https://github.com/vedang/pdf-tools][pdf-tools]].
3. Listing [[lst:define-org-yt-link-type]] reimplements the code of the post
[[https://bitspook.in/blog/extending-org-mode-to-handle-youtube-links/][Extending org-mode to handle YouTube links]] allowing to open the YouTube link
[[yt://www.youtube.com/watch?v=eaZUZCzaIgw][Extending org-mode to handle YouTube links]] link.
4. Listing [[lst:patch-org-info-link-type]] patches the function =org-info-export=
and listing [[lst:emacs-lisp-setup-buffer-local-ol-info]] sets the constants
~org-info-emacs-documents~ and ~org-info-other-documents~ as buffer local
variables in order to export the =info-org-link= types in this document to
=html= and LaTeX correctly.
@ -2501,36 +2506,42 @@ variables in order to export the =info-org-link= types in this document to
#+name: lst:org-ref-like-org-link-types
#+begin_src emacs-lisp
(with-eval-after-load 'ol
(org-link-set-parameters
"ac*" :export (lambda (path _desc backend _info)
(org-link-set-parameters "ac*" :export #'org-ref-ac*-export)
(org-link-set-parameters "cite" :export #'org-ref-cite-export)
(org-link-set-parameters "eqref" :export #'org-ref-eqref-export)
(org-link-set-parameters "hyperlink" :export #'org-ref-hyperlink-export)
(org-link-set-parameters "label" :export #'org-ref-label-export)
(org-link-set-parameters "ref" :export #'org-ref-ref-export)
(defun org-ref-ac*-export (path _desc backend _info)
(pcase backend
(`latex (format "\\gls*{%s}" path))
(_ path))))
(org-link-set-parameters
"cite" :export (lambda (path _desc backend _info)
(_ path)))
(defun org-ref-cite-export (path _desc backend _info)
(pcase backend
(`latex (format "\\cite{%s}" path))
(_ path))))
(org-link-set-parameters
"eqref" :export (lambda (path _desc backend _info)
(_ path)))
(defun org-ref-eqref-export (path _desc backend _info)
(pcase backend
(`latex (format "\\eqref{%s}" path))
(_ path))))
(org-link-set-parameters
"hyperlink" :export (lambda (path desc backend _info)
(_ path)))
(defun org-ref-hyperlink-export (path desc backend _info)
(pcase backend
(`latex (format "\\hyperlink{%s}{%s}" path desc))
(_ path))))
(org-link-set-parameters
"label" :export (lambda (path _desc backend _info)
(_ path)))
(defun org-ref-label-export (path _desc backend _info)
(pcase backend
(`latex (format "\\label{%s}" path))
(_ path))))
(org-link-set-parameters
"ref" :export (lambda (path _desc backend _info)
(_ path)))
(defun org-ref-ref-export (path _desc backend _info)
(pcase backend
(`latex (format "\\ref{%s}" path))
(_ path)))))
(_ path))))
#+end_src
#+caption[Define an =org-link= type for =pdf-tools=]: