From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ryo TAKAISHI Subject: Re: [PATCH] Capture: Expand keyword within %(SEXP) in template Date: Mon, 05 Nov 2012 00:05:55 +0900 Message-ID: <87vcdl4dd8.fsf@gmail.com> References: <1351848001-11636-1-git-send-email-ryo.takaishi.0@gmail.com> <87ip9oi5qt.fsf@gmail.com> <878vak9kib.fsf@gmail.com> <87a9v0hz7j.fsf@gmail.com> <87lieknhjy.fsf@gmail.com> <87sj8rgjn6.fsf@gmail.com> <87hap5rek7.fsf@gmail.com> <87vcdlbjjq.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:46982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV1ly-0002rs-Dy for emacs-orgmode@gnu.org; Sun, 04 Nov 2012 10:06:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TV1lx-0005qD-59 for emacs-orgmode@gnu.org; Sun, 04 Nov 2012 10:06:02 -0500 Received: from mail-da0-f41.google.com ([209.85.210.41]:51639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV1lw-0005q9-UA for emacs-orgmode@gnu.org; Sun, 04 Nov 2012 10:06:01 -0500 Received: by mail-da0-f41.google.com with SMTP id i14so2442283dad.0 for ; Sun, 04 Nov 2012 07:06:00 -0800 (PST) In-Reply-To: <87vcdlbjjq.fsf@gmail.com> (Nicolas Goaziou's message of "Sun, 04 Nov 2012 14:10:33 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nicolas Goaziou Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > Otherwise the code is fine. Would you provide a complete patch, i.e. > with `git format-patch'? The changelog entry may be: I create a complete patch for current commit. Regards, Ryo --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-capture-Expand-keywords-within-sexp-placeholder-.patch >From d82c99bb643e2c61e1f5b598a687160340a1558f Mon Sep 17 00:00:00 2001 From: Ryo TAKAISHI Date: Mon, 5 Nov 2012 00:01:08 +0900 Subject: [PATCH] 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. --- doc/org.texi | 4 +++- lisp/org-capture.el | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index b23f492..dd1d9b9 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -6852,7 +6852,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.} +%(@var{sexp}) @r{Evaluate Elisp @var{sexp} and replace with the result@footnote{For } + @r{convenience, %:keyword (see above) placeholders within the expression} + @r{will be expanded.}.} @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..d0f7297 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 with the result@(For + convenience, %:keyword (see above) placeholders within the expression + will be expanded.). %<...> 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 --=-=-=--