summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-04-17 14:18:06 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-04-17 14:18:06 +0200
commit03873f070c2020a71e3ae7fc805d20edfcd3f4f0 (patch)
tree3b1bf79423a45c47ebf578deef31066a937082be
parent166364bc96e515c301f0dce9005cd010599d31c2 (diff)
downloadorg-mode-03873f070c2020a71e3ae7fc805d20edfcd3f4f0.tar.gz
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 <darkfeline@felesatra.moe> <http://permalink.gmane.org/gmane.emacs.orgmode/113020>
-rw-r--r--lisp/org-capture.el49
1 files changed, 25 insertions, 24 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 7a2007e..a951f81 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.