From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Re: question about capture templates Date: Tue, 22 Feb 2011 10:19:35 +0100 Message-ID: <546EF11C-2E76-4802-A0D6-1584BDDAB550@gmail.com> References: <80ei71o17z.fsf@missioncriticalit.com> <87k4gtpcvp.fsf@berkeley.edu> <80bp255935.fsf@missioncriticalit.com> <87r5b0d5qu.fsf@berkeley.edu> Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=46659 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ProPO-0006Vk-DE for emacs-orgmode@gnu.org; Tue, 22 Feb 2011 04:19:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ProPC-0004CJ-Ko for emacs-orgmode@gnu.org; Tue, 22 Feb 2011 04:19:39 -0500 Received: from mail-ww0-f49.google.com ([74.125.82.49]:65194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ProPC-0004C6-EW for emacs-orgmode@gnu.org; Tue, 22 Feb 2011 04:19:38 -0500 Received: by wwb17 with SMTP id 17so7180331wwb.30 for ; Tue, 22 Feb 2011 01:19:37 -0800 (PST) In-Reply-To: <87r5b0d5qu.fsf@berkeley.edu> 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: Richard Lawrence Cc: emacs-orgmode@gnu.org On Feb 22, 2011, at 5:59 AM, Richard Lawrence wrote: > "Filippo A. Salustri" writes: >=20 >> 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. >=20 > 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: >=20 > #+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 >=20 > 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.: >=20 > * My capture template > The car of foo is %(car foo). > The cdr of foo is %(cdr foo). > %a > etc. ... >=20 > 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. I do love dynamic scoping, this give a lot of power in Emacs. Org-mode internals use that power often. > 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. >=20 > One gotcha: S-expressions in templates are apparently always evaluated > as function calls -- you can't just directly access a string value, = like > %(foo). I guess you mean a variable value? The shortest form may be %(symbol-value foo) if you want to access the value of a variable in a template. Kind regards - Carsten=