[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] org-capture: Update plist before finalizing
From: |
Leo Vivier |
Subject: |
[PATCH] org-capture: Update plist before finalizing |
Date: |
Sun, 26 Jul 2020 00:50:49 +0200 |
Hi there,
I’m working on the parallelisation of `org-capture' for Org-roam, and
I’ve run into a problem with the updating of `org-capture-plist'.
;;---------------------------------------------------------------------
;; DESCRIPTION
;;---------------------------------------------------------------------
We use the global-variable `org-capture-plist' to populate the
local-variable `org-capture-current-plist' on the init of the
`org-capture' buffer. However, we do not do the opposite (i.e. update
the global-variable with the local-variable) on `org-capture-finalize'.
This is fine for the majority of `org-capture-finalize', since we’re
using the LOCAL arg of `org-capture-get' to read
`org-capture-current-plist' instead of `org-capture-list', but this
trick does not work for `org-capture-after-finalize', since the hook is
run after the `org-capture-buffer' has been closed.
This causes problem with `:kill-buffer t', and it limits what can be
done with cleanup functions in `org-capture-after-finalize'.
;;---------------------------------------------------------------------
;; DEMONSTRATION
;;---------------------------------------------------------------------
Tested in emacs -Q.
Summary:
- Start a capture process (A)
- Start another capture process (B)
- Cancel B
- Cancel A
Form:
--------------------------------[START]--------------------------------
;; Eval the following form:
(progn
(setq org-capture-templates
'(("a" "foo" plain (file "/tmp/foo.org") "* %?"
:kill-buffer t)
("b" "bar" plain (file "/tmp/bar.org") "* %?"
:kill-buffer t)))
(let* ((a (save-window-excursion
(org-capture nil "a")
(current-buffer)))
(b (save-window-excursion
(org-capture nil "b")
(current-buffer))))
(with-current-buffer b
(org-capture-kill))
(with-current-buffer a
(org-capture-kill))))
;; Result: (error "Selecting deleted buffer")
;; `foo.org' is still alive
---------------------------------[END]---------------------------------
;;---------------------------------------------------------------------
;; ANALYSIS
;;---------------------------------------------------------------------
The problem happens during `org-capture-after-finalize'. A’s
`org-capture-finalize' does not update `org-capture-plist' with the value
of `org-current-capture-plist' during its execution, which means that
`org-capture-plist' still holds B’s value, including :buffer. Since B’s
base-buffer was killed, :buffer points to a killed buffer, which is what
is raising the error.
;;---------------------------------------------------------------------
;; PATCH
;;---------------------------------------------------------------------
I propose to update `org-capture-plist' early in `org-capture-finalize'.
I don’t think this would have unforeseen effects, since
`org-capture-list' is already meant to be transient, and we’d only be
expanding its use from init-only to init-and-exit.
HTH,
--
Leo Vivier
0001-org-capture-Update-plist-before-finalizing.patch
Description: Text Data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] org-capture: Update plist before finalizing,
Leo Vivier <=