Function: rotate-windows
rotate-windows is an autoloaded, interactive and byte-compiled
function defined in window-x.el.gz.
Signature
(rotate-windows &optional WINDOW REVERSE)
Documentation
Rotate windows under WINDOW in cyclic ordering.
Optional argument REVERSE says to rotate windows backward, in reverse cyclic order.
If WINDOW is nil, it defaults to the root window of the selected frame.
Interactively, a prefix argument says to rotate the parent window of the selected window.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/window-x.el.gz
;;;###autoload
(defun rotate-windows (&optional window reverse)
"Rotate windows under WINDOW in cyclic ordering.
Optional argument REVERSE says to rotate windows backward, in reverse
cyclic order.
If WINDOW is nil, it defaults to the root window of the selected frame.
Interactively, a prefix argument says to rotate the parent window of the
selected window."
(interactive (list (window--rotate-interactive-arg)))
(when (or (not window) (window-live-p window))
(user-error "No windows to rotate"))
(let* ((frame (window-frame window))
(selected-window (frame-selected-window window))
(win-tree (car (window-tree-normal-sizes window)))
(winls (or
(seq-filter
(lambda (win)
(and (window-live-p win)
(not (window-dedicated-p win))))
(flatten-list win-tree))
(user-error "All windows are dedicated")))
(rotated-ls (if reverse
(append (cdr winls) (list (car winls)))
(append (last winls) winls)))
(other-window-arg (if reverse 1 -1))
(first-window (car rotated-ls))
(new-win-tree
;; Recursively process `win-tree' and construct a new tree
;; with the same shape and rotated windows at the leaves.
(named-let rec ((tree win-tree))
(cond
((consp tree) (cons (rec (car tree)) (rec (cdr tree))))
((and (window-live-p tree)
(not (window-dedicated-p tree)))
(pop rotated-ls))
(t tree)))))
(when (or (seq-some #'window-atom-root winls)
(seq-some #'window-fixed-size-p winls))
(user-error "Cannot rotate windows due to fixed size or atom windows"))
(delete-other-windows-internal first-window window)
(window--transpose-1 new-win-tree first-window '(below . right) t nil)
(set-frame-selected-window frame selected-window)
(when rotate-windows-change-selected
(other-window other-window-arg)
(while (not (memq (selected-window) winls))
(other-window other-window-arg)))))