From 779d6b85acf9c30d7230bffccb2f98764372034a Mon Sep 17 00:00:00 2001 From: Joris Caravati Date: Sun, 12 May 2024 21:29:52 +0200 Subject: [PATCH] lisp/org.el: Add `org-after-note-stored-hook' * lisp/org.el: Add `org-after-note-stored-hook' which is called at the end of the `org-store-log-note' function. * etc/ORG-NEWS: Document the new hook. This change allows customization after a note is taken. One case where it is useful is when one wants to move a task after a state change but cannot do so in `org-after-todo-state-change' because the new state is configured to take a note (with '@' in `org-todo-keywords'). Setting this hook in `org-after-todo-state-change' allows to defer the move after the note is taken and prevents the note to be placed where the task was before being moved. TINYCHANGE --- etc/ORG-NEWS | 4 ++++ lisp/org.el | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 87b72ad12..4b7636765 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -1569,6 +1569,10 @@ optional argument =NEW-HEADING-CONTAINER= specifies where in the buffer it will be added. If not specified, new headings are created at level 1 at the end of the accessible part of the buffer, as before. +*** New hook [[doc::org-after-note-stored-hook][org-after-note-stored-hook]] + +This new hook runs when a note has been stored. + ** Miscellaneous *** =org-crypt.el= now applies initial visibility settings to decrypted entries diff --git a/lisp/org.el b/lisp/org.el index 598b4ca23..64f6d07ee 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -1990,6 +1990,9 @@ Lisp variable `org-state'." :group 'org-todo :type 'hook) +(defcustom org-after-note-stored-hook nil + "Hook which is run after a note was stored") + (defvar org-blocker-hook nil "Hook for functions that are allowed to block a state change. @@ -10845,6 +10848,7 @@ items are State notes." (unless (string-empty-p line) (indent-line-to ind) (insert-and-inherit line)))) + (run-hooks 'org-after-note-stored-hook) (message "Note stored") (org-back-to-heading t)))))) ;; Don't add undo information when called from `org-agenda-todo'. -- 2.44.0