comparison lisp/window.el @ 11086:22693a280a42

(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
author Richard M. Stallman <rms@gnu.org>
date Wed, 22 Mar 1995 16:57:58 +0000
parents 3f98c129f7bc
children 8904c26c2182
comparison
equal deleted inserted replaced
11085:a9c7a7f91693 11086:22693a280a42
20 ;; along with GNU Emacs; see the file COPYING. If not, write to 20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 22
23 ;;; Code: 23 ;;; Code:
24 24
25 ;;;; Window tree functions.
26
27 (defun one-window-p (&optional nomini all-frames)
28 "Returns non-nil if the selected window is the only window (in its frame).
29 Optional arg NOMINI non-nil means don't count the minibuffer
30 even if it is active.
31
32 The optional arg ALL-FRAMES t means count windows on all frames.
33 If it is `visible', count windows on all visible frames.
34 ALL-FRAMES nil or omitted means count only the selected frame,
35 plus the minibuffer it uses (which may be on another frame).
36 If ALL-FRAMES is neither nil nor t, count only the selected frame."
37 (let ((base-window (selected-window)))
38 (if (and nomini (eq base-window (minibuffer-window)))
39 (setq base-window (next-window base-window)))
40 (eq base-window
41 (next-window base-window (if nomini 'arg) all-frames))))
42
43 (defun walk-windows (proc &optional minibuf all-frames)
44 "Cycle through all visible windows, calling PROC for each one.
45 PROC is called with a window as argument.
46
47 Optional second arg MINIBUF t means count the minibuffer window even
48 if not active. MINIBUF nil or omitted means count the minibuffer iff
49 it is active. MINIBUF neither t nor nil means not to count the
50 minibuffer even if it is active.
51
52 Several frames may share a single minibuffer; if the minibuffer
53 counts, all windows on all frames that share that minibuffer count
54 too. Therefore, when a separate minibuffer frame is active,
55 `walk-windows' includes the windows in the frame from which you
56 entered the minibuffer, as well as the minibuffer window. But if the
57 minibuffer does not count, only windows from WINDOW's frame count.
58
59 Optional third arg ALL-FRAMES t means include windows on all frames.
60 ALL-FRAMES nil or omitted means cycle within the frames as specified
61 above. ALL-FRAMES = `visible' means include windows on all visible frames.
62 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
63 Anything else means restrict to WINDOW's frame."
64 ;; If we start from the minibuffer window, don't fail to come back to it.
65 (if (window-minibuffer-p (selected-window))
66 (setq minibuf t))
67 (let* ((walk-windows-start (selected-window))
68 (walk-windows-current walk-windows-start))
69 (while (progn
70 (setq walk-windows-current
71 (next-window walk-windows-current minibuf all-frames))
72 (funcall proc walk-windows-current)
73 (not (eq walk-windows-current walk-windows-start))))))
74
75 (defun minibuffer-window-active-p (window)
76 "Return t if WINDOW (a minibuffer window) is now active."
77 ;; nil nil means include WINDOW's frame
78 ;; and other frames using WINDOW as minibuffer,
79 ;; and include minibuffer if active.
80 (let ((prev (previous-window window nil nil)))
81 ;; If PREV equals WINDOW, WINDOW must be on a minibuffer-only frame
82 ;; and it's not currently being used. So return nil.
83 (and (not (eq window prev))
84 (let ((should-be-same (next-window prev nil nil)))
85 ;; If next-window doesn't reverse previous-window,
86 ;; WINDOW must be outside the cycle specified by nil nil.
87 (eq should-be-same window)))))
88
25 (defun count-windows (&optional minibuf) 89 (defun count-windows (&optional minibuf)
26 "Returns the number of visible windows. 90 "Returns the number of visible windows.
27 Optional arg NO-MINI non-nil means don't count the minibuffer 91 Optional arg NO-MINI non-nil means don't count the minibuffer
28 even if it is active." 92 even if it is active."
29 (let ((count 0)) 93 (let ((count 0))
71 (select-window w) 135 (select-window w)
72 (let ((newsize (cdr (assq w newsizes)))) 136 (let ((newsize (cdr (assq w newsizes))))
73 (enlarge-window (- newsize 137 (enlarge-window (- newsize
74 (window-height)))))) 138 (window-height))))))
75 'nomini))) 139 'nomini)))
76 140
77 ;;; I think this should be the default; I think people will prefer it--rms. 141 ;;; I think this should be the default; I think people will prefer it--rms.
78 (defvar split-window-keep-point t 142 (defvar split-window-keep-point t
79 "*If non-nil, split windows keeps the original point in both children. 143 "*If non-nil, split windows keeps the original point in both children.
80 This is often more convenient for editing. 144 This is often more convenient for editing.
81 If nil, adjust point in each of the two windows to minimize redisplay. 145 If nil, adjust point in each of the two windows to minimize redisplay.
131 (interactive "P") 195 (interactive "P")
132 (let ((size (and arg (prefix-numeric-value arg)))) 196 (let ((size (and arg (prefix-numeric-value arg))))
133 (and size (< size 0) 197 (and size (< size 0)
134 (setq size (+ (window-width) size))) 198 (setq size (+ (window-width) size)))
135 (split-window nil size t))) 199 (split-window nil size t)))
136 200
137 (defun enlarge-window-horizontally (arg) 201 (defun enlarge-window-horizontally (arg)
138 "Make current window ARG columns wider." 202 "Make current window ARG columns wider."
139 (interactive "p") 203 (interactive "p")
140 (enlarge-window arg t)) 204 (enlarge-window arg t))
141 205