bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Jose A Ortega Ruiz
Subject: bug#53398: 29.0.50; narrow-to-region induces buffer recentering
Date: Sat, 22 Jan 2022 19:13:21 +0000

On Fri, Jan 21 2022, Lars Ingebrigtsen wrote:

> Jose A Ortega Ruiz <jao@gnu.org> writes:
>
>>   - start composing a message, e.g. a reply, so that the current window
>>     shows only a portion of the buffer, and not the signature
>>
>>   - with point somewhere on the lower half of the window, C-c C-z
>>     (message-kill-to-signature)
>>
>>   - the text from point to signature is deleted alright, but the buffer
>>     contents is recentered, as if one had invoked recenter /twice/, so
>>     the window gets scrolled up.  previous behaviour was that the window
>>     wouldn't scroll at all, one would just see the contents of the
>>     buffer below point change (and show the signature).
>
> I've tried reproducing this in Emacs 29 with various contents in the
> buffer and with various window sizes, but `C-c C-z' doesn't seem to do
> any recentring for me.
>
> Can you create a test recipe, starting from "emacs -Q", that
> demonstrates the problem?

Yes, i finally managed to create a recipe.  It's kind of exotic and
involves setting a custom set-message-function that adds properties to
the displayed message (!).

More concretely, with emacs -Q, eval this code:

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

That triggers the recentering for me.  I just create a file with a bunch
of lines containing, e.g.

--8<---------------cut here---------------start------------->8---
slkdfjsldkfj
slkdfjsldkfj
slkdfjsldkfj
slkdfjsldkfj

slkdfjsldkfj
slkdfjsldkfj
slkdfjsldkfj
slkdfjsldkfj

;; ^^ repeat the above a bunch of times so that you don't
;; see the signature part below

-- 
slkdfjsldkfj
slkdfjsldkfj
slkdfjsldkfj
slkdfjsldkfj
--8<---------------cut here---------------end--------------->8---

Then load-library message, just move somewhere in the buffer without the
signature being visible and M-x message-kill-to-signature.

In my real case, i have a set-message-function that adds a varied amount
of extra status information aligned to the right.  I have a previous
version with adds the padding by computing manually the needed width and
simply concatenating in the middle with format and width spec, no fancy
'display properties.  With that function, the recentering does not
happen.

Hope this helps!

Cheers,
jao
-- 
What sane person could live in this world and not be crazy?
  -Ursula K. Le Guin, author





reply via email to

[Prev in Thread] Current Thread [Next in Thread]