From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 KI7BCvDUMmMArQAAbAwnHQ (envelope-from ) for ; Tue, 27 Sep 2022 12:48:16 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 4HnwCvDUMmN59wAA9RJhRA (envelope-from ) for ; Tue, 27 Sep 2022 12:48:16 +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 C99743C462 for ; Tue, 27 Sep 2022 12:48:15 +0200 (CEST) Received: from localhost ([::1]:59744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1od88L-00052l-Vb for larch@yhetil.org; Tue, 27 Sep 2022 06:48:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od86Y-0004zx-Es for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 06:46:24 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:36671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1od86W-0000Vz-5u for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 06:46:21 -0400 Received: by mail-qk1-x72a.google.com with SMTP id i3so5749170qkl.3 for ; Tue, 27 Sep 2022 03:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:subject:to:from:user-agent:from:to:cc :subject:date; bh=aOOZ34qXFKw7pw2JvVOj9AQLeUrj+iFiW5Lj7cjodhM=; b=VwASw+FeW01jAX5h5Vn5fTeINOv6OV/9HKlh1c1mwdSaWUTl6jmaR1hMA8aYij3k7y R4BswJusKQ5sl2LPUUlKEp+iUhCEj09Y9v2/0GDApCH8ZhrXhopgNMEWlbrCHQ6SW3fJ M3TedXVL6YTo/Pv8vNqaRU1iivgIMlfNFBvEuePhiJFd5PIpQ1gomQUP7ZEtnyX+24uc Y9FXqopOC28JpxUgqXoDH0DVBygJXVF3gYg8Iqso2cKG8suib9sUOJLi9Fh0lQrs55St 4KFqHWWBGqCm1yOhlZNm8pqSi2uTCc0j1lmXgPKeWx2yK2DM0eUE7hmMr/HA2+ZcKoA2 MpTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:to:from:user-agent :x-gm-message-state:from:to:cc:subject:date; bh=aOOZ34qXFKw7pw2JvVOj9AQLeUrj+iFiW5Lj7cjodhM=; b=57SOC67kLvOrMxNG38Mz2LsarNiMd2k1nQ3vO8HHntqRpexDdprZz6lYvUgGYMKe1P hUXyjXwunUjdeyo3kfZxubvZL1A4vA4FKLJt/0ISIXvHycfLeuk96Lx00QoyOw1aX5mC gwkcGbU44qFrZXzO4azjedL6xNborBHf33ZAqIitNWwVYcRels4avxzv1Z5Z/JZ/33xm KHvlCXpFDZLXXQ19dkBBVvwDdemOCKJNfc2kegINKV1kq39LCbD/YAhUbDKBFGHtibFB Bu636u5Z6XAQxXtGDncLoRFhThon9bNI2u8VG/MrPOMXiP+wnChjj/5X+6Hs/Tewq9PC 3LFA== X-Gm-Message-State: ACrzQf3VpsGhDkZ0O3VisZjySA2fIBM/JuyEf0QP7dAIsZB3+JQPjcHg FzjXDZhqt1E0c0sFB9iZ4+Mv86t7ur4= X-Google-Smtp-Source: AMsMyM5At37ORHRDanCknTtiOyVxRlJWJ4IrrKO1Cujq4WuYAGlwYIcWhftF1kLhW7bVDQDPmo5sGQ== X-Received: by 2002:a05:620a:4407:b0:6cb:e0a6:87f2 with SMTP id v7-20020a05620a440700b006cbe0a687f2mr17048627qkp.724.1664275575578; Tue, 27 Sep 2022 03:46:15 -0700 (PDT) Received: from nbook ([2601:82:c200:166d:7a0:14e6:e26:75bd]) by smtp.gmail.com with ESMTPSA id l19-20020ac84593000000b003437a694049sm573455qtn.96.2022.09.27.03.46.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 03:46:15 -0700 (PDT) User-agent: mu4e 1.9.0; emacs 29.0.50 From: No Wayman To: emacs-orgmode@gnu.org Subject: [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 06:46:23 -0400 Message-ID: <87mtalozym.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; format=flowed Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=iarchivedmywholelife@gmail.com; helo=mail-qk1-x72a.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=1664275695; 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:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=aOOZ34qXFKw7pw2JvVOj9AQLeUrj+iFiW5Lj7cjodhM=; b=PtwpGv1jZ3zs8R5zT29OjeHMz52zKOCtESTdm3Ea89ntoDrAT2tPTQYHWkwTcEhnDPvG5e Qsv0FOZE1bLiNBFH0zgYN9QOzK1bERNIi1iFElM4KVt43bt4KRRpQ/Z50XGuFzUnH1g2KC cqH/sbyFc/zf7B0iISccGc3QJlpSbrM22JZ23HMD84eTjYIbAbwyc8yCZbnib/lyJ1mCEZ npS5a/HJydfpyynQUdr5GQpGV2T/rWtCXWf3vi+ECoMSkHBUCp2nbQpADnHVDMifxyKTXN t6B+NPg8oGSxJ7X0cZ8j4qB0bqTIiRqW0a/io0b9lk6hikP7SA8voWIQCOZTQQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664275695; a=rsa-sha256; cv=none; b=e/Fm/Q/gWdMKZkPMdHpxhSA6MfTLDZANFk2I9MxUbk/lcxsR/bwZxsu5uLTqYtGDhdB3Dq xzuzaw7ed60Zgk2oVLy50qE3KaJX3LxbioCCJWUZw6YS3vkVtMBAWhg3qCW7pE6Vmvy31D lrjm5LEEXRY+NsbYfrY6oLMAQdoIADos0Ae5P+O+bvFQOqaZ5OqhA3b8/2hnCECM2xgneD 2byrHGZLtmnTwcW2Ex1RyEYRUprNW017DQnCANhALKTH1cjtX2ZGVFOCR6KdzVMaOPWV7c l0NZFwr0FgeIALQbstdY50SE5cRQK8mg92nVmziB1fGCsqZp6VJiYEmbcCvJig== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VwASw+Fe; 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: -7.34 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VwASw+Fe; 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: C99743C462 X-Spam-Score: -7.34 X-Migadu-Scanner: scn0.migadu.com X-TUID: Njc3c27SPnxx 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