Subject: bug#18545: 24.4.50: Bug - forward-line inside with-selected-window

From: Stefan Monnier <[email-masked]>
Date: Fri, 26 Sep 2014 15:32:11 -0400

>> >> Why does
>> >> (with-selected-window (get-buffer-window "*Completions*")
>> >> (recenter 5))
>> >> require an explicit call to wset_redisplay from recenter, whereas
>> >> (with-selected-window (get-buffer-window "*Completions*")
>> >> (forward-line 1))
>> >> doesn't need an explicit call to wset_redisplay (or bset_redisplay) from
>> >> forward-line?
>> > I think that's because forward-line moves point, while recenter
>> > doesn't.
>> But I don't see why moving point would help: calling wset_redisplay
>> should only change the fact that this window is considered for
>> redisplay
> There are redisplay optimizations that don't depend on whether we
> consider a window for redisplay; see around line 13700 in xdisp.c from
> emacs-24.  You will see a little ways below that place that we test
> point against its recorded value in w->last_point, for example.

Right, but these are only for the current-buffer/selected-window,
whereas the example modifies another window (and another buffer), so
they first need to be considered (via [bwf]set_redisplay) before
anything else will look at them.

>> so if it's needed for the recenter case, that means that
>> without it, the window would not be considered at all
> 'with-selected-window makes' the offending window selected, and the
> selected window is always considered for redisplay, right?

No.  If it were the wset_redisplay you added would have been a no-op.

Oh, wait I see it now.  We do test if point changed, in
redisplay_window:15965:

  if (!just_this_one_p
      && REDISPLAY_SOME_P ()
      && !w->redisplay
      && !f->redisplay
      && !buffer->text->redisplay
      && BUF_PT (buffer) == w->last_point)
    return;

So indeed changing point ends up doing the moral equivalent of bset_redisplay.

        Stefan