all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Make window-list return windows for all frames
@ 2023-06-15 12:41 Arthur Miller
  2023-06-15 13:09 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Arthur Miller @ 2023-06-15 12:41 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1440 bytes --]

While working on info.el I needed a function to return info windows on all
frames. I was a bit surprised to discover there is no built-in option in
window-list or elsewhere as far as I can see to get all windows for all frames,
or a filtered list containing interesting windows for all frames. I ended up
with this:

#+begin_src emacs-lisp
(defun window-list-by-mode (mode &optional all-frames)
  "Return list of windows displaying buffers whose major mode is MODE.

If ALL-FRAMES is non-nil, consider all frames, otherwise just selected
frame."
  (mapcar
   (lambda (window) (cons (prin1-to-string window) window))
   (cl-remove-if-not
    (lambda (window)
      (with-current-buffer (window-buffer window)
        (eq major-mode mode)))
    (if all-frames
        (apply #'nconc (mapcar (lambda (f) (window-list f)) (frame-list)))
      (window-list)))))
#+end_src

Anyway, looking at window.c, I can see that window_candidate_p actually does
consider windows on all frames, but 't option is never passed through from
window-list. To save gymnastics via apply and nconc and doing the double work, I
have patched window-list function to let 't option further and documented the
change. It seems to me that it works as intended. I have tested myself, I hope I
haven't missed some possible case, but I'm a little suspisious: what was the
reason why this wasn't documented and used? I mean, it is already there, but
cut-off for some reason?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Return-window-list-for-all-frames.patch --]
[-- Type: text/x-patch, Size: 2512 bytes --]

From 1123400eaebdbe68dab527f9fe4397050f112890 Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Thu, 15 Jun 2023 14:17:08 +0200
Subject: [PATCH] Return window-list for all frames

Add option to window-list to return windows for all frames.
* src/window.c Modify to return all windows when FRAME is 't.
* doc/elisp/window.text Document the change.
---
 doc/lispref/windows.texi | 3 ++-
 src/window.c             | 8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 0196ed0e813..bbb60403a86 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -227,7 +227,8 @@ Windows and Frames
 @defun window-list &optional frame minibuffer window
 This function returns a list of all live windows owned by the specified
 @var{frame}.  If @var{frame} is omitted or @code{nil}, it defaults to
-the selected frame (@pxref{Input Focus}).
+the selected frame (@pxref{Input Focus}).  If @var{frame} is @code{t},
+the list of windows for all frames is returned.
 
 The optional argument @var{minibuffer} specifies whether to include the
 minibuffer window (@pxref{Minibuffer Windows}) in that list.  If
diff --git a/src/window.c b/src/window.c
index e22fea0bb7a..7d1fa5deef6 100644
--- a/src/window.c
+++ b/src/window.c
@@ -2989,9 +2989,10 @@ window_list_1 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
 }
 
 
-DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
-       doc: /* Return a list of windows on FRAME, starting with WINDOW.
+DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0, doc
+       : /* Return a list of windows on FRAME, starting with WINDOW.
 FRAME nil or omitted means use the selected frame.
+FRAME t means return list of live windows for all frames.
 WINDOW nil or omitted means use the window selected within FRAME.
 MINIBUF t means include the minibuffer window, even if it isn't active.
 MINIBUF nil or omitted means include the minibuffer window only
@@ -3002,10 +3003,11 @@ DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
   if (NILP (window))
     window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window;
   CHECK_WINDOW (window);
+
   if (NILP (frame))
     frame = selected_frame;
 
-  if (!EQ (frame, XWINDOW (window)->frame))
+  if (!EQ (frame, XWINDOW (window)->frame) && !(BASE_EQ (frame, Qt)))
     error ("Window is on a different frame");
 
   return window_list_1 (window, minibuf, frame);
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2023-06-27 16:44 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-15 12:41 Make window-list return windows for all frames Arthur Miller
2023-06-15 13:09 ` Eli Zaretskii
2023-06-15 14:01   ` Arthur Miller
2023-06-15 15:22     ` Eli Zaretskii
2023-06-15 16:32       ` Arthur Miller
2023-06-16  7:29         ` Gregory Heytings
2023-06-16 10:03           ` Arthur Miller
2023-06-16 10:34             ` Eli Zaretskii
2023-06-16 14:21               ` martin rudalics
2023-06-17  8:39                 ` Eli Zaretskii
2023-06-17  9:39                   ` martin rudalics
2023-06-17 10:42                     ` Eli Zaretskii
2023-06-18 13:36                       ` Arthur Miller
2023-06-19  6:55                       ` Arthur Miller
2023-06-20  6:25                         ` martin rudalics
2023-06-27 16:44                           ` Arthur Miller
2023-06-15 16:11     ` [External] : " Drew Adams
2023-06-15 17:18       ` Arthur Miller
2023-06-15 13:12 ` Gregory Heytings
2023-06-15 14:04   ` Arthur Miller
2023-06-15 14:19     ` Gregory Heytings
2023-06-15 16:19       ` Arthur Miller
2023-06-15 17:15         ` Gregory Heytings
2023-06-15 17:53           ` Arthur Miller
2023-06-15 13:50 ` Po Lu
2023-06-15 18:02   ` Arthur Miller

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.