4

Is there a built-in function to return a window in a particular corner of a frame (e.g., lower-left, upper-left, upper-right, lower-right).

The following is a first draft to locate the lower-left corner, which returns a list (for debugging purposes) containing the desired window.

(let ((win-list (window-list))
      ret)
  (mapc
    (lambda (win)
      (when (and (window-live-p win)
                 (with-selected-window win
                   (and
                     (null (window-in-direction 'left))
                     (null (window-in-direction 'below)))))
        (push win ret)))
    win-list)
  ret)


+-------------+--------------+
|             |   YOU ARE    |
|             |   HERE "X"   |
|             |              |
+-------------+--------------+
|   GET THIS  |              |
|   WINDOW    |              |
|             |              |
+-------------+--------------+
1
  • 1
    There is window-at-x-y but it needs coordinates in pixels. There is also window-at-side-list so you could do (intersection (window-at-side-list nil 'left) (window-at-side-list nil 'bottom)).
    – NickD
    Jan 13, 2022 at 1:46

1 Answer 1

1

(This isn't really an answer, it's more like an optimization, using the "Answer" box just for its formatting). Your solution's approach seems good to me. Here is how I would write it:

(seq-find   ;; or -first if you prefer dash.el
 (lambda (win)
   (and (window-live-p win)
        (with-selected-window win
          (and
           (null (window-in-direction 'left)) 
           (null (window-in-direction 'below))))))    
 (window-list))

A few lines shorter, and also returns as soon as a match is found rather than checking every window even after a match is found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.