From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ryo TAKAISHI Subject: Re: [PATCH] Capture: Expand keyword within %(SEXP) in template Date: Sat, 03 Nov 2012 00:36:01 +0900 Message-ID: <87lieknhjy.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> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:53383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TUJI0-0004Y8-Sc for emacs-orgmode@gnu.org; Fri, 02 Nov 2012 11:36:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TUJHz-0006PP-TK for emacs-orgmode@gnu.org; Fri, 02 Nov 2012 11:36:08 -0400 Received: from mail-da0-f41.google.com ([209.85.210.41]:63201) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TUJHz-0006PK-Mg for emacs-orgmode@gnu.org; Fri, 02 Nov 2012 11:36:07 -0400 Received: by mail-da0-f41.google.com with SMTP id i14so1808310dad.0 for ; Fri, 02 Nov 2012 08:36:07 -0700 (PDT) In-Reply-To: <87a9v0hz7j.fsf@gmail.com> (Nicolas Goaziou's message of "Fri, 02 Nov 2012 15:11:12 +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 Nicolas Goaziou writes: > Ryo TAKAISHI writes: > >> I did'nt come up with to use it. >> But "%(func %:description)" or "%(func (plist-get >> org-store-link-plist :description))", I think the former is readble >> template than the latter. > > Probably, but it's also more error-prone. > > For example, your code operates only at top-level, i.e. it won't handle > something like: > > %(fun arg1 (sub-fun %:description)) > > It will also error out if any atom isn't a symbol, i.e.: > > %(format "%d" 1) > > It's all about pro and cons. > > > Regards, I fix these problem. A new patch expand keyword recursively, and only symbol. Regards, --- lisp/org-capture.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 1dfffc6..b8c9844 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1621,10 +1621,23 @@ 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 (mapcar '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) + (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