Subject: Re: bug#51590: follow-mode is broken with header-line and tab-line

From: Alan Mackenzie <[email-masked]>
Date: Sat, 6 Nov 2021 11:50:48 +0000

Hello, Eli.

On Sat, Nov 06, 2021 at 09:00:44 +0200, Eli Zaretskii wrote:
> > Date: Fri, 5 Nov 2021 21:45:32 +0000
> > Cc: Juri Linkov <[email-masked]>, [email-masked]
> > From: Alan Mackenzie <[email-masked]>

> > Yes.  There's a bug in posn-at-x-y, in that either the function or the
> > documentation is wrong.

> It isn't a bug, it is a deliberately implemented behavior.  See also
> bug#15783.

> > The doc says, rather unhelpfully, "By default, X and Y are relative to
> > [the] text area of the selected window.".  What does "[the] text area"
> > mean?

> In the ELisp manual, type "i text area of a window RET" and read there.

> I've now made changes there to make clear that the header-line and the
> tab-line _are_ included in the text area.

I'm just confused at the moment, after having spent several hours trying
to sort things out in my head.

I think "window body" and "window text area" mean the same thing, but
I'm not sure.

The picture in elisp page "Basic Windows" seems to show "window body
height" as NOT including the header line or tab line.  That picture
seems to show the header line as being ABOVE the text area, not part of
it.

The current implementation of posn-at-x-y includes the header line in
its Y coordinate, BUT NOT THE TAB LINE.  I think this is a bug.

window-inside-pixel-edges, aka (window-edges &optional WINDOW BODY
ABSOLUTE PIXELWISE) with BODY and PIXELWISE non-nil, returns (according
to the elisp page) "the edges of WINDOW's body".  This "body" DOES NOT
include the tab line or the header line.  When I run the function on an
info page with tab-bar-mode enabled in my tty I get:

    (0 2 240 65)
       ^

..  This would appear to contradict the above notion of "body" as
including the header and tab lines.

It seems to me that we really need two distinct terms here, one for the
text area of the buffer including the header and tab lines, and another
for the "pure" text area without those lines.  Maybe something like
"extended body" vs. "text area", or something like that.

> > In posn-at-x-y, "the text area" _INCLUDES_ THE HEADER LINE.

> Yes.  As it should.

OK.

> > It would appear this behaviour of posn-at-x-y is also in Emacs 27.2.  It
> > would probably be catastrophic to fix posn-at-x-y, since so many
> > programs will have compensated for this bug.  So, we should probably fix
> > the doc of the function.

> Done on the emacs-28 branch.

Thanks!

> > But we can fix follow-calc-win-end, by replacing the form at 2 with:

> >     (last-line-pos (posn-point (+ (posn-at-x-y 0 (1- ht) win)
> >                                   (window-header-line-height win))))

Actually, that's not right.  It should be

(last-line-pos (posn-point (posn-at-x-y 
                            0 (+ (1- ht) (window-header-line-height
			                  win)))))
, but that's a mere detail.  It appears to solve much of Juri's bug.

> What about the tab-line (which AFAIU was the trigger for this bug)?

Yes, that needs to be incorporated, too.

The other hunk of Juri's patch, in follow-scroll-down, is needed, but I
don't think it's quite right when combined with my suggestion for
follow-calc-win-end above.

> > And I think we (probably me ;-) should go through the elisp manual and
> > doc strings replacing vague phrases like "the text area of the window"
> > with explicit descriptions involving "the header line", etc.

> That'd be going overboard.  We could place a cross-reference in some
> of those places to the "Frame Layout" node, though.  Suggestions for
> such places are welcome.

OK.  But I think there's confusion in the manual and doc strings, and
even the code, and that it's not just me.

-- 
Alan Mackenzie (Nuremberg, Germany).