* How to use org-capture with "dynamic ID" targets? @ 2013-01-16 22:38 Darlan Cavalcante Moreira 2013-01-24 19:01 ` Bastien 0 siblings, 1 reply; 5+ messages in thread From: Darlan Cavalcante Moreira @ 2013-01-16 22:38 UTC (permalink / raw) To: emacs-orgmode I'm trying to set-up some org-capture templates using the ID target type. However, I need the ID to be determined either as the return value of a function or as the value of a variable. When I use a template such as --8<---------------cut here---------------start------------->8--- ("f" "The template description" table-line (id "someIDstring") "this is the template content" :table-line-pos "II-1" :immediate-finish t) --8<---------------cut here---------------end--------------->8--- everything works as expected and a table in the headline with ID "someIDstring" is used. However, if I try --8<---------------cut here---------------start------------->8--- ("f" "The template description" table-line (id some_variable) "this is the template content" :table-line-pos "II-1" :immediate-finish t) --8<---------------cut here---------------end--------------->8--- or --8<---------------cut here---------------start------------->8--- ("f" "The template description" table-line (id (some_function)) "this is the template content" :table-line-pos "II-1" :immediate-finish t) --8<---------------cut here---------------end--------------->8--- then it does not work even if some_variable or (some_function) provides the correct ID value. It seems that (id something) will always interpret "something" as a string (no matter if I put it inside quotes or not). Is it possible to achieve what I want with the current org-capture implementation? If not, consider this as a feature request. The reason behind this is that each month I want a different target table for this capture template and I already implemented a function that returns the correct ID. If I can somehow make the ID target type use the return value of this function then this capture template will use the correct table each month. If not, I would be forced to manually change the capture template in the beginning of each month (something I will definitely forget). -- Darlan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to use org-capture with "dynamic ID" targets? 2013-01-16 22:38 How to use org-capture with "dynamic ID" targets? Darlan Cavalcante Moreira @ 2013-01-24 19:01 ` Bastien 2013-01-28 18:05 ` Darlan Cavalcante Moreira 0 siblings, 1 reply; 5+ messages in thread From: Bastien @ 2013-01-24 19:01 UTC (permalink / raw) To: Darlan Cavalcante Moreira; +Cc: emacs-orgmode Hi Darlan, Darlan Cavalcante Moreira <darcamo@gmail.com> writes: > everything works as expected and a table in the headline with ID > "someIDstring" is used. However, if I try > > ("f" "The template description" table-line > (id some_variable) > "this is the template content" > :table-line-pos "II-1" > :immediate-finish t) Can you provide the full (setq org-capture-templates ...) s-expression? Did you tried this? (setq org-capture-templates `(("f" "The template description" table-line (id ,some_variable) "this is the template content" :table-line-pos "II-1" :immediate-finish t))) > then it does not work even if some_variable or (some_function) provides the > correct ID value. It seems that > (id something) > will always interpret "something" as a string (no matter if I put it inside > quotes or not). Yes, it expects a string. > Is it possible to achieve what I want with the current org-capture > implementation? See above. The problem being, of course, that the capture template for "f" will use some_variable *statically* -- if the value of the some_variable variable changed after you evaluated the s-expression (setq org-capture-templates ...) then the new value will not be known. > If not, consider this as a feature request. What feature exactly? To allow a function here that would dynamically set the id? > The reason behind this is that each month I want a different target table > for this capture template and I already implemented a function that returns > the correct ID. If I can somehow make the ID target type use the return > value of this function then this capture template will use the correct > table each month. If not, I would be forced to manually change the capture > template in the beginning of each month (something I will definitely > forget). If you want to use a function ,some_variable will not work, check ,@ constructs in the Elisp manual. Thanks, -- Bastien ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to use org-capture with "dynamic ID" targets? 2013-01-24 19:01 ` Bastien @ 2013-01-28 18:05 ` Darlan Cavalcante Moreira 2013-01-29 5:26 ` Eric Abrahamsen 0 siblings, 1 reply; 5+ messages in thread From: Darlan Cavalcante Moreira @ 2013-01-28 18:05 UTC (permalink / raw) To: Bastien; +Cc: emacs-orgmode At Thu, 24 Jan 2013 20:01:47 +0100, Bastien wrote: > > Hi Darlan, > > Darlan Cavalcante Moreira <darcamo@gmail.com> writes: > > > everything works as expected and a table in the headline with ID > > "someIDstring" is used. However, if I try > > > > ("f" "The template description" table-line > > (id some_variable) > > "this is the template content" > > :table-line-pos "II-1" > > :immediate-finish t) > > Can you provide the full (setq org-capture-templates ...) > s-expression? Hi Bastien, First I created an org-mode file with the following content to act as the target. --8<---------------cut here---------------start------------->8--- * Test table :PROPERTIES: :ID: MyTestID :END: | | Nome | Valor | |---+----------------+-------| | | something | 12.00 | | | something else | 23.45 | |---+----------------+-------| | # | Total | 35.45 | #+TBLFM: @4$3=vsum(@2..@-1);%.2f --8<---------------cut here---------------end--------------->8--- The capture template is something as simple as --8<---------------cut here---------------start------------->8--- (setq org-capture-templates '( ("f" "Add a new product and value") ("ff" "Table" table-line (id "MyTestID") "|| %^{Product} | %^{Value} |" :table-line-pos "II-1" :immediate-finish t))) --8<---------------cut here---------------end--------------->8--- This works as expected, but for my use case each month the target should be a different table (which I create with a different ID). Obviously manually changing the capture template each month is error prone and easy to forget. Therefore, tried to change the ID to a function providing the new target or a variable. For instance the code below. --8<---------------cut here---------------start------------->8--- (setq myIDVar "MyTestID") (setq org-capture-templates '( ("f" "Add a new product and value") ("ff" "Table" table-line (id myIDVar) "|| %^{Product} | %^{Value} |" :table-line-pos "II-1" :immediate-finish t))) --8<---------------cut here---------------end--------------->8--- When I try to capture with this second template Emacs complains that it cannot find the target ID "myIDVar". What I expected is that it would search for the ID "MyTestID" that is the value of myIDVar and not for an ID "myIDVar" I have also tried the code below and it does not work either --8<---------------cut here---------------start------------->8--- (defun some-function-return-the-id () "DOCSTRING" (interactive) "MyTestID") (setq org-capture-templates '( ("f" "Add a new product and value") ("ff" "Table" table-line (id (some-function-return-the-id)) "|| %^{Product} | %^{Value} |" :table-line-pos "II-1" :immediate-finish t))) --8<---------------cut here---------------end--------------->8--- > Did you tried this? > > (setq org-capture-templates > `(("f" "The template description" table-line > (id ,some_variable) > "this is the template content" > :table-line-pos "II-1" > :immediate-finish t))) > > > then it does not work even if some_variable or (some_function) provides the > > correct ID value. It seems that > > (id something) > > will always interpret "something" as a string (no matter if I put it inside > > quotes or not). > > Yes, it expects a string. > > > Is it possible to achieve what I want with the current org-capture > > implementation? > > See above. The problem being, of course, that the capture template > for "f" will use some_variable *statically* -- if the value of the > some_variable variable changed after you evaluated the s-expression > (setq org-capture-templates ...) then the new value will not be > known. > This is something I'll have to keep in mind. However, I don't expect this to be a problem since I start Emacs everyday. It is enough for me if I can set the ID to a variable (before setting org-capture-templates) and it uses the variable value as the ID, instead of trying to interpret the variable name as the ID. In fact, even if I ever need to change the variable value after org-capture-templates was set I'm fine by just reevaluating (setq org-capture-templates ...) again so that it sees the new value. > > If not, consider this as a feature request. > > What feature exactly? To allow a function here that would dynamically > set the id? > Exactly. Simple using the value of whatever list object I put there. Be it a variable value or a function that provides the. I'm fine if the value provided by a variable or a function is only read when org-capture-templates is set. > > The reason behind this is that each month I want a different target table > > for this capture template and I already implemented a function that returns > > the correct ID. If I can somehow make the ID target type use the return > > value of this function then this capture template will use the correct > > table each month. If not, I would be forced to manually change the capture > > template in the beginning of each month (something I will definitely > > forget). > > If you want to use a function ,some_variable will not work, check > ,@ constructs in the Elisp manual. > My lisp knowledge is very limited to what I have seen in my Emacs initialization (and a lot of trying and error). But I have never seen "@" used in lisp nor I know what terms to search for it.. Regards, Darlan > Thanks, > > -- > Bastien ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to use org-capture with "dynamic ID" targets? 2013-01-28 18:05 ` Darlan Cavalcante Moreira @ 2013-01-29 5:26 ` Eric Abrahamsen 2013-01-29 14:20 ` Darlan Cavalcante Moreira 0 siblings, 1 reply; 5+ messages in thread From: Eric Abrahamsen @ 2013-01-29 5:26 UTC (permalink / raw) To: emacs-orgmode Darlan Cavalcante Moreira <darcamo@gmail.com> writes: > At Thu, 24 Jan 2013 20:01:47 +0100, > Bastien wrote: >> Did you tried this? >> >> (setq org-capture-templates >> `(("f" "The template description" table-line >> (id ,some_variable) >> "this is the template content" >> :table-line-pos "II-1" >> :immediate-finish t))) > This is something I'll have to keep in mind. However, I don't expect this > to be a problem since I start Emacs everyday. It is enough for me if I can > set the ID to a variable (before setting org-capture-templates) and it uses > the variable value as the ID, instead of trying to interpret the variable > name as the ID. In fact, even if I ever need to change the variable value > after org-capture-templates was set I'm fine by just reevaluating (setq > org-capture-templates ...) again so that it sees the new value. > Exactly. Simple using the value of whatever list object I put there. Be it > a variable value or a function that provides the. I'm fine if the value > provided by a variable or a function is only read when > org-capture-templates is set. > My lisp knowledge is very limited to what I have seen in my Emacs > initialization (and a lot of trying and error). But I have never seen "@" > used in lisp nor I know what terms to search for it.. All this above is pretty much exactly what you're looking for. Check out the "Backquote" section of the elisp manual for a pretty good introduction. If you quote using a backtick (`) rather than an apostrophe ('), you can use the comma (,) later on to evaluate variable values, see the example at top. I don't believe you need the @ here, but the manual section I mentioned explains it. I used to do this in my agenda commands, but it wasn't really practical because of the "only evaluate once" problem. If you restart emacs every day, that won't really be an issue for you. E ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to use org-capture with "dynamic ID" targets? 2013-01-29 5:26 ` Eric Abrahamsen @ 2013-01-29 14:20 ` Darlan Cavalcante Moreira 0 siblings, 0 replies; 5+ messages in thread From: Darlan Cavalcante Moreira @ 2013-01-29 14:20 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: emacs-orgmode It works! Thanks Eric. The backquote plus ',' did the job. I now understand why my previous attempts didn't work and I can imagine what would be necessary to implement the feature I requested (not worth it). -- Darlan At Tue, 29 Jan 2013 13:26:05 +0800, Eric Abrahamsen wrote: > > Darlan Cavalcante Moreira <darcamo@gmail.com> writes: > > > At Thu, 24 Jan 2013 20:01:47 +0100, > > Bastien wrote: > >> Did you tried this? > >> > >> (setq org-capture-templates > >> `(("f" "The template description" table-line > >> (id ,some_variable) > >> "this is the template content" > >> :table-line-pos "II-1" > >> :immediate-finish t))) > > > This is something I'll have to keep in mind. However, I don't expect this > > to be a problem since I start Emacs everyday. It is enough for me if I can > > set the ID to a variable (before setting org-capture-templates) and it uses > > the variable value as the ID, instead of trying to interpret the variable > > name as the ID. In fact, even if I ever need to change the variable value > > after org-capture-templates was set I'm fine by just reevaluating (setq > > org-capture-templates ...) again so that it sees the new value. > > > > Exactly. Simple using the value of whatever list object I put there. Be it > > a variable value or a function that provides the. I'm fine if the value > > provided by a variable or a function is only read when > > org-capture-templates is set. > > > My lisp knowledge is very limited to what I have seen in my Emacs > > initialization (and a lot of trying and error). But I have never seen "@" > > used in lisp nor I know what terms to search for it.. > > All this above is pretty much exactly what you're looking for. Check out > the "Backquote" section of the elisp manual for a pretty good > introduction. If you quote using a backtick (`) rather than an > apostrophe ('), you can use the comma (,) later on to evaluate variable > values, see the example at top. I don't believe you need the @ here, but > the manual section I mentioned explains it. > > I used to do this in my agenda commands, but it wasn't really practical > because of the "only evaluate once" problem. If you restart emacs every > day, that won't really be an issue for you. > > E > > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-01-29 14:20 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-01-16 22:38 How to use org-capture with "dynamic ID" targets? Darlan Cavalcante Moreira 2013-01-24 19:01 ` Bastien 2013-01-28 18:05 ` Darlan Cavalcante Moreira 2013-01-29 5:26 ` Eric Abrahamsen 2013-01-29 14:20 ` Darlan Cavalcante Moreira
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).