Subject: bug#4812: 23.1.50; delete-window move point to the wrong window

From: martin rudalics <[email-masked]>
Date: Tue, 27 Oct 2009 10:46:39 +0100

> A frame is setup as follows with point in window 1.
 >
 >     +------------------+----------+
 >     |                  |          |
 >     |        1         |     2    |
 >     |                  |          |
 >     |                  |          |
 >     |------------------+----------+
 >     |                  |          |
 >     |        4         |     3    |
 >     |                  |          |
 >     |                  |          |
 >     +------------------+----------+
 >
 >
 > Assume each window is displaying different buffers. If I move point to
 > window 4 and `M-x delete-window', the point is moved to window 2.

When describing window-layouts please alway describe the sequence of
events that got you there.  In the layout above it's not clear whether
the initial split was a horizontal one or a vertical one.

 > It seems to me it is more intuitive if the point is remained in the
 > window that is enlarged due to delete-window, in this case, window 1.

I suppose you refer to the case where window 4 is selected at the time
you delete it and want window 1 get selected thereafter.  `point' is
never changed by deleting windows.

The situation is not that simple, unfortunately.  In your first bug
report you talked about quitting the calc window.  In that case, I
suppose, you'd rather want to select the window that was selected at the
time you invoked calc (unless another window got selected in between).
So suppose you're in window 1, invoke calc which splits window 4, and
quit calc, you'd rather go back to window 1 instead of window 4.  But
you might have, in between, selected window 3 so quitting calc should
get you back to window 3.  Handling all possible scenarios (including
those that create/delete other windows in between) is tricky.

Also, note that in a configuration like

  -----------
|  1  |  2  |
|-----------|
|     3     |
  -----------

deleting window 3 will enlarge windows 1 and 2 so you still need another
strategy to decide which window should get selected.

martin