emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] org-capture is not reentrant [9.5.2 (9.5.2-gfbff08 @ /home/ignacio/.emacs.d/elpa/org-9.5.2/)]
@ 2022-02-10 10:25 Ignacio Casso
  2022-10-20  3:35 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Ignacio Casso @ 2022-02-10 10:25 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I recently tried to use (org-capture '(4) key) (i.e., C-u prefix
argument GOTO, so not actually capturing anything, just
moving to the target) as part of the function passed as target for
another capture template, using file+function, as in the example below:

       (setq org-capture-templates
             '(("i" "Inner" entry
                (file+headline "/tmp/foo.org" "Target")
                "* Wrong Heading"
                :immediate-finish t)
               ("o" "Outer" entry
                (file+function "/tmp/foo.org" capture-target) ;;
                "* It works!!"
                :immediate-finish t)))

       (defun capture-target ()
         (org-capture '(4) "i"))

       (org-capture nil "o")

The result was:
* Target
** Wrong heading

So it worked for moving point to the desired target, but it overwrote
other parts of the template. I took a quick look at the code and it
seems that a global property list is used internally for the capture
process, which seems to be only initialized at the start of the capture
process and therefore the inner capture would overwrite it in our
case. I saw also that the global property list is copied to a buffer
local property list for the case of starting a new capture process
before typing C-c C-c in the indirect capture buffer.

Do you think it would be easy to recycle that code to also have a stack
of property lists and allow reentrancy? Would yo consider it useful? I
would, but not really worth it to implement unless it's a low hanging
fruit. If it is, I'd volunteer to do so (although my elisp-fu may be a
little bit lacking yet).

Regards,

Ignacio


Emacs  : GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20)
 of 2022-01-16
Package: Org mode version 9.5.2 (9.5.2-gfbff08 @ /home/ignacio/.emacs.d/elpa/org-9.5.2/)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG] org-capture is not reentrant [9.5.2 (9.5.2-gfbff08 @ /home/ignacio/.emacs.d/elpa/org-9.5.2/)]
  2022-02-10 10:25 [BUG] org-capture is not reentrant [9.5.2 (9.5.2-gfbff08 @ /home/ignacio/.emacs.d/elpa/org-9.5.2/)] Ignacio Casso
@ 2022-10-20  3:35 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2022-10-20  3:35 UTC (permalink / raw)
  To: Ignacio Casso; +Cc: emacs-orgmode

Ignacio Casso <ignaciocasso@hotmail.com> writes:

> ... I took a quick look at the code and it
> seems that a global property list is used internally for the capture
> process, which seems to be only initialized at the start of the capture
> process and therefore the inner capture would overwrite it in our
> case. I saw also that the global property list is copied to a buffer
> local property list for the case of starting a new capture process
> before typing C-c C-c in the indirect capture buffer.

Confirmed.

Your understanding is correct. Capture inside capture is not supported
because of the internal capture code design.

> Do you think it would be easy to recycle that code to also have a stack
> of property lists and allow reentrancy? Would yo consider it useful? I
> would, but not really worth it to implement unless it's a low hanging
> fruit. If it is, I'd volunteer to do so (although my elisp-fu may be a
> little bit lacking yet).

It will be definitely useful. We have bugs surfaced from time to time
because of nested captures. However, one will need to check the logic
inside org-capture first and identify how to switch from global
variables holding the capture state to something more robust.

A good first step could be looking through org-capture code and the
functions it calls and supplying comments to places in the code that are
not immediately clear. Such comments would be useful for others as well.

We can also help in the process, if you volunteer.

-- 
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>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-20  3:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-10 10:25 [BUG] org-capture is not reentrant [9.5.2 (9.5.2-gfbff08 @ /home/ignacio/.emacs.d/elpa/org-9.5.2/)] Ignacio Casso
2022-10-20  3:35 ` Ihor Radchenko

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