浏览代码

Allow %<num> escapes to capture templates, expanded to text entered in <num>'th prompt

* org-capture.el (org-capture-fill-template): Expand %<num>
escape sequences into text entered for <num>'th %^{PROMPT} escape.
Toby Cubitt 13 年之前
父节点
当前提交
e13d182ce8
共有 2 个文件被更改,包括 39 次插入24 次删除
  1. 21 18
      doc/org.texi
  2. 18 6
      lisp/org-capture.el

+ 21 - 18
doc/org.texi

@@ -6670,28 +6670,28 @@ these sequences literally, escape the @kbd{%} with a backslash.}  allow
 dynamic insertion of content.  The templates are expanded in the order given here:
 dynamic insertion of content.  The templates are expanded in the order given here:
 
 
 @smallexample
 @smallexample
-%[@var{file}]     @r{insert the contents of the file given by @var{file}.}
-%(@var{sexp})     @r{evaluate Elisp @var{sexp} and replace with the result.}
-%<...>      @r{the result of format-time-string on the ... format specification.}
-%t          @r{timestamp, date only.}
-%T          @r{timestamp with date and time.}
-%u, %U      @r{like the above, but inactive timestamps.}
-%a          @r{annotation, normally the link created with @code{org-store-link}.}
-%i          @r{initial content, the region when capture is called while the}
+%[@var{file}]     @r{Insert the contents of the file given by @var{file}.}
+%(@var{sexp})     @r{Evaluate Elisp @var{sexp} and replace with the result.}
+%<...>      @r{The result of format-time-string on the ... format specification.}
+%t          @r{Timestamp, date only.}
+%T          @r{Timestamp, with date and time.}
+%u, %U      @r{Like the above, but inactive timestamps.}
+%a          @r{Annotation, normally the link created with @code{org-store-link}.}
+%i          @r{Initial content, the region when capture is called while the}
             @r{region is active.}
             @r{region is active.}
             @r{The entire text will be indented like @code{%i} itself.}
             @r{The entire text will be indented like @code{%i} itself.}
-%A          @r{like @code{%a}, but prompt for the description part.}
+%A          @r{Like @code{%a}, but prompt for the description part.}
 %c          @r{Current kill ring head.}
 %c          @r{Current kill ring head.}
 %x          @r{Content of the X clipboard.}
 %x          @r{Content of the X clipboard.}
-%k          @r{title of the currently clocked task.}
-%K          @r{link to the currently clocked task.}
-%n          @r{user name (taken from @code{user-full-name}).}
-%f          @r{file visited by current buffer when org-capture was called.}
-%F          @r{full path of the file or directory visited by current buffer.}
-%:keyword   @r{specific information for certain link types, see below.}
-%^g         @r{prompt for tags, with completion on tags in target file.}
-%^G         @r{prompt for tags, with completion all tags in all agenda files.}
-%^t         @r{like @code{%t}, but prompt for date.  Similarly @code{%^T}, @code{%^u}, @code{%^U}.}
+%k          @r{Title of the currently clocked task.}
+%K          @r{Link to the currently clocked task.}
+%n          @r{User name (taken from @code{user-full-name}).}
+%f          @r{File visited by current buffer when org-capture was called.}
+%F          @r{Full path of the file or directory visited by current buffer.}
+%:keyword   @r{Specific information for certain link types, see below.}
+%^g         @r{Prompt for tags, with completion on tags in target file.}
+%^G         @r{Prompt for tags, with completion all tags in all agenda files.}
+%^t         @r{Like @code{%t}, but prompt for date.  Similarly @code{%^T}, @code{%^u}, @code{%^U}.}
             @r{You may define a prompt like @code{%^@{Birthday@}t}.}
             @r{You may define a prompt like @code{%^@{Birthday@}t}.}
 %^C         @r{Interactive selection of which kill or clip to use.}
 %^C         @r{Interactive selection of which kill or clip to use.}
 %^L         @r{Like @code{%^C}, but insert as link.}
 %^L         @r{Like @code{%^C}, but insert as link.}
@@ -6700,6 +6700,9 @@ dynamic insertion of content.  The templates are expanded in the order given her
             @r{You may specify a default value and a completion table with}
             @r{You may specify a default value and a completion table with}
             @r{%^@{prompt|default|completion2|completion3...@}.}
             @r{%^@{prompt|default|completion2|completion3...@}.}
             @r{The arrow keys access a prompt-specific history.}
             @r{The arrow keys access a prompt-specific history.}
+%<n>        @r{Insert the text entered for at the nth %^{prompt}, where <n>
+            @r{represents a digit, 1 to 9.}
+%?          @r{After completing the template, position cursor here.}
 @end smallexample
 @end smallexample
 
 
 @noindent
 @noindent

+ 18 - 6
lisp/org-capture.el

@@ -248,6 +248,8 @@ be replaced with content and expanded in this order:
               A default value and a completion table ca be specified like this:
               A default value and a completion table ca be specified like this:
               %^{prompt|default|completion2|completion3|...}.
               %^{prompt|default|completion2|completion3|...}.
   %?          After completing the template, position cursor here.
   %?          After completing the template, position cursor here.
+  %<n>        Insert the text entered for at the nth %^{prompt}, where <n>
+              represents a digit, 1 to 9.
 
 
 Apart from these general escapes, you can access information specific to the
 Apart from these general escapes, you can access information specific to the
 link type that is created.  For example, calling `org-capture' in emails
 link type that is created.  For example, calling `org-capture' in emails
@@ -1326,7 +1328,7 @@ The template may still contain \"%?\" for cursor positioning."
 	 (org-startup-folded nil)
 	 (org-startup-folded nil)
 	 (org-inhibit-startup t)
 	 (org-inhibit-startup t)
 	 org-time-was-given org-end-time-was-given x
 	 org-time-was-given org-end-time-was-given x
-	 prompt completions char time pos default histvar)
+	 prompt completions char time pos default histvar strings)
 
 
     (setq org-store-link-plist
     (setq org-store-link-plist
 	  (plist-put org-store-link-plist :annotation v-a)
 	  (plist-put org-store-link-plist :annotation v-a)
@@ -1468,11 +1470,21 @@ The template may still contain \"%?\" for cursor positioning."
 				   nil nil (list org-end-time-was-given)))
 				   nil nil (list org-end-time-was-given)))
 	   (t
 	   (t
 	    (let (org-completion-use-ido)
 	    (let (org-completion-use-ido)
-	      (insert (org-completing-read-no-i
-		       (concat (if prompt prompt "Enter string")
-			       (if default (concat " [" default "]"))
-			       ": ")
-		       completions nil nil nil histvar default)))))))
+	      (push (org-completing-read-no-i
+		     (concat (if prompt prompt "Enter string")
+			     (if default (concat " [" default "]"))
+			     ": ")
+		     completions nil nil nil histvar default)
+		    strings)
+	      (insert (car strings)))))))
+      ;; Replace %n escapes with nth %^{...} string
+      (setq strings (nreverse strings))
+      (goto-char (point-min))
+      (while (re-search-forward "%\\([1-9]\\)+" nil t)
+	(unless (org-capture-escaped-%)
+	  (replace-match
+	   (nth (1- (string-to-number (match-string 1))) strings)
+	   nil t)))
       ;; Make sure there are no empty lines before the text, and that
       ;; Make sure there are no empty lines before the text, and that
       ;; it ends with a newline character
       ;; it ends with a newline character
       (goto-char (point-min))
       (goto-char (point-min))