Function: windows-sharing-edge
windows-sharing-edge is a byte-compiled function defined in
window.el.gz.
Signature
(windows-sharing-edge &optional WINDOW EDGE WITHIN)
Documentation
Return list of live windows sharing the same edge with WINDOW.
WINDOW must be a valid window and defaults to the selected one.
EDGE stands for the edge to share and must be either left,
above, right or below. Omitted or nil, EDGE defaults to
left.
WITHIN nil means to find a live window that shares the opposite
EDGE with WINDOW. For example, if EDGE equals left, WINDOW has
to share (part of) the right edge of any window returned. WITHIN
non-nil means to find all live windows that share the same EDGE
with WINDOW (Window must be internal in this case). So if EDGE
equals left, WINDOW's left edge has to fully encompass the left
edge of any window returned.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun windows-sharing-edge (&optional window edge within)
"Return list of live windows sharing the same edge with WINDOW.
WINDOW must be a valid window and defaults to the selected one.
EDGE stands for the edge to share and must be either `left',
`above', `right' or `below'. Omitted or nil, EDGE defaults to
`left'.
WITHIN nil means to find a live window that shares the opposite
EDGE with WINDOW. For example, if EDGE equals `left', WINDOW has
to share (part of) the right edge of any window returned. WITHIN
non-nil means to find all live windows that share the same EDGE
with WINDOW (Window must be internal in this case). So if EDGE
equals `left', WINDOW's left edge has to fully encompass the left
edge of any window returned."
(setq window (window-normalize-window window))
(setq edge (or edge 'left))
(when (and within (window-live-p window))
(error "Cannot share edge from within live window %s" window))
(let ((window-edges (window-edges window nil nil t))
(horizontal (memq edge '(left right)))
(n (pcase edge
('left 0) ('above 1) ('right 2) ('below 3))))
(unless (numberp n)
(error "Invalid EDGE %s" edge))
(let ((o (mod (+ 2 n) 4))
(p (if horizontal 1 0))
(q (if horizontal 3 2))
windows)
(walk-window-tree
(lambda (other)
(let ((other-edges (window-edges other nil nil t)))
(when (and (not (eq window other))
(= (nth n window-edges)
(nth (if within n o) other-edges))
(cond
((= (nth p window-edges) (nth p other-edges)))
((< (nth p window-edges) (nth p other-edges))
(< (nth p other-edges) (nth q window-edges)))
(t
(< (nth p window-edges) (nth q other-edges)))))
(setq windows (cons other windows)))))
(window-frame window) nil 'nomini)
(reverse windows))))