+2011-06-07 Martin Rudalics <rudalics@gmx.at>
+
+ * window.el (get-lru-window, get-largest-window): Move here from
+ window.c. Rename first argument to ALL-FRAMES. Rephrase
+ doc-strings.
+ (get-buffer-window-list): Rewrite using window-list-1. Rephrase
+ doc-string.
+
2011-06-06 Martin Rudalics <rudalics@gmx.at>
* window.el (window-right, window-left, window-child)
(defalias 'some-window 'get-window-with-predicate)
-;; This should probably be written in C (i.e., without using `walk-windows').
+(defun get-lru-window (&optional all-frames dedicated)
+ "Return the least recently used window on frames specified by ALL-FRAMES.
+Return a full-width window if possible. A minibuffer window is
+never a candidate. A dedicated window is never a candidate
+unless DEDICATED is non-nil, so if all windows are dedicated, the
+value is nil. Avoid returning the selected window if possible.
+
+The following non-nil values of the optional argument ALL-FRAMES
+have special meanings:
+
+- t means consider all windows on all existing frames.
+
+- `visible' means consider all windows on all visible frames on
+ the current terminal.
+
+- 0 (the number zero) means consider all windows on all visible
+ and iconified frames on the current terminal.
+
+- A frame means consider all windows on that frame only.
+
+Any other value of ALL-FRAMES means consider all windows on the
+selected frame and no others."
+ (let (best-window best-time second-best-window second-best-time time)
+ (dolist (window (window-list-1 nil nil all-frames))
+ (when (or dedicated (not (window-dedicated-p window)))
+ (setq time (window-use-time window))
+ (if (or (eq window (selected-window))
+ (not (window-full-width-p window)))
+ (when (or (not second-best-time) (< time second-best-time))
+ (setq second-best-time time)
+ (setq second-best-window window))
+ (when (or (not best-time) (< time best-time))
+ (setq best-time time)
+ (setq best-window window)))))
+ (or best-window second-best-window)))
+
+(defun get-largest-window (&optional all-frames dedicated)
+ "Return the largest window on frames specified by ALL-FRAMES.
+A minibuffer window is never a candidate. A dedicated window is
+never a candidate unless DEDICATED is non-nil, so if all windows
+are dedicated, the value is nil.
+
+The following non-nil values of the optional argument ALL-FRAMES
+have special meanings:
+
+- t means consider all windows on all existing frames.
+
+- `visible' means consider all windows on all visible frames on
+ the current terminal.
+
+- 0 (the number zero) means consider all windows on all visible
+ and iconified frames on the current terminal.
+
+- A frame means consider all windows on that frame only.
+
+Any other value of ALL-FRAMES means consider all windows on the
+selected frame and no others."
+ (let ((best-size 0)
+ best-window size)
+ (dolist (window (window-list-1 nil nil all-frames))
+ (when (or dedicated (not (window-dedicated-p window)))
+ (setq size (* (window-total-size window)
+ (window-total-size window t)))
+ (when (> size best-size)
+ (setq best-size size)
+ (setq best-window window))))
+ best-window))
+
(defun get-buffer-window-list (&optional buffer-or-name minibuf all-frames)
"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.
-The optional arguments MINIBUF and ALL-FRAMES specify the set of
-windows to consider. See `walk-windows' for the precise meaning
-of these arguments."
- (let ((buffer (cond
- ((not buffer-or-name) (current-buffer))
- ((bufferp buffer-or-name) buffer-or-name)
- (t (get-buffer buffer-or-name))))
+Any windows showing BUFFER-OR-NAME on the selected frame are listed
+first.
+
+MINIBUF t means include the minibuffer window even if the
+minibuffer is not active. MINIBUF nil or omitted means include
+the minibuffer window only if the minibuffer is active. Any
+other value means do not include the minibuffer window even if
+the minibuffer is active.
+
+ALL-FRAMES nil or omitted means consider all windows on the
+selected frame, plus the minibuffer window if specified by the
+MINIBUF argument. If the minibuffer counts, consider all windows
+on all frames that share that minibuffer too. The following
+non-nil values of ALL-FRAMES have special meanings:
+
+- t means consider all windows on all existing frames.
+
+- `visible' means consider all windows on all visible frames on
+ the current terminal.
+
+- 0 (the number zero) means consider all windows on all visible
+ and iconified frames on the current terminal.
+
+- A frame means consider all windows on that frame only.
+
+Anything else means consider all windows on the selected frame
+and no others."
+ (let ((buffer (normalize-live-buffer buffer-or-name))
windows)
- (walk-windows (function (lambda (window)
- (if (eq (window-buffer window) buffer)
- (setq windows (cons window windows)))))
- minibuf all-frames)
- windows))
+ (dolist (window (window-list-1 (frame-first-window) minibuf all-frames))
+ (when (eq (window-buffer window) buffer)
+ (setq windows (cons window windows))))
+ (nreverse windows)))
(defun minibuffer-window-active-p (window)
"Return t if WINDOW is the currently active minibuffer window."
delete_all_subwindows with window as argument.
(delete_all_subwindows): Take a window as argument and not a
structure. Rewrite.
+ (window_loop): Remove handling of GET_LRU_WINDOW and
+ GET_LARGEST_WINDOW.
+ (Fget_lru_window, Fget_largest_window): Move to window.el.
* window.h: Extern window_body_cols instead of
window_box_text_cols. delete_all_subwindows now takes a
{
WINDOW_LOOP_UNUSED,
GET_BUFFER_WINDOW, /* Arg is buffer */
- GET_LRU_WINDOW, /* Arg is t for full-width windows only */
DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
DELETE_BUFFER_WINDOWS, /* Arg is buffer */
- GET_LARGEST_WINDOW,
UNSHOW_BUFFER, /* Arg is buffer */
REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */
CHECK_ALL_WINDOWS
}
break;
- case GET_LRU_WINDOW:
- /* `obj' is an integer encoding a bitvector.
- `obj & 1' means consider only full-width windows.
- `obj & 2' means consider also dedicated windows. */
- if (((XINT (obj) & 1) && !WINDOW_FULL_WIDTH_P (w))
- || (!(XINT (obj) & 2) && !NILP (w->dedicated))
- /* Minibuffer windows are always ignored. */
- || MINI_WINDOW_P (w))
- break;
- if (NILP (best_window)
- || (XFASTINT (XWINDOW (best_window)->use_time)
- > XFASTINT (w->use_time)))
- best_window = window;
- break;
-
case DELETE_OTHER_WINDOWS:
if (!EQ (window, obj))
Fdelete_window (window);
}
break;
- case GET_LARGEST_WINDOW:
- { /* nil `obj' means to ignore dedicated windows. */
- /* Ignore dedicated windows and minibuffers. */
- if (MINI_WINDOW_P (w) || (NILP (obj) && !NILP (w->dedicated)))
- break;
-
- if (NILP (best_window))
- best_window = window;
- else
- {
- struct window *b = XWINDOW (best_window);
- if (XFASTINT (w->total_lines) * XFASTINT (w->total_cols)
- > XFASTINT (b->total_lines) * XFASTINT (b->total_cols))
- best_window = window;
- }
- }
- break;
-
case UNSHOW_BUFFER:
if (EQ (w->buffer, obj))
{
return decode_window (window)->use_time;
}
-DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 2, 0,
- doc: /* Return the window least recently selected or used for display.
-\(LRU means Least Recently Used.)
-
-Return a full-width window if possible.
-A minibuffer window is never a candidate.
-A dedicated window is never a candidate, unless DEDICATED is non-nil,
- so if all windows are dedicated, the value is nil.
-If optional argument FRAME is `visible', search all visible frames.
-If FRAME is 0, search all visible and iconified frames.
-If FRAME is t, search all frames.
-If FRAME is nil, search only the selected frame.
-If FRAME is a frame, search only that frame. */)
- (Lisp_Object frame, Lisp_Object dedicated)
-{
- register Lisp_Object w;
- /* First try for a window that is full-width */
- w = window_loop (GET_LRU_WINDOW,
- NILP (dedicated) ? make_number (1) : make_number (3),
- 0, frame);
- if (!NILP (w) && !EQ (w, selected_window))
- return w;
- /* If none of them, try the rest */
- return window_loop (GET_LRU_WINDOW,
- NILP (dedicated) ? make_number (0) : make_number (2),
- 0, frame);
-}
-
-DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 2, 0,
- doc: /* Return the largest window in area.
-A minibuffer window is never a candidate.
-A dedicated window is never a candidate unless DEDICATED is non-nil,
- so if all windows are dedicated, the value is nil.
-If optional argument FRAME is `visible', search all visible frames.
-If FRAME is 0, search all visible and iconified frames.
-If FRAME is t, search all frames.
-If FRAME is nil, search only the selected frame.
-If FRAME is a frame, search only that frame. */)
- (Lisp_Object frame, Lisp_Object dedicated)
-{
- return window_loop (GET_LARGEST_WINDOW, dedicated, 0,
- frame);
-}
-
DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0,
doc: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
BUFFER-OR-NAME may be a buffer or a buffer name and defaults to the
defsubr (&Snext_window);
defsubr (&Sprevious_window);
defsubr (&Sother_window);
- defsubr (&Sget_lru_window);
- defsubr (&Sget_largest_window);
defsubr (&Sget_buffer_window);
defsubr (&Sdelete_other_windows);
defsubr (&Sdelete_windows_on);