* org-remember templates with dynamic target headline @ 2009-06-17 3:27 Daniel J. Sinder 2009-06-17 6:20 ` Nick Dokos 0 siblings, 1 reply; 5+ messages in thread From: Daniel J. Sinder @ 2009-06-17 3:27 UTC (permalink / raw) To: org-mode I want a remember template that will have a target headline based on the date on which I call org-remember. For a simple example, the effect I'd like to achieve is shown by putting the following in my .emacs: (setq org-remember-templates `(("Journal" ?j "* %u %?\n" "~/org/wjournal.org" ,(format-time-string "%G: Week %V")))) I'm an elisp noob, but I realize the problem here is that format-time-string is only evaluated once when my .emacs is read. So, unless I restart emacs every week. This doesn't work. How can I cause format-time-string to be re-evaluated whenever org-remember is called? Thanks, Dan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: org-remember templates with dynamic target headline 2009-06-17 3:27 org-remember templates with dynamic target headline Daniel J. Sinder @ 2009-06-17 6:20 ` Nick Dokos 2009-06-18 5:09 ` Carsten Dominik 0 siblings, 1 reply; 5+ messages in thread From: Nick Dokos @ 2009-06-17 6:20 UTC (permalink / raw) To: Daniel J. Sinder; +Cc: org-mode Daniel J. Sinder <djsinder@gmail.com> wrote: > I want a remember template that will have a target headline based on > the date on which I call org-remember. > > For a simple example, the effect I'd like to achieve is shown by > putting the following in my .emacs: > > (setq org-remember-templates > `(("Journal" ?j "* %u %?\n" "~/org/wjournal.org" > ,(format-time-string "%G: Week %V")))) > > I'm an elisp noob, but I realize the problem here is that > format-time-string is only evaluated once when my .emacs is read. So, > unless I restart emacs every week. This doesn't work. > > How can I cause format-time-string to be re-evaluated whenever > org-remember is called? > You cannot, unless you change the code. Keith Swartz had a similar question recently and although I cannot find it in the Gmane archive (second time today - maybe I'm doing something wrong), here is the last part of the thread: ,---- | To: Robert Goldman <rpgoldman@sift.info> | cc: emacs-orgmode@gnu.org | From: Nick Dokos <nicholas.dokos@hp.com> | Cc: nicholas.dokos@hp.com | Reply-to: nicholas.dokos@hp.com | Subject: Re: [Orgmode] Re: Emacs-orgmode Digest, Vol 39, Issue 122 | X-Mailer: MH-E 8.1; nmh 1.2; GNU Emacs 23.0.93 | Date: Sat, 30 May 2009 15:39:40 -0400 | Sender: nick@gamaville.dokosmarshall.org | | Robert Goldman <rpgoldman@sift.info> wrote: | | > > Date: Fri, 29 May 2009 23:24:58 -0700 | > > From: Keith Swartz <gnu@oneroad.com> | > > Subject: [Orgmode] Lazy evaluation when defining org-remember-template | > > To: "[orgmode]" <emacs-orgmode@gnu.org> | > > Message-ID: <4A20D13A.2000603@oneroad.com> | > > Content-Type: text/plain; charset=ISO-8859-1; format=flowed | > > | > > ... | > > | > > Is there a way I can make that command evaluate at the time it is | > > invoked, rather than when it is defined? I vaguely recall doing | > > something like this, but that was five job roles, three houses, two | > > recessions, and two kids ago. :) | > > | > | > I can't swear that this will work, but note that the way you have | > written this, it will all be evaluated at load time, as you say. the | > 'list' function will evaluate its arguments to build the list. | > | > Now, if you don't want this to be evaluated when org-remember-templates | > is set, you can quote the form: | > | > '(format-time-string "%A") | > | > [note that you quoted the argument to format-time-string. I don't | > believe that's necessary, since strings evaluate to themselves, but I | > have not tested this.] | > | > Actually, I think you would get something easier to read if you quoted | > the whole list, instead of quoting each element. Something like: | > | > (list '("Todo" ?t "* TODO %?%^{To do} %^g\n :LOGBOOK:\n - | > Added: %U\n :END:" "d:/tmp/_my.todo" (format-time-string "%A")))) | > | | That's correct. | | > The question then is, "what happens when org-remember-templates is | > retrieved?" What you want is for this function to be evaluated when the | > templates are found and used. That will be done by | > org-remember-apply-template, which we can examine.... | > | > Unfortunately, I don't see in there anything which retrieves (nth 4 | > entry), which is the place where your format-time-string goes, so I'm | > not sure what is handling this. It's a little confusing reading that | > function's code, since "headline" is ambiguous between whether it means | > the headline of the remember note to be inserted or the headline under | > which to insert the note... I believe it's the former. | > | | It's the latter. | | You can figure out things like this fairly quickly by inserting a | (debug) at the appropriate place, and re-evaluating the defun. When the | function gets called, it will jump into the debugger when it evals the | (debug) form, and you can use the full power of lisp to examine | state. For example, here I defined the template the way you suggested, | placed a (debug) in org-remember-apply-template, just after the | insertion of the template in the remember buffer, re-evaluated the defun | (there is an eval-defun, but I prefer to do that by going to the end of | the defun - which I can do quickly: repeat M-C-u until I'm at the | beginning of the defun and M-C-f to move over the whole defun - and then | C-x C-e to eval the last sexpression.) | | I then call org-remember and in the resulting debug buffer, say | | e headline<RET> | | which says | | (format-time-string "%A") | | e entry<RET> | | which says | | ("* TODO %?%^{To do} %^g | :LOGBOOK: | - | Added: %U | :END:" (quote "d:/tmp/_my.todo") (format-time-string "%A")) | | Now you can see that the headline is the third element of this list | (i.e. (nth 2 entry) - the numbering starts from 0). | | > Perhaps someone else can figure this out, or perhaps you could just try | > quoting the list and seeing if it works to evaluate the | > format-time-string when you want it to. Org usually does The Right Thing. | > | But even org cannot perform miracles !-) Somebody has to "force the thunk" | in order for delayed evaluation to work. You'd need something like this | patch: | | --- a/lisp/org-remember.el | +++ b/lisp/org-remember.el | @@ -388,7 +388,7 @@ to be run from that hook to function properly." | (functionp (nth 1 entry)))) | (nth 1 entry) | org-default-notes-file)) | - (headline (nth 2 entry)) | + (headline (eval (nth 2 entry))) | (v-c (and (> (length kill-ring) 0) (current-kill 0))) | (v-x (or (org-get-x-clipboard 'PRIMARY) | (org-get-x-clipboard 'CLIPBOARD) | | This should work in simple cases (in particular, because the headline is | a string and strings evaluate to themselves, so it should not adversely affect | any existing template), but I certainly have not thought about repercussions | (including the possibility of *very* obscure bugs because somebody mistyped | something in the template - that would be a maintenance nightmare that Carsten | might not be willing to take on). | | Thanks, | Nick `---- HTH, Nick ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: org-remember templates with dynamic target headline 2009-06-17 6:20 ` Nick Dokos @ 2009-06-18 5:09 ` Carsten Dominik 2009-06-19 23:09 ` Keith Swartz 0 siblings, 1 reply; 5+ messages in thread From: Carsten Dominik @ 2009-06-18 5:09 UTC (permalink / raw) To: nicholas.dokos; +Cc: Keith Swartz, org-mode On Jun 17, 2009, at 8:20 AM, Nick Dokos wrote: > Daniel J. Sinder <djsinder@gmail.com> wrote: > >> I want a remember template that will have a target headline based on >> the date on which I call org-remember. >> >> For a simple example, the effect I'd like to achieve is shown by >> putting the following in my .emacs: >> >> (setq org-remember-templates >> `(("Journal" ?j "* %u %?\n" "~/org/wjournal.org" >> ,(format-time-string "%G: Week %V")))) >> >> I'm an elisp noob, but I realize the problem here is that >> format-time-string is only evaluated once when my .emacs is read. >> So, >> unless I restart emacs every week. This doesn't work. >> >> How can I cause format-time-string to be re-evaluated whenever >> org-remember is called? >> > > You cannot, unless you change the code. Keith Swartz had a similar > question recently and although I cannot find it in the Gmane archive > (second time today - maybe I'm doing something wrong), here is the > last > part of the thread: Hi Nick, thank you for the reminder, I had wanted to do something about this. I am indeed a bit hesitant to allow just a lisp form here, because erroneous setup of the remember template structure might then lead to hard-to-trace problems. However, I am fine with allowing a *function* in this element, as it is in fact already allowed for the target file name. I have just pushed a fix that will accept a function in this place and call it to get the true headline. Daniel, Keith, Hope that solves your issue. - Carsten > > ,---- > | To: Robert Goldman <rpgoldman@sift.info> > | cc: emacs-orgmode@gnu.org > | From: Nick Dokos <nicholas.dokos@hp.com> > | Cc: nicholas.dokos@hp.com > | Reply-to: nicholas.dokos@hp.com > | Subject: Re: [Orgmode] Re: Emacs-orgmode Digest, Vol 39, Issue 122 > | X-Mailer: MH-E 8.1; nmh 1.2; GNU Emacs 23.0.93 > | Date: Sat, 30 May 2009 15:39:40 -0400 > | Sender: nick@gamaville.dokosmarshall.org > | > | Robert Goldman <rpgoldman@sift.info> wrote: > | > | > > Date: Fri, 29 May 2009 23:24:58 -0700 > | > > From: Keith Swartz <gnu@oneroad.com> > | > > Subject: [Orgmode] Lazy evaluation when defining org-remember- > template > | > > To: "[orgmode]" <emacs-orgmode@gnu.org> > | > > Message-ID: <4A20D13A.2000603@oneroad.com> > | > > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > | > > > | > > ... > | > > > | > > Is there a way I can make that command evaluate at the time it > is > | > > invoked, rather than when it is defined? I vaguely recall doing > | > > something like this, but that was five job roles, three > houses, two > | > > recessions, and two kids ago. :) > | > > > | > > | > I can't swear that this will work, but note that the way you have > | > written this, it will all be evaluated at load time, as you > say. the > | > 'list' function will evaluate its arguments to build the list. > | > > | > Now, if you don't want this to be evaluated when org-remember- > templates > | > is set, you can quote the form: > | > > | > '(format-time-string "%A") > | > > | > [note that you quoted the argument to format-time-string. I don't > | > believe that's necessary, since strings evaluate to themselves, > but I > | > have not tested this.] > | > > | > Actually, I think you would get something easier to read if you > quoted > | > the whole list, instead of quoting each element. Something like: > | > > | > (list '("Todo" ?t "* TODO %?%^{To do} %^g\n :LOGBOOK:\n - > | > Added: %U\n :END:" "d:/tmp/_my.todo" (format-time-string "%A")))) > | > > | > | That's correct. > | > | > The question then is, "what happens when org-remember-templates is > | > retrieved?" What you want is for this function to be evaluated > when the > | > templates are found and used. That will be done by > | > org-remember-apply-template, which we can examine.... > | > > | > Unfortunately, I don't see in there anything which retrieves > (nth 4 > | > entry), which is the place where your format-time-string goes, > so I'm > | > not sure what is handling this. It's a little confusing reading > that > | > function's code, since "headline" is ambiguous between whether > it means > | > the headline of the remember note to be inserted or the headline > under > | > which to insert the note... I believe it's the former. > | > > | > | It's the latter. > | > | You can figure out things like this fairly quickly by inserting a > | (debug) at the appropriate place, and re-evaluating the defun. > When the > | function gets called, it will jump into the debugger when it evals > the > | (debug) form, and you can use the full power of lisp to examine > | state. For example, here I defined the template the way you > suggested, > | placed a (debug) in org-remember-apply-template, just after the > | insertion of the template in the remember buffer, re-evaluated the > defun > | (there is an eval-defun, but I prefer to do that by going to the > end of > | the defun - which I can do quickly: repeat M-C-u until I'm at the > | beginning of the defun and M-C-f to move over the whole defun - > and then > | C-x C-e to eval the last sexpression.) > | > | I then call org-remember and in the resulting debug buffer, say > | > | e headline<RET> > | > | which says > | > | (format-time-string "%A") > | > | e entry<RET> > | > | which says > | > | ("* TODO %?%^{To do} %^g > | :LOGBOOK: > | - > | Added: %U > | :END:" (quote "d:/tmp/_my.todo") (format-time-string "%A")) > | > | Now you can see that the headline is the third element of this list > | (i.e. (nth 2 entry) - the numbering starts from 0). > | > | > Perhaps someone else can figure this out, or perhaps you could > just try > | > quoting the list and seeing if it works to evaluate the > | > format-time-string when you want it to. Org usually does The > Right Thing. > | > > | But even org cannot perform miracles !-) Somebody has to "force > the thunk" > | in order for delayed evaluation to work. You'd need something like > this > | patch: > | > | --- a/lisp/org-remember.el > | +++ b/lisp/org-remember.el > | @@ -388,7 +388,7 @@ to be run from that hook to function properly." > | (functionp (nth 1 entry)))) > | (nth 1 entry) > | org-default-notes-file)) > | - (headline (nth 2 entry)) > | + (headline (eval (nth 2 entry))) > | (v-c (and (> (length kill-ring) 0) (current-kill 0))) > | (v-x (or (org-get-x-clipboard 'PRIMARY) > | (org-get-x-clipboard 'CLIPBOARD) > | > | This should work in simple cases (in particular, because the > headline is > | a string and strings evaluate to themselves, so it should not > adversely affect > | any existing template), but I certainly have not thought about > repercussions > | (including the possibility of *very* obscure bugs because somebody > mistyped > | something in the template - that would be a maintenance nightmare > that Carsten > | might not be willing to take on). > | > | Thanks, > | Nick > `---- > > HTH, > Nick > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: org-remember templates with dynamic target headline 2009-06-18 5:09 ` Carsten Dominik @ 2009-06-19 23:09 ` Keith Swartz 2009-06-20 4:03 ` Carsten Dominik 0 siblings, 1 reply; 5+ messages in thread From: Keith Swartz @ 2009-06-19 23:09 UTC (permalink / raw) To: Carsten Dominik; +Cc: Keith Swartz, org-mode Hi Carsten, I think that would work, yes. Can you give an example of what it would look like now? Are you saying we can use a function call for a single element, or to produce the entire list? Thanks, Keith Carsten Dominik wrote: > > On Jun 17, 2009, at 8:20 AM, Nick Dokos wrote: > >> Daniel J. Sinder <djsinder@gmail.com> wrote: >> >>> I want a remember template that will have a target headline based on >>> the date on which I call org-remember. >>> >>> For a simple example, the effect I'd like to achieve is shown by >>> putting the following in my .emacs: >>> >>> (setq org-remember-templates >>> `(("Journal" ?j "* %u %?\n" "~/org/wjournal.org" >>> ,(format-time-string "%G: Week %V")))) >>> >>> I'm an elisp noob, but I realize the problem here is that >>> format-time-string is only evaluated once when my .emacs is read. So, >>> unless I restart emacs every week. This doesn't work. >>> >>> How can I cause format-time-string to be re-evaluated whenever >>> org-remember is called? >>> >> >> You cannot, unless you change the code. Keith Swartz had a similar >> question recently and although I cannot find it in the Gmane archive >> (second time today - maybe I'm doing something wrong), here is the last >> part of the thread: > > > Hi Nick, > > thank you for the reminder, I had wanted to do something about this. > > I am indeed a bit hesitant to allow just a lisp form here, because > erroneous > setup of the remember template structure might then lead > to hard-to-trace problems. > > However, I am fine with allowing a *function* in this element, as > it is in fact already allowed for the target file name. > > I have just pushed a fix that will accept a function in this place > and call it to get the true headline. > > Daniel, Keith, > > Hope that solves your issue. > > - Carsten > >> >> ,---- >> | To: Robert Goldman <rpgoldman@sift.info> >> | cc: emacs-orgmode@gnu.org >> | From: Nick Dokos <nicholas.dokos@hp.com> >> | Cc: nicholas.dokos@hp.com >> | Reply-to: nicholas.dokos@hp.com >> | Subject: Re: [Orgmode] Re: Emacs-orgmode Digest, Vol 39, Issue 122 >> | X-Mailer: MH-E 8.1; nmh 1.2; GNU Emacs 23.0.93 >> | Date: Sat, 30 May 2009 15:39:40 -0400 >> | Sender: nick@gamaville.dokosmarshall.org >> | >> | Robert Goldman <rpgoldman@sift.info> wrote: >> | >> | > > Date: Fri, 29 May 2009 23:24:58 -0700 >> | > > From: Keith Swartz <gnu@oneroad.com> >> | > > Subject: [Orgmode] Lazy evaluation when defining >> org-remember-template >> | > > To: "[orgmode]" <emacs-orgmode@gnu.org> >> | > > Message-ID: <4A20D13A.2000603@oneroad.com> >> | > > Content-Type: text/plain; charset=ISO-8859-1; format=flowed >> | > > >> | > > ... >> | > > >> | > > Is there a way I can make that command evaluate at the time it is >> | > > invoked, rather than when it is defined? I vaguely recall doing >> | > > something like this, but that was five job roles, three houses, >> two >> | > > recessions, and two kids ago. :) >> | > > >> | > >> | > I can't swear that this will work, but note that the way you have >> | > written this, it will all be evaluated at load time, as you say. >> the >> | > 'list' function will evaluate its arguments to build the list. >> | > >> | > Now, if you don't want this to be evaluated when >> org-remember-templates >> | > is set, you can quote the form: >> | > >> | > '(format-time-string "%A") >> | > >> | > [note that you quoted the argument to format-time-string. I don't >> | > believe that's necessary, since strings evaluate to themselves, >> but I >> | > have not tested this.] >> | > >> | > Actually, I think you would get something easier to read if you >> quoted >> | > the whole list, instead of quoting each element. Something like: >> | > >> | > (list '("Todo" ?t "* TODO %?%^{To do} %^g\n :LOGBOOK:\n - >> | > Added: %U\n :END:" "d:/tmp/_my.todo" (format-time-string "%A")))) >> | > >> | >> | That's correct. >> | >> | > The question then is, "what happens when org-remember-templates is >> | > retrieved?" What you want is for this function to be evaluated >> when the >> | > templates are found and used. That will be done by >> | > org-remember-apply-template, which we can examine.... >> | > >> | > Unfortunately, I don't see in there anything which retrieves (nth 4 >> | > entry), which is the place where your format-time-string goes, so >> I'm >> | > not sure what is handling this. It's a little confusing reading >> that >> | > function's code, since "headline" is ambiguous between whether it >> means >> | > the headline of the remember note to be inserted or the headline >> under >> | > which to insert the note... I believe it's the former. >> | > >> | >> | It's the latter. >> | >> | You can figure out things like this fairly quickly by inserting a >> | (debug) at the appropriate place, and re-evaluating the defun. When >> the >> | function gets called, it will jump into the debugger when it evals the >> | (debug) form, and you can use the full power of lisp to examine >> | state. For example, here I defined the template the way you suggested, >> | placed a (debug) in org-remember-apply-template, just after the >> | insertion of the template in the remember buffer, re-evaluated the >> defun >> | (there is an eval-defun, but I prefer to do that by going to the >> end of >> | the defun - which I can do quickly: repeat M-C-u until I'm at the >> | beginning of the defun and M-C-f to move over the whole defun - and >> then >> | C-x C-e to eval the last sexpression.) >> | >> | I then call org-remember and in the resulting debug buffer, say >> | >> | e headline<RET> >> | >> | which says >> | >> | (format-time-string "%A") >> | >> | e entry<RET> >> | >> | which says >> | >> | ("* TODO %?%^{To do} %^g >> | :LOGBOOK: >> | - >> | Added: %U >> | :END:" (quote "d:/tmp/_my.todo") (format-time-string "%A")) >> | >> | Now you can see that the headline is the third element of this list >> | (i.e. (nth 2 entry) - the numbering starts from 0). >> | >> | > Perhaps someone else can figure this out, or perhaps you could >> just try >> | > quoting the list and seeing if it works to evaluate the >> | > format-time-string when you want it to. Org usually does The >> Right Thing. >> | > >> | But even org cannot perform miracles !-) Somebody has to "force the >> thunk" >> | in order for delayed evaluation to work. You'd need something like >> this >> | patch: >> | >> | --- a/lisp/org-remember.el >> | +++ b/lisp/org-remember.el >> | @@ -388,7 +388,7 @@ to be run from that hook to function properly." >> | (functionp (nth 1 entry)))) >> | (nth 1 entry) >> | org-default-notes-file)) >> | - (headline (nth 2 entry)) >> | + (headline (eval (nth 2 entry))) >> | (v-c (and (> (length kill-ring) 0) (current-kill 0))) >> | (v-x (or (org-get-x-clipboard 'PRIMARY) >> | (org-get-x-clipboard 'CLIPBOARD) >> | >> | This should work in simple cases (in particular, because the >> headline is >> | a string and strings evaluate to themselves, so it should not >> adversely affect >> | any existing template), but I certainly have not thought about >> repercussions >> | (including the possibility of *very* obscure bugs because somebody >> mistyped >> | something in the template - that would be a maintenance nightmare >> that Carsten >> | might not be willing to take on). >> | >> | Thanks, >> | Nick >> `---- >> >> HTH, >> Nick >> >> >> _______________________________________________ >> Emacs-orgmode mailing list >> Remember: use `Reply All' to send replies to the list. >> Emacs-orgmode@gnu.org >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: org-remember templates with dynamic target headline 2009-06-19 23:09 ` Keith Swartz @ 2009-06-20 4:03 ` Carsten Dominik 0 siblings, 0 replies; 5+ messages in thread From: Carsten Dominik @ 2009-06-20 4:03 UTC (permalink / raw) To: Keith Swartz; +Cc: org-mode On Jun 20, 2009, at 1:09 AM, Keith Swartz wrote: > Hi Carsten, > > I think that would work, yes. Can you give an example of what it > would look like now? Are you saying we can use a function call for a > single element, or to produce the entire list? Please see Jere's answer in the "Use environment variable...." thread. - Carsten > > Thanks, > Keith > > > Carsten Dominik wrote: >> >> On Jun 17, 2009, at 8:20 AM, Nick Dokos wrote: >> >>> Daniel J. Sinder <djsinder@gmail.com> wrote: >>> >>>> I want a remember template that will have a target headline based >>>> on >>>> the date on which I call org-remember. >>>> >>>> For a simple example, the effect I'd like to achieve is shown by >>>> putting the following in my .emacs: >>>> >>>> (setq org-remember-templates >>>> `(("Journal" ?j "* %u %?\n" "~/org/wjournal.org" >>>> ,(format-time-string "%G: Week %V")))) >>>> >>>> I'm an elisp noob, but I realize the problem here is that >>>> format-time-string is only evaluated once when my .emacs is >>>> read. So, >>>> unless I restart emacs every week. This doesn't work. >>>> >>>> How can I cause format-time-string to be re-evaluated whenever >>>> org-remember is called? >>>> >>> >>> You cannot, unless you change the code. Keith Swartz had a similar >>> question recently and although I cannot find it in the Gmane archive >>> (second time today - maybe I'm doing something wrong), here is the >>> last >>> part of the thread: >> >> >> Hi Nick, >> >> thank you for the reminder, I had wanted to do something about this. >> >> I am indeed a bit hesitant to allow just a lisp form here, because >> erroneous >> setup of the remember template structure might then lead >> to hard-to-trace problems. >> >> However, I am fine with allowing a *function* in this element, as >> it is in fact already allowed for the target file name. >> >> I have just pushed a fix that will accept a function in this place >> and call it to get the true headline. >> >> Daniel, Keith, >> >> Hope that solves your issue. >> >> - Carsten >> >>> >>> ,---- >>> | To: Robert Goldman <rpgoldman@sift.info> >>> | cc: emacs-orgmode@gnu.org >>> | From: Nick Dokos <nicholas.dokos@hp.com> >>> | Cc: nicholas.dokos@hp.com >>> | Reply-to: nicholas.dokos@hp.com >>> | Subject: Re: [Orgmode] Re: Emacs-orgmode Digest, Vol 39, Issue 122 >>> | X-Mailer: MH-E 8.1; nmh 1.2; GNU Emacs 23.0.93 >>> | Date: Sat, 30 May 2009 15:39:40 -0400 >>> | Sender: nick@gamaville.dokosmarshall.org >>> | >>> | Robert Goldman <rpgoldman@sift.info> wrote: >>> | >>> | > > Date: Fri, 29 May 2009 23:24:58 -0700 >>> | > > From: Keith Swartz <gnu@oneroad.com> >>> | > > Subject: [Orgmode] Lazy evaluation when defining org- >>> remember-template >>> | > > To: "[orgmode]" <emacs-orgmode@gnu.org> >>> | > > Message-ID: <4A20D13A.2000603@oneroad.com> >>> | > > Content-Type: text/plain; charset=ISO-8859-1; format=flowed >>> | > > >>> | > > ... >>> | > > >>> | > > Is there a way I can make that command evaluate at the time >>> it is >>> | > > invoked, rather than when it is defined? I vaguely recall >>> doing >>> | > > something like this, but that was five job roles, three >>> houses, two >>> | > > recessions, and two kids ago. :) >>> | > > >>> | > >>> | > I can't swear that this will work, but note that the way you >>> have >>> | > written this, it will all be evaluated at load time, as you >>> say. the >>> | > 'list' function will evaluate its arguments to build the list. >>> | > >>> | > Now, if you don't want this to be evaluated when org-remember- >>> templates >>> | > is set, you can quote the form: >>> | > >>> | > '(format-time-string "%A") >>> | > >>> | > [note that you quoted the argument to format-time-string. I >>> don't >>> | > believe that's necessary, since strings evaluate to >>> themselves, but I >>> | > have not tested this.] >>> | > >>> | > Actually, I think you would get something easier to read if >>> you quoted >>> | > the whole list, instead of quoting each element. Something >>> like: >>> | > >>> | > (list '("Todo" ?t "* TODO %?%^{To do} %^g\n :LOGBOOK:\n - >>> | > Added: %U\n :END:" "d:/tmp/_my.todo" (format-time-string >>> "%A")))) >>> | > >>> | >>> | That's correct. >>> | >>> | > The question then is, "what happens when org-remember- >>> templates is >>> | > retrieved?" What you want is for this function to be >>> evaluated when the >>> | > templates are found and used. That will be done by >>> | > org-remember-apply-template, which we can examine.... >>> | > >>> | > Unfortunately, I don't see in there anything which retrieves >>> (nth 4 >>> | > entry), which is the place where your format-time-string goes, >>> so I'm >>> | > not sure what is handling this. It's a little confusing >>> reading that >>> | > function's code, since "headline" is ambiguous between whether >>> it means >>> | > the headline of the remember note to be inserted or the >>> headline under >>> | > which to insert the note... I believe it's the former. >>> | > >>> | >>> | It's the latter. >>> | >>> | You can figure out things like this fairly quickly by inserting a >>> | (debug) at the appropriate place, and re-evaluating the defun. >>> When the >>> | function gets called, it will jump into the debugger when it >>> evals the >>> | (debug) form, and you can use the full power of lisp to examine >>> | state. For example, here I defined the template the way you >>> suggested, >>> | placed a (debug) in org-remember-apply-template, just after the >>> | insertion of the template in the remember buffer, re-evaluated >>> the defun >>> | (there is an eval-defun, but I prefer to do that by going to the >>> end of >>> | the defun - which I can do quickly: repeat M-C-u until I'm at the >>> | beginning of the defun and M-C-f to move over the whole defun - >>> and then >>> | C-x C-e to eval the last sexpression.) >>> | >>> | I then call org-remember and in the resulting debug buffer, say >>> | >>> | e headline<RET> >>> | >>> | which says >>> | >>> | (format-time-string "%A") >>> | >>> | e entry<RET> >>> | >>> | which says >>> | >>> | ("* TODO %?%^{To do} %^g >>> | :LOGBOOK: >>> | - >>> | Added: %U >>> | :END:" (quote "d:/tmp/_my.todo") (format-time-string "%A")) >>> | >>> | Now you can see that the headline is the third element of this >>> list >>> | (i.e. (nth 2 entry) - the numbering starts from 0). >>> | >>> | > Perhaps someone else can figure this out, or perhaps you could >>> just try >>> | > quoting the list and seeing if it works to evaluate the >>> | > format-time-string when you want it to. Org usually does The >>> Right Thing. >>> | > >>> | But even org cannot perform miracles !-) Somebody has to "force >>> the thunk" >>> | in order for delayed evaluation to work. You'd need something >>> like this >>> | patch: >>> | >>> | --- a/lisp/org-remember.el >>> | +++ b/lisp/org-remember.el >>> | @@ -388,7 +388,7 @@ to be run from that hook to function >>> properly." >>> | (functionp (nth 1 entry)))) >>> | (nth 1 entry) >>> | org-default-notes-file)) >>> | - (headline (nth 2 entry)) >>> | + (headline (eval (nth 2 entry))) >>> | (v-c (and (> (length kill-ring) 0) (current-kill 0))) >>> | (v-x (or (org-get-x-clipboard 'PRIMARY) >>> | (org-get-x-clipboard 'CLIPBOARD) >>> | >>> | This should work in simple cases (in particular, because the >>> headline is >>> | a string and strings evaluate to themselves, so it should not >>> adversely affect >>> | any existing template), but I certainly have not thought about >>> repercussions >>> | (including the possibility of *very* obscure bugs because >>> somebody mistyped >>> | something in the template - that would be a maintenance >>> nightmare that Carsten >>> | might not be willing to take on). >>> | >>> | Thanks, >>> | Nick >>> `---- >>> >>> HTH, >>> Nick >>> >>> >>> _______________________________________________ >>> Emacs-orgmode mailing list >>> Remember: use `Reply All' to send replies to the list. >>> Emacs-orgmode@gnu.org >>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode >> >> ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-06-20 4:04 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-06-17 3:27 org-remember templates with dynamic target headline Daniel J. Sinder 2009-06-17 6:20 ` Nick Dokos 2009-06-18 5:09 ` Carsten Dominik 2009-06-19 23:09 ` Keith Swartz 2009-06-20 4:03 ` Carsten Dominik
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).