From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id r0FkLGq3HF+gJAAA0tVLHw (envelope-from ) for ; Sat, 25 Jul 2020 22:51:22 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id WAe6J2q3HF+hLAAAB5/wlQ (envelope-from ) for ; Sat, 25 Jul 2020 22:51:22 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 317F794077C for ; Sat, 25 Jul 2020 22:51:22 +0000 (UTC) Received: from localhost ([::1]:43208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jzT0h-0002oL-SA for larch@yhetil.org; Sat, 25 Jul 2020 18:51:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jzT0L-0002o0-0P for emacs-orgmode@gnu.org; Sat, 25 Jul 2020 18:50:57 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:40816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jzT0H-0008Oz-Se for emacs-orgmode@gnu.org; Sat, 25 Jul 2020 18:50:56 -0400 Received: by mail-wr1-x436.google.com with SMTP id l2so832271wrc.7 for ; Sat, 25 Jul 2020 15:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version; bh=GlUKR9YWQ5f71x4CzP4dIHPTZCI9AJOn8cn2Fq68zeM=; b=JiMtRpLUg3kzb+ZjFTOo+SIUWAz3+27LSpggVEjO34Z1kSPM0arUlrsDAl40Yr/zFd glI34zx+hfiVwHkaKfdOFYU36Je6HoomdQZ91A1VIOhQKqBlALabmrmf0VCgW6NsJ3yt KrNXLNaEITztToholiyKpmMJaSkR4fK67nh6MtaK5l/6fgeLnhMgA/tzPns2yX1NnBxX 3Y61pv7fBsRWQmaESjmH0XxhORjYype7iTeD2KQCpb2gnHHh4ESE69qu5kk0o1XAg6mp T5+VzY7HaaHBPhWkms60EEkm+uNnUTw7zDTXhcez0b08WQroCrpxNmyPH8rucI+SmOo8 xSlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version; bh=GlUKR9YWQ5f71x4CzP4dIHPTZCI9AJOn8cn2Fq68zeM=; b=YAuqsNTxS7JJJD1qGjiC7QzijnhAzYvdfeVRLAIXfO1ux3MQjfYvhc6XIIMWUMHy4v 4W7ZcyirFYucvxG+EjHkdlAmFvs+wG61NiqfdeHiDxfh0Z896twZ80gLRWo5KPl8lkBb 3TRiElsv8TL8I/bl71/jl6oIVMBpwFWIcq5U1yX5iUKZulC1HVmJBUzBqKPJ8kqunC6g ZY0EhUN5gkZLAR+fHR91o7ss6HNYbBxR/rrY3j2BHXTzJnDuTKKHyMNY19LgG43If7JU w25+Wtzyfoou4PUyr/waTJT+1dzQjATM//Y5ld4crsSqB4n95VCl6aSIhWTnNHAYs+AD 7f4g== X-Gm-Message-State: AOAM5320457iHkd5EiuzbFe5HNzY66/GPHS/4E0Ukggc7mAFL6JlzfIh ST4f/CcJDh0CxHQvzVQchwCETIU= X-Google-Smtp-Source: ABdhPJyT/xFzcW1eRuwmJm65znaETT9lsIuJzLPbmBEzQmg0/yH0uS/qT2t4Ij/PvUGhXvTS0klw3g== X-Received: by 2002:adf:c981:: with SMTP id f1mr13976956wrh.14.1595717451590; Sat, 25 Jul 2020 15:50:51 -0700 (PDT) Received: from thinkpad.localdomain ([2a01:e35:2f1c:c140:f15:3c01:a7b9:18f]) by smtp.gmail.com with ESMTPSA id 33sm6980478wri.16.2020.07.25.15.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 15:50:50 -0700 (PDT) From: Leo Vivier To: emacs-orgmode@gnu.org Subject: [PATCH] org-capture: Update plist before finalizing Date: Sun, 26 Jul 2020 00:50:49 +0200 Message-ID: <87h7tv9pkm.fsf@hidden> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=leo.vivier+dev@gmail.com; helo=mail-wr1-x436.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=JiMtRpLU; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.59 X-TUID: 9xEX+tyJNylD --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi there, I=E2=80=99m working on the parallelisation of `org-capture' for Org-roam, a= nd I=E2=80=99ve 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=E2=80=99re 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=E2=80=99s `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=E2=80=99s value, including :buffer. Sinc= e B=E2=80=99s 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=E2=80=99t think this would have unforeseen effects, since `org-capture-list' is already meant to be transient, and we=E2=80=99d only = be expanding its use from init-only to init-and-exit. HTH, --=20 Leo Vivier --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-capture-Update-plist-before-finalizing.patch >From d14f15ab76d60c3f65837a6d14712dadabf324bf Mon Sep 17 00:00:00 2001 From: Leo Vivier Date: Sat, 25 Jul 2020 21:53:07 +0200 Subject: [PATCH] org-capture: Update plist before finalizing * lisp/org-capture.el (org-capture-finalize): Update `org-capture-plist' with local-value before finalizing. --- lisp/org-capture.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 2cc1ce394..223ed4124 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -728,6 +728,9 @@ captured item after finalizing." (run-hooks 'org-capture-prepare-finalize-hook) + ;; Update `org-capture-plist' with the local-value + (setq org-capture-plist org-capture-current-plist) + ;; Did we start the clock in this capture buffer? (when (and org-capture-clock-was-started org-clock-marker -- 2.27.0 --=-=-=--