diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2021-04-18 13:59:55 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2021-04-18 14:02:06 +0200 |
commit | 9ba4c952423024568e878a4a5f1f594ee78cb264 (patch) | |
tree | 554c1e01517a0155c2891ddfff8e9423bcda5f2e | |
parent | e4f4a153dfb147342b963ebe3f8d6b2579d5b900 (diff) | |
download | org-mode-9ba4c952423024568e878a4a5f1f594ee78cb264.tar.gz |
Add DOI links export
* lisp/ol-doi.el: New file.
* lisp/ol.el (org-link-doi-server-url): Move to new file.
(org-link--open-doi): Remove function.
* lisp/org.el (org-modules): Autoload new library for backward
compatibility.
Reported-by: yarnton--- via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
<http://lists.gnu.org/r/emacs-orgmode/2020-09/msg00908.html>
-rw-r--r-- | lisp/ol-doi.el | 70 | ||||
-rw-r--r-- | lisp/ol.el | 15 | ||||
-rw-r--r-- | lisp/org.el | 6 |
3 files changed, 73 insertions, 18 deletions
diff --git a/lisp/ol-doi.el b/lisp/ol-doi.el new file mode 100644 index 0000000..dfde380 --- /dev/null +++ b/lisp/ol-doi.el @@ -0,0 +1,70 @@ +;;; ol-doi.el --- DOI links support in Org -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 Free Software Foundation, Inc. + +;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr> + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; This library introduces the "doi" link type in Org, and provides +;; code for opening and exporting such links. + +;;; Code: + +(require 'ol) + +(defcustom org-link-doi-server-url "https://doi.org/" + "The URL of the DOI server." + :group 'org-link-follow + :version "24.3" + :type 'string + :safe #'stringp) + +(defun org-link-doi-open (path arg) + "Open a \"doi\" type link. +PATH is a the path to search for, as a string." + (browse-url (url-encode-url (concat org-link-doi-server-url path)) arg)) + +(defun org-link-doi-export (path desc backend info) + "Export a \"doi\" type link. +PATH is the DOI name. DESC is the description of the link, or +nil. BACKEND is a symbol representing the backend used for +export. INFO is a a plist containing the export parameters." + (let ((uri (concat org-link-doi-server-url path))) + (pcase backend + (`html + (format "<a href=\"%s\">%s</a>" uri (or desc uri))) + (`latex + (if desc (format "\\href{%s}{%s}" uri desc) + (format "\\url{%s}" uri))) + (`ascii + (if (not desc) (format "<%s>" uri) + (concat (format "[%s]" desc) + (and (not (plist-get info :ascii-links-to-notes)) + (format " (<%s>)" uri))))) + (`texinfo + (if (not desc) (format "@uref{%s}" uri) + (format "@uref{%s, %s}" uri desc))) + (_ uri)))) + +(org-link-set-parameters "doi" + :follow #'org-link-doi-open + :export #'org-link-doi-export) + + +(provide 'org-link-doi) +(provide 'ol-doi) +;;; ol-doi.el ends here @@ -282,13 +282,6 @@ links created by planner." :type '(choice (const nil) (function)) :safe #'null) -(defcustom org-link-doi-server-url "https://doi.org/" - "The URL of the DOI server." - :group 'org-link-follow - :version "24.3" - :type 'string - :safe #'stringp) - (defcustom org-link-frame-setup '((vm . vm-visit-folder-other-frame) (vm-imap . vm-visit-imap-folder-other-frame) @@ -1306,14 +1299,6 @@ If there is no description, use the link target." ;;; Built-in link types -;;;; "doi" link type -(defun org-link--open-doi (path arg) - "Open a \"doi\" type link. -PATH is a the path to search for, as a string." - (browse-url (url-encode-url (concat org-link-doi-server-url path)) arg)) - -(org-link-set-parameters "doi" :follow #'org-link--open-doi) - ;;;; "elisp" link type (defun org-link--open-elisp (path _) "Open a \"elisp\" type link. diff --git a/lisp/org.el b/lisp/org.el index f7fd90c..c273810 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -680,7 +680,7 @@ defined in org-duration.el.") (org-load-modules-maybe 'force) (org-element-cache-reset 'all))) -(defcustom org-modules '(ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus ol-info ol-irc ol-mhe ol-rmail ol-eww) +(defcustom org-modules '(ol-doi ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus ol-info ol-irc ol-mhe ol-rmail ol-eww) "Modules that should always be loaded together with org.el. If a description starts with <C>, the file is not part of Emacs @@ -697,8 +697,7 @@ to add the symbol `xyz', and the package must have a call to: For export specific modules, see also `org-export-backends'." :group 'org :set 'org-set-modules - :version "26.1" - :package-version '(Org . "9.2") + :package-version '(Org . "9.5") :type '(set :greedy t (const :tag " bbdb: Links to BBDB entries" ol-bbdb) @@ -706,6 +705,7 @@ For export specific modules, see also `org-export-backends'." (const :tag " crypt: Encryption of subtrees" org-crypt) (const :tag " ctags: Access to Emacs tags with links" org-ctags) (const :tag " docview: Links to Docview buffers" ol-docview) + (const :tag " doi: Links to DOI references" ol-docview) (const :tag " eww: Store link to URL of Eww" ol-eww) (const :tag " gnus: Links to GNUS folders/messages" ol-gnus) (const :tag " habit: Track your consistency with habits" org-habit) |