emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] DOCT integration: template specific hooks [9.5.5 (9.5.5-g003cc7 @ /home/n/.emacs.d/elpaca/builds/org/)]
@ 2022-09-27 10:46 No Wayman
  2022-09-27 11:06 ` No Wayman
  2022-09-27 20:56 ` No Wayman
  0 siblings, 2 replies; 7+ messages in thread
From: No Wayman @ 2022-09-27 10:46 UTC (permalink / raw)
  To: emacs-orgmode

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-07  5:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 10:46 [PATCH] DOCT integration: template specific hooks [9.5.5 (9.5.5-g003cc7 @ /home/n/.emacs.d/elpaca/builds/org/)] No Wayman
2022-09-27 11:06 ` No Wayman
2022-09-27 20:37   ` No Wayman
2022-09-27 20:56 ` No Wayman
2022-10-06  2:51   ` Ihor Radchenko
2022-10-06 10:47     ` No Wayman
2022-10-07  5:42       ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).