From: Joris Caravati via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
To: Emacs org-mode <emacs-orgmode@gnu.org>
Subject: [PATCH] Add org-after-note-stored-hook
Date: Tue, 02 Jan 2024 23:13:06 +0100 [thread overview]
Message-ID: <m2plyjid8q.fsf@kyon.home> (raw)
[-- Attachment #1: Type: text/plain, Size: 926 bytes --]
Hello,
I've been archiving tasks automatically using
`org-after-todo-state-change-hook' but I've been recently bit with a
note (entering a todo state configured with '@') being placed where the
task was before its archival.
This patch aims to offer a way to defer the archival after the
note is stored. Actually, I am using it like this:
#+begin_src elisp
(add-to-list 'org-after-todo-state-change-hook
(lambda ()
;; States configured without mandatory note
(when (member org-state '("DONE"))
(my/org-roam-archive-to-today))
;; States configured with mandatory note
(when (member org-state '("CANCELLED" "READ"))
(add-to-list 'org-after-note-stored-hook 'my/org-roam-archive-to-today))))
#+end_src
With `my/org-roam-archive-to-today' removing itself from
`org-after-note-stored-hook'.
Hopefully I did not miss an existing way to do this.
Regards,
Joris
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-org-after-note-stored-hook.patch --]
[-- Type: text/x-patch, Size: 2342 bytes --]
From 18de09a3aa08e3d06f180165530cbaeeccdf3ccf Mon Sep 17 00:00:00 2001
From: Joris Caravati <tyx@sula.io>
Date: Tue, 2 Jan 2024 22:50:32 +0100
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 | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c54473f55..911e8ffeb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -742,6 +742,10 @@ Completion is enabled for links to man pages added using ~org-insert-link~:
=C-c C-l man RET emacscl TAB= to get =emacsclient=. Of course, the ~ol-man~
library should be loaded first.
+*** New hook [[doc::org-after-note-stored-hook][org-after-note-stored-hook]]
+
+This new hook runs when a note has been stored.
+
** New functions and changes in function arguments
*** ~org-fold-hide-drawer-all~ is now interactive
diff --git a/lisp/org.el b/lisp/org.el
index 6e6e075b4..fad21d8ba 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1944,6 +1944,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.
@@ -10729,7 +10732,8 @@ items are State notes."
(with-current-buffer (marker-buffer org-log-note-return-to)
(goto-char org-log-note-return-to))
(move-marker org-log-note-return-to nil)
- (when org-log-post-message (message "%s" org-log-post-message)))
+ (when org-log-post-message (message "%s" org-log-post-message))
+ (run-hooks 'org-after-note-stored-hook))
(defun org-remove-empty-drawer-at (pos)
"Remove an empty drawer at position POS.
--
2.38.5
next reply other threads:[~2024-01-02 22:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 22:13 Joris Caravati via General discussions about Org-mode. [this message]
2024-05-09 8:20 ` [PATCH] Add org-after-note-stored-hook Joris Caravati via General discussions about Org-mode.
2024-05-09 11:38 ` Ihor Radchenko
2024-05-11 16:53 ` Ihor Radchenko
2024-05-12 20:12 ` Joris Caravati via General discussions about Org-mode.
2024-05-18 11:26 ` Ihor Radchenko
2024-05-20 19:46 ` Joris Caravati via General discussions about Org-mode.
2024-05-21 11:37 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2plyjid8q.fsf@kyon.home \
--to=emacs-orgmode@gnu.org \
--cc=tyx+org@sula.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).