Function: combine-windows
combine-windows is a function defined in window.c.
Signature
(combine-windows FIRST LAST)
Documentation
Combine windows from FIRST to LAST inclusive.
FIRST and LAST must be different, valid windows in the same combination,
that is, windows with the same parent window. If LAST is not reachable
from FIRST by applying window-next-sibling repeatedly, invert FIRST
and LAST.
If FIRST has no previous and LAST has no next sibling, return nil. Otherwise, make a new parent window whose first child window becomes FIRST and whose last child window becomes LAST, insert that parent window in the window tree in lieu of the windows starting with FIRST and ending with LAST and return the new parent window.
Probably introduced at or before Emacs version 31.1.
Source Code
// Defined in /usr/src/emacs/src/window.c
{
struct window *f = decode_valid_window (first);
struct window *l = decode_valid_window (last);
struct window *w = f;
if (f == l)
/* Don't make a matryoshka window. */
error ("Cannot combine a window with itself");
while (w != l && !NILP (w->next))
w = XWINDOW (w->next);
if (w != l)
{
w = l;
while (w != f && !NILP (w->next))
w = XWINDOW (w->next);
if (w == f)
/* Invert FIRST and LAST. */
{
f = l;
l = w;
XSETWINDOW (first, f);
XSETWINDOW (last, l);
}
else
error ("Windows to combine must be children of same parent");
}
if (NILP (f->prev) && NILP (l->next))
/* FIRST and LAST are already the first and last child of their
parent. */
return Qnil;
/* Make new parent window PARENT. */
Lisp_Object parent = make_parent_window (f->frame);
struct window *p = XWINDOW (parent);
bool horflag = XWINDOW (f->parent)->horizontal;
/* Splice in PARENT into the window tree. */
wset_parent (p, f->parent);
wset_combination (p, horflag, first);
if (NILP (f->prev))
/* FIRST has no previous sibling. Make PARENT the first child of
FIRST's old parent. */
wset_combination (XWINDOW (p->parent), horflag, parent);
else
/* FIRST has a previous sibling. Make PARENT the new next sibling
of FIRST's previous sibling. */
{
wset_next (XWINDOW (f->prev), parent);
wset_prev (p, f->prev);
wset_prev (f, Qnil);
}
if (!NILP (l->next))
/* LAST has a next sibling. Make PARENT the new previous sibling of
LAST's old next sibling. */
{
wset_prev (XWINDOW (l->next), parent);
wset_next (p, l->next);
wset_next (l, Qnil);
}
/* Set up PARENT's positions and sizes. */
p->pixel_left = f->pixel_left;
p->left_col = f->left_col;
p->pixel_top = f->pixel_top;
p->top_line = f->top_line;
if (horflag)
{
p->pixel_width = l->pixel_left + l->pixel_width - f->pixel_left;
p->total_cols = l->left_col + l->total_cols - f->left_col;
p->pixel_height = f->pixel_height;
p->total_lines = f->total_lines;
}
else
{
p->pixel_height = l->pixel_top + l->pixel_height - f->pixel_top;
p->total_lines = l->top_line + l->total_lines - f->top_line;
p->pixel_width = f->pixel_width;
p->total_cols = f->total_cols;
}
/* Fix parent slots for PARENT's children and assign them new normal
sizes. */
window_set_parent_and_normal_sizes (parent);
/* Assign new normal sizes for PARENT and its siblings. */
window_set_parent_and_normal_sizes (p->parent);
return parent;
}