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    |              |
|             |              |
+-------------+--------------+
Drew
  • 75,699
  • 9
  • 109
  • 225
lawlist
  • 18,826
  • 5
  • 37
  • 118
  • 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 '22 at 01:46

1 Answers1

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.

Phil Hudson
  • 1,651
  • 10
  • 13