From 03873f070c2020a71e3ae7fc805d20edfcd3f4f0 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 17 Apr 2017 14:18:06 +0200 Subject: [PATCH] org-capture: Fix clipboard history with %^C or %^L place holders * lisp/org-capture.el (org-capture--clipboards): New variable. (org-capture-fill-template): Use new variable. Reported-by: Allen Li --- lisp/org-capture.el | 49 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 7a2007e2d..a951f81c8 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1549,6 +1549,9 @@ Lisp programs can force the template by setting KEYS to a string." '(("C" "Customize org-capture-templates") ("q" "Abort")))))) +(defvar org-capture--clipboards nil + "List various clipboards values.") + (defun org-capture-fill-template (&optional template initial annotation) "Fill a template and return the filled template as a string. The template may still contain \"%?\" for cursor positioning." @@ -1597,12 +1600,13 @@ The template may still contain \"%?\" for cursor positioning." org-clock-heading))) (v-f (or (org-capture-get :original-file-nondirectory) "")) (v-F (or (org-capture-get :original-file) "")) - (clipboards (delq nil - (list v-i - (org-get-x-clipboard 'PRIMARY) - (org-get-x-clipboard 'CLIPBOARD) - (org-get-x-clipboard 'SECONDARY) - v-c)))) + (org-capture--clipboards + (delq nil + (list v-i + (org-get-x-clipboard 'PRIMARY) + (org-get-x-clipboard 'CLIPBOARD) + (org-get-x-clipboard 'SECONDARY) + v-c)))) (setq org-store-link-plist (plist-put org-store-link-plist :annotation v-a)) (setq org-store-link-plist (plist-put org-store-link-plist :initial v-i)) @@ -1742,24 +1746,21 @@ The template may still contain \"%?\" for cursor positioning." (and (org-at-heading-p) (let ((org-ignore-region t)) (org-set-tags nil 'align)))))) - ("C" - (cond - ((= (length clipboards) 1) (insert (car clipboards))) - ((> (length clipboards) 1) - (insert (read-string "Clipboard/kill value: " - (car clipboards) - '(clipboards . 1) - (car clipboards)))))) - ("L" - (cond ((= (length clipboards) 1) - (org-insert-link 0 (car clipboards))) - ((> (length clipboards) 1) - (org-insert-link - 0 - (read-string "Clipboard/kill value: " - (car clipboards) - '(clipboards . 1) - (car clipboards)))))) + ((or "C" "L") + (let ((insert-fun (if (equal key "C") #'insert + (lambda (s) (org-insert-link 0 s)))) + (first-value (car org-capture--clipboards))) + (pcase (length org-capture--clipboards) + (nil nil) + (`(,value) (funcall insert-fun value)) + (`(,first-value . ,_) + (funcall insert-fun + (read-string "Clipboard/kill value: " + first-value + 'org-capture--clipboards + first-value))) + (_ (error "Invalid `org-capture--clipboards' value: %S" + org-capture--clipboards))))) ("p" (org-set-property prompt nil)) ((guard key) ;; These are the date/time related ones.