emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tim Landscheidt <tim@tim-landscheidt.de>
To: emacs-orgmode@gnu.org
Subject: How to execute Lisp code /after/ a capture template has been filled before it is finalized?
Date: Sat, 23 Dec 2023 17:38:56 +0000	[thread overview]
Message-ID: <87plywu8cv.fsf@vagabond.tim-landscheidt.de> (raw)

Hi,

I (want to) have a capture template that fills a table and
then (re-)calculates a cell based on a formula (and aligns
the table):

| - Note taken on %U \\\\
|   | Coin | Count
|   |-------+--------|
|   | 0.01 | %^{Number of € 0.01 coins|0} |
|   | 0.02 | %^{Number of € 0.02 coins|0} |
|   | 0.05 | %^{Number of € 0.05 coins|0} |
|   | 0.10 | %^{Number of € 0.10 coins|0} |
|   | 0.20 | %^{Number of € 0.20 coins|0} |
|   | 0.50 | %^{Number of € 0.50 coins|0} |
|   | 1.00 | %^{Number of € 1.00 coins|0} |
|   | 2.00 | %^{Number of € 2.00 coins|0} |
|   |-------+--------|
|   |      | |
|   #+TBLFM: @>$>=(@I$1..@II$1)*(@I$2..@II$2)

If I naively append "%(org-table-recalculate t)" to that
template, the expression gets evaluated immediately when I
start the capture and the text:

| %![Error: (user-error Not at a table)]

gets appended to the capture buffer /before/ I get prompted
for the first field.

Looking at the hooks for org-capture-mode, I also thought
about recalculating the table at finalizing the capture (*1)
and tried:

| %(progn (message "org-capture-prepare-finalize-hook = %S" org-capture-prepare-finalize-hook) (add-hook 'org-capture-prepare-finalize-hook (lambda nil (message "Hook called.")) 0 t) (message "org-capture-prepare-finalize-hook = %S" org-capture-prepare-finalize-hook) "")

but to my surprise, org-capture-prepare-finalize-hook is nil
prior to the add-hook call, has stored the function after
the add-hook call, but in the interactive capture buffer is
nil again (and no message is printed in *Messages*).

How can I evaluate Lisp code after all prompts have been
answered?

TIA,
Tim

(*1)   I would prefer not doing this, as in this case I
       could not see the result prior to finalizing.


             reply	other threads:[~2023-12-23 17:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-23 17:38 Tim Landscheidt [this message]
2023-12-23 18:11 ` How to execute Lisp code /after/ a capture template has been filled before it is finalized? Ihor Radchenko
2023-12-24 13:16   ` Tim Landscheidt

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=87plywu8cv.fsf@vagabond.tim-landscheidt.de \
    --to=tim@tim-landscheidt.de \
    --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).