emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Joris Caravati <tyx+org@sula.io>
Cc: emacs-orgmode list <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] Add org-after-note-stored-hook
Date: Sat, 18 May 2024 11:26:21 +0000	[thread overview]
Message-ID: <87ikzbtl7m.fsf@localhost> (raw)
In-Reply-To: <m25xviokli.fsf@kyon.home>

[-- Attachment #1: Type: text/plain, Size: 1485 bytes --]

Joris Caravati <tyx+org@sula.io> writes:

>> An easier way would be forcing note earlier by calling
>> `org-add-log-note' from your hook.
>
> I remember trying that before adding the hook (and I tried again today)
> but the problem with adding the note directly is that I only seem to
> manage storing the note where the task was before being archived,
> eg. with this (or any variants I could think of while making sense of
> what note functions do):
>
> #+begin_src elisp
>   (when (member (plist-get properties ':to) '("CANCELLED" "READ"))
>     (org-add-log-note)
>     (my/org-roam-archive-to-today))
> #+end_src
>
> which I find logical, since `org-store-log-note' is only called after
> =C-c C-c= is pressed, whereas the archival function is called just after
> the note buffer is created. So I still struggle to see how I could do
> without the hook (maybe if the archival function would return the
> position of the task after moving it, but that seems more complicated
> than just using the hook).

Right. Yet, using a hook is still not ideal - what if you configure todo
keywords to not store note at all in future? Then, the hook will never
be executed or will be executed at the time you don't expect.

Note-taking mechanisms is generally tricky - it is schedule-based,
with note being taken after the current command is executed.

I think I know how to make it possible for the note to be taken at the
right place after subtree archival. May you try the attached patch?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-save-markers-in-region-Store-log-note-marker.patch --]
[-- Type: text/x-patch, Size: 1561 bytes --]

From 2e24b634275c61ab913851b11d8b8f053f0f88f0 Mon Sep 17 00:00:00 2001
Message-ID: <2e24b634275c61ab913851b11d8b8f053f0f88f0.1716030861.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 18 May 2024 13:12:50 +0200
Subject: [PATCH] org-save-markers-in-region: Store log note marker

* lisp/org.el (org-save-markers-in-region): Store
`org-log-note-marker' when storing and reinstalling Org markers.

This change automatically handles note taken after refiling/archiving
without trying to place the note in place of the moved
subtree/heading.

Link: https://orgmode.org/list/m2plyjid8q.fsf@kyon.home
---
 lisp/org.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index 8d921f11e..bec8a87a4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7365,6 +7365,7 @@ (defvar org-markers-to-move nil
 Those markers are stored together with their positions relative to
 the start of the region.")
 
+(defvar org-log-note-marker) ; defined later
 (defun org-save-markers-in-region (beg end)
   "Check markers in region.
 If these markers are between BEG and END, record their position relative
@@ -7374,6 +7375,7 @@ (defun org-save-markers-in-region (beg end)
 buffer.  After re-insertion, `org-reinstall-markers-in-region' must be
 called immediately, to move the markers with the entries."
   (setq org-markers-to-move nil)
+  (org-check-and-save-marker org-log-note-marker beg end)
   (when (featurep 'org-clock)
     (org-clock-save-markers-for-cut-and-paste beg end))
   (when (featurep 'org-agenda)
-- 
2.45.1


[-- Attachment #3: Type: text/plain, Size: 1096 bytes --]


>> It will probably be better to run such new hooks right before (message "Note stored")
>> in `org-store-log-note'.
>
> A patch modified to match the suggested location for the `run-hooks' is
> attached.

Thanks!
Applied, onto main, with amendments.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f3e306c73
I added necessary keywords to the defcustom, changed the docstring to
state explicitly that the point is at the note taken when running a
hook, and changed the NEWS entry to (1) not have a link - we usually do
not do it; (2) moved it under appropriate heading.
I also removed your example from the commit message as it is not the
best illustration (see my considerations above).
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f3e306c73

You are now listed among Org mode contributors.
https://git.sr.ht/~bzg/worg/commit/3093b569

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

  reply	other threads:[~2024-05-18 11:25 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
2024-05-12 20:12   ` Joris Caravati via General discussions about Org-mode.
2024-05-18 11:26     ` Ihor Radchenko [this message]
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=87ikzbtl7m.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 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).