29.11 Changing Window Layouts

Sometimes it can be useful to change the layout of windows such that two or more windows occupy the locations of each other. The commands described in this section do that in an orderly manner. Conceptually, these commands affect a rectangular subset of the windows on a frame. As a rule, they neither affect the location of a frame’s minibuffer window nor of any of its side windows (see Side Windows).

Common to all these commands is that they preserve the identity of windows by deleting them first and resurrecting them (see Resurrecting Windows) in their new locations afterwards. No window gets lost and no window is added or duplicated. Where possible, these commands try to preserve the relative size of windows as well as all other non-geometric properties including parameters.

The window argument of all functions described in this section must specify a valid parent window (see Windows and Frames). If it is nil, it stands for the main window (see Side Windows) of the selected frame. Interactively, a prefix argument means to operate on the parent window of the selected window. In the examples given below, we shall always assume that the windows displayed constitute their frame’s main window and the window argument is nil unless stated otherwise.

The first two commands rotate a window layout either clockwise or counterclockwise.

Command: window-layout-rotate-clockwise &optional window

This command rotates the window layout clockwise by 90 degrees. Imagine a layout with three live windows A, B and C as depicted on the left below. Then this command will produce the layout on the right.

     ___________       ___________
    |           |     |     |     |
    |     A     |     |  B  |     |
    |___________| --> |_____|  A  |
    |     |     |     |     |     |
    |  B  |  C  |     |  C  |     |
    |_____|_____|     |_____|_____|

Command: window-layout-rotate-anticlockwise &optional window

This is like window-layout-rotate-clockwise but rotates the layout in the opposite direction as demonstrated in the example below.

     ___________       ___________
    |           |     |     |     |
    |     A     |     |     |  C  |
    |___________| --> |  A  |_____|
    |     |     |     |     |     |
    |  B  |  C  |     |     |  B  |
    |_____|_____|     |_____|_____|

The next two commands FLIP the window layout—rotate it around an imaginary horizontal or vertical axis.

Command: window-layout-flip-topdown &optional window

This command flips windows such that windows on the bottom become windows on the top and vice-versa as in the example below.

     ___________       ___________
    |           |     |     |     |
    |     A     |     |  B  |  C  |
    |___________| --> |_____|_____|
    |     |     |     |           |
    |  B  |  C  |     |     A     |
    |_____|_____|     |___________|

Command: window-layout-flip-leftright &optional window

This command rearranges window in a way that the windows on the right become the window on the left, and vice-versa.

     ___________        ___________
    |           |     |           |
    |     A     |     |     A     |
    |___________| --> |___________|
    |     |     |     |     |     |
    |  B  |  C  |     |  C  |  B  |
    |_____|_____|     |_____|_____|

The next command can be used for TRANSPOSING windows—changing horizontal splits to vertical ones and vice-versa.

Command: window-layout-transpose &optional window

This command reorganizes windows such that every horizontal split becomes a vertical split and vice versa.

     ___________       ___________
    |           |     |     |     |
    |     A     |     |     |  B  |
    |___________| --> |  A  |_____|
    |     |     |     |     |     |
    |  B  |  C  |     |     |  C  |
    |_____|_____|     |_____|_____|

The final two commands can be used to rotate windows within the existing layout. They are like the commands that rotate the layout but leave the underlying structure of the layout unchanged. What actually changes are the positions of windows within the existing layout.

Command: rotate-windows &optional window reverse

This rotate windows under window in cyclic ordering. The optional argument reverse means to rotate windows backward, in reverse cyclic order.

     ___________        ___________
    |           |      |           |
    |     A     |      |     C     |
    |___________| -->  |___________|
    |     |     |      |     |     |
    |  B  |  C  |      |  A  |  B  |
    |_____|_____|      |_____|_____|

Command: rotate-windows-back &optional window

This command rotates windows under window backward in cyclic ordering.

     ___________        ___________
    |           |      |           |
    |     A     |      |     B     |
    |___________| -->  |___________|
    |     |     |      |     |     |
    |  B  |  C  |      |  C  |  A  |
    |_____|_____|      |_____|_____|

The last two commands are subject to the following option.

User Option: rotate-windows-change-selected

If this is nil, the selected window will remain unaffected by rotate-windows and rotate-windows-back. Otherwise, the selected window will change to the window that appears at the location of the selected window before any of these commands were invoked.