unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Pengji Zhang <me@pengjiz.com>
To: notmuch@notmuchmail.org
Cc: Damien Cassou <damien@cassou.me>
Subject: Re: [PATCH] emacs/show: Only recenter interactively
Date: Sun, 15 Dec 2024 17:33:25 +0800	[thread overview]
Message-ID: <87o71dguje.fsf@pengjiz.com> (raw)
In-Reply-To: <20241123151601.16201-2-damien@cassou.me>

Damien Cassou <damien@cassou.me> writes:

> Several notmuch-show commands recenter the window by calling
> `notmuch-show-message-adjust`. This is fine when these commands are
> called interactively but not when used inside non-interactive
> functions. An example of the problem is when `which-func-mode` is
> activated: each time the user moves the point to a different line, the
> window is recentered. This happens because `which-func-mode` calls
> `imenu` which calls `notmuch-show-imenu-prev-index-position-function`
> which calls `notmuch-show-previous-message` which recenters the
> window.
>
> This patch makes sure that commands only invoke
> `notmuch-show-message-adjust` when they have been called
> interactively.

I think this is a reasonable change. Thanks! I am not a maintainer, but
here is my review of your patch.

> ---
>  emacs/notmuch-show.el | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 14e3c698..c08375b8 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -1535,7 +1535,7 @@ (defun notmuch-show-goto-message (msg-id)
>  		   until (not (notmuch-show-goto-message-next)))
>      (goto-char (point-min))
>      (message "Message-id not found."))
> -  (notmuch-show-message-adjust))
> +  (when (interactive-p) (notmuch-show-message-adjust)))

'notmuch-show-goto-message' is not a command. So it is always called
non-interactively.

>  (defun notmuch-show-apply-state (state)
>    "Apply STATE to the current buffer.
> @@ -2052,7 +2052,7 @@ (defun notmuch-show-rewind ()
>        (when (<= (count-screen-lines (window-start) start-of-message)
>  		next-screen-context-lines)
>  	(goto-char (notmuch-show-message-top))
> -	(notmuch-show-message-adjust))
> +	(when (interactive-p) (notmuch-show-message-adjust)))
>        ;; Move to the top left of the window.
>        (goto-char (window-start)))
>       (t
> @@ -2109,7 +2109,7 @@ (defun notmuch-show-next-message (&optional pop-at-end)
>  thread, navigate to the next thread in the parent search buffer."
>    (interactive "P")
>    (if (notmuch-show-goto-message-next)
> -      (notmuch-show-message-adjust)
> +      (when (interactive-p) (notmuch-show-message-adjust))
>      (if pop-at-end
>  	(notmuch-show-next-thread)
>        (goto-char (point-max)))))
> @@ -2120,7 +2120,7 @@ (defun notmuch-show-previous-message ()
>    (if (= (point) (notmuch-show-message-top))
>        (notmuch-show-goto-message-previous)
>      (notmuch-show-move-to-message-top))
> -  (notmuch-show-message-adjust))
> +  (when (interactive-p) (notmuch-show-message-adjust)))
>  
>  (defun notmuch-show-next-open-message (&optional pop-at-end)
>    "Show the next open message.
> @@ -2134,7 +2134,7 @@ (defun notmuch-show-next-open-message (&optional pop-at-end)
>      (while (and (setq r (notmuch-show-goto-message-next))
>  		(not (notmuch-show-message-visible-p))))
>      (if r
> -	(notmuch-show-message-adjust)
> +	(when (interactive-p) (notmuch-show-message-adjust))
>        (if pop-at-end
>  	  (notmuch-show-next-thread)
>  	(goto-char (point-max))))
> @@ -2147,7 +2147,7 @@ (defun notmuch-show-next-matching-message ()
>      (while (and (setq r (notmuch-show-goto-message-next))
>  		(not (notmuch-show-get-prop :match))))
>      (if r
> -	(notmuch-show-message-adjust)
> +	(when (interactive-p) (notmuch-show-message-adjust))
>        (goto-char (point-max)))))
>  
>  (defun notmuch-show-open-if-matched ()
> @@ -2176,7 +2176,7 @@ (defun notmuch-show-previous-open-message ()
>  		  (notmuch-show-goto-message-previous)
>  		(notmuch-show-move-to-message-top))
>  	      (not (notmuch-show-message-visible-p))))
> -  (notmuch-show-message-adjust))
> +  (when (interactive-p) (notmuch-show-message-adjust)))
>  
>  (defun notmuch-show-view-raw-message ()
>    "View the original source of the current message."

'interactive-p' is a long obsolete function. I think we should at least
use 'called-interactively-p'. Even better, as suggested in the
documentation of 'called-interactively-p', we may add an optional
argument and make use of the interactive form. E.g.,

--8<---------------cut here---------------start------------->8---
-(defun notmuch-show-previous-open-message ()
+(defun notmuch-show-previous-open-message (&optional adjust)
   "Show the previous open message."
-  (interactive)
+  (interactive (list t))
   (while (and (if (= (point) (notmuch-show-message-top))
 		  (notmuch-show-goto-message-previous)
 		(notmuch-show-move-to-message-top))
 	      (not (notmuch-show-message-visible-p))))
-  (notmuch-show-message-adjust))
+  (when adjust (notmuch-show-message-adjust)))
--8<---------------cut here---------------end--------------->8---

Best,
Pengji

  parent reply	other threads:[~2024-12-15  9:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-23 15:16 [PATCH] emacs/show: Only recenter interactively Damien Cassou
2024-12-15  8:12 ` Damien Cassou
2024-12-15  9:33 ` Pengji Zhang [this message]
2024-12-15 12:47   ` Damien Cassou
2024-12-17 11:44     ` Pengji Zhang
2024-12-17 19:32       ` Damien Cassou

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://notmuchmail.org/

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

  git send-email \
    --in-reply-to=87o71dguje.fsf@pengjiz.com \
    --to=me@pengjiz.com \
    --cc=damien@cassou.me \
    --cc=notmuch@notmuchmail.org \
    /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://yhetil.org/notmuch.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).