Subject: Re: bug#21730: 25.0.50; Random errors in redisplay--pre-redisplay-functions

From: Philipp Stephani <[email-masked]>
Date: Wed, 14 Sep 2016 17:01:34 +0000

Eli Zaretskii <[email-masked]> schrieb am Sa., 31. Okt. 2015 um 14:34 Uhr:

> > From: Michael Welsh Duggan <[email-masked]>
> > Date: Sat, 31 Oct 2015 09:07:05 -0400
> >
> > > I've changed the (bobp) to (= point 1).  I'll run it for a couple of
> > > weeks and report back.
> >
> > This change seems to have done the trick.  I have not encountered the
> > error in several days.
>
> Thanks for testing.  I pushed the change, and I'm arking this bug as
> done.
>
>
>
This change was  reverted in 76ef52267cf887e3e1aa6d25b3b16dd0601dd459.
It also doesn't seem correct. cursor-sensor--detect is only used in
pre-redisplay-functions, and the documentation of that variable says:
"Hook run just before redisplay.
It is called in each window that is to be redisplayed.  It takes one
argument,
which is the window that will be redisplayed.  When run, the
‘current-buffer’
is set to the buffer displayed in that window."
That means that (bobp) is correct and (= point 1) cannot give a different
result, unless narrowing is in effect (then only bobp is correct).
Given that replacing (bobp) with (= point 1) does solve this bug, the
documentation of pre-redisplay-functions must be incorrect, i.e. the
current buffer is not the buffer of the window passed as argument. I think
the only way how this can happen is that a previous entry in
pre-redisplay-functions has changed the current buffer. Probably the
implementation of redisplay--pre-redisplay-functions should be changed from
(with-current-buffer (window-buffer win)
          (run-hook-with-args 'pre-redisplay-functions win))
to
(run-hook-wrapped 'pre-redisplay-functions
  (lambda (func) (with-current-buffer (window-buffer win)
     (funcall func win)
     nil))
or so.

So we might try the following: Replace redisplay--pre-redisplay-functions
(and indeed, all hooks that document anything about the current buffer) as
above. Then add (cl-assert (eq (current-buffer) (window-buffer window)) to
cursor-sensor--detect and remove  code such as (window-point window),
because that must be equal to (point). WDYT? Or am I misunderstanding
something?