From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Lawrence Subject: Re: question about capture templates Date: Mon, 21 Feb 2011 20:59:21 -0800 Message-ID: <87r5b0d5qu.fsf@berkeley.edu> References: <80ei71o17z.fsf@missioncriticalit.com> <87k4gtpcvp.fsf@berkeley.edu> <80bp255935.fsf@missioncriticalit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=59021 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrkH6-0006zz-Gf for emacs-orgmode@gnu.org; Mon, 21 Feb 2011 23:55:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PrkH5-0004Qa-3x for emacs-orgmode@gnu.org; Mon, 21 Feb 2011 23:55:00 -0500 Received: from lo.gmane.org ([80.91.229.12]:33981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PrkH4-0004Q2-Ll for emacs-orgmode@gnu.org; Mon, 21 Feb 2011 23:54:59 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PrkH2-0004MG-Vm for emacs-orgmode@gnu.org; Tue, 22 Feb 2011 05:54:56 +0100 Received: from c-67-164-33-170.hsd1.ca.comcast.net ([67.164.33.170]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Feb 2011 05:54:56 +0100 Received: from richard.lawrence by c-67-164-33-170.hsd1.ca.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Feb 2011 05:54:56 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org "Filippo A. Salustri" writes: > org-capture clearly has the original buffer handy (for %a > stuff) yet I can't get it out of there without hacking the org code, which I > am loathe to do. I too was in a situation just today where I was calling org-capture programatically, and needed access to stuff in the calling environment. My solution (which may not be very good, and may not work for you) is to dynamically scope the calling environment stuff that I need into the org-capture call, like so: #+begin_src emacs-lisp ; in the calling code, I scope some val I need into `foo...' (let ((foo some-val-I-need)) (org-capture nil "tm")) #+end_src Then, in the template identified by "tm", I have S-expression expansion that operates on foo, even though it wasn't explicitly passed as a parameter, e.g.: * My capture template The car of foo is %(car foo). The cdr of foo is %(cdr foo). %a etc. ... This works well enough for me, though it may feel kind of icky, since from the template writer's perspective, `foo' looks like a global variable whose value could be coming from anywhere. Accordingly, then, this solution is mostly useful if you know that you're going to be using the template via custom Elisp calls to org-capture, and not via the usual capture interface, so that you can guarantee that `foo' has a useful value when the template is expanded. One gotcha: S-expressions in templates are apparently always evaluated as function calls -- you can't just directly access a string value, like %(foo). Hope that's helpful! Richard P.S. Since you say you have Scheme experience: note that this solution would NOT work in Scheme, since Scheme, unlike Emacs Lisp, is lexically scoped.