From f4bed78a19516d80b50045616d04887b81e2d5b4 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 17 Feb 2020 11:28:50 +0100 Subject: [PATCH] Move custom links to new tooling * contrib/lisp/ol-bookmark.el (org-bookmark-open): * contrib/lisp/ol-elisp-symbol.el (elisp-symbol-open): * contrib/lisp/ol-git-link.el (org-gitbare-open): (org-git-open): * contrib/lisp/ol-man.el (org-man-open): * contrib/lisp/ol-mew.el (org-mew-open): * contrib/lisp/ol-notmuch.el (org-notmuch-open): (org-notmuch-search-open): (org-notmuch-tree-open): * contrib/lisp/ol-vm.el (org-vm-open): (org-vm-imap-open): * contrib/lisp/ol-wl.el (org-wl-open): * contrib/lisp/org-mac-link.el (org-mac-together-item-open): (org-mac-addressbook-item-open): (org-mac-skim-open): (org-mac-acrobat-open): (org-mac-outlook-message-open): (org-mac-evernote-note-open): (org-devonthink-item-open): (org-mac-message-open): * contrib/lisp/org-mairix.el (org-mairix-open): * lisp/ol-bbdb.el (org-bbdb-export): (org-bbdb-open): * lisp/ol-bibtex.el (org-bibtex-open): * lisp/ol-docview.el (org-docview-open): * lisp/ol-eshell.el (org-eshell-open): * lisp/ol-eww.el ("eww"): * lisp/ol-gnus.el (org-gnus-open): * lisp/ol-info.el (org-info-open): * lisp/ol-irc.el (org-irc-visit): * lisp/ol-mhe.el (org-mhe-open): * lisp/ol-rmail.el ("rmail"): (org-rmail-open): * lisp/ol.el (org-link--open-doi): (org-link--open-elisp): (org-link--open-help): (org-link--open-shell): * lisp/org-id.el (org-id-open): * testing/lisp/test-ox.el (test-org-export/custom-protocol-maybe): Use new tooling. * doc/org-manual.org (Adding Hyperlink Types): Adapt example. --- contrib/lisp/ol-bookmark.el | 2 +- contrib/lisp/ol-elisp-symbol.el | 8 ++------ contrib/lisp/ol-git-link.el | 4 ++-- contrib/lisp/ol-man.el | 2 +- contrib/lisp/ol-mew.el | 2 +- contrib/lisp/ol-notmuch.el | 6 +++--- contrib/lisp/ol-vm.el | 4 ++-- contrib/lisp/ol-wl.el | 2 +- contrib/lisp/org-mac-link.el | 16 ++++++++-------- contrib/lisp/org-mairix.el | 2 +- doc/org-manual.org | 9 +++++++-- lisp/ol-bbdb.el | 4 ++-- lisp/ol-bibtex.el | 12 +++++------- lisp/ol-docview.el | 2 +- lisp/ol-eshell.el | 2 +- lisp/ol-eww.el | 15 ++++++++++----- lisp/ol-gnus.el | 2 +- lisp/ol-info.el | 2 +- lisp/ol-irc.el | 2 +- lisp/ol-mhe.el | 2 +- lisp/ol-rmail.el | 6 ++++-- lisp/ol.el | 10 +++++----- lisp/org-id.el | 3 +-- testing/lisp/test-ox.el | 6 +++--- 24 files changed, 65 insertions(+), 60 deletions(-) diff --git a/contrib/lisp/ol-bookmark.el b/contrib/lisp/ol-bookmark.el index 4114f4af9..db975e4f1 100644 --- a/contrib/lisp/ol-bookmark.el +++ b/contrib/lisp/ol-bookmark.el @@ -52,7 +52,7 @@ Otherwise prompt the user for the right bookmark to use." :follow #'org-bookmark-open :store #'org-bookmark-store-link) -(defun org-bookmark-open (bookmark) +(defun org-bookmark-open (bookmark _) "Visit the bookmark BOOKMARK." (bookmark-jump bookmark)) diff --git a/contrib/lisp/ol-elisp-symbol.el b/contrib/lisp/ol-elisp-symbol.el index 46084826c..d9c83085b 100644 --- a/contrib/lisp/ol-elisp-symbol.el +++ b/contrib/lisp/ol-elisp-symbol.el @@ -82,12 +82,8 @@ :follow #'org-elisp-symbol-open :store #'org-elisp-symbol-store-link) -(defun org-elisp-symbol-open (path) - "Visit the emacs-lisp elisp-symbol at PATH." - (let* ((search (when (string-match "::\\(.+\\)\\'" path) - (match-string 1 path))) - (path (substring path 0 (match-beginning 0)))) - (org-open-file path t nil search))) +(defun org-elisp-symbol-open (symbol arg) + (org-link-open-as-file symbol arg)) (defun org-elisp-symbol-store-link () "Store a link to an emacs-lisp elisp-symbol." diff --git a/contrib/lisp/ol-git-link.el b/contrib/lisp/ol-git-link.el index 9f3e12c09..4076e24ce 100644 --- a/contrib/lisp/ol-git-link.el +++ b/contrib/lisp/ol-git-link.el @@ -73,7 +73,7 @@ ;; bare git link (org-link-set-parameters "gitbare" :follow #'org-gitbare-open) -(defun org-gitbare-open (str) +(defun org-gitbare-open (str _) (let* ((strlist (org-git-split-string str)) (gitdir (nth 0 strlist)) (object (nth 1 strlist))) @@ -96,7 +96,7 @@ ;; user friendly link (org-link-set-parameters "git" :follow #'org-git-open :store #'org-git-store-link) -(defun org-git-open (str) +(defun org-git-open (str _) (let* ((strlist (org-git-split-string str)) (filepath (nth 0 strlist)) (commit (nth 1 strlist)) diff --git a/contrib/lisp/ol-man.el b/contrib/lisp/ol-man.el index fce70110f..580556ade 100644 --- a/contrib/lisp/ol-man.el +++ b/contrib/lisp/ol-man.el @@ -35,7 +35,7 @@ :group 'org-link :type '(choice (const man) (const woman))) -(defun org-man-open (path) +(defun org-man-open (path _) "Visit the manpage on PATH. PATH should be a topic that can be thrown at the man command." (funcall org-man-command path)) diff --git a/contrib/lisp/ol-mew.el b/contrib/lisp/ol-mew.el index 6372ffd01..3ce6244d9 100644 --- a/contrib/lisp/ol-mew.el +++ b/contrib/lisp/ol-mew.el @@ -191,7 +191,7 @@ with \"t\" key." (let ((folder-or-path (mew-summary-folder-name))) (mew-folder-path-to-folder folder-or-path t)))))) -(defun org-mew-open (path) +(defun org-mew-open (path _) "Follow the Mew message link specified by PATH." (let (folder message-id) (cond ((string-match "\\`\\(+.*\\)+\\+\\([0-9]+\\)\\'" path) ; for Bastien's diff --git a/contrib/lisp/ol-notmuch.el b/contrib/lisp/ol-notmuch.el index d0bb3623a..0fa0c5a2c 100644 --- a/contrib/lisp/ol-notmuch.el +++ b/contrib/lisp/ol-notmuch.el @@ -86,7 +86,7 @@ Should accept a notmuch search string as the sole argument." (org-link-add-props :link link :description desc) link))) -(defun org-notmuch-open (path) +(defun org-notmuch-open (path _) "Follow a notmuch message link specified by PATH." (funcall org-notmuch-open-function path)) @@ -113,7 +113,7 @@ Can link to more than one message, if so all matching messages are shown." :description desc) link))) -(defun org-notmuch-search-open (path) +(defun org-notmuch-search-open (path _) "Follow a notmuch message link specified by PATH." (message "%s" path) (org-notmuch-search-follow-link path)) @@ -139,7 +139,7 @@ Can link to more than one message, if so all matching messages are shown." :description desc) link))) -(defun org-notmuch-tree-open (path) +(defun org-notmuch-tree-open (path _) "Follow a notmuch message link specified by PATH." (message "%s" path) (org-notmuch-tree-follow-link path)) diff --git a/contrib/lisp/ol-vm.el b/contrib/lisp/ol-vm.el index 50384e321..bf820ce6f 100644 --- a/contrib/lisp/ol-vm.el +++ b/contrib/lisp/ol-vm.el @@ -95,7 +95,7 @@ (org-add-link-props :link link :description desc) link)))) -(defun org-vm-open (path) +(defun org-vm-open (path _) "Follow a VM message link specified by PATH." (let (folder article) (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path)) @@ -127,7 +127,7 @@ (when article (org-vm-select-message (org-link-add-angle-brackets article))))) -(defun org-vm-imap-open (path) +(defun org-vm-imap-open (path _) "Follow a VM link to an IMAP folder." (require 'vm-imap) (when (string-match "\\([^:]+\\):\\([^#]+\\)#?\\(.+\\)?" path) diff --git a/contrib/lisp/ol-wl.el b/contrib/lisp/ol-wl.el index d358e47bd..8c716adef 100644 --- a/contrib/lisp/ol-wl.el +++ b/contrib/lisp/ol-wl.el @@ -255,7 +255,7 @@ ENTITY is a message entity." (concat "@" (or (cdr server) (car server)))) (if article (concat "#" article) ""))))) -(defun org-wl-open (path) +(defun org-wl-open (path &rest _) "Follow the WL message link specified by PATH. When called with one prefix, open message in namazu search folder with `org-wl-namazu-default-index' as search index. When called diff --git a/contrib/lisp/org-mac-link.el b/contrib/lisp/org-mac-link.el index f822e3ba3..d16190e5a 100644 --- a/contrib/lisp/org-mac-link.el +++ b/contrib/lisp/org-mac-link.el @@ -494,7 +494,7 @@ The links are of the form ::split::." ;; Handle links from together.app (org-link-set-parameters "x-together-item" :follow #'org-mac-together-item-open) -(defun org-mac-together-item-open (uid) +(defun org-mac-together-item-open (uid _) "Open UID, which is a reference to an item in Together." (shell-command (concat "open -a Together \"x-together-item:" uid "\""))) @@ -553,7 +553,7 @@ The links are of the form ::split::." ;; Handle links from AddressBook.app (org-link-set-parameters "addressbook" :follow #'org-mac-addressbook-item-open) -(defun org-mac-addressbook-item-open (uid) +(defun org-mac-addressbook-item-open (uid _) "Open UID, which is a reference to an item in the addressbook." (shell-command (concat "open \"addressbook:" uid "\""))) @@ -588,7 +588,7 @@ The links are of the form ::split::." (org-link-set-parameters "skim" :follow #'org-mac-skim-open) -(defun org-mac-skim-open (uri) +(defun org-mac-skim-open (uri _) "Visit page of pdf in Skim" (let* ((page (when (string-match "::\\(.+\\)\\'" uri) (match-string 1 uri))) @@ -647,7 +647,7 @@ The links are of the form ::split::." (org-link-set-parameters "acrobat" :follow #'org-mac-acrobat-open) -(defun org-mac-acrobat-open (uri) +(defun org-mac-acrobat-open (uri _) "Visit page of pdf in Acrobat" (let* ((page (when (string-match "::\\(.+\\)\\'" uri) (match-string 1 uri))) @@ -697,7 +697,7 @@ The links are of the form ::split::." (org-link-set-parameters "mac-outlook" :follow #'org-mac-outlook-message-open) -(defun org-mac-outlook-message-open (msgid) +(defun org-mac-outlook-message-open (msgid _) "Open a message in Outlook" (do-applescript (concat @@ -809,7 +809,7 @@ after heading." (org-link-set-parameters "mac-evernote" :follow #'org-mac-evernote-note-open) -(defun org-mac-evernote-note-open (noteid) +(defun org-mac-evernote-note-open (noteid _) "Open a note in Evernote" (do-applescript (concat @@ -860,7 +860,7 @@ note(s) in Evernote.app and make a link out of it/them." (org-link-set-parameters "x-devonthink-item" :follow #'org-devonthink-item-open) -(defun org-devonthink-item-open (uid) +(defun org-devonthink-item-open (uid _) "Open UID, which is a reference to an item in DEVONthink Pro Office." (shell-command (concat "open \"x-devonthink-item:" uid "\""))) @@ -908,7 +908,7 @@ selected items in DEVONthink Pro Office and make link(s) out of it/them." (org-link-set-parameters "message" :follow #'org-mac-message-open) -(defun org-mac-message-open (message-id) +(defun org-mac-message-open (message-id _) "Visit the message with MESSAGE-ID. This will use the command `open' with the message URL." (start-process (concat "open message:" message-id) nil diff --git a/contrib/lisp/org-mairix.el b/contrib/lisp/org-mairix.el index 4678b1a4e..8968bd007 100644 --- a/contrib/lisp/org-mairix.el +++ b/contrib/lisp/org-mairix.el @@ -139,7 +139,7 @@ the buffer just like 'message-send-and-exit' does." (cons (list link desc) org-stored-links))) (message-bury (current-buffer))) -(defun org-mairix-open (search) +(defun org-mairix-open (search _) "Function to open mairix link. We first need to split it into its individual parts, and then diff --git a/doc/org-manual.org b/doc/org-manual.org index ff252fb4a..e69856e0d 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -19835,7 +19835,7 @@ The following =ol-man.el= file implements it (require 'ol) (org-link-set-parameters "man" - :follow org-man-command + :follow #'org-man-open :export #'org-man-export :store #'org-man-store-link) @@ -19844,6 +19844,11 @@ The following =ol-man.el= file implements it :group 'org-link :type '(choice (const man) (const woman))) +(defun org-man-open (path _) + "Visit the manpage on PATH. +PATH should be a topic that can be thrown at the man command." + (funcall org-man-command path)) + (defun org-man-store-link () "Store a link to a man page." (when (memq major-mode '(Man-mode woman-mode)) @@ -19863,7 +19868,7 @@ The following =ol-man.el= file implements it (match-string 1 (buffer-name)) (error "Cannot create link to this man page"))) -(defun org-man-export (link description format) +(defun org-man-export (link description format _) "Export a man page link from Org files." (let ((path (format "http://man.he.net/?topic=%s§ion=all" link)) (desc (or description link))) diff --git a/lisp/ol-bbdb.el b/lisp/ol-bbdb.el index 8aaf52d7d..c6e5ab35f 100644 --- a/lisp/ol-bbdb.el +++ b/lisp/ol-bbdb.el @@ -236,7 +236,7 @@ date year)." :link link :description name) link))) -(defun org-bbdb-export (path desc format) +(defun org-bbdb-export (path desc format _) "Create the export version of a BBDB link specified by PATH or DESC. If exporting to either HTML or LaTeX FORMAT the link will be italicized, in all other cases it is left unchanged." @@ -249,7 +249,7 @@ italicized, in all other cases it is left unchanged." (format "%s" desc)) (t desc))) -(defun org-bbdb-open (name) +(defun org-bbdb-open (name _) "Follow a BBDB link to NAME." (require 'bbdb-com) (let ((inhibit-redisplay (not debug-on-error))) diff --git a/lisp/ol-bibtex.el b/lisp/ol-bibtex.el index 5bc02172e..fee97a2fd 100644 --- a/lisp/ol-bibtex.el +++ b/lisp/ol-bibtex.el @@ -134,7 +134,6 @@ (declare-function org-insert-heading "org" (&optional arg invisible-ok top)) (declare-function org-map-entries "org" (func &optional match scope &rest skip)) (declare-function org-narrow-to-subtree "org" ()) -(declare-function org-open-file "org" (path &optional in-emacs line search)) (declare-function org-set-property "org" (property value)) (declare-function org-toggle-tag "org" (tag &optional onoff)) @@ -483,12 +482,11 @@ With optional argument OPTIONAL, also prompt for optional fields." :follow #'org-bibtex-open :store #'org-bibtex-store-link) -(defun org-bibtex-open (path) - "Visit the bibliography entry on PATH." - (let* ((search (when (string-match "::\\(.+\\)\\'" path) - (match-string 1 path))) - (path (substring path 0 (match-beginning 0)))) - (org-open-file path t nil search))) +(defun org-bibtex-open (path arg) + "Visit the bibliography entry on PATH. +ARG, when non-nil, is a universal prefix argument. See +`org-open-file' for details." + (org-link-open-as-file path arg)) (defun org-bibtex-store-link () "Store a link to a BibTeX entry." diff --git a/lisp/ol-docview.el b/lisp/ol-docview.el index c2246f956..0c6419fba 100644 --- a/lisp/ol-docview.el +++ b/lisp/ol-docview.el @@ -68,7 +68,7 @@ ((eq format 'ascii) (format "%s (%s)" desc path)) (t path))))) -(defun org-docview-open (link) +(defun org-docview-open (link _) (string-match "\\(.*?\\)\\(?:::\\([0-9]+\\)\\)?$" link) (let ((path (match-string 1 link)) (page (and (match-beginning 2) diff --git a/lisp/ol-eshell.el b/lisp/ol-eshell.el index 7e742f889..2bc1a2938 100644 --- a/lisp/ol-eshell.el +++ b/lisp/ol-eshell.el @@ -33,7 +33,7 @@ :follow #'org-eshell-open :store #'org-eshell-store-link) -(defun org-eshell-open (link) +(defun org-eshell-open (link _) "Switch to an eshell buffer and execute a command line. The link can be just a command line (executed in the default eshell buffer) or a command line prefixed by a buffer name diff --git a/lisp/ol-eww.el b/lisp/ol-eww.el index f32c06b6c..27e32bc3a 100644 --- a/lisp/ol-eww.el +++ b/lisp/ol-eww.el @@ -46,17 +46,22 @@ ;;; Code: (require 'ol) (require 'cl-lib) +(require 'eww) +;; For Emacsen < 25. (defvar eww-current-title) (defvar eww-current-url) -(defvar eww-data) -(defvar eww-mode-map) - -(declare-function eww-current-url "eww") ;; Store Org link in Eww mode buffer -(org-link-set-parameters "eww" :follow #'eww :store #'org-eww-store-link) +(org-link-set-parameters "eww" + :follow #'org-eww-open + :store #'org-eww-store-link) + +(defun org-eww-open (url _) + "Open URL with Eww in the current buffer." + (eww url)) + (defun org-eww-store-link () "Store a link to the url of an EWW buffer." (when (eq major-mode 'eww-mode) diff --git a/lisp/ol-gnus.el b/lisp/ol-gnus.el index cc1f717e2..c3c53ed3c 100644 --- a/lisp/ol-gnus.el +++ b/lisp/ol-gnus.el @@ -210,7 +210,7 @@ If `org-store-link' was called with a prefix arg the meaning of (format "nntp+%s:%s" (or (cdr server) (car server)) group) article))) -(defun org-gnus-open (path) +(defun org-gnus-open (path _) "Follow the Gnus message or folder link specified by PATH." (unless (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path) (error "Error in Gnus link %S" path)) diff --git a/lisp/ol-info.el b/lisp/ol-info.el index 58d45a7f7..864fbc47d 100644 --- a/lisp/ol-info.el +++ b/lisp/ol-info.el @@ -59,7 +59,7 @@ :link link :desc desc) link))) -(defun org-info-open (path) +(defun org-info-open (path _) "Follow an Info file and node link specified by PATH." (org-info-follow-link path)) diff --git a/lisp/ol-irc.el b/lisp/ol-irc.el index 3a347791e..a2f8086b3 100644 --- a/lisp/ol-irc.el +++ b/lisp/ol-irc.el @@ -78,7 +78,7 @@ :store #'org-irc-store-link :export #'org-irc-export) -(defun org-irc-visit (link) +(defun org-irc-visit (link _) "Parse LINK and dispatch to the correct function based on the client found." (let ((link (org-irc-parse-link link))) (cond diff --git a/lisp/ol-mhe.el b/lisp/ol-mhe.el index 099882db1..50002b0e8 100644 --- a/lisp/ol-mhe.el +++ b/lisp/ol-mhe.el @@ -96,7 +96,7 @@ supported by MH-E." (org-link-add-props :link link :description desc) link)))) -(defun org-mhe-open (path) +(defun org-mhe-open (path _) "Follow an MH-E message link specified by PATH." (let (folder article) (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path)) diff --git a/lisp/ol-rmail.el b/lisp/ol-rmail.el index cad8eaa16..e43fc932e 100644 --- a/lisp/ol-rmail.el +++ b/lisp/ol-rmail.el @@ -43,7 +43,9 @@ (defvar rmail-file-name) ; From rmail.el ;; Install the link type -(org-link-set-parameters "rmail" :follow #'org-rmail-open :store #'org-rmail-store-link) +(org-link-set-parameters "rmail" + :follow #'org-rmail-open + :store #'org-rmail-store-link) ;; Implementation (defun org-rmail-store-link () @@ -75,7 +77,7 @@ (rmail-show-message rmail-current-message) link))))) -(defun org-rmail-open (path) +(defun org-rmail-open (path _) "Follow an Rmail message link to the specified PATH." (let (folder article) (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path)) diff --git a/lisp/ol.el b/lisp/ol.el index 797b36f04..ea559a783 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -1279,15 +1279,15 @@ If there is no description, use the link target." ;;; Built-in link types ;;;; "doi" link type -(defun org-link--open-doi (path) +(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)))) + (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) +(defun org-link--open-elisp (path _) "Open a \"elisp\" type link. PATH is the sexp to evaluate, as a string." (if (or (and (org-string-nw-p org-link-elisp-skip-confirm-regexp) @@ -1308,7 +1308,7 @@ PATH is the sexp to evaluate, as a string." (org-link-set-parameters "file" :complete #'org-link-complete-file) ;;;; "help" link type -(defun org-link--open-help (path) +(defun org-link--open-help (path _) "Open a \"help\" type link. PATH is a symbol name, as a string." (pcase (intern path) @@ -1326,7 +1326,7 @@ PATH is a symbol name, as a string." (browse-url (concat scheme ":" url) arg)))) ;;;; "shell" link type -(defun org-link--open-shell (path) +(defun org-link--open-shell (path _) "Open a \"shell\" type link. PATH is the command to execute, as a string." (if (or (and (org-string-nw-p org-link-shell-skip-confirm-regexp) diff --git a/lisp/org-id.el b/lisp/org-id.el index 3efbde04d..91142917a 100644 --- a/lisp/org-id.el +++ b/lisp/org-id.el @@ -75,7 +75,6 @@ (declare-function message-make-fqdn "message" ()) (declare-function org-goto-location "org-goto" (&optional _buf help)) -(declare-function org-link-set-parameters "ol" (type &rest rest)) ;;; Customization @@ -674,7 +673,7 @@ optional argument MARKERP, return the position as a new marker." (org-link-store-props :link link :description desc :type "id") link))) -(defun org-id-open (id) +(defun org-id-open (id _) "Go to the entry with id ID." (org-mark-ring-push) (let ((m (org-id-find id 'marker)) diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 551d9b717..08b55169d 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -2997,7 +2997,7 @@ Para2" (string-match "success" (progn - (org-link-set-parameters "foo" :export (lambda (p d f) "success")) + (org-link-set-parameters "foo" :export (lambda (p d f i) "success")) (org-export-string-as "[[foo:path]]" (org-export-create-backend @@ -3013,7 +3013,7 @@ Para2" "success" (progn (org-link-set-parameters - "foo" :export (lambda (p d f) (and (eq f 'test) "success"))) + "foo" :export (lambda (p d f i) (and (eq f 'test) "success"))) (org-export-string-as "[[foo:path]]" (org-export-create-backend @@ -3030,7 +3030,7 @@ Para2" "success" (progn (org-link-set-parameters - "foo" :export (lambda (p d f) (and (eq f 'test) "success"))) + "foo" :export (lambda (p d f i) (and (eq f 'test) "success"))) (org-export-string-as "[[foo:path]]" (org-export-create-backend