From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:700:3204::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id yLXPB4EviGUnvQAAkFu2QA (envelope-from ) for ; Sun, 24 Dec 2023 14:17:53 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id CPXEAYEviGVthgEAe85BDQ (envelope-from ) for ; Sun, 24 Dec 2023 14:17:53 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1703423873; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ROoJkXhMRCDYP6cfdDipkQ1cfvfvtHVLMzZ/lyyI/Gc=; b=OQYBOr+U5TQ3AIvAuyo3HvwrJZEtbMfRzUIsoBeidyNIHAYEGWFxMSrUi7r+mSWq92CVEU B520zIJSVRtJunCtnibUKrpNZIt3e6zq1Yj5Tw+a1pJ/ZMNowUaqjOJ8k0TZe1bnh5x3wt 3i+w9R/BCV36PCTgkYdUSx+NikTrY6OqRUpcv+5Ccw/fd6PX2AEoVcPoEsoqw6oWKAIO2J qJn3Mtrxm+NiQiw1BkzUwQs7Jjk2iJyxPskO/5qKcThlTGGUwmqRp0j+DPazy2BQtN8+eM GcbjwI9VqgQ5Z4vdJ6yOUAwOA4MXIxOLQo6AZjp6r7HKhOleAiGKWw95JoRkcg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1703423873; a=rsa-sha256; cv=none; b=P2qqWSTvrXAvGt7wkFNpHqfuCCpOM8ra93q3jezttEbrXe6pkOKOFYyCDdxMe06X7OmsTq BS4guL6edBQTqawHzkxjjbOuq2pEjlLwq+06NwtbLhE7FcLGSGekMFr4CB8vzSMsJXTL3N DWBC1hOW9HY2bo/JOSB+X5JXZ/Qt8Y3bEcazSw25NTCzHXlAmDyFr3wx1NeA4cm2MT2wSE z611Ik2n+TX4MD1vMuY9gbmEn0rVNuValXQs/Z1L5cH2YFf27wN46Do2OXOewD0FTmlN+4 Xwto7qZIrOCnby0riBrqxndLy9uhRakQ4IfASBW62GLLWHwsn0TbX6iHrCDrqA== 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 BB149159F8 for ; Sun, 24 Dec 2023 14:17:52 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHOLg-0005Ch-Cp; Sun, 24 Dec 2023 08:16:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHOLe-0005CT-Qn for emacs-orgmode@gnu.org; Sun, 24 Dec 2023 08:16:54 -0500 Received: from gavdos.tim-landscheidt.de ([2a01:4f8:1c0c:4bd6::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHOLc-0001km-4k for emacs-orgmode@gnu.org; Sun, 24 Dec 2023 08:16:54 -0500 Received: from port-62-145-29-194.static.as20676.net ([62.145.29.194]:36872 helo=vagabond) by gavdos.tim-landscheidt.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rHOLZ-008OfE-17; Sun, 24 Dec 2023 13:16:49 +0000 From: Tim Landscheidt To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: How to execute Lisp code /after/ a capture template has been filled before it is finalized? Organization: https://www.tim-landscheidt.de/ References: <87plywu8cv.fsf@vagabond.tim-landscheidt.de> <877cl4dc1j.fsf@localhost> Date: Sun, 24 Dec 2023 13:16:48 +0000 In-Reply-To: <877cl4dc1j.fsf@localhost> (Ihor Radchenko's message of "Sat, 23 Dec 2023 18:11:20 +0000") Message-ID: <87sf3rpwov.fsf@vagabond.tim-landscheidt.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a01:4f8:1c0c:4bd6::1; envelope-from=tim@tim-landscheidt.de; helo=gavdos.tim-landscheidt.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -1.10 X-Spam-Score: -1.10 X-Migadu-Queue-Id: BB149159F8 X-TUID: 9iCjmiUORlKl Ihor Radchenko wrote: > [=E2=80=A6] > %(...) 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#n1= 270 I'm using Emacs 28.3, so that is something for the future. But your pointer made me read the source and adjust my men- tal picture: I had always thought that capturing opened a window showing a narrowed section of the buffer, invoked org-capture-mode-hook, then inserted the template and went on from there. Instead (CMIIW), the template is evaluated in a temporary buffer, the result is pasted in the capture buffer, and then org-capture-mode-hook is invoked. That means inter alia that org-capture-mode-hook can work on the "completed" tem- plate. For my problem, I thus first (partly) replicated Org 9.6's behaviour by adding: | (lambda nil | (if | (version< org-version "9.6") | (let | ((hook | (org-capture-get :hook))) | (if | (functionp hook) | (funcall hook) | (mapc #'funcall hook))))) to org-capture-mode-hook. Then I thought about using org-table-map-tables to call org-table-recalculate on all tables in the capture buffer to avoid having to figure out where my table was. But org-table-map-tables unfortunately widens the buffer before iterating, so this was no option. Therefore, to keep it simple, I amended my template by add- ing "%?" to the cell where the sum is put in and setting the :hook property to org-table-recalculate. (I also added ";%.2f" to the formula for formatting.) In the end, this works very nicely. Thanks! Tim