[PATCH] emacs: notmuch-tree: mark the initial message at point as read

classic Classic list List threaded Threaded
4 messages Options
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

[PATCH] emacs: notmuch-tree: mark the initial message at point as read

When moving between message in a tree or show buffer, the message at
point is marked as read.  Likewise when creating such a buffer, then
the message that is initially at point is supposed to be marked as
read as well.

The latter worked for `notmuch-show' but not for `notmuch-tree'.
Press "RET" or "M-RET" in a search buffer to observe these behaviors.

In both cases the marking is supposed to be done by the function
`notmuch-show-command-hook'.  In the case of `notmuch-show' that
function is added directly to `post-command-hook'.

`notmuch-tree' instead adds the function `notmuch-tree-command-hook'
to `post-command-hook' and that calls `notmuch-show-command-hook',
in the respective show buffer, but of course only if that exists.

Because the tree buffer is created asynchronously, the show buffer
doesn't exist yet by the time the `post-command-hook' is run, so
we have to explicitly run `notmuch-tree-command-hook' once the
show buffer exists.

The show buffer is created when `notmuch-tree-goto-and-insert-msg'
calls `notmuch-tree-show-message-in'.  `notmuch-tree-process-filter'
is what finally brings us here.
---
 emacs/notmuch-tree.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 13007a13..d9265fd5 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -949,7 +949,8 @@ (defun notmuch-tree-goto-and-insert-msg (msg)
       (goto-char (point-max))
       (forward-line -1)
       (when notmuch-tree-open-target
- (notmuch-tree-show-message-in)))))
+ (notmuch-tree-show-message-in)
+ (notmuch-tree-command-hook)))))
 
 (defun notmuch-tree-insert-tree (tree depth tree-status first last)
   "Insert the message tree TREE at depth DEPTH in the current thread.
--
2.30.1
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] emacs: notmuch-tree: mark the initial message at point as read

On Tue, Feb 16 2021, Jonas Bernoulli wrote:

> When moving between message in a tree or show buffer, the message at
> point is marked as read.  Likewise when creating such a buffer, then
> the message that is initially at point is supposed to be marked as
> read as well.
>
> The latter worked for `notmuch-show' but not for `notmuch-tree'.
> Press "RET" or "M-RET" in a search buffer to observe these behaviors.
>
> In both cases the marking is supposed to be done by the function
> `notmuch-show-command-hook'.  In the case of `notmuch-show' that
> function is added directly to `post-command-hook'.
>
> `notmuch-tree' instead adds the function `notmuch-tree-command-hook'
> to `post-command-hook' and that calls `notmuch-show-command-hook',
> in the respective show buffer, but of course only if that exists.
>
> Because the tree buffer is created asynchronously, the show buffer
> doesn't exist yet by the time the `post-command-hook' is run, so
> we have to explicitly run `notmuch-tree-command-hook' once the
> show buffer exists.
>
> The show buffer is created when `notmuch-tree-goto-and-insert-msg'
> calls `notmuch-tree-show-message-in'.  `notmuch-tree-process-filter'
> is what finally brings us here.

Long message, small change (which is good). I try to understand
whether adding notmuch-tree-command-hook to post-command-hook in
notmuch-tree.el (not in this change) actually have any effect.

Tomi

> ---
>  emacs/notmuch-tree.el | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
> index 13007a13..d9265fd5 100644
> --- a/emacs/notmuch-tree.el
> +++ b/emacs/notmuch-tree.el
> @@ -949,7 +949,8 @@ (defun notmuch-tree-goto-and-insert-msg (msg)
>        (goto-char (point-max))
>        (forward-line -1)
>        (when notmuch-tree-open-target
> - (notmuch-tree-show-message-in)))))
> + (notmuch-tree-show-message-in)
> + (notmuch-tree-command-hook)))))
>  
>  (defun notmuch-tree-insert-tree (tree depth tree-status first last)
>    "Insert the message tree TREE at depth DEPTH in the current thread.
> --
> 2.30.1
> _______________________________________________
> notmuch mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] emacs: notmuch-tree: mark the initial message at point as read

> I try to understand whether adding notmuch-tree-command-hook to
> post-command-hook in notmuch-tree.el (not in this change) actually
> have any effect.

You're right, that's unnecessary, and it gets worse.

`notmuch-tree-command-hook' is unnecessary too and if it weren't,
then it would fail because its added to the buffer-local value of
`post-command-hook', but that buffer is not the current buffer
when the hook is run.

Using `post-command-hook' in any form for this is questionable in the
first place.  The idiomatic approach would be to use the `point-entered'
text property hook.  Or `notmuch-tree-{previous,next}-message' could
just do the marking explicitly.

It's also not okay that `notmuch-tree-show-message-in' keeps recreating
the window.

`notmuch-show-command-hook' forces redisplay to update values that pass
along, but don't and shouldn't use.  There is more than one function to
mark a message as read and they don't all end up doing the same thing.

What effectively does the marking is

(defun notmuch-tree-show-message-in ()
  ...
  (when notmuch-show-mark-read-tags
    (notmuch-tree-tag-update-display notmuch-show-mark-read-tags))
  ...)

I am going to refactor this mess, but that will take a while.

     Jonas
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Jonas Bernoulli Jonas Bernoulli
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] emacs: notmuch-tree: mark the initial message at point as read

Hm, when no tree buffer is involved, then `notmuch-show-command-hook'
probably is required.  Anyway, there seems to be some undead code and
rethinking all this would be a good idea.
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]