comparison lisp/window.el @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children 223736d75acb
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
31 31
32 ;;; Code: 32 ;;; Code:
33 33
34 ;;;; Window tree functions. 34 ;;;; Window tree functions.
35 35
36 (defun one-window-p (&optional nomini all-frames device) 36 (defun one-window-p (&optional nomini which-frames which-devices)
37 "Return non-nil if the selected window is the only window (in its frame). 37 "Return non-nil if the selected window is the only window (in its frame).
38 Optional arg NOMINI non-nil means don't count the minibuffer 38 Optional arg NOMINI non-nil means don't count the minibuffer
39 even if it is active. 39 even if it is active.
40 40
41 The optional arg ALL-FRAMES t means count windows on all frames. 41 By default, only the windows in the selected frame are considered.
42 If it is `visible', count windows on all visible frames. 42 The optional argument WHICH-FRAMES changes this behavior:
43 ALL-FRAMES nil or omitted means count only the selected frame, 43 WHICH-FRAMES nil or omitted means count only the selected frame,
44 plus the minibuffer it uses (which may be on another frame). 44 plus the minibuffer it uses (which may be on another frame).
45 ALL-FRAMES = 0 means count windows on all visible and iconified frames. 45 WHICH-FRAMES = `visible' means include windows on all visible frames.
46 If ALL-FRAMES is any other value, count only the selected frame. 46 WHICH-FRAMES = 0 means include windows on all visible and iconified frames.
47 47 WHICH-FRAMES = t means include windows on all frames including invisible frames.
48 If optional third argument DEVICE is nil or omitted, count frames 48 If WHICH-FRAMES is any other value, count only the selected frame.
49 on all devices. 49
50 If a device, count frames only on that device. 50 The optional third argument WHICH-DEVICES further clarifies on which
51 If a device type, count frames only on devices of that type. 51 devices to search for frames as specified by WHICH-FRAMES. This value
52 Otherwise, count frames only on the selected device." 52 is only meaningful if WHICH-FRAMES is non-nil.
53 If nil or omitted, search all devices on the selected console.
54 If a device, only search that device.
55 If a console, search all devices on that console.
56 If a device type, search all devices of that type.
57 If `window-system', search all devices on window-system consoles.
58 Any other non-nil value means search all devices."
53 (let ((base-window (selected-window))) 59 (let ((base-window (selected-window)))
54 (if (and nomini (eq base-window (minibuffer-window))) 60 (if (and nomini (eq base-window (minibuffer-window)))
55 (setq base-window (next-window base-window))) 61 (setq base-window (next-window base-window)))
56 (eq base-window 62 (eq base-window
57 (next-window base-window (if nomini 'arg) all-frames device)))) 63 (next-window base-window (if nomini 'arg) which-frames which-devices))))
58 64
59 (defun walk-windows (proc &optional minibuf all-frames device) 65 (defun walk-windows (function &optional minibuf which-frames which-devices)
60 "Cycle through all visible windows, calling PROC for each one. 66 "Cycle through all visible windows, calling FUNCTION for each one.
61 PROC is called with a window as argument. 67 FUNCTION is called with a window as argument.
62 68
63 Optional second arg MINIBUF t means count the minibuffer window even 69 Optional second arg MINIBUF t means count the minibuffer window even
64 if not active. MINIBUF nil or omitted means count the minibuffer iff 70 if not active. MINIBUF nil or omitted means count the minibuffer iff
65 it is active. MINIBUF neither t nor nil means not to count the 71 it is active. MINIBUF neither t nor nil means not to count the
66 minibuffer even if it is active. 72 minibuffer even if it is active.
68 Several frames may share a single minibuffer; if the minibuffer 74 Several frames may share a single minibuffer; if the minibuffer
69 counts, all windows on all frames that share that minibuffer count 75 counts, all windows on all frames that share that minibuffer count
70 too. Therefore, when a separate minibuffer frame is active, 76 too. Therefore, when a separate minibuffer frame is active,
71 `walk-windows' includes the windows in the frame from which you 77 `walk-windows' includes the windows in the frame from which you
72 entered the minibuffer, as well as the minibuffer window. But if the 78 entered the minibuffer, as well as the minibuffer window. But if the
73 minibuffer does not count, only windows from WINDOW's frame count. 79 minibuffer does not count, only the selected window counts.
74 80
75 ALL-FRAMES is the optional third argument. 81 By default, only the windows in the selected frame are included.
76 ALL-FRAMES nil or omitted means cycle within the frames as specified above. 82 The optional argument WHICH-FRAMES changes this behavior:
77 ALL-FRAMES = `visible' means include windows on all visible frames. 83 WHICH-FRAMES nil or omitted means cycle within the frames as specified above.
78 ALL-FRAMES = 0 means include windows on all visible and iconified frames. 84 WHICH-FRAMES = `visible' means include windows on all visible frames.
79 ALL-FRAMES = t means include windows on all frames including invisible frames. 85 WHICH-FRAMES = 0 means include windows on all visible and iconified frames.
86 WHICH-FRAMES = t means include windows on all frames including invisible frames.
80 Anything else means restrict to WINDOW's frame. 87 Anything else means restrict to WINDOW's frame.
81 88
82 If optional fourth argument DEVICE is nil or omitted, include frames 89 The optional fourth argument WHICH-DEVICES further clarifies on which
83 on all devices. 90 devices to search for frames as specified by WHICH-FRAMES. This value
84 If a device, include frames only on that device. 91 is only meaningful if WHICH-FRAMES is non-nil.
85 If a device type, include frames only on devices of that type. 92 If nil or omitted, search all devices on the selected console.
86 Otherwise, include frames only on the selected device." 93 If a device, only search that device.
94 If a console, search all devices on that console.
95 If a device type, search all devices of that type.
96 If `window-system', search all devices on window-system consoles.
97 Any other non-nil value means search all devices."
87 ;; If we start from the minibuffer window, don't fail to come back to it. 98 ;; If we start from the minibuffer window, don't fail to come back to it.
88 (if (window-minibuffer-p (selected-window)) 99 (if (window-minibuffer-p (selected-window))
89 (setq minibuf t)) 100 (setq minibuf t))
90 ;; Note that, like next-window & previous-window, this behaves a little 101 ;; Note that, like next-window & previous-window, this behaves a little
91 ;; strangely if the selected window is on an invisible frame: it hits 102 ;; strangely if the selected window is on an invisible frame: it hits
92 ;; some of the windows on that frame, and all windows on visible frames. 103 ;; some of the windows on that frame, and all windows on visible frames.
93 (let* ((walk-windows-start (selected-window)) 104 (let* ((walk-windows-start (selected-window))
94 (walk-windows-current walk-windows-start)) 105 (walk-windows-current walk-windows-start))
95 (while (progn 106 (while (progn
96 (setq walk-windows-current 107 (setq walk-windows-current
97 (next-window walk-windows-current minibuf all-frames 108 (next-window walk-windows-current minibuf which-frames
98 device)) 109 which-devices))
99 (funcall proc walk-windows-current) 110 (funcall function walk-windows-current)
100 (not (eq walk-windows-current walk-windows-start)))))) 111 (not (eq walk-windows-current walk-windows-start))))))
101 ;; The old XEmacs definition of the above clause. It's more correct in 112 ;; The old XEmacs definition of the above clause. It's more correct in
102 ;; that it will never hit a window that's already been hit even if you 113 ;; that it will never hit a window that's already been hit even if you
103 ;; do something odd like `delete-other-windows', but has the problem 114 ;; do something odd like `delete-other-windows', but has the problem
104 ;; that it conses. (This may be called repeatedly, from lazy-lock 115 ;; that it conses. (This may be called repeatedly, from lazy-lock
105 ;; for example.) 116 ;; for example.)
106 ; (let* ((walk-windows-history nil) 117 ; (let* ((walk-windows-history nil)
107 ; (walk-windows-current (selected-window))) 118 ; (walk-windows-current (selected-window)))
108 ; (while (progn 119 ; (while (progn
109 ; (setq walk-windows-current 120 ; (setq walk-windows-current
110 ; (next-window walk-windows-current minibuf all-frames 121 ; (next-window walk-windows-current minibuf which-frames
111 ; device)) 122 ; which-devices))
112 ; (not (memq walk-windows-current walk-windows-history))) 123 ; (not (memq walk-windows-current walk-windows-history)))
113 ; (setq walk-windows-history (cons walk-windows-current 124 ; (setq walk-windows-history (cons walk-windows-current
114 ; walk-windows-history)) 125 ; walk-windows-history))
115 ; (funcall proc walk-windows-current)))) 126 ; (funcall function walk-windows-current))))
116 127
117 (defun minibuffer-window-active-p (window) 128 (defun minibuffer-window-active-p (window)
118 "Return t if WINDOW (a minibuffer window) is now active." 129 "Return t if WINDOW (a minibuffer window) is now active."
119 (eq window (active-minibuffer-window))) 130 (eq window (active-minibuffer-window)))
120 131
211 222
212 If the variable split-window-keep-point is non-nil, both new windows 223 If the variable split-window-keep-point is non-nil, both new windows
213 will get the same value of point as the current window. This is often 224 will get the same value of point as the current window. This is often
214 more convenient for editing. 225 more convenient for editing.
215 226
216 Otherwise, we chose window starts so as to minimize the amount of 227 Otherwise, we choose window starts so as to minimize the amount of
217 redisplay; this is convenient on slow terminals. The new selected 228 redisplay; this is convenient on slow terminals. The new selected
218 window is the one that the current value of point appears in. The 229 window is the one that the current value of point appears in. The
219 value of point can change if the text around point is hidden by the 230 value of point can change if the text around point is hidden by the
220 new mode line. 231 new mode line.
221 232
327 (let ((buffer (current-buffer))) 338 (let ((buffer (current-buffer)))
328 (delete-window (selected-window)) 339 (delete-window (selected-window))
329 (kill-buffer buffer)) 340 (kill-buffer buffer))
330 (error "Aborted"))) 341 (error "Aborted")))
331 342
332 ;;; New with XEmacs 20.3 343 (defun window-list (&optional minibuf which-frames which-devices)
333 ;;; Suggested by Noah Friedman, and tuned by Hrvoje Niksic.
334 (defun window-list (&optional minibuf all-frames device)
335 "Return a list of existing windows. 344 "Return a list of existing windows.
336 If the optional argument MINIBUF is non-nil, then include minibuffer 345 If the optional argument MINIBUF is non-nil, then include minibuffer
337 windows in the result. 346 windows in the result.
338 347
339 By default, only the windows in the selected frame are returned. 348 By default, only the windows in the selected frame are returned.
340 The optional argument ALL-FRAMES changes this behavior: 349 The optional argument WHICH-FRAMES changes this behavior:
341 ALL-FRAMES = `visible' means include windows on all visible frames. 350 WHICH-FRAMES = `visible' means include windows on all visible frames.
342 ALL-FRAMES = 0 means include windows on all visible and iconified frames. 351 WHICH-FRAMES = 0 means include windows on all visible and iconified frames.
343 ALL-FRAMES = t means include windows on all frames including invisible frames. 352 WHICH-FRAMES = t means include windows on all frames including invisible frames.
344 Anything else means restrict to the selected frame. 353 Anything else means restrict to the selected frame.
345 The optional fourth argument DEVICE further clarifies which frames to 354
346 search as specified by ALL-FRAMES. This value is only meaningful if 355 The optional fourth argument WHICH-DEVICES further clarifies on which
347 ALL-FRAMES is non-nil. 356 devices to search for frames as specified by WHICH-FRAMES. This value
348 If nil or omitted, search only the selected device. 357 is only meaningful if WHICH-FRAMES is non-nil.
349 If a device, search frames only on that device. 358 If nil or omitted, search all devices on the selected console.
350 If a device type, search frames only on devices of that type. 359 If a device, only search that device.
351 Any other non-nil value means search frames on all devices." 360 If a console, search all devices on that console.
361 If a device type, search all devices of that type.
362 If `window-system', search all devices on window-system consoles.
363 Any other non-nil value means search all devices."
352 (let ((wins nil)) 364 (let ((wins nil))
353 (walk-windows (lambda (win) 365 (walk-windows (lambda (win)
354 (push win wins)) 366 (push win wins))
355 minibuf all-frames device) 367 minibuf which-frames which-devices)
356 wins)) 368 wins))
357 369
358 ;;; window.el ends here 370 ;;; window.el ends here