Subject: bug#53398: 29.0.50; narrow-to-region induces buffer recentering

From: Eli Zaretskii <[email-masked]>
Date: Fri, 21 Jan 2022 09:07:52 +0200

> From: Jose A Ortega Ruiz <[email-masked]>
> Date: Thu, 20 Jan 2022 20:59:25 +0000
> 
>        (defun message-kill-to-signature (&optional arg)
>           "Kill all text up to the signature.
>         If a numeric argument or prefix arg is given, leave that number
>         of lines before the signature intact."
>           (interactive "P" message-mode)
>           (save-excursion
>             (save-restriction
>               (let ((point (point)))
>         	(narrow-to-region point (point-max))  ;;;;;; <------------------------
>         	(message-goto-signature)
>         	(unless (eobp)
>         	  (if (and arg (numberp arg))
>         	      (forward-line (- -1 arg))
>         	    (end-of-line -1)))
>         	(unless (= point (point))
>         	  (kill-region point (point))
>         	  (unless (bolp)
>         	    (insert "\n")))))))
> 
> so i am (wild) guessing that the spurious recenter might be related with
> save-restriction workings in combination with narrow, but i don't really
> know what i'm talking about :)

Any chance of having a reproduction recipe that is simpler and
preferably doesn't include message.el at all?  IOW, if your guess is
correct, and the problem is inside narrow-to-region, we shouldn't need
this elaborate setup to show the issue, right?  Can you show such a
recipe?

Also, you say "previous behavior was", but when did you see that
previous behavior and in what Emacs version?

> The only variable related to scroll i can see changed from its default
> value in my config is scroll-preserve-screen-position, which i set to
> 'always, but changing its value doesn't affect the behaviour above in
> any way.

So you are saying that this recentering doesn't happen in "emacs -Q",
even if you do invoke that Message mode command?  If so, please try
to find which of your customizations do affect it.