Subject: Re: bug#76186: 31.0.50; (recenter 0) sometimes does not recenter as expected

From: Eli Zaretskii <[email-masked]>
Date: Sun, 16 Mar 2025 17:47:01 +0200

> Cc: [email-masked], [email-masked]
> Date: Sun, 16 Mar 2025 17:20:51 +0200
> From: Eli Zaretskii <[email-masked]>
> 
> > From: Stephen Berman <[email-masked]>
> > Cc: Markus Triska <[email-masked]>,  [email-masked]
> > Date: Sun, 16 Mar 2025 14:20:33 +0100
> > 
> > Although you already said upthread you could not reproduce the issue
> > with the test code I posted, I'd ask you to try again with the attached
> > file, i.e. from the shell:
> > 
> > emacs -Q -l bug#76186.el
> > 
> > This file differs from the one I posted upthread only in that the first
> > occurrence of `(redisplay)' is commented out, so possibly you overlooked
> > that when you tested previously (my explanation of my testing was a bit
> > terse).  With that difference I consistently get the unexpected
> > recentering after a single iteration.  What's more, I've now also
> > reproduced this with emacs-30 running under MS-Windows 10 in a virtual
> > machine (I used emacs-30.1-installer.exe downloaded from a GNU mirror).
> > Perhaps I missed something when debugging this, so if you can also
> > reproduce it, you might be able to debug it better than I did.
> 
> Will do, thanks.

Sigh...  I will look into this when I have time, but from what I've
seen until now, this reproducer is unfortunately not very interesting.
The reason is that it only reproduces the problem if I invoke it
exactly as you show:

  emacs -Q -l bug#76186.el

But if I start "emacs -Q" and then manually load-file bug#76186.el
into the running Emacs, the problem doesn't happen here.  Moreover, if
I make the following small modification of your code, by adding these
3 lines:

  (blink-cursor-mode -1)
  (global-eldoc-mode -1)
  (sit-for 0.1)

just before the call to sometimes-not-recentering, and invoke Emacs
exactly as above, the problem also disappears.  So it looks like at
least one of the reasons in the case that reproduces immediately is
that Emacs starts running the function with the initial GUI frame not
yet finalized (it takes time for the GUI system to initialize and show
a window on the desktop), which is a huge turn-off for me, because
basically we are working with an insufficiently finalized display
arrangement (e.g., who knows what are the frame dimensions known to
the display code at that point?), and that is very uninteresting.

Still, I will try to step through the code when I have time, although
it's unlikely to uncover more than I already said in this thread.