[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template
From: |
Ryo TAKAISHI |
Subject: |
Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template |
Date: |
Sun, 04 Nov 2012 16:51:36 +0900 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) |
Nicolas Goaziou <address@hidden> writes:
> The code looks good, although I would have moved the external `mapcar'
> within the worker function in order to make its purpose clearer.
>
> Also, would you mind to provide a docstring for the function? Something
> along the lines of:
>
> "Recursively replace capture link keywords in ATTR sexp.
> Such keywords are prefixed with "%:". See `org-capture-template' for
> more information."
>
> You may also want to rename it
> `org-capture--expand-keyword-in-embedded-elisp' to insist on the fact it
> is an internal function. That's not mandatory, though.
>
> Finally, this feature must be documented in `org-capture-templates'
> docstring and org.texi.
Hello,
I fixed and added document in docstring & org.texi.
Is my additional document fully?
Regards,
Ryo
doc/org.texi | 2 ++
lisp/org-capture.el | 20 +++++++++++++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/doc/org.texi b/doc/org.texi
index b23f492..b661dac 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6853,6 +6853,8 @@ dynamic insertion of content. The templates are expanded
in the order given her
@smallexample
address@hidden @r{Insert the contents of the file given by @var{file}.}
%(@var{sexp}) @r{Evaluate Elisp @var{sexp} and replace with the result.}
+ @r{If sexp's attr is link keyword (@code{%:keyword}),}
+ @r{it will be expanded using @code{org-store-link-plist}.}
@r{The sexp must return a string.}
%<...> @r{The result of format-time-string on the ... format
specification.}
%t @r{Timestamp, date only.}
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 1dfffc6..fcaa4f9 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -224,6 +224,8 @@ 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.
+ If sexp's attr is link keyword (%:keyword), it will
+ be expanded using `org-store-link-plist`.
%<...> 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* ((sexp (org-capture-expand-keyword-in-embedded-elisp
+ (read (current-buffer))))
+ (result (org-eval sexp)))
(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)
--
1.7.9.5
- [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Ryo TAKAISHI, 2012/11/02
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Nicolas Goaziou, 2012/11/02
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Ryo TAKAISHI, 2012/11/02
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Nicolas Goaziou, 2012/11/02
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Ryo TAKAISHI, 2012/11/02
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Nicolas Goaziou, 2012/11/03
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template,
Ryo TAKAISHI <=
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Nicolas Goaziou, 2012/11/04
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Ryo TAKAISHI, 2012/11/04
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Nicolas Goaziou, 2012/11/04
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Ryo TAKAISHI, 2012/11/05
- Re: [O] [PATCH] Capture: Expand keyword within %(SEXP) in template, Nicolas Goaziou, 2012/11/05