unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jose A Ortega Ruiz <jao@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 53398@debbugs.gnu.org
Subject: bug#53398: 29.0.50; narrow-to-region induces buffer recentering
Date: Sat, 22 Jan 2022 19:13:21 +0000	[thread overview]
Message-ID: <87czkj8tym.fsf@gnus.jao.io> (raw)
In-Reply-To: <87fsphv1t7.fsf@gnus.org>

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	other threads:[~2022-01-22 19:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 20:59 bug#53398: 29.0.50; narrow-to-region induces buffer recentering Jose A Ortega Ruiz
2022-01-21  7:07 ` Eli Zaretskii
2022-01-21 10:08 ` Lars Ingebrigtsen
2022-01-22 19:13   ` Jose A Ortega Ruiz [this message]
2022-01-23  6:08     ` Eli Zaretskii
2022-01-23 12:33       ` Lars Ingebrigtsen
2022-01-23 15:42         ` Jose A Ortega Ruiz
2022-01-23 16:12           ` Lars Ingebrigtsen
2022-01-23 16:34           ` Eli Zaretskii
2022-01-23 17:04             ` Jose A Ortega Ruiz

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://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87czkj8tym.fsf@gnus.jao.io \
    --to=jao@gnu.org \
    --cc=53398@debbugs.gnu.org \
    --cc=larsi@gnus.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://git.savannah.gnu.org/cgit/emacs.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).