Re: [Orgmode] Re: question about capture templates
Carsten, Would your mod be implemented in the git build of 22 Feb? Cheers. Fil On 22 February 2011 04:15, Carsten Dominik carsten.domi...@gmail.comwrote: On Feb 22, 2011, at 1:39 AM, Filippo A. Salustri wrote: Thanks to everyone for the varied and thoughtful responses. I didn't think of backquotes, but I know about them from Scheme, and no, they shouldn't work in this case. Very frustrating. 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. Hmmm. I'll think some more. If I come up with anything; I'll report it. I have just implemented that whenever you mean a file name in capture templates, you can instead give a function, a variable, or a lisp form. So your original attempt (m Message entry (file+datetree (buffer-file-name (buffer-base-buffer))) * MSG @ %U %?\n %a) should now work. Hope this helps - Carsten Cheers. Fil 2011/2/21 Sébastien Vauban wxhgmqzgw...@spammotel.com Hi Richard, Richard Lawrence wrote: Sébastien Vauban wxhgmqzgw...@spammotel.com writes: Filippo A. Salustri wrote: I would really like to be able to vary the file into which a captured item goes. Specifically, I'd like to insert the item into whatever file I was visiting when I started the capture. You have to use backquotes so that expressions are considered as code to execute, instead of data. See Emacs manual. I'm not sure that backquotes will do what the OP wants. Backquotes will allow the OP to compute the value of a target file at the time the (setq org-capture templates ...) form is evaluated. The OP needs a way to determine the target file at the time of capture (right?), not at the time the variable is set. You're definitely right. I missed the distinction at Org launch time vs at execution time... Pull my answer off the records ;-) Best regards, Seb -- Sébastien Vauban ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode -- Filippo A. Salustri, Ph.D., P.Eng. Mechanical and Industrial Engineering Ryerson University 350 Victoria St, Toronto, ON M5B 2K3, Canada Tel: 416/979-5000 ext 7749 Fax: 416/979-5265 Email: salus...@ryerson.ca http://deseng.ryerson.ca/~fil/ ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten -- Filippo A. Salustri, Ph.D., P.Eng. Mechanical and Industrial Engineering Ryerson University 350 Victoria St, Toronto, ON M5B 2K3, Canada Tel: 416/979-5000 ext 7749 Fax: 416/979-5265 Email: salus...@ryerson.ca http://deseng.ryerson.ca/~fil/ ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: question about capture templates
Yup; I just tried the git snapshot of 23 Feb and it's working. Thanks!! Cheers. Fil On 22 February 2011 04:15, Carsten Dominik carsten.domi...@gmail.comwrote: On Feb 22, 2011, at 1:39 AM, Filippo A. Salustri wrote: Thanks to everyone for the varied and thoughtful responses. I didn't think of backquotes, but I know about them from Scheme, and no, they shouldn't work in this case. Very frustrating. 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. Hmmm. I'll think some more. If I come up with anything; I'll report it. I have just implemented that whenever you mean a file name in capture templates, you can instead give a function, a variable, or a lisp form. So your original attempt (m Message entry (file+datetree (buffer-file-name (buffer-base-buffer))) * MSG @ %U %?\n %a) should now work. Hope this helps - Carsten Cheers. Fil 2011/2/21 Sébastien Vauban wxhgmqzgw...@spammotel.com Hi Richard, Richard Lawrence wrote: Sébastien Vauban wxhgmqzgw...@spammotel.com writes: Filippo A. Salustri wrote: I would really like to be able to vary the file into which a captured item goes. Specifically, I'd like to insert the item into whatever file I was visiting when I started the capture. You have to use backquotes so that expressions are considered as code to execute, instead of data. See Emacs manual. I'm not sure that backquotes will do what the OP wants. Backquotes will allow the OP to compute the value of a target file at the time the (setq org-capture templates ...) form is evaluated. The OP needs a way to determine the target file at the time of capture (right?), not at the time the variable is set. You're definitely right. I missed the distinction at Org launch time vs at execution time... Pull my answer off the records ;-) Best regards, Seb -- Sébastien Vauban ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode -- Filippo A. Salustri, Ph.D., P.Eng. Mechanical and Industrial Engineering Ryerson University 350 Victoria St, Toronto, ON M5B 2K3, Canada Tel: 416/979-5000 ext 7749 Fax: 416/979-5265 Email: salus...@ryerson.ca http://deseng.ryerson.ca/~fil/ ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten -- Filippo A. Salustri, Ph.D., P.Eng. Mechanical and Industrial Engineering Ryerson University 350 Victoria St, Toronto, ON M5B 2K3, Canada Tel: 416/979-5000 ext 7749 Fax: 416/979-5265 Email: salus...@ryerson.ca http://deseng.ryerson.ca/~fil/ ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: question about capture templates
On Feb 22, 2011, at 1:39 AM, Filippo A. Salustri wrote: Thanks to everyone for the varied and thoughtful responses. I didn't think of backquotes, but I know about them from Scheme, and no, they shouldn't work in this case. Very frustrating. 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. Hmmm. I'll think some more. If I come up with anything; I'll report it. I have just implemented that whenever you mean a file name in capture templates, you can instead give a function, a variable, or a lisp form. So your original attempt (m Message entry (file+datetree (buffer-file-name (buffer-base-buffer))) * MSG @ %U %?\n %a) should now work. Hope this helps - Carsten Cheers. Fil 2011/2/21 Sébastien Vauban wxhgmqzgw...@spammotel.com Hi Richard, Richard Lawrence wrote: Sébastien Vauban wxhgmqzgw...@spammotel.com writes: Filippo A. Salustri wrote: I would really like to be able to vary the file into which a captured item goes. Specifically, I'd like to insert the item into whatever file I was visiting when I started the capture. You have to use backquotes so that expressions are considered as code to execute, instead of data. See Emacs manual. I'm not sure that backquotes will do what the OP wants. Backquotes will allow the OP to compute the value of a target file at the time the (setq org-capture templates ...) form is evaluated. The OP needs a way to determine the target file at the time of capture (right?), not at the time the variable is set. You're definitely right. I missed the distinction at Org launch time vs at execution time... Pull my answer off the records ;-) Best regards, Seb -- Sébastien Vauban ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode -- Filippo A. Salustri, Ph.D., P.Eng. Mechanical and Industrial Engineering Ryerson University 350 Victoria St, Toronto, ON M5B 2K3, Canada Tel: 416/979-5000 ext 7749 Fax: 416/979-5265 Email: salus...@ryerson.ca http://deseng.ryerson.ca/~fil/ ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: question about capture templates
On Feb 22, 2011, at 5:59 AM, Richard Lawrence wrote: Filippo A. Salustri salus...@ryerson.ca 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. 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. 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 ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: question about capture templates
Hi Carsten, Carsten Dominik carsten.domi...@gmail.com writes: I have just implemented that whenever you mean a file name in capture templates, you can instead give a function, a variable, or a lisp form. So your original attempt (m Message entry (file+datetree (buffer-file-name (buffer-base-buffer))) * MSG @ %U %?\n %a) should now work. Neat, thanks! -- Bastien ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: question about capture templates
Carsten Dominik carsten.domi...@gmail.com writes: I do love dynamic scoping, this give a lot of power in Emacs. Org-mode internals use that power often. This is venturing a bit far afield, at least for this thread, but I'm curious if anyone knows: does the recent work on supporting Elisp in Guile mean that Elisp applications are eventually expected to be ported to Scheme? And if so, what does that mean for Org development? 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? Right, yes, a variable with a string value. I guess my point is more properly stated by saying there doesn't seem to be a way to evaluate an atomic S-expression in a template. But this seems like a fair trade for not having to write a second set of parentheses around every non-atomic expression. The shortest form may be %(symbol-value foo) if you want to access the value of a variable in a template. That's handy -- thanks! Richard ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: question about capture templates
Hi Filippo, Filippo A. Salustri wrote: I would really like to be able to vary the file into which a captured item goes. Specifically, I'd like to insert the item into whatever file I was visiting when I started the capture. I've been trying something like this: (m Message entry (file+datetree (buffer-file-name (buffer-base-buffer))) * MSG @ %U %?\n %a) But the (buffer-file-name (buffer-base-buffer)) doesn't work because the item keeps ending up in the default capture file. Can anyone suggest a way to do this? You have to use backquotes so that expressions are considered as code to execute, instead of data. See Emacs manual. In your case, something like this should do it (untested): #+begin_src emacs-lisp (setq org-capture-templates `((m Message entry (file+datetree ,(buffer-file-name (buffer-base-buffer))) * MSG @ %U %?\n %a))) #+end_src See backquote used instead of quote. See comma in front of functions and variables. Here, though, I'm not sure whether another comma is needed or not in front of =buffer-base-buffer=. Best regards, Seb -- Sébastien Vauban ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: question about capture templates
Sébastien Vauban wxhgmqzgw...@spammotel.com writes: Filippo A. Salustri wrote: I would really like to be able to vary the file into which a captured item goes. Specifically, I'd like to insert the item into whatever file I was visiting when I started the capture. You have to use backquotes so that expressions are considered as code to execute, instead of data. See Emacs manual. I'm not sure that backquotes will do what the OP wants. Backquotes will allow the OP to compute the value of a target file at the time the (setq org-capture templates ...) form is evaluated. The OP needs a way to determine the target file at the time of capture (right?), not at the time the variable is set. Unfortunately, I don't have any suggestions on how to hack that. If the target of most captures can be determined based on their type, maybe you can just use the refile mechanism (C-c C-w instead of C-c C-c) to manually handle the exceptions. If not, maybe look into wrapping or replacing org-capture-refile somehow. Best, Richard ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: question about capture templates
Hi Richard, Richard Lawrence wrote: Sébastien Vauban wxhgmqzgw...@spammotel.com writes: Filippo A. Salustri wrote: I would really like to be able to vary the file into which a captured item goes. Specifically, I'd like to insert the item into whatever file I was visiting when I started the capture. You have to use backquotes so that expressions are considered as code to execute, instead of data. See Emacs manual. I'm not sure that backquotes will do what the OP wants. Backquotes will allow the OP to compute the value of a target file at the time the (setq org-capture templates ...) form is evaluated. The OP needs a way to determine the target file at the time of capture (right?), not at the time the variable is set. You're definitely right. I missed the distinction at Org launch time vs at execution time... Pull my answer off the records ;-) Best regards, Seb -- Sébastien Vauban ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: question about capture templates
Thanks to everyone for the varied and thoughtful responses. I didn't think of backquotes, but I know about them from Scheme, and no, they shouldn't work in this case. Very frustrating. 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. Hmmm. I'll think some more. If I come up with anything; I'll report it. Cheers. Fil 2011/2/21 Sébastien Vauban wxhgmqzgw...@spammotel.com Hi Richard, Richard Lawrence wrote: Sébastien Vauban wxhgmqzgw...@spammotel.com writes: Filippo A. Salustri wrote: I would really like to be able to vary the file into which a captured item goes. Specifically, I'd like to insert the item into whatever file I was visiting when I started the capture. You have to use backquotes so that expressions are considered as code to execute, instead of data. See Emacs manual. I'm not sure that backquotes will do what the OP wants. Backquotes will allow the OP to compute the value of a target file at the time the (setq org-capture templates ...) form is evaluated. The OP needs a way to determine the target file at the time of capture (right?), not at the time the variable is set. You're definitely right. I missed the distinction at Org launch time vs at execution time... Pull my answer off the records ;-) Best regards, Seb -- Sébastien Vauban ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode -- Filippo A. Salustri, Ph.D., P.Eng. Mechanical and Industrial Engineering Ryerson University 350 Victoria St, Toronto, ON M5B 2K3, Canada Tel: 416/979-5000 ext 7749 Fax: 416/979-5265 Email: salus...@ryerson.ca http://deseng.ryerson.ca/~fil/ ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] Re: question about capture templates
Filippo A. Salustri salus...@ryerson.ca 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. ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] Re: question about capture templates
Filippo A. Salustri salus...@ryerson.ca wrote: Very frustrating. 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. Hmmm. I'll think some more. If I come up with anything; I'll report it. The original buffer is accessible in the capture context using (org-capture-get :original-buffer) as Carsten pointed out in the following post: http://thread.gmane.org/gmane.emacs.orgmode/35759/focus=35799 HTH, Nick ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode