GNU bug report logs - #18618
25.0.50; `window-end win t` produces erroenous result with `window-scroll-functions` hook.

Previous Next

Package: emacs;

Reported by: Keith David Bershatsky <esq <at> lawlist.com>

Date: Fri, 3 Oct 2014 01:08:02 UTC

Severity: normal

Tags: notabug

Found in version 25.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 18618 <at> debbugs.gnu.org, esq <at> lawlist.com
Subject: bug#18618: 25.0.50; `window-end win t` produces erroenous result with `window-scroll-functions` hook.
Date: Sat, 29 May 2021 09:24:23 +0300
tags 18618 notabug
close 18618
thanks

> From: Lars Ingebrigtsen <larsi <at> gnus.org>
> Date: Sat, 29 May 2021 05:37:18 +0200
> Cc: 18618 <at> debbugs.gnu.org
> 
> Keith David Bershatsky <esq <at> lawlist.com> writes:
> 
> > Steps to reproduce the issue.
> >
> > 1.  Create a function that reports (e.g., a message) the value of `(window-end win t)` and attach that function to the `window-scroll-functions` hook.
> >
> > 2.  Open a long file in either fundamental-mode or text-mode.
> >
> > 3.  M-x end-of-buffer
> >
> > 4.  M-x beginning-of-buffer
> >
> > The result of step 4 reports an erroneous window-end value that is at
> > the very end of the buffer, instead of the correct window-end (i.e.,
> > which is much closer to the beginning of the buffer).
> 
> (I'm going through old bug reports that unfortunately got no response at
> the time.)
> 
> This problem is still present in Emacs 28.  Here's an easier test case:
> 
> (defun foo (win _)
>   (message "End: %s" (window-end win t))
>   nil)
> (push 'foo window-scroll-functions)
> 
> This reports the same number in both 3) and 4) when transient-mark-mode
> is switched on, but not when it's off.  It's also correct if that mode
> is on, and the region is active.
> 
> I haven't tried to debug further -- perhaps it's immediately obvious to
> somebody what could be causing this glitch?

This isn't supposed to work.  The doc string of window-end says:

  Return position at which display currently ends in WINDOW.
  WINDOW must be a live window and defaults to the selected one.
  This is updated by redisplay, when it runs to completion.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

By contrast, window-scroll-functions is a hook run by the display
engine in the middle of redisplaying a window, when the display engine
concludes that it is about to scroll the window.  At that point, the
window's redisplay is by definition not complete yet, so this can only
work by chance.  Which is why window-scroll-functions' doc string says
explicitly this doesn't work:

  Note that the value of ‘window-end’ is not valid when these functions are
  called.

So Emacs behaves here as designed and as documented, and I'm therefore
closing this bug.




This bug report was last modified 3 years and 361 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.