I understand that when a window is split, the original window and the new window become children under a new "parent window".
I would like the option to somehow register these windows such that when either child window is deleted, the other child and the parent are also automatically deleted.
Here's why I want this ...
I'm using a complicated 3rd-party package that has a number of ways to create buffers and windows. Under certain isolated conditions (usually during a conditional operation within a hook function), I split certain windows.
If I use the standard facilities of this package to delete the original window (which is now one of the two children), the other, newly created child window remains.
I know that I can write code to determine the parent of a window being deleted and to write more code to delete its parent and sibling windows. However, this involves manually modifying functions within this complicated 3rd-party package, and I'd like to avoid this.
Ideally, I'd like to somehow register the children and the parent at the time that the window is initially split, so that whenever one of the three windows is deleted, the other two are also automatically deleted. This way, when the existing 3rd-party code deletes the original window as part of its normal processing, the parent and the other child will also automatically be deleted.
I have not been able to find any such facility in emacs nor in any searches. Does such a thing exist, by any chance?
One idea which occurs to me is to write wrapper functions for
split-window and install them via emacs' advice mechanism. But is there perhaps another mechanism for my desired functionality which might already exist?
Thank you very much for any suggestions.
NOTE: In digging through the emacs source code, I notice something called an "atomic window" or an "atom window". I can't find many docs for this, but it seems like it might give me what I want. For example, look at the final paragraph of the doc string for
(delete-window &optional WINDOW)
Delete WINDOW. WINDOW must be a valid window and defaults to the selected one. Return nil.
If the variable ‘ignore-window-parameters’ is non-nil or the ‘delete-window’ parameter of WINDOW equals t, do not process any parameters of WINDOW. Otherwise, if the ‘delete-window’ parameter of WINDOW specifies a function, call that function with WINDOW as its sole argument and return the value returned by that function.
Otherwise, if WINDOW is part of an atomic window, call ‘delete-window’ with the root of the atomic window as its argument. Signal an error if WINDOW is either the only window on its frame, the last non-side window, or part of an atomic window that is its frame’s root window.
... and here's the doc string for a function I found called
(display-buffer-in-atom-window BUFFER ALIST)
Display BUFFER in an atomic window. This function displays BUFFER in a new window that will be combined with an existing window to form an atomic window. If the existing window is already part of an atomic window, add the new window to that atomic window. Operations like ‘split-window’ or ‘delete-window’, when applied to a constituent of an atomic window, are applied atomically to the root of that atomic window.
ALIST is an association list of symbols and values. The following symbols can be used.
‘window’ specifies the existing window the new window shall be
combined with. Use ‘window-atom-root’ to make the new window a
sibling of an atomic window’s root. If an internal window is
specified here, all children of that window become part of the
atomic window too. If no window is specified, the new window
becomes a sibling of the selected window. By default, the
‘window-atom’ parameter of the existing window is set to ‘main’
provided it is live and was not set before.
‘side’ denotes the side of the existing window where the new window shall be located. Valid values are ‘below’, ‘right’, ‘above’ and ‘left’. The default is ‘below’. By default, the ‘window-atom’ parameter of the new window is set to this value.
The return value is the new window, nil when creating that window failed.
I'll be investigating this atom(ic) window thing, and I'll report back.