Subject: bug#75352: 29.4; end-of-buffer is buggy after set-mark-command with some fonts

From: Vincent Lefevre <[email-masked]>
Date: Sun, 5 Jan 2025 23:55:26 +0100

On 2025-01-04 22:00:36 +0200, Eli Zaretskii wrote:
> > Date: Sat, 4 Jan 2025 20:25:04 +0100
> > From: Vincent Lefevre <[email-masked]>
> > Cc: [email-masked]
> > 
> > On 2025-01-04 16:36:20 +0200, Eli Zaretskii wrote:
> > > > With the Noto Mono font and a file with some Japanese characters
> > > > (I suspect that the reason of the need of such characters is that
> > > > they slightly modify the cell height, and the font can change by
> > > > just moving the cursor; see below), after set-mark-command (C-SPC),
> > > > end-of-buffer (M->) does not go to the end of the buffer.
> > > 
> > > end-of-buffer scrolls the window to show EOB not-quite-at-the-bottom
> > > of the window.  So what you describe can happen with unusual fonts.
> > > 
> > > Why is that a problem?
> > 
> > The main problem is not a display problem, but the fact that the
> > cursor (point) is not at the end of the buffer.
> 
> My point is that M-> doesn't guarantee that.

For the end user, this is very surprising (even with strange font
settings, something that is not documented, AFAIK, and for which
one gets no errors or warnings).

> > I've attached a screenshot to show what I get. The cursor (not visible
> > on the screenshot) is just below the yellow area, on the first column.
> > Note that the last line is only partly visible: one just has the top
> > of the "x".
> 
> Didn't you say that point then moves back into the viewport, and is
> set to line 35?  Or what am I missing.

I just said that the cursor was on line 35, which is the line that is
just below the yellow area (unless Emacs gives incorrect information
on the line number).

> > > > $ emacs -Q --eval="(set-fontset-font t 'unicode (font-spec :name \"Noto Mono\"))" file
> > > 
> > > This set-fontset-font setting is not a good idea: it tells Emacs that
> > > the named font can display _any_ Unicode character, which is usually
> > > not true: almost all fonts support only a subset of Unicode.
> > 
> > This was taken from https://emacs.stackexchange.com/q/17205/29118
> > (the goal was to prevent a fallback to a font with different metrics,
> > breaking column alignments; well, at least this was working for
> > math characters, IIRC).
> 
> That is not how you do that.  You should instead use set-fontset-font
> to specify a particular suitable font for the 'mathematical' script.

I want something that would be applied for every available glyphs,
so that the display looks somewhat typographically consistent.

Note that the line I gave was just for a simple example. In my actual
settings, I provide other fonts: DejaVu Sans Mono and DejaVu Sans.
Since DejaVu Sans provides a lot of glyphs for various scripts,
I had initially thought that this would be complete for my needs
(though DejaVu Sans has the drawback to change the width of the
cells).

[...]
> And yes, if the font changes, what was inside the viewport can become
> outside, and that could cause Emacs move point.

IMHO, in such a case (when used with end-of-buffer), Emacs should scroll,
keeping the point position.

-- 
Vincent Lefèvre <[email-masked]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)