all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Joris Caravati <tyx+org@sula.io>
Cc: Emacs org-mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] Add org-after-note-stored-hook
Date: Sat, 11 May 2024 16:53:16 +0000	[thread overview]
Message-ID: <8734qouw77.fsf@localhost> (raw)
In-Reply-To: <m2plyjid8q.fsf@kyon.home>

Joris Caravati via "General discussions about Org-mode."
<emacs-orgmode@gnu.org> writes:

> 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.

An easier way would be forcing note earlier by calling
`org-add-log-note' from your hook.

Although, removing heading from inside
`org-after-todo-state-change-hook' is a bad idea - Org mode does not
expect the heading to disappear from under the cursor when this hook is
executed. I recommend using `org-trigger-hook' instead.

So, your patch does not seem necessary to achieve what you want.

That said, it does make sense to add a hook after storing a log note,
but not at the very end, when point may not be at the note stored:

>    (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))

This will leave point in buffer where the note was invoked. For example,
in agenda buffer. I doubt that the users of this hook will expect such a
thing.

It will probably be better to run such new hooks right before (message "Note stored")
in `org-store-log-note'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  parent reply	other threads:[~2024-05-11 16:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 22:13 [PATCH] Add org-after-note-stored-hook Joris Caravati via General discussions about Org-mode.
2024-05-09  8:20 ` Joris Caravati via General discussions about Org-mode.
2024-05-09 11:38   ` Ihor Radchenko
2024-05-11 16:53 ` Ihor Radchenko [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8734qouw77.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.