all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: martin rudalics <rudalics@gmx.at>, Eli Zaretskii <eliz@gnu.org>
Cc: 21305@debbugs.gnu.org
Subject: bug#21305: 25.0.50; `get-buffer-window-list' doc - what order?
Date: Sat, 22 Aug 2015 07:31:38 -0700 (PDT)	[thread overview]
Message-ID: <9aa1dcd7-1781-41aa-bf47-7b280b26da1e@default> (raw)
In-Reply-To: <55D8195A.4040804@gmx.at>

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

> `get-buffer-window-list' is in window.el.  Couldn't you try giving
> it a fourth argument, say SORT, which, if `lru-first' or `mru-first',
> would cause it to return the windows in the corresponding order?

Patch attached.

[-- Attachment #2: window-2015-08-22.patch --]
[-- Type: application/octet-stream, Size: 2238 bytes --]

diff -uw window.el window-patched-2015-08-22.el
--- window.el	2015-08-22 07:17:03.887665500 -0700
+++ window-patched-2015-08-22.el	2015-08-22 07:26:37.984069400 -0700
@@ -2296,11 +2296,10 @@
 	  (setq best-window window))))
     best-window))
 
-(defun get-buffer-window-list (&optional buffer-or-name minibuf all-frames)
+(defun get-buffer-window-list (&optional buffer-or-name minibuf all-frames sort)
   "Return list of all windows displaying BUFFER-OR-NAME, or nil if none.
 BUFFER-OR-NAME may be a buffer or the name of an existing buffer
-and defaults to the current buffer.  If the selected window displays
-BUFFER-OR-NAME, it will be the first in the resulting list.
+and defaults to the current buffer.
 
 MINIBUF t means include the minibuffer window even if the
 minibuffer is not active.  MINIBUF nil or omitted means include
@@ -2324,14 +2323,28 @@
 
 - A frame means consider all windows on that frame only.
 
-Anything else means consider all windows on the selected frame
-and no others."
+Anything else for ALL-FRAMES means consider all windows on the
+selected frame and no others.
+
+By default (SORT is nil), the order of the windows in the result is
+unspecified, except that if the selected window shows BUFFER-OR-NAME
+then it is first.
+
+Non-nil SORT means return the windows sorted by last use time:
+- `mru' means most  recently used comes first
+- `lru' means least recently used comes first"
   (let ((buffer (window-normalize-buffer buffer-or-name))
 	windows)
     (dolist (window (window-list-1 (selected-window) minibuf all-frames))
-      (when (eq (window-buffer window) buffer)
-	(setq windows (cons window windows))))
-    (nreverse windows)))
+      (when (eq (window-buffer window) buffer)	(setq windows  (cons window windows))))
+    (setq windows  (nreverse windows))
+    (when sort
+      (let ((pred  (case sort
+                     (lru (lambda (w1 w2) (time-less-p (window-use-time w1) (window-use-time w2))))
+                     (mru (lambda (w1 w2) (time-less-p (window-use-time w2) (window-use-time w1)))))))
+        (setq windows  (sort windows pred))))
+    windows))
+
 
 (defun minibuffer-window-active-p (window)
   "Return t if WINDOW is the currently active minibuffer window."

  reply	other threads:[~2015-08-22 14:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<089f48ed-6ce9-4753-abcf-3f86d43a278e@default>
     [not found] ` <<83vbc8iyut.fsf@gnu.org>
2015-08-21 13:21   ` bug#21305: 25.0.50; `get-buffer-window-list' doc - what order? Drew Adams
2015-08-21 13:51     ` Eli Zaretskii
2015-08-21 15:28     ` martin rudalics
2015-08-21 15:30       ` Drew Adams
2015-08-21 15:58         ` martin rudalics
2015-08-20 17:49           ` Drew Adams
2015-08-21 12:56             ` Eli Zaretskii
2015-08-21 16:12             ` Drew Adams
2015-08-21 16:32               ` Drew Adams
2015-08-21 17:42                 ` Drew Adams
2015-08-22  6:40                   ` martin rudalics
2015-08-22 14:31                     ` Drew Adams [this message]
2015-08-22 16:01                       ` Stefan Monnier
2015-08-22 17:23                         ` Drew Adams
2015-08-22 17:30                           ` Eli Zaretskii
2015-08-23 13:33                         ` martin rudalics
2015-08-21 16:00           ` Drew Adams
     [not found] <<5430f5a7-2939-4f96-8c6c-3e820ffcfd6b@default>
     [not found] ` <<83oai0iwbc.fsf@gnu.org>
2015-08-21 15:08   ` Drew Adams
2015-08-21 15:21     ` Eli Zaretskii
     [not found] ` <<55D74386.6010708@gmx.at>
     [not found]   ` <<7036da11-d296-45a9-b6ee-d7b68830927e@default>
     [not found]     ` <<55D74AA3.1070202@gmx.at>
     [not found]       ` <<1b17a036-c525-4dbc-84fa-cc8adc2b6488@default>
     [not found]         ` <<50fbb71c-8a6d-45b4-a467-a31bcc73ac09@default>
     [not found]           ` <<a18faa5f-a31e-49c2-809b-64fdd40fa273@default>
     [not found]             ` <<55D8195A.4040804@gmx.at>
     [not found]               ` <<9aa1dcd7-1781-41aa-bf47-7b280b26da1e@default>
     [not found]                 ` <<jwvoahziaao.fsf-monnier+emacsbugs@gnu.org>
     [not found]                   ` <<cf171405-a9e3-4312-b456-ff68352d4052@default>
     [not found]                     ` <<83a8tji626.fsf@gnu.org>
2015-08-22 19:01                       ` Drew Adams
2015-08-23 22:34                         ` Stefan Monnier
     [not found] <<870b6a90-e498-4ed9-9e41-d498edf33aec@default>
     [not found] ` <<83mvxkis5t.fsf@gnu.org>
2015-08-21 15:28   ` Drew Adams
2015-08-21 18:28     ` Eli Zaretskii
     [not found]   ` <<b7c7a7fe-1e8a-4add-8585-1698e16348cf@default>
     [not found]     ` <<83lhd4ijh3.fsf@gnu.org>
2015-08-21 19:18       ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9aa1dcd7-1781-41aa-bf47-7b280b26da1e@default \
    --to=drew.adams@oracle.com \
    --cc=21305@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.