summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo TAKAISHI <ryo.takaishi.0@gmail.com>2012-11-04 15:01:08 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-11-05 00:29:25 (GMT)
commitfb143b6787d6206d0927b30c6610cee2e5c2933a (patch)
tree11a254816d7b45d0f148d8130e83afcba72355ba
parent5acffad561465ce9706299ffbe847269e1ab32f8 (diff)
downloadorg-mode-fb143b6787d6206d0927b30c6610cee2e5c2933a.zip
org-mode-fb143b6787d6206d0927b30c6610cee2e5c2933a.tar.gz
org-capture: Expand keywords within %(sexp) placeholder in template
* lisp/org-capture.el: (org-capture--expand-keyword-in-embedded-elisp): New function. (org-capture-expand-embedded-elisp): Use new function.
-rw-r--r--doc/org.texi4
-rw-r--r--lisp/org-capture.el22
2 files changed, 23 insertions, 3 deletions
diff --git a/doc/org.texi b/doc/org.texi
index b23f492..bf67876 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6853,7 +6853,9 @@ dynamic insertion of content. The templates are expanded in the order given her
@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 sexp must return a string.}
+ @r{For convenience, %:keyword (see below) placeholders}
+ @r{within the expression will be expanded prior to this.}
+ @r{The sexp must return a string.}
%<...> @r{The result of format-time-string on the ... format specification.}
%t @r{Timestamp, date only.}
%T @r{Timestamp, with date and time.}
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 1dfffc6..695c5eb 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -223,7 +223,9 @@ freely formatted text. Furthermore, the following %-escapes will
be replaced with content and expanded in this order:
%[pathname] Insert the contents of the file given by `pathname'.
- %(sexp) Evaluate elisp `(sexp)' and replace with the result.
+ %(sexp) Evaluate elisp `(sexp)' and replace it with the results.
+ For convenience, %:keyword (see below) placeholders within
+ the expression will be expanded prior to this.
%<...> The result of format-time-string on the ... format specification.
%t Time stamp, date only.
%T Time stamp with date and time.
@@ -1621,10 +1623,26 @@ The template may still contain \"%?\" for cursor positioning."
(goto-char (match-beginning 0))
(let ((template-start (point)))
(forward-char 1)
- (let ((result (org-eval (read (current-buffer)))))
+ (let ((result (org-eval
+ (org-capture--expand-keyword-in-embedded-elisp
+ (read (current-buffer))))))
(delete-region template-start (point))
(insert result))))))
+(defun org-capture--expand-keyword-in-embedded-elisp (attr)
+ "Recursively replace capture link keywords in ATTR sexp.
+Such keywords are prefixed with "%:". See `org-capture-template'
+for more information."
+ (cond ((consp attr)
+ (mapcar 'org-capture--expand-keyword-in-embedded-elisp attr))
+ ((symbolp attr)
+ (let* ((attr-symbol (symbol-name attr))
+ (key (and (string-match "%\\(:.*\\)" attr-symbol)
+ (intern (match-string 1 attr-symbol)))))
+ (or (plist-get org-store-link-plist key)
+ attr)))
+ (t attr)))
+
(defun org-capture-inside-embedded-elisp-p ()
"Return non-nil if point is inside of embedded elisp %(sexp)."
(let (beg end)