window-in-direction

window-in-direction is a compiled Lisp function in `window.el'.

(window-in-direction DIRECTION &optional WINDOW IGNORE SIGN WRAP MINI)

Return window in DIRECTION as seen from WINDOW.
More precisely, return the nearest window in direction DIRECTION
as seen from the position of `window-point' in window WINDOW.
DIRECTION must be one of `above', `below', `left' or `right'.
WINDOW must be a live window and defaults to the selected one.

Do not return a window whose `no-other-window' parameter is
non-nil. If the nearest window's `no-other-window' parameter is
non-nil, try to find another window in the indicated direction.
If, however, the optional argument IGNORE is non-nil, return that
window even if its `no-other-window' parameter is non-nil.

Optional argument SIGN a negative number means to use the right
or bottom edge of WINDOW as reference position instead of
`window-point'. SIGN a positive number means to use the left or
top edge of WINDOW as reference position.

Optional argument WRAP non-nil means to wrap DIRECTION around
frame borders. This means to return for WINDOW at the top of the
frame and DIRECTION `above' the minibuffer window if the frame
has one, and a window at the bottom of the frame otherwise.

Optional argument MINI nil means to return the minibuffer window
if and only if it is currently active. MINI non-nil means to
return the minibuffer window even when it's not active. However,
if WRAP non-nil, always act as if MINI were nil.

Return nil if no suitable window can be found.