emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Darlan Cavalcante Moreira <darcamo@gmail.com>
To: Bastien <bzg@altern.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: How to use org-capture with "dynamic ID" targets?
Date: Mon, 28 Jan 2013 15:05:48 -0300	[thread overview]
Message-ID: <5106be00.0c5e650a.1535.fffff1fa@mx.google.com> (raw)
In-Reply-To: <87pq0u1k2s.fsf@bzg.ath.cx>

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

  reply	other threads:[~2013-01-29  3:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2013-01-29  5:26     ` Eric Abrahamsen
2013-01-29 14:20       ` Darlan Cavalcante Moreira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5106be00.0c5e650a.1535.fffff1fa@mx.google.com \
    --to=darcamo@gmail.com \
    --cc=bzg@altern.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).