Subject: Re: bug#32790: 27.0.50; point jumps unexpectedly after delete-window

From: martin rudalics <[email-masked]>
Date: Thu, 27 Sep 2018 20:44:23 +0200

> I think we need exactly the same customization as we created for
 > compare-windows-get-window-function, but instead of finding a window to
 > compare, we need to find a window to select after deleting the
 > selected window.
 >
 >    (defcustom compare-windows-get-window-function
 >      'compare-windows-get-recent-window
 >      "Function that provides the window to compare with."
 >      :type '(choice
 >              (function-item :tag "Most recently used window"
 >                             compare-windows-get-recent-window)
 >              (function-item :tag "Next window"
 >                             compare-windows-get-next-window)
 >              (function :tag "Your function"))
 >      :group 'compare-windows
 >      :version "25.1")
 >
 > I suppose that for the option "Next window" the window next to the
 > deleted window is its sibling that will get its space after
 > deletion, right?

Not usually.  'delete-window' prefers the left sibling because that's
the classic way to work with windows: The new window appears on the
right of or below the window split.  Deleting the new window "returns"
its space to the window on the left or above, if that exists.  The
"next window" of any window OTOH is preferably its right sibling, if
that exists, or something "further down" in the window tree.

So first of all we have to decide which window should get the space
when we delete a window and make that customizable, if necessary.
Note, however, that when an application or a user has bound the
non-option 'window-combination-limit' to t, each window has only one
sibling and there is nothing to customize - the space will be always
returned to that sibling.  OTOH, if 'window-combination-resize' is
non-nil, the space is returned proportionally to all windows in the
same combination and again there is nothing to customize.

When that first issue has been settled, we can easily add to the
option we talk about here a value that selects the window that has
received the space of the deleted window - with the restrictions noted
above.

 > Regarding the name, what about select-window-after-delete-function?

If we make the value a function like compare-w.el does.  Note in this
context that we probably do not want to select a window on another
frame (including iconified or invisible ones) so the functions
compare-w provides are probably not very useful here.  BTW I didn't
even know about compare-w - its name is too obscure to associate it
with windows.

martin