Subject: Re: bug#32850: 27.0.50; window-swap-states doesn't swap window prev/next-buffers

From: Juri Linkov <[email-masked]>
Date: Sun, 30 Sep 2018 23:00:52 +0300

>> Actually not to change the course of history, but keep it together with
>> its window, or rather an imaginary window - when using window-swap-states,
>> it looks like windows are swapped: since window's buffer is moved
>> to a new location, the feeling is that the whole window is moved to
>> a new place, because what defines a window is its state more than
>> a location on the screen, so to not break the history of buffers
>> in the window, prev/next buffers should be swapped as well, to
>> keep the chain of buffers: prev-buffers - current buffer - next-buffer,
>> so 'C-x <C-left>' (previous-buffer) and 'C-x <C-right>' (next-buffer)
>> will navigate in the preserved history in the same order it navigated
>> in the old window location.
>
> Swapping the states of two windows does not swap their identities.
> That is, the windows themselves remain where they are, only their
> buffers change.  If we changed their previous and next buffers, we
> would tell a lie.  And we might introduce some slight inconsistency
> because the previous/next buffers of a window are no more elements of
> the 'buffer-list' of their respective frames when the windows are on
> different frames.  I doubt that has any consequences, though ...

If a window buffer is part of the window state and not window identity,
then prev/next-buffers should be swapped together with the window buffer
as part of the window state, and not window identity.

IOW, the window buffer is inseparable from the list of prev/next-buffers.
For example, in such sequences of buffers:

  *info*<1> *info*<2> *info*<3> *info*<4> *info*<5>
  prev buffers      current buffer     next buffers

and

  *grep*<1> *grep*<2> *grep*<3> *grep*<4> *grep*<5>
  prev buffers      current buffer     next buffers

window-swap-states currently breaks the list of related buffers,
e.g. after swapping only the window buffers, but not window
prev/next-buffers:

  *info*<1> *info*<2> *grep*<3> *info*<4> *info*<5>
  prev buffers      current buffer     next buffers

and

  *grep*<1> *grep*<2> *info*<3> *grep*<4> *grep*<5>
  prev buffers      current buffer     next buffers

'C-x <C-left>' and 'C-x <C-right>' become broken.

> So if you want this change, please provide an option say
> 'window-swap-states-swap-history' and, if that is non-nil, support the
> changes from your 'rotate-window-buffers'.

Forget 'rotate-window-buffers', it's a bad name and I want to throw it away.
What I need is for Emacs to provide a consistent behavior by default.