Tim Landscheidt <t...@tim-landscheidt.de> writes:

> 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):
> ...
> 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) "")

%(...) expansion is executed _before_ capture template is fully
 calculated. It is generally not designed to side-effect functions.

You can instead use template-local hooks, introduced in Org 9.6. See
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/etc/ORG-NEWS#n1270

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to