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 GCx/KL9CPmNCBwEAbAwnHQ (envelope-from ) for ; Thu, 06 Oct 2022 04:51:43 +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 aJWUJ79CPmM6ggEAG6o9tA (envelope-from ) for ; Thu, 06 Oct 2022 04:51:43 +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 1C3E3CF9F for ; Thu, 6 Oct 2022 04:51:43 +0200 (CEST) Received: from localhost ([::1]:43946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogGz7-00028A-9P for larch@yhetil.org; Wed, 05 Oct 2022 22:51:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogGyN-00027u-G0 for emacs-orgmode@gnu.org; Wed, 05 Oct 2022 22:50:55 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:41507) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ogGyL-0003Bw-FZ for emacs-orgmode@gnu.org; Wed, 05 Oct 2022 22:50:55 -0400 Received: by mail-pj1-x1035.google.com with SMTP id x32-20020a17090a38a300b00209dced49cfso559278pjb.0 for ; Wed, 05 Oct 2022 19:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date; bh=XEpcXI0CyIpNBdI/XgObmphw6RiIUsBoyfwtzJW2IWo=; b=gbHoZa90g6UVEz7tvby40jqseQmEcTQcwitqVo4lfRoeDi0AXAceYwmoMPZIh+RynF +rBS4huGBO2sp1ds0/F32ovMHmTV4zLGg70NWa7r6SBDtebqPDO7DcWXphoxsUj8lKIq r1fhWv0HofcLhLGW2MJaGEj28Ese5YInrDi0kp0twx3X4EjehKCcxPMQfT2xnH+fzs6F h8HtIrMp8v+nEbVKkRfaPj7SLJEL3dRgUikaHiVVdS1aFeCpS+hxZw7JlqLVF4bhfiEC xIURmbXyVQB9SDQrgNHKU+i5e72y+WpA5A0GQaih/XnVbK/D3HeCTJiTTgG6PYDt7Xt0 3W/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date; bh=XEpcXI0CyIpNBdI/XgObmphw6RiIUsBoyfwtzJW2IWo=; b=CN5D9CH+eh3jPGvkLd6o2yY69VRWSa6dA4YNIWmKgrJLwQyaXOLv26bB0b4RIhJ9KS UTpgfws/MCHL9CpAlrKED0QLAwr8SeKP6JwLbAyXDj7rhKZLR/fabv2AMuqJmQu8O3fW 5apMFukNpNKn1mcSOn4Uog+mvCYt/O2jBK/pk7bgNjuq7Xdg8310CZJUZ2sBDVqFHhsP WrY7Qn7BJa1wkn4kIZbU9ldWeWqLhC2sjxdVflv0Fd3JW5Ufp6UxioQfhRpYE2Eo+L2U 3x+82d4t0F3R56TS2MvMj3rfU2OZWKLnU8AXH3FVNJDwJndA/9FfK6luvXfABkbT9Ivc D5yQ== X-Gm-Message-State: ACrzQf0y1raJY0X9RC6rhGa03VP2YbovFUezUlsNEhkIeHfBDiQacfUb QWhQIqtx4vKqD0+HhI69jv8= X-Google-Smtp-Source: AMsMyM6h05Du351ypMbw66+gWJai5vcYNTV7pE5Rz7nVHxAjwkiHF+Ofip5a6vaDCTQq/+2iV+OOiw== X-Received: by 2002:a17:902:ea09:b0:179:c4bc:20e2 with SMTP id s9-20020a170902ea0900b00179c4bc20e2mr2469076plg.132.1665024651830; Wed, 05 Oct 2022 19:50:51 -0700 (PDT) Received: from localhost ([1.83.154.214]) by smtp.gmail.com with ESMTPSA id e88-20020a17090a6fe100b00205d85cfb30sm1809688pjk.20.2022.10.05.19.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 19:50:51 -0700 (PDT) From: Ihor Radchenko To: No Wayman Cc: 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/)] In-Reply-To: <87czbg352p.fsf@gmail.com> References: <87mtalozym.fsf@gmail.com> <87czbg352p.fsf@gmail.com> Date: Thu, 06 Oct 2022 10:51:43 +0800 Message-ID: <87bkqp7jgg.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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=1665024703; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=XEpcXI0CyIpNBdI/XgObmphw6RiIUsBoyfwtzJW2IWo=; b=uzUAo4sc2MpkPShpk05seb3Fm7tlBTFWhgfJyfe2pHFue2d5i4v+h1LLhausnmUzxeYg1o NjOlpKNKy7GWax0QJf8p17/HHKZwyuljdF1FivnG2xjIK0g8z04gEBBzOwUJZM+w0xEXXy S0FirNYX1ptG4xXIl3er5nZJM7a+JfRjhb7F7rwxMSbGLygV7ue9jkLpKWy9SwBDoYIp4S zJHQkvl1OiNJTOD8l6fpr8riAL0H25uaiZBUyrp6uOsgTeAbTghySw6neyEwr5rtGaIazp m+5fTGOn+aDRn+/NGO6jfjlg6nbnuc7OCmBAlQHNGlwq16bKrt1GH/PSP0XJ1w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665024703; a=rsa-sha256; cv=none; b=cNy6vxbFuEcniqZllHXDyFdZrlt3L6WbYP0sNrLGMXY8v+n2yc8MBGIRtkLH+AkCictnJL p+5y7KUE8Zb241P9r2/0x8F1VpopMPUqXGFA6Uf61toJb3tAu1unCPbVZygtGcRVvft0yk X9P8Jr1Sf1GN7/BBhDILBxIz9enbEZUW3E3whmI5LcxJnFQ76svU9hL16guefoRwxUClTo 6QfmsBNevKDt+nE0nBEp63Kv7hZfk6KXZuNUHZ4XquakpvPdb7Mex583jMLtXLzUTtnqWv Blrfg0jDZZqN157vriRxSud6p9DEgFbv2vj7xUkQJ/jgLCTGJe8kkhLhX3UvCg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gbHoZa90; 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: -8.36 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gbHoZa90; 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: 1C3E3CF9F X-Spam-Score: -8.36 X-Migadu-Scanner: scn0.migadu.com X-TUID: S1YOBuBBLkXt No Wayman writes: > The attached patch is the first step toward integrating DOCT[1] > syntax into Org mode. Thanks! This is most welcome. > It adds property options to org-capture-templates which make it > easier to run template-specific hooks. > ... > 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. LGTM. > 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'. Then, please add an appropriate comment in the code. > See attached patch. > > 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. Nitpick: Execute > (org-capture-place-template): execute :hook functions. > * doc/org-manual.org Document template hook properties. You also need to add an appropriate ORG-NEWS entry. > + - ~:hook~ :: > + > + A function or list of functions run before `org-capture-mode-hook' > + when the template is selected. You did not mention the number of arguments passed to the functions. > + - ~: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. In the above, please use the quoting consistently. This is an Org file, so do not use `symbol'. Instead, use ~symbol', as documented in doc/Documentation_Standards.org > :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. Again, the number of arguments passed to the hooks should be documented. > > +(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'." It is unclear what "KEYWORD functions" refers to. > + (let ((value (org-capture-get keyword local))) > + (if (functionp value) > + (funcall value) > + (mapc #'funcall value)))) The reasoning why not `run-hooks' might be commented here. > > + ;; Do not use the local arg to `org-capture-get' here. > + ;; The buffer-local value has been stored on `org-capture-plist'. Did you mean "... local arg to `org-capture--run-template-function'"? > + (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)) Here and above, it would be a bit more clear to use something like 'local instead of t argument. Also, please add some tests into testing/lisp/test-org-capture.el. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at