annotate lisp/window.el @ 267:966663fcf606 r20-5b32

Import from CVS: tag r20-5b32
author cvs
date Mon, 13 Aug 2007 10:26:29 +0200
parents 2c611d1463a6
children c5d627a313b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; window.el --- XEmacs window commands aside from those written in C.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1989, 1993-94, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995, 1996 Ben Wing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Keywords: frames, extensions, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;;; Synched up with: Emacs/Mule zeta.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;;;; Window tree functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 (defun one-window-p (&optional nomini all-frames device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 "Returns non-nil if the selected window is the only window (in its frame).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38 Optional arg NOMINI non-nil means don't count the minibuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 even if it is active.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 The optional arg ALL-FRAMES t means count windows on all frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 If it is `visible', count windows on all visible frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 ALL-FRAMES nil or omitted means count only the selected frame,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 plus the minibuffer it uses (which may be on another frame).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 ALL-FRAMES = 0 means count windows on all visible and iconified frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 If ALL-FRAMES is any other value, count only the selected frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 If optional third argument DEVICE is nil or omitted, count frames
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 on all devices.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 If a device, count frames only on that device.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 If a device type, count frames only on devices of that type.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 Otherwise, count frames only on the selected device."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 (let ((base-window (selected-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 (if (and nomini (eq base-window (minibuffer-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (setq base-window (next-window base-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 (eq base-window
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 (next-window base-window (if nomini 'arg) all-frames device))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 (defun walk-windows (proc &optional minibuf all-frames device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 "Cycle through all visible windows, calling PROC for each one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 PROC is called with a window as argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 Optional second arg MINIBUF t means count the minibuffer window even
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 if not active. MINIBUF nil or omitted means count the minibuffer iff
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 it is active. MINIBUF neither t nor nil means not to count the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 minibuffer even if it is active.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 Several frames may share a single minibuffer; if the minibuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 counts, all windows on all frames that share that minibuffer count
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 too. Therefore, when a separate minibuffer frame is active,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 `walk-windows' includes the windows in the frame from which you
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 entered the minibuffer, as well as the minibuffer window. But if the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 minibuffer does not count, only windows from WINDOW's frame count.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 ALL-FRAMES is the optional third argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 ALL-FRAMES nil or omitted means cycle within the frames as specified above.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 ALL-FRAMES = `visible' means include windows on all visible frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 ALL-FRAMES = t means include windows on all frames including invisible frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 Anything else means restrict to WINDOW's frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 If optional fourth argument DEVICE is nil or omitted, include frames
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 on all devices.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 If a device, include frames only on that device.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 If a device type, include frames only on devices of that type.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 Otherwise, include frames only on the selected device."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 ;; If we start from the minibuffer window, don't fail to come back to it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 (if (window-minibuffer-p (selected-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 (setq minibuf t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 ;; Note that, like next-window & previous-window, this behaves a little
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 ;; strangely if the selected window is on an invisible frame: it hits
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 ;; some of the windows on that frame, and all windows on visible frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (let* ((walk-windows-start (selected-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 (walk-windows-current walk-windows-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (while (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 (setq walk-windows-current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 (next-window walk-windows-current minibuf all-frames
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 device))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 (funcall proc walk-windows-current)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 (not (eq walk-windows-current walk-windows-start))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 ;; The old XEmacs definition of the above clause. It's more correct in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 ;; that it will never hit a window that's already been hit even if you
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 ;; do something odd like `delete-other-windows', but has the problem
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 ;; that it conses. (This may be called repeatedly, from lazy-lock
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 ;; for example.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 ; (let* ((walk-windows-history nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 ; (walk-windows-current (selected-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 ; (while (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 ; (setq walk-windows-current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 ; (next-window walk-windows-current minibuf all-frames
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 ; device))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 ; (not (memq walk-windows-current walk-windows-history)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 ; (setq walk-windows-history (cons walk-windows-current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 ; walk-windows-history))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 ; (funcall proc walk-windows-current))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 (defun minibuffer-window-active-p (window)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 "Return t if WINDOW (a minibuffer window) is now active."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (eq window (active-minibuffer-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (defmacro save-selected-window (&rest body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 "Execute BODY, then select the window that was selected before BODY."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 (list 'let
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 '((save-selected-window-window (selected-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (list 'unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 (cons 'progn body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 (list 'and ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 (list 'window-live-p 'save-selected-window-window)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 (list 'select-window 'save-selected-window-window)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (defun count-windows (&optional minibuf)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 "Returns the number of visible windows.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 Optional arg MINIBUF non-nil means count the minibuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 even if it is inactive."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (let ((count 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 (walk-windows (function (lambda (w)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 (setq count (+ count 1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 minibuf)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 (defun balance-windows ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 "Makes all visible windows the same height (approximately)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (let ((count -1) levels newsizes size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 ;FSFmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 ;;; Don't count the lines that are above the uppermost windows.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 ;;; (These are the menu bar lines, if any.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 ;(mbl (nth 1 (window-edges (frame-first-window (selected-frame))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 ;; Find all the different vpos's at which windows start,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 ;; then count them. But ignore levels that differ by only 1.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (save-window-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (let (tops (prev-top -2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (walk-windows (function (lambda (w)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (setq tops (cons (nth 1 (window-pixel-edges w))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 tops))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 'nomini)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 (setq tops (sort tops '<))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 (while tops
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (if (> (car tops) (1+ prev-top))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 (setq prev-top (car tops)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 count (1+ count)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (setq levels (cons (cons (car tops) count) levels))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (setq tops (cdr tops)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 (setq count (1+ count))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 ;; Subdivide the frame into that many vertical levels.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 ;FSFmacs (setq size (/ (- (frame-height) mbl) count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 (setq size (/ (window-pixel-height (frame-root-window)) count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 (walk-windows (function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 (lambda (w)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 (select-window w)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (let ((newtop (cdr (assq (nth 1 (window-pixel-edges))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 levels)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (newbot (or (cdr (assq
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 (+ (window-pixel-height)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (nth 1 (window-pixel-edges)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 levels))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 count)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 (setq newsizes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 (cons (cons w (* size (- newbot newtop)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 newsizes)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 'nomini)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 (walk-windows (function (lambda (w)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 (select-window w)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 (let ((newsize (cdr (assq w newsizes))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 (enlarge-window
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 (/ (- newsize (window-pixel-height))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 (face-height 'default))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 'nomini)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 ;;; I think this should be the default; I think people will prefer it--rms.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 (defcustom split-window-keep-point t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 "*If non-nil, split windows keeps the original point in both children.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 This is often more convenient for editing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 If nil, adjust point in each of the two windows to minimize redisplay.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 This is convenient on slow terminals, but point can move strangely."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 :group 'windows)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 (defun split-window-vertically (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 "Split current window into two windows, one above the other.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 The uppermost window gets ARG lines and the other gets the rest.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 Negative arg means select the size of the lowermost window instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 With no argument, split equally or close to it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 Both windows display the same buffer now current.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 If the variable split-window-keep-point is non-nil, both new windows
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 will get the same value of point as the current window. This is often
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 more convenient for editing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 Otherwise, we chose window starts so as to minimize the amount of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 redisplay; this is convenient on slow terminals. The new selected
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 window is the one that the current value of point appears in. The
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 value of point can change if the text around point is hidden by the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 new mode line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216 Programs should probably use split-window instead of this."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 (let ((old-w (selected-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219 (old-point (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220 (size (and arg (prefix-numeric-value arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 (window-full-p nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 new-w bottom moved)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 (and size (< size 0) (setq size (+ (window-height) size)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 (setq new-w (split-window nil size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 (or split-window-keep-point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 (set-buffer (window-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 (goto-char (window-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 (setq moved (vertical-motion (window-height)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 (set-window-start new-w (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 (if (> (point) (window-point new-w))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 (set-window-point new-w (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234 (and (= moved (window-height))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 (setq window-full-p t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 (vertical-motion -1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 (setq bottom (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 (and window-full-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 (<= bottom (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241 (set-window-point old-w (1- bottom)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 (and window-full-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 (<= (window-start new-w) old-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 (set-window-point new-w old-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246 (select-window new-w)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 new-w))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 (defun split-window-horizontally (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 "Split current window into two windows side by side.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251 This window becomes the leftmost of the two, and gets ARG columns.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 Negative arg means select the size of the rightmost window instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 No arg means split equally."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 (let ((size (and arg (prefix-numeric-value arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 (and size (< size 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257 (setq size (+ (window-width) size)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 (split-window nil size t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 (defun enlarge-window-horizontally (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 "Make current window ARG columns wider."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 (enlarge-window arg t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 (defun shrink-window-horizontally (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 "Make current window ARG columns narrower."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268 (shrink-window arg t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 (defun shrink-window-if-larger-than-buffer (&optional window)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 "Shrink the WINDOW to be as small as possible to display its contents.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272 Do not shrink to less than `window-min-height' lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 Do nothing if the buffer contains more lines than the present window height,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 or if some of the window's contents are scrolled out of view,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 or if the window is not the full width of the frame,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 or if the window is the only window of its frame."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 (or window (setq window (selected-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 (set-buffer (window-buffer window))
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
281 (let ((n 0)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
282 (test-pos
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
283 (- (point-max)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
284 ;; If buffer ends with a newline, ignore it when counting
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
285 ;; height unless point is after it.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
286 (if (and (not (eobp))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
287 (eq ?\n (char-after (1- (point-max)))))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
288 1 0)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
289 (mini (frame-property (window-frame window) 'minibuffer))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
290 (edges (window-pixel-edges (selected-window))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 (if (and (< 1 (let ((frame (selected-frame)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 (select-frame (window-frame window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 (count-windows)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (select-frame frame))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 ;; check to make sure that we don't have horizontally
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 ;; split windows
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298 (eq (frame-highest-window (window-frame window) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 (frame-highest-window (window-frame window) -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300 (pos-visible-in-window-p (point-min) window)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301 (not (eq mini 'only))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 (or (not mini) (eq mini t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 (< (nth 3 edges)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 (nth 1 (window-pixel-edges mini)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 (> (nth 1 edges)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 0)))
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
307 (progn
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
308 (save-window-excursion
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
309 (goto-char (point-min))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
310 (while (and (window-live-p window)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
311 (pos-visible-in-window-p test-pos window))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
312 (shrink-window 1 nil window)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
313 (setq n (1+ n))))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
314 (if (> n 0)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
315 (shrink-window (min (1- n)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
316 (- (window-height window)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
317 (1+ window-min-height)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
318 nil
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
319 window)))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321 (defun kill-buffer-and-window ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 "Kill the current buffer and delete the selected window."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 (let ((buffer (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 (delete-window (selected-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 (kill-buffer buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 (error "Aborted")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 ;;; New with XEmacs 20.3
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331 ;;; Suggested by Noah Friedman, and tuned by Hrvoje Niksic.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 (defun window-list (&optional minibuf all-frames device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 "Return a list of existing windows.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 If the optional argument MINIBUF is non-nil, then include minibuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 windows in the result.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337 By default, only the windows in the selected frame are returned.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 The optional argument ALL-FRAMES changes this behavior:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 ALL-FRAMES = `visible' means include windows on all visible frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 ALL-FRAMES = t means include windows on all frames including invisible frames.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 Anything else means restrict to the selected frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343 The optional fourth argument DEVICE further clarifies which frames to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 search as specified by ALL-FRAMES. This value is only meaningful if
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 ALL-FRAMES is non-nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346 If nil or omitted, search only the selected device.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 If a device, search frames only on that device.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348 If a device type, search frames only on devices of that type.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349 Any other non-nil value means search frames on all devices."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 (let ((wins nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 (walk-windows (lambda (win)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
352 (push win wins))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
353 minibuf all-frames device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354 wins))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 ;;; window.el ends here