aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2011-06-07 15:23:08 +0200
committerMartin Rudalics2011-06-07 15:23:08 +0200
commit190b47e683f61b30533bcc548f8be9d3b861029e (patch)
tree0cf48df3e7dba31caad6abe2a81e0f5936ff5c4e
parentfa8a67e67454a900e4cf7b93fed96f27ea41b1b8 (diff)
downloademacs-190b47e683f61b30533bcc548f8be9d3b861029e.tar.gz
emacs-190b47e683f61b30533bcc548f8be9d3b861029e.zip
Move get-lru-window and get-largest-window to window.el.
* window.c (window_loop): Remove handling of GET_LRU_WINDOW and GET_LARGEST_WINDOW. (Fget_lru_window, Fget_largest_window): Move to window.el. * 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.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/window.el113
-rw-r--r--src/ChangeLog3
-rw-r--r--src/window.c81
4 files changed, 111 insertions, 94 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8cc1c3f1e26..910591d1887 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12011-06-07 Martin Rudalics <rudalics@gmx.at>
2
3 * window.el (get-lru-window, get-largest-window): Move here from
4 window.c. Rename first argument to ALL-FRAMES. Rephrase
5 doc-strings.
6 (get-buffer-window-list): Rewrite using window-list-1. Rephrase
7 doc-string.
8
12011-06-06 Martin Rudalics <rudalics@gmx.at> 92011-06-06 Martin Rudalics <rudalics@gmx.at>
2 10
3 * window.el (window-right, window-left, window-child) 11 * window.el (window-right, window-left, window-child)
diff --git a/lisp/window.el b/lisp/window.el
index 0da3f5ae1de..5905443de67 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -640,25 +640,112 @@ arguments."
640 640
641(defalias 'some-window 'get-window-with-predicate) 641(defalias 'some-window 'get-window-with-predicate)
642 642
643;; This should probably be written in C (i.e., without using `walk-windows'). 643(defun get-lru-window (&optional all-frames dedicated)
644 "Return the least recently used window on frames specified by ALL-FRAMES.
645Return a full-width window if possible. A minibuffer window is
646never a candidate. A dedicated window is never a candidate
647unless DEDICATED is non-nil, so if all windows are dedicated, the
648value is nil. Avoid returning the selected window if possible.
649
650The following non-nil values of the optional argument ALL-FRAMES
651have special meanings:
652
653- t means consider all windows on all existing frames.
654
655- `visible' means consider all windows on all visible frames on
656 the current terminal.
657
658- 0 (the number zero) means consider all windows on all visible
659 and iconified frames on the current terminal.
660
661- A frame means consider all windows on that frame only.
662
663Any other value of ALL-FRAMES means consider all windows on the
664selected frame and no others."
665 (let (best-window best-time second-best-window second-best-time time)
666 (dolist (window (window-list-1 nil nil all-frames))
667 (when (or dedicated (not (window-dedicated-p window)))
668 (setq time (window-use-time window))
669 (if (or (eq window (selected-window))
670 (not (window-full-width-p window)))
671 (when (or (not second-best-time) (< time second-best-time))
672 (setq second-best-time time)
673 (setq second-best-window window))
674 (when (or (not best-time) (< time best-time))
675 (setq best-time time)
676 (setq best-window window)))))
677 (or best-window second-best-window)))
678
679(defun get-largest-window (&optional all-frames dedicated)
680 "Return the largest window on frames specified by ALL-FRAMES.
681A minibuffer window is never a candidate. A dedicated window is
682never a candidate unless DEDICATED is non-nil, so if all windows
683are dedicated, the value is nil.
684
685The following non-nil values of the optional argument ALL-FRAMES
686have special meanings:
687
688- t means consider all windows on all existing frames.
689
690- `visible' means consider all windows on all visible frames on
691 the current terminal.
692
693- 0 (the number zero) means consider all windows on all visible
694 and iconified frames on the current terminal.
695
696- A frame means consider all windows on that frame only.
697
698Any other value of ALL-FRAMES means consider all windows on the
699selected frame and no others."
700 (let ((best-size 0)
701 best-window size)
702 (dolist (window (window-list-1 nil nil all-frames))
703 (when (or dedicated (not (window-dedicated-p window)))
704 (setq size (* (window-total-size window)
705 (window-total-size window t)))
706 (when (> size best-size)
707 (setq best-size size)
708 (setq best-window window))))
709 best-window))
710
644(defun get-buffer-window-list (&optional buffer-or-name minibuf all-frames) 711(defun get-buffer-window-list (&optional buffer-or-name minibuf all-frames)
645 "Return list of all windows displaying BUFFER-OR-NAME, or nil if none. 712 "Return list of all windows displaying BUFFER-OR-NAME, or nil if none.
646BUFFER-OR-NAME may be a buffer or the name of an existing buffer 713BUFFER-OR-NAME may be a buffer or the name of an existing buffer
647and defaults to the current buffer. 714and defaults to the current buffer.
648 715
649The optional arguments MINIBUF and ALL-FRAMES specify the set of 716Any windows showing BUFFER-OR-NAME on the selected frame are listed
650windows to consider. See `walk-windows' for the precise meaning 717first.
651of these arguments." 718
652 (let ((buffer (cond 719MINIBUF t means include the minibuffer window even if the
653 ((not buffer-or-name) (current-buffer)) 720minibuffer is not active. MINIBUF nil or omitted means include
654 ((bufferp buffer-or-name) buffer-or-name) 721the minibuffer window only if the minibuffer is active. Any
655 (t (get-buffer buffer-or-name)))) 722other value means do not include the minibuffer window even if
723the minibuffer is active.
724
725ALL-FRAMES nil or omitted means consider all windows on the
726selected frame, plus the minibuffer window if specified by the
727MINIBUF argument. If the minibuffer counts, consider all windows
728on all frames that share that minibuffer too. The following
729non-nil values of ALL-FRAMES have special meanings:
730
731- t means consider all windows on all existing frames.
732
733- `visible' means consider all windows on all visible frames on
734 the current terminal.
735
736- 0 (the number zero) means consider all windows on all visible
737 and iconified frames on the current terminal.
738
739- A frame means consider all windows on that frame only.
740
741Anything else means consider all windows on the selected frame
742and no others."
743 (let ((buffer (normalize-live-buffer buffer-or-name))
656 windows) 744 windows)
657 (walk-windows (function (lambda (window) 745 (dolist (window (window-list-1 (frame-first-window) minibuf all-frames))
658 (if (eq (window-buffer window) buffer) 746 (when (eq (window-buffer window) buffer)
659 (setq windows (cons window windows))))) 747 (setq windows (cons window windows))))
660 minibuf all-frames) 748 (nreverse windows)))
661 windows))
662 749
663(defun minibuffer-window-active-p (window) 750(defun minibuffer-window-active-p (window)
664 "Return t if WINDOW is the currently active minibuffer window." 751 "Return t if WINDOW is the currently active minibuffer window."
diff --git a/src/ChangeLog b/src/ChangeLog
index c7bcdec0512..435b5ea7468 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -10,6 +10,9 @@
10 delete_all_subwindows with window as argument. 10 delete_all_subwindows with window as argument.
11 (delete_all_subwindows): Take a window as argument and not a 11 (delete_all_subwindows): Take a window as argument and not a
12 structure. Rewrite. 12 structure. Rewrite.
13 (window_loop): Remove handling of GET_LRU_WINDOW and
14 GET_LARGEST_WINDOW.
15 (Fget_lru_window, Fget_largest_window): Move to window.el.
13 16
14 * window.h: Extern window_body_cols instead of 17 * window.h: Extern window_body_cols instead of
15 window_box_text_cols. delete_all_subwindows now takes a 18 window_box_text_cols. delete_all_subwindows now takes a
diff --git a/src/window.c b/src/window.c
index ee62f57ee07..5b95db634a0 100644
--- a/src/window.c
+++ b/src/window.c
@@ -2487,10 +2487,8 @@ enum window_loop
2487{ 2487{
2488 WINDOW_LOOP_UNUSED, 2488 WINDOW_LOOP_UNUSED,
2489 GET_BUFFER_WINDOW, /* Arg is buffer */ 2489 GET_BUFFER_WINDOW, /* Arg is buffer */
2490 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
2491 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */ 2490 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
2492 DELETE_BUFFER_WINDOWS, /* Arg is buffer */ 2491 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
2493 GET_LARGEST_WINDOW,
2494 UNSHOW_BUFFER, /* Arg is buffer */ 2492 UNSHOW_BUFFER, /* Arg is buffer */
2495 REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */ 2493 REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */
2496 CHECK_ALL_WINDOWS 2494 CHECK_ALL_WINDOWS
@@ -2573,21 +2571,6 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2573 } 2571 }
2574 break; 2572 break;
2575 2573
2576 case GET_LRU_WINDOW:
2577 /* `obj' is an integer encoding a bitvector.
2578 `obj & 1' means consider only full-width windows.
2579 `obj & 2' means consider also dedicated windows. */
2580 if (((XINT (obj) & 1) && !WINDOW_FULL_WIDTH_P (w))
2581 || (!(XINT (obj) & 2) && !NILP (w->dedicated))
2582 /* Minibuffer windows are always ignored. */
2583 || MINI_WINDOW_P (w))
2584 break;
2585 if (NILP (best_window)
2586 || (XFASTINT (XWINDOW (best_window)->use_time)
2587 > XFASTINT (w->use_time)))
2588 best_window = window;
2589 break;
2590
2591 case DELETE_OTHER_WINDOWS: 2574 case DELETE_OTHER_WINDOWS:
2592 if (!EQ (window, obj)) 2575 if (!EQ (window, obj))
2593 Fdelete_window (window); 2576 Fdelete_window (window);
@@ -2632,24 +2615,6 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2632 } 2615 }
2633 break; 2616 break;
2634 2617
2635 case GET_LARGEST_WINDOW:
2636 { /* nil `obj' means to ignore dedicated windows. */
2637 /* Ignore dedicated windows and minibuffers. */
2638 if (MINI_WINDOW_P (w) || (NILP (obj) && !NILP (w->dedicated)))
2639 break;
2640
2641 if (NILP (best_window))
2642 best_window = window;
2643 else
2644 {
2645 struct window *b = XWINDOW (best_window);
2646 if (XFASTINT (w->total_lines) * XFASTINT (w->total_cols)
2647 > XFASTINT (b->total_lines) * XFASTINT (b->total_cols))
2648 best_window = window;
2649 }
2650 }
2651 break;
2652
2653 case UNSHOW_BUFFER: 2618 case UNSHOW_BUFFER:
2654 if (EQ (w->buffer, obj)) 2619 if (EQ (w->buffer, obj))
2655 { 2620 {
@@ -2740,50 +2705,6 @@ time is the least recently selected one. */)
2740 return decode_window (window)->use_time; 2705 return decode_window (window)->use_time;
2741} 2706}
2742 2707
2743DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 2, 0,
2744 doc: /* Return the window least recently selected or used for display.
2745\(LRU means Least Recently Used.)
2746
2747Return a full-width window if possible.
2748A minibuffer window is never a candidate.
2749A dedicated window is never a candidate, unless DEDICATED is non-nil,
2750 so if all windows are dedicated, the value is nil.
2751If optional argument FRAME is `visible', search all visible frames.
2752If FRAME is 0, search all visible and iconified frames.
2753If FRAME is t, search all frames.
2754If FRAME is nil, search only the selected frame.
2755If FRAME is a frame, search only that frame. */)
2756 (Lisp_Object frame, Lisp_Object dedicated)
2757{
2758 register Lisp_Object w;
2759 /* First try for a window that is full-width */
2760 w = window_loop (GET_LRU_WINDOW,
2761 NILP (dedicated) ? make_number (1) : make_number (3),
2762 0, frame);
2763 if (!NILP (w) && !EQ (w, selected_window))
2764 return w;
2765 /* If none of them, try the rest */
2766 return window_loop (GET_LRU_WINDOW,
2767 NILP (dedicated) ? make_number (0) : make_number (2),
2768 0, frame);
2769}
2770
2771DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 2, 0,
2772 doc: /* Return the largest window in area.
2773A minibuffer window is never a candidate.
2774A dedicated window is never a candidate unless DEDICATED is non-nil,
2775 so if all windows are dedicated, the value is nil.
2776If optional argument FRAME is `visible', search all visible frames.
2777If FRAME is 0, search all visible and iconified frames.
2778If FRAME is t, search all frames.
2779If FRAME is nil, search only the selected frame.
2780If FRAME is a frame, search only that frame. */)
2781 (Lisp_Object frame, Lisp_Object dedicated)
2782{
2783 return window_loop (GET_LARGEST_WINDOW, dedicated, 0,
2784 frame);
2785}
2786
2787DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0, 2708DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0,
2788 doc: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none. 2709 doc: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2789BUFFER-OR-NAME may be a buffer or a buffer name and defaults to the 2710BUFFER-OR-NAME may be a buffer or a buffer name and defaults to the
@@ -7431,8 +7352,6 @@ frame to be redrawn only if it is a tty frame. */);
7431 defsubr (&Snext_window); 7352 defsubr (&Snext_window);
7432 defsubr (&Sprevious_window); 7353 defsubr (&Sprevious_window);
7433 defsubr (&Sother_window); 7354 defsubr (&Sother_window);
7434 defsubr (&Sget_lru_window);
7435 defsubr (&Sget_largest_window);
7436 defsubr (&Sget_buffer_window); 7355 defsubr (&Sget_buffer_window);
7437 defsubr (&Sdelete_other_windows); 7356 defsubr (&Sdelete_other_windows);
7438 defsubr (&Sdelete_windows_on); 7357 defsubr (&Sdelete_windows_on);