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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 23 Jan 2022 08:08:10 +0200

> From: Jose A Ortega Ruiz <[email-masked]>
> Date: Sat, 22 Jan 2022 19:13:21 +0000
> Cc: [email-masked]
> 
>      (defun text-with-right-padding (text)
>        (let* ((len (+ (string-pixel-width text) (string-pixel-width " ")))
>               (padding (propertize "-"
>                                    'display
>                                    `(space :align-to (- (+ right right-margin) (,len))))))
>          (concat padding text " ")))
> 
>      (defun custom-set-message (msg)
>        (when msg (concat msg (text-with-right-padding (buffer-name)))))
> 
>      (setq set-message-function #'custom-set-message)
> 
> text-with-right-padding is copied directly from a message in emacs-devel
> and i don't fully understand it (in particular, i cannot make sense of
> the parens around (,len)), but it does its intended job: with
> custom-set-message one sees messages displayed with the current buffer
> name attached and padded to the right.

These customizations cause the echo-area message become too long for a
single screen line.  That in turn causes Emacs to resize the
mini-window to show the echo-area message, and that indirectly causes
the recentering you see.

So I don't think there's anything in this behavior that isn't
expected.  If you want to prevent recentering, try setting
max-mini-window-height to 1, so that mini-windows aren't resized.  (I
didn't try it, though.)  Or just don't ask the echo-area messages to
display so much stuff.