From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gFiONDNlM2PByQAAbAwnHQ (envelope-from ) for ; Tue, 27 Sep 2022 23:03:47 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id eEeeMzNlM2MkLgAAG6o9tA (envelope-from ) for ; Tue, 27 Sep 2022 23:03:47 +0200 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 7CAA419235 for ; Tue, 27 Sep 2022 23:03:47 +0200 (CEST) Received: from localhost ([::1]:35852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odHk1-000268-FW for larch@yhetil.org; Tue, 27 Sep 2022 17:03:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odHfT-0007DH-NO for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 16:59:03 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:43934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odHfR-0000zD-Ub for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 16:59:03 -0400 Received: by mail-qt1-x82b.google.com with SMTP id a20so6833419qtw.10 for ; Tue, 27 Sep 2022 13:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:to:from:user-agent :references:from:to:cc:subject:date; bh=avaCPC69/3ZSRRIlbHnJbFFOIVpVKidb6/IAedmLEuo=; b=iEoQorm2DJggFi8mLqyMNpScCPE12yAbNIsKhbgnrt4beeNyM54Ahzot7boIsQmnr8 VEt+xbuHfuz6V+EtdGnrQGdEpWalCrb/7DEo8OEZ8MUZEKI32FxYzJIBwifOHVfVMz5W bx/q9lb07cInBrG2Da2bw+MykQhuWChOqslj4Azv231rhZXmvMWiezLmps4PQfsrij2u wLv6P/1pCB77yeBUgqhoYvbca/OAlvfDjkEDFW1GkxKDZJ/ymIs8cCrZttNPvMpxW8zz NDdZNNiajx9VmAbFym2vIRz4EmQt/cDvvVyVcjVf0Wb6w1+odigPg93eg9T6tRZmEH9Q Ji7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:to:from:user-agent :references:x-gm-message-state:from:to:cc:subject:date; bh=avaCPC69/3ZSRRIlbHnJbFFOIVpVKidb6/IAedmLEuo=; b=lCufAzUz5C6Viy60SvSWqEq4RyK1xCaY2pVJUGaapku+5yoAuPT1xVmNYXPrgZjj51 STWbV00Lu6Y6SqNtpMswoLOlG8sSF0dW+vvB2CUcDUBSMSlbL4axeP/5bDSHQfKrKCX1 ILy9zDRVtDsdz8g3+dAbZuonHWOE1BiP4gnAvHaKhBfuN/YfUfpH8wirvZIS43p19rTA P0HxdCRMWx+7IPLV+WUeEqkQjB/mNmd6HtkyYshQu1BTsK3X1ucsN2M6dILVww9lAvk1 0rM+XyqWYgDHO2bYWaOrta7rbqq8JGR5mBrv26/7g/ehqG8uBRKoPPphkFdaXQ4Ehb/L /XEQ== X-Gm-Message-State: ACrzQf2NbkoGECrVOvjO/pFIEMwBb3IA/3xzzsqp3VO3HGD0Sj1HxsCI /nR1HbgnGqvZ1o+VtSAgpdqnS7Jfx4o= X-Google-Smtp-Source: AMsMyM6z8rn5Cmp/oPYfqs3/OZdvLSgDggg3rPSi7Bdgk8MhFhlF20vO4RlCSlkri8CUe6nqtUz7sA== X-Received: by 2002:ac8:7f81:0:b0:35b:bbd9:9876 with SMTP id z1-20020ac87f81000000b0035bbbd99876mr23812556qtj.224.1664312340322; Tue, 27 Sep 2022 13:59:00 -0700 (PDT) Received: from nbook ([2601:82:c200:166d:7a0:14e6:e26:75bd]) by smtp.gmail.com with ESMTPSA id bq36-20020a05620a46a400b006b9bf03d9c6sm1735662qkb.104.2022.09.27.13.58.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 13:58:59 -0700 (PDT) References: <87mtalozym.fsf@gmail.com> User-agent: mu4e 1.9.0; emacs 29.0.50 From: No Wayman To: emacs-orgmode@gnu.org Subject: Re: [PATCH] DOCT integration: template specific hooks [9.5.5 (9.5.5-g003cc7 @ /home/n/.emacs.d/elpaca/builds/org/)] Date: Tue, 27 Sep 2022 16:56:45 -0400 In-reply-to: <87mtalozym.fsf@gmail.com> Message-ID: <87czbg352p.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=iarchivedmywholelife@gmail.com; helo=mail-qt1-x82b.google.com 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 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" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664312627; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=avaCPC69/3ZSRRIlbHnJbFFOIVpVKidb6/IAedmLEuo=; b=BH8SfUAfe/k6sMoUwmDw6Q+tGURrxUFejXO3Yulnynisw2KCleBvzpmWhNlS+pm2RqHt8p EmSIGNuy1C4d5QRL77cXJg5LK+6mt88Y7iZxDCN+YJaIcIfIoOzy8Go67VskkFd72n4oLS bAj/VpV8j/91cDtm7XrYGJlUlisRdVyfx5fQsQt/RB34Lnd/O9mOXj9QY0UwsSI/IXXuIV +VidJxDK0nTLf2OAi/iUCuLFAd2Gb5kHBDBCV+HDmO8AXVQ0w8xwhiu0un9QqSBbkMSw4D Ml4kSixVEaWIxFF6iEu4owNkEvmO7jD86rqC9gq3jnZbxtMPxy6/ZFJ1OEiF/w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664312627; a=rsa-sha256; cv=none; b=PV9A4VKPR5J/UmOPm0S2Ri08nAAvw6NlCeHwF0ya6V5DApcb7NizleKwQUjBTRer50Dfqy nA9WDiIXl8pCcUJyzNnx4mwxjndwSDF2fH5KjZoo4unHtPTp+YQghHdF7eJrTUoBvSIm/i 4QrVzRZh/TFeeNid+ideZjzC7+dRvfa+/biX4tHYM6p9H4VnRWOQ2Y6Wu4E5/xnE7LOD07 vh5FsBRrBkizCrQDhHNf69p/ZzWvakcB6QO1WuAo/MLUcMUj2Bk3vMrVYT3XLCjWlkCqQL wR/1zxhntnkwEfSNLpPVEdthKY/yotR+QMjaAmdVtDdUaJtmYsEvkiNNH9fmvg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iEoQorm2; dmarc=pass (policy=none) header.from=gmail.com; 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" X-Migadu-Spam-Score: -2.83 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iEoQorm2; dmarc=pass (policy=none) header.from=gmail.com; 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" X-Migadu-Queue-Id: 7CAA419235 X-Spam-Score: -2.83 X-Migadu-Scanner: scn1.migadu.com X-TUID: 5ZsboxV+rMoO --=-=-= Content-Type: text/plain; format=flowed On second thought, I'd prefer the keywords to allow a single function or a list of functions. This prevents breakage with current DOCT syntax and is cleaner IMO. e.g. #+begin_srce emacs-lisp :lexical t (let ((org-capture-templates '(("t" "test" plain (file "/tmp/test.org") "test %?" :hook (lambda () (insert "PASS")))))) (org-capture nil "t")) #+end_src See attached patch. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-capture-Add-template-hook-properties.patch Content-Description: single-or-list-of-fns >From 780194a5af6a8a6c7fbb602e834dcbec78016070 Mon Sep 17 00:00:00 2001 From: Nicholas Vollmer Date: Tue, 27 Sep 2022 05:44:33 -0400 Subject: [PATCH] org-capture: Add template hook properties * lisp/org-capture.el (org-capture-templates): Document template hook properties. (org-capture-finalize): execute :prepare/:before/:after-finalize functions. (org-capture-place-template): execute :hook functions. * doc/org-manual.org Document template hook properties. --- doc/org-manual.org | 20 ++++++++++++++++++++ lisp/org-capture.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/doc/org-manual.org b/doc/org-manual.org index ab8a295e5..c1321f6cd 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -7838,6 +7838,26 @@ Now lets look at the elements of a template definition. Each entry in - ~:refile-targets :: Temporarily set ~org-refile-targets~ to the value of this property. + - ~:hook~ :: + + A function or list of functions run before `org-capture-mode-hook' + when the template is selected. + + - ~:prepare-finalize~ :: + + A function or list of functions run before `org-capture-prepare-finalize-hook' + when the template is selected. + + - ~:before-finalize~ :: + + A function or list of functions run before `org-capture-before-finalize-hook' + when the template is selected. + + - ~:after-finalize~ :: + + A function or list of functions run before `org-capture-after-finalize-hook' + when the template is selected. + **** Template expansion :PROPERTIES: :DESCRIPTION: Filling in information about time and context. diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 428d0ac0e..e5528a849 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -297,6 +297,21 @@ properties are: :no-save Do not save the target file after finishing the capture. + :hook A function or list of functions run before + `org-capture-mode-hook' when the template is selected. + + :prepare-finalize A function or list of functions run before + `org-capture-prepare-finalize-hook' + when the template is selected. + + :before-finalize A function or list of functions run before + `org-capture-before-finalize-hook' + when the template is selected. + + :after-finalize A function or list of functions run before + `org-capture-after-finalize-hook' + when the template is selected. + The template defines the text to be inserted. Often this is an Org mode entry (so the first line should start with a star) that will be filed as a child of the target headline. It can also be @@ -740,6 +755,14 @@ of the day at point (if any) or the current HH:MM time." (format "* Template function %S not found" f))) (_ "* Invalid capture template")))) +(defun org-capture--run-template-functions (keyword &optional local) + "Run template's KEYWORD functions. +If LOCAL is non-nil use the buffer-local value of `org-capture-plist'." + (let ((value (org-capture-get keyword local))) + (if (functionp value) + (funcall value) + (mapc #'funcall value)))) + (defun org-capture-finalize (&optional stay-with-capture) "Finalize the capture process. With prefix argument STAY-WITH-CAPTURE, jump to the location of the @@ -751,6 +774,7 @@ captured item after finalizing." (buffer-base-buffer (current-buffer))) (error "This does not seem to be a capture buffer for Org mode")) + (org-capture--run-template-functions :prepare-finalize t) (run-hooks 'org-capture-prepare-finalize-hook) ;; Update `org-capture-plist' with the buffer-local value. Since @@ -823,6 +847,7 @@ captured item after finalizing." ;; the indirect buffer has been killed. (org-capture-store-last-position) + (org-capture--run-template-functions :before-finalize t) ;; Run the hook (run-hooks 'org-capture-before-finalize-hook)) @@ -871,6 +896,9 @@ captured item after finalizing." ;; Restore the window configuration before capture (set-window-configuration return-wconf)) + ;; Do not use the local arg to `org-capture-get' here. + ;; The buffer-local value has been stored on `org-capture-plist'. + (org-capture--run-template-functions :after-finalize) (run-hooks 'org-capture-after-finalize-hook) ;; Special cases (cond @@ -1147,6 +1175,7 @@ may have been stored before." (`item (org-capture-place-item)) (`checkitem (org-capture-place-item))) (setq-local org-capture-current-plist org-capture-plist) + (org-capture--run-template-functions :hook t) (org-capture-mode 1)) (defun org-capture-place-entry () -- 2.37.3 --=-=-=--