diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-12-01 19:33:35 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-12-01 19:33:35 +0100 |
commit | 0cc231a7bb9f261640205943ddeb42ad8cefc43d (patch) | |
tree | 338d2b5172774d055cd001f159af3161b74b160a | |
parent | 6fe212a3ec479b3a2b9665bb348b92c225db1562 (diff) | |
download | org-mode-0cc231a7bb9f261640205943ddeb42ad8cefc43d.tar.gz |
Call store link functions only once
* lisp/org.el (org-store-link): Call store link functions only once.
Fixes: 19914
-rw-r--r-- | lisp/org.el | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/lisp/org.el b/lisp/org.el index 9f9a943..7ec61bb 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9639,28 +9639,37 @@ active region." (move-beginning-of-line 2) (set-mark (point))))) (setq org-store-link-plist nil) - (let (link cpltxt desc description search - txt custom-id agenda-link sfuns sfunsn) + (let (link cpltxt desc description search txt custom-id agenda-link) (cond - - ;; Store a link using an external link type + ;; Store a link using an external link type, if any function is + ;; available. If more than one can generate a link from current + ;; location, ask which one to use. ((and (not (equal arg '(16))) - (setq sfuns - (delq - nil (mapcar (lambda (f) - (let (fs) (if (funcall f) (push f fs)))) - (org-store-link-functions))) - sfunsn (mapcar (lambda (fu) (symbol-name (car fu))) sfuns)) - (or (and (cdr sfuns) - (funcall (intern - (completing-read - "Which function for creating the link? " - sfunsn nil t (car sfunsn))))) - (funcall (caar sfuns))) - (setq link (plist-get org-store-link-plist :link) - desc (or (plist-get org-store-link-plist - :description) - link)))) + (let ((results-alist nil)) + (dolist (f (org-store-link-functions)) + (when (funcall f) + ;; XXX: return value is not link's plist, so we + ;; store the new value before it is modified. It + ;; would be cleaner to ask store link functions to + ;; return the plist instead. + (push (cons f (copy-sequence org-store-link-plist)) + results-alist))) + (pcase results-alist + (`nil nil) + (`((,_ . ,_)) t) ;single choice: nothing to do + (`((,name . ,_) . ,_) + ;; Reinstate link plist associated to the chosen + ;; function. + (apply #'org-store-link-props + (cdr (assoc-string + (completing-read + "Which function for creating the link? " + (mapcar #'car results-alist) nil t name) + results-alist))) + t)))) + (setq link (plist-get org-store-link-plist :link)) + (setq desc (or (plist-get org-store-link-plist :description) + link))) ;; Store a link from a source code buffer. ((org-src-edit-buffer-p) |