From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id yBnbM2DaMmP7ZwEAbAwnHQ (envelope-from ) for ; Tue, 27 Sep 2022 13:11:28 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 0NK1M2DaMmPr/wAAauVa8A (envelope-from ) for ; Tue, 27 Sep 2022 13:11:28 +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 673A63CFC5 for ; Tue, 27 Sep 2022 13:11:27 +0200 (CEST) Received: from localhost ([::1]:60406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1od8Uo-0003TM-4p for larch@yhetil.org; Tue, 27 Sep 2022 07:11:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od8Ox-00018t-Px for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 07:05:25 -0400 Received: from mail-qv1-xf2b.google.com ([2607:f8b0:4864:20::f2b]:37815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1od8Ov-0004XW-CX for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 07:05:23 -0400 Received: by mail-qv1-xf2b.google.com with SMTP id y9so5980201qvo.4 for ; Tue, 27 Sep 2022 04:05:19 -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=lrKQ2NU1N0w/fQPFxTDctwEl9LuzAtfBEhqTQqfrDC4=; b=CyRr9mSkFABqmDNA71Cj1+2KSj8CnD7DbSL5sTfcNfqsCDi79aUznnDjjE6GsiOPEu urtN2qv3PTAhVFRuDSJIt6qVsWBfm0p2jstru3jenYPWZhZd3T9zu9FbmLAaQrjDHIdc dyXlSDqkzAGmxag1e0BEo5Ygk9KfhyLatY/c7EA3hSauObx95suDKTrD+qor59k0Yl4V scdZwzHK3bH221RBpnqF3OVHoZgStqsV8LES70nzkuS+jzpkpawqRMlZ9C/GOgUmvZOS +JI70aSFR7ddH6vq9l4JHVKWglRtPOz989cRozlwL6koHDrx2ZjSSMtbgtotsRjsPcvf XMAg== 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=lrKQ2NU1N0w/fQPFxTDctwEl9LuzAtfBEhqTQqfrDC4=; b=EDMYABpTV7a37gyxmlwp+AOiDE7VfzkIAwTjeh4LyOTSGJGDY0Lk6LTy55jL8Kaa8t aelnk3ogN5FKHvly51KPrC5VqIb2P0PR/RHJnv3dwUPrMu+HXIaCHeBRZK9mC6HgWsFy z3dlUUqZlLMgjFTTz1ttj0CKcTOJXXnJI87sWvhvABB2meHT650PfL+DynJN34HKgB4d YuZt0w6IaZa44Ix+zdC+K43KQcQG5V53Sc3mxtls/YQAaJP88HzZGaJvWzX0W//1GYo6 bF15wpGRm3zkVy5+8xwOzEEFAGyQ6p/z1au08yiOd55YfXTd/XerOEEIBp7a8RxTWO+/ iOzA== X-Gm-Message-State: ACrzQf0GUYNLSqzU8yddnMEmroVP1yf42Lzz+2U3fe5wa06Kql09Rr4U /fcbUWaNV6znwVjsc0FAOvwVUz35X4M= X-Google-Smtp-Source: AMsMyM6AVHIJBVEBHxOsMfcpl3LsHmfqfDgK+gxrGcqOkkIDSvpxVyq9lqoh+m35rPnGLyuVzUAQIQ== X-Received: by 2002:a05:6214:4101:b0:4af:8cdc:20c4 with SMTP id kc1-20020a056214410100b004af8cdc20c4mr1704021qvb.6.1664276718680; Tue, 27 Sep 2022 04:05:18 -0700 (PDT) Received: from nbook ([2601:82:c200:166d:7a0:14e6:e26:75bd]) by smtp.gmail.com with ESMTPSA id br26-20020a05622a1e1a00b00342b7e4241fsm607998qtb.77.2022.09.27.04.05.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 04:05:17 -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 07:06:08 -0400 In-reply-to: <87mtalozym.fsf@gmail.com> Message-ID: <87ill9oz2v.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::f2b; envelope-from=iarchivedmywholelife@gmail.com; helo=mail-qv1-xf2b.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-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664277087; 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=lrKQ2NU1N0w/fQPFxTDctwEl9LuzAtfBEhqTQqfrDC4=; b=IIZSNXAuQPgLmMd00fzRGMrRzZwd0KXj7nsWqVSrbfF0QekdLZfoCKoMo9IQWshvTBd6aX YXu8GKt37JTurdhnsFBtfjFUetLDqLJouICIVtHs+WLyTFSB5WHF2qbp99amKI5DJGDwpb vOmJB9M3cK8cyk95Lel0PGHi9uDg8VizUqgU5XQPVZ//0Krf8ypwBQZDL8MVALo5YN5MKD QUwqV+fUMKEuQyyHDxnV4hdNgPoC4KWzWH7G0sgFGhkN0vC7sb/yUlzmcCzADo8zI6VzSo 4OzI0wl1pyePSx2HJRiKDcpLOUWePrDDSZ2Y8DkJ05smcNr/FyVFDqtxPux6mQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664277087; a=rsa-sha256; cv=none; b=USJQ/FvLN+dzbz2xu89zYBU/3qeoHD2Kyl8ADQp8Ijz0klWZ1TYJ0/4/16asMzzqVmZ4c0 mVnhh2gFxgqVxPAbHkmo0Zv+S2LIDOX09xqeYmFDs9eooch4pHluzDf/9YJI+QIR6xeXU8 B+BdkCB5//7HVnzoEB3tg02a1yRsoK5EiWG4MyVdIa87YvTPS7m08/mJ4XDpKzAtmGxuaW IFahLm2Fz8eBm0fqKh/R8tD8Aap3AXWqVybo0gOM8FzsP7AECiBOMSpD5NYqwXQJLylB8C NsvNzOMLPbTxxZn15yLRLpOUpo2TzFn1QudriZUDIowDOEKKj410HnopaIe2Dw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=CyRr9mSk; 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: -5.84 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=CyRr9mSk; 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: 673A63CFC5 X-Spam-Score: -5.84 X-Migadu-Scanner: scn0.migadu.com X-TUID: +lTtGxcaxPRT --=-=-= Content-Type: text/plain; format=flowed No Wayman writes: > The attached patch is the first step toward integrating DOCT[1] > syntax into Org mode. > It adds property options to org-capture-templates which make it > easier to run template-specific hooks. > The current approach for running such hooks involves adding to > the > desired global hook variable and filtering by the template's > keys. > e.g. > > #+begin_src emacs-lisp :lexical t > (defun +example-template-hook () > (when (eq (org-capture-get :key t) "e") > (message "hook run"))) > > (add-hook 'org-capture-mode-hook #'+example-template-hook) > > (let ((org-capture-templates '("e" "example" (file "") ""))) > (org-capture nil "e")) > #+end_src > > > The hook has to be maintained separately from the template > declaration. > The criteria to determine the selected template is baked into > the > hook function. > This is fragile (change the binding for the template and you > must > update the hook function), > mixes concerns, and makes templates harder to share. > > Contrast the above with the following syntax enabled by the > attached patch: > > #+begin_src emacs-lisp :lexical t > (let ((org-capture-templates > '(("t" "test" plain (file "/tmp/test.org") > "test %?" > :hook ((lambda () (insert "mode-hook\n"))) > :before-finalize ((lambda () (insert > "before-finalize\n"))) > ;; Only a message because this happens outside the > context > ;; of the capture buffer. > :after-finalize ((lambda () (message > "after-finalize"))) > :prepare-finalize ((lambda () (insert > "prepare-finalize\n"))))))) > (org-capture nil "t")) > #+end_src > > These template-specific hook functions run prior to their global > counterparts. > > Ihor, an implementation note: I have not used `run-hooks' with > these because they have no associated symbol. > The functions are lists stored directly on `org-capture-plist'. > > [1]: https://github.com/progfolio/doct And, of course, the patch... --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-capture-Add-template-hook-properties.patch >From 790e8c517ba933025e50302e9c990ccf9265b55c 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 | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/doc/org-manual.org b/doc/org-manual.org index ab8a295e5..ed2322949 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 list of functions run before `org-capture-mode-hook' + when the template is selected. + + - ~:prepare-finalize~ :: + + A list of functions run before `org-capture-prepare-finalize-hook' + when the template is selected. + + - ~:before-finalize~ :: + + A list of functions run before `org-capture-before-finalize-hook' + when the template is selected. + + - ~:after-finalize~ :: + + A 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..af1502ede 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 list of functions run before + `org-capture-mode-hook' when the template is selected. + + :prepare-finalize A list of functions run before + `org-capture-prepare-finalize-hook' + when the template is selected. + + :before-finalize A list of functions run before + `org-capture-before-finalize-hook' + when the template is selected. + + :after-finalize A 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 @@ -751,6 +766,7 @@ captured item after finalizing." (buffer-base-buffer (current-buffer))) (error "This does not seem to be a capture buffer for Org mode")) + (mapc #'funcall (org-capture-get :prepare-finalize t)) (run-hooks 'org-capture-prepare-finalize-hook) ;; Update `org-capture-plist' with the buffer-local value. Since @@ -823,6 +839,7 @@ captured item after finalizing." ;; the indirect buffer has been killed. (org-capture-store-last-position) + (mapc #'funcall (org-capture-get :before-finalize t)) ;; Run the hook (run-hooks 'org-capture-before-finalize-hook)) @@ -871,6 +888,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 has been stored on `org-capture-plist'. + (mapc #'funcall (org-capture-get :after-finalize)) (run-hooks 'org-capture-after-finalize-hook) ;; Special cases (cond @@ -1147,6 +1167,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) + (mapc #'funcall (org-capture-get :hook t)) (org-capture-mode 1)) (defun org-capture-place-entry () -- 2.37.3 --=-=-=--