Mercurial > hg > xemacs-beta
annotate lisp/window-xemacs.el @ 4940:9113c5044de8
(for main branch) add long comment about types of magic symbols
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-01-20 Ben Wing <ben@xemacs.org>
* symbols.c:
Add long comment about the types of magic symbols, and the various
declarations that go along with them.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 20 Jan 2010 22:30:33 -0600 |
parents | e95ddfd6a409 |
children | f00192e1cd49 308d34e9f07d |
rev | line source |
---|---|
428 | 1 ;;; window-xemacs.el --- XEmacs window commands aside from those written in C. |
2 | |
3 ;; Copyright (C) 1985, 1989, 1993-94, 1997 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995, 1996 Ben Wing. | |
5 | |
6 ;; Maintainer: XEmacs Development Team | |
7 ;; Keywords: frames, extensions, dumped | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | |
12 ;; under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; XEmacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with XEmacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Synched up with: Not synched. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;; This file is dumped with XEmacs. | |
31 | |
32 ;; slb - 5/29/97 | |
33 ;; Split apart from window.el in order to keep that file better in synch | |
34 ;; with Emacs. | |
35 | |
36 ;;; Code: | |
37 | |
38 (defgroup windows nil | |
39 "Windows within a frame." | |
40 :group 'environment) | |
41 | |
42 (defun recenter (&optional n window) | |
43 "Center point in WINDOW and redisplay frame. With N, put point on line N. | |
44 The desired position of point is always relative to the window. | |
45 Just C-u as prefix means put point in the center of the window. | |
46 No N (i.e., it is nil) erases the entire frame and then | |
47 redraws with point in the center of the window. | |
48 If WINDOW is nil, the selected window is used." | |
49 (interactive "_P") | |
50 (center-to-window-line (if (consp n) nil n) window) | |
51 (when (null n) | |
52 (redraw-frame (window-frame window) t))) | |
53 | |
444 | 54 (defun backward-other-window (count &optional which-frames which-devices) |
55 "Select the COUNT'th different window on this frame, going backwards. | |
56 This is just like calling `other-window' with COUNT negated." | |
428 | 57 (interactive "p") |
444 | 58 (other-window (- count) which-frames which-devices)) |
428 | 59 |
60 (defalias 'windows-of-buffer 'get-buffer-window-list) | |
61 | |
62 (defun buffer-in-multiple-windows-p (&optional buffer) | |
63 "Return t if BUFFER is in multiple windows. | |
64 If BUFFER is not specified, the current buffer will be used." | |
65 (setq buffer (or buffer | |
66 (get-buffer buffer) | |
67 (get-file-buffer buffer) | |
68 (current-buffer))) | |
69 (> (length (windows-of-buffer buffer)) 1)) | |
70 | |
71 (defun window-list (&optional frame minibuf window) | |
72 "Return a list of windows on FRAME, beginning with WINDOW. | |
73 FRAME and WINDOW default to the selected ones. | |
74 Optional second arg MINIBUF t means count the minibuffer window | |
75 even if not active. If MINIBUF is neither t nor nil it means | |
76 not to count the minibuffer even if it is active." | |
1261 | 77 (setq frame (or frame (selected-frame)) |
78 window (or window (selected-window frame))) | |
428 | 79 (if (not (eq (window-frame window) frame)) |
80 (error "Window must be on frame.")) | |
81 (let ((current-frame (selected-frame)) | |
82 list) | |
83 (unwind-protect | |
84 (save-window-excursion | |
85 (select-frame frame) | |
86 (walk-windows | |
87 (function (lambda (cur-window) | |
88 (if (not (eq window cur-window)) | |
89 (setq list (cons cur-window list))))) | |
90 minibuf) | |
91 (setq list (cons window list))) | |
92 (select-frame current-frame)))) | |
93 | |
94 ;; We used to have set-window-dedicated-p as an obsolete version | |
95 ;; of set-window-buffer-dedicated, but it really makes more sense | |
96 ;; this way. | |
97 | |
98 (make-obsolete 'set-window-buffer-dedicated 'set-window-dedicated-p) | |
99 (defun set-window-buffer-dedicated (window buffer) | |
100 "Make WINDOW display BUFFER and be dedicated to that buffer. | |
101 Then Emacs will not automatically change which buffer appears in WINDOW. | |
102 If BUFFER is nil, make WINDOW not be dedicated (but don't change which | |
103 buffer appears in it currently)." | |
104 (if (bufferp buffer) | |
105 (set-window-buffer window (get-buffer-create buffer))) | |
106 (set-window-dedicated-p window (not (null buffer)))) | |
1149 | 107 |
108 ;; Window configurations | |
428 | 109 |
3646 | 110 (defcustom window-configuration-includes-position nil |
111 "*Whether restoring window configurations will restore positions too. | |
112 If nil, only the size of windows will be restored. | |
113 | |
114 Note that setting this value to t may have counterintuitive consequences, | |
115 if a window manager employing virtual desktops is in use." | |
116 :type 'boolean | |
117 :group 'windows) | |
118 | |
1149 | 119 (defstruct saved-window |
120 currentp minibufferp minibuffer-scrollp | |
121 buffer mark-marker | |
122 start-marker | |
123 point-marker | |
124 pixel-left pixel-top pixel-right pixel-bottom | |
125 hscroll modeline-hscroll | |
126 dedicatedp | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
127 first-hchild first-vchild next-child |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
128 window) |
1149 | 129 |
130 (defstruct window-configuration | |
131 frame | |
2872 | 132 frame-top frame-left |
1149 | 133 frame-pixel-width frame-pixel-height |
134 current-buffer | |
135 minibuffer-pixel-height | |
136 min-width min-height | |
137 saved-root-window) | |
138 | |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
139 ; make sure we don't get affected by harmful advice |
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
140 (fset 'real-split-window (symbol-function 'split-window)) |
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
141 (fset 'real-delete-window (symbol-function 'delete-window)) |
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
142 |
1149 | 143 (defun window-configuration-equal (conf-1 conf-2) |
144 "Returns a boolean indicating whether the two given configurations | |
3646 | 145 are identical. |
146 | |
147 Window configurations containing windows with different window | |
148 positions are not identical iff `window-configuration-includes-position' | |
149 is t." | |
1149 | 150 (or (eq conf-1 conf-2) |
151 (and (eq (window-configuration-frame conf-1) | |
152 (window-configuration-frame conf-2)) | |
153 (= (window-configuration-frame-pixel-width conf-1) | |
154 (window-configuration-frame-pixel-width conf-2)) | |
155 (= (window-configuration-frame-pixel-height conf-1) | |
156 (window-configuration-frame-pixel-height conf-2)) | |
3646 | 157 (if window-configuration-includes-position |
158 (and (equal (window-configuration-frame-top conf-1) | |
159 (window-configuration-frame-top conf-2)) | |
160 (equal (window-configuration-frame-left conf-1) | |
161 (window-configuration-frame-left conf-2))) | |
162 t) | |
1149 | 163 (eq (window-configuration-current-buffer conf-1) |
164 (window-configuration-current-buffer conf-2)) | |
165 (saved-window-equal (window-configuration-saved-root-window conf-1) | |
166 (window-configuration-saved-root-window conf-2))))) | |
167 | |
168 (defun saved-window-equal (saved-1 saved-2) | |
169 "Returns a boolean indicating whether the two given saved windows | |
170 are identical." | |
171 (or (eq saved-1 saved-2) | |
172 (and (eq (saved-window-currentp saved-1) | |
173 (saved-window-currentp saved-2)) | |
174 (eq (saved-window-minibuffer-scrollp saved-1) | |
175 (saved-window-minibuffer-scrollp saved-2)) | |
176 (eq (saved-window-buffer saved-1) | |
177 (saved-window-buffer saved-2)) | |
178 (equal (saved-window-mark-marker saved-1) | |
179 (saved-window-mark-marker saved-2)) | |
180 (or (and (saved-window-currentp saved-1) | |
181 (saved-window-currentp saved-2)) | |
182 (equal (saved-window-start-marker saved-1) | |
183 (saved-window-start-marker saved-2))) | |
184 (or (and (saved-window-currentp saved-1) | |
185 (saved-window-currentp saved-2)) | |
186 (equal (saved-window-point-marker saved-1) | |
187 (saved-window-point-marker saved-2))) | |
188 (= (saved-window-pixel-left saved-1) | |
189 (saved-window-pixel-left saved-2)) | |
190 (= (saved-window-pixel-top saved-1) | |
191 (saved-window-pixel-top saved-2)) | |
192 (= (saved-window-pixel-right saved-1) | |
193 (saved-window-pixel-right saved-2)) | |
194 (= (saved-window-pixel-bottom saved-1) | |
195 (saved-window-pixel-bottom saved-2)) | |
196 (= (saved-window-hscroll saved-1) | |
197 (saved-window-hscroll saved-2)) | |
1387 | 198 (equal (saved-window-modeline-hscroll saved-1) |
199 (saved-window-modeline-hscroll saved-2)) | |
1149 | 200 (eq (saved-window-dedicatedp saved-1) |
201 (saved-window-dedicatedp saved-2)) | |
202 (maybe-saved-window-equal (saved-window-first-hchild saved-1) | |
203 (saved-window-first-hchild saved-2)) | |
204 (maybe-saved-window-equal (saved-window-first-vchild saved-1) | |
205 (saved-window-first-vchild saved-2)) | |
206 (maybe-saved-window-equal (saved-window-next-child saved-1) | |
207 (saved-window-next-child saved-2))))) | |
208 | |
209 (defun maybe-saved-window-equal (maybe-saved-1 maybe-saved-2) | |
210 "Returns a boolean indicating whether the two given saved windows | |
211 or NILs are identical." | |
212 (cond | |
213 ((and (not maybe-saved-1) (not maybe-saved-2)) t) | |
214 ((not maybe-saved-1) (not maybe-saved-2)) | |
215 ((not maybe-saved-2) (not maybe-saved-1)) | |
216 (t (saved-window-equal maybe-saved-1 maybe-saved-2)))) | |
217 | |
218 (defun current-window-configuration (&optional frame) | |
219 "Return an object representing the current window configuration of FRAME. | |
220 If FRAME is nil or omitted, use the selected frame. | |
221 This describes the number of windows, their sizes and current buffers, | |
222 and for each window on FRAME the displayed buffer, where display | |
223 starts, and the positions of point and mark. | |
224 An exception is made for point in the current buffer: | |
225 its value is -not- saved." | |
226 (let ((frame (or frame (selected-frame)))) | |
227 ;; The original C code used complicated but still incomplete logic | |
228 ;; to decide if and how to restore the size of the minibuffer. It | |
229 ;; goes something like this: | |
230 ; (let ((real-font-height | |
231 ; (font-height (face-font 'default) frame)) | |
232 ; (minibuffer-height | |
233 ; (if (and (minibuffer-window frame) | |
234 ; (not (frame-minibuffer-only-p frame))) | |
235 ; (window-pixel-height (minibuffer-window frame)) | |
236 ; 0))) | |
237 ; ...) | |
238 | |
239 (make-window-configuration | |
240 :frame frame | |
2885 | 241 :frame-top (frame-property frame 'top) |
242 :frame-left (frame-property frame 'left) | |
1149 | 243 :frame-pixel-width (frame-pixel-width frame) |
244 :frame-pixel-height (frame-pixel-height frame) | |
245 :current-buffer (current-buffer) | |
246 :min-width window-min-width :min-height window-min-height | |
247 :minibuffer-pixel-height (window-pixel-height (minibuffer-window frame)) | |
248 ;; this tries to do what the old code did: | |
249 ; :minibuffer-height (if (zerop (% minibuffer-height real-font-height)) | |
250 ; (- (/ minibuffer-height real-font-height)) ; lines | |
251 ; minibuffer-height) ; pixels | |
252 :saved-root-window (root-window->saved-window (frame-root-window frame))))) | |
253 | |
254 (defun root-window->saved-window (window) | |
255 "Converts a root window into a tree of saved-window structures." | |
256 (let ((buffer (window-buffer window)) | |
257 (edges (window-pixel-edges window))) | |
258 (let ((left (nth 0 edges)) | |
259 (top (nth 1 edges)) | |
260 (right (nth 2 edges)) | |
261 (bottom (nth 3 edges))) | |
262 (let ((saved-window | |
263 (make-saved-window | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
264 :window window |
1149 | 265 :currentp (eq window (selected-window (window-frame window))) |
266 :minibufferp (eq window (minibuffer-window (window-frame window))) | |
267 :minibuffer-scrollp (eq window minibuffer-scroll-window) | |
268 :buffer buffer | |
269 :pixel-left left :pixel-top top :pixel-right right :pixel-bottom bottom | |
270 :hscroll (window-hscroll window) | |
271 :modeline-hscroll (modeline-hscroll window) | |
272 :dedicatedp (window-dedicated-p window) | |
273 :first-hchild (if (window-first-hchild window) | |
274 (root-window->saved-window (window-first-hchild window)) | |
275 nil) | |
276 :first-vchild (if (window-first-vchild window) | |
277 (root-window->saved-window (window-first-vchild window)) | |
278 nil) | |
279 :next-child (if (window-next-child window) | |
280 (root-window->saved-window (window-next-child window)) | |
281 nil)))) | |
282 (if buffer | |
283 (progn | |
284 (let ((marker (make-marker))) | |
285 (set-marker marker (window-start window) buffer) | |
286 (setf (saved-window-start-marker saved-window) marker)) | |
4136 | 287 (if (not (eq buffer (current-buffer))) |
288 (let ((marker (make-marker))) | |
289 (set-marker marker (window-point window) buffer) | |
290 (setf (saved-window-point-marker saved-window) marker))) | |
1149 | 291 (setf (saved-window-mark-marker saved-window) |
292 (copy-marker (mark-marker t buffer))))) | |
293 saved-window)))) | |
294 | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
295 (defmacro save-window-excursion/mapping (&rest body) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
296 "Execute body, preserving window sizes and contents. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
297 Restores which buffer appears in which window, where display starts, |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
298 as well as the current buffer. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
299 Return alist mapping old windows to new windows. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
300 This alist maps the originally captured windows to the windows that correspond |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
301 to them in the restored configuration. It does not include entries for |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
302 windows that have not changed identity. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
303 Does not restore the value of point in current buffer." |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
304 (let ((window-config (gensym 'window-config)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
305 (mapping (gensym 'mapping))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
306 `(let ((,window-config (current-window-configuration)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
307 (,mapping)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
308 (unwind-protect |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
309 (progn ,@body) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
310 (setq ,mapping (set-window-configuration/mapping ,window-config))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
311 ,mapping))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
312 |
4674
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
313 (defun set-window-configuration (configuration &optional set-frame-size-p) |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
314 "Set the configuration of windows and buffers as specified by CONFIGURATION. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
315 CONFIGURATION must be a value previously returned |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
316 by `current-window-configuration'. |
4674
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
317 If SET-FRAME-SIZE-P is true, the frame size is also restored. |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
318 " |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
319 (set-window-configuration/mapping configuration set-frame-size-p) |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
320 nil) ; make sure nobody relies on mapping return value |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
321 |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
322 (defun set-window-configuration/mapping (configuration &optional set-frame-size-p) |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
323 "Set the configuration of windows and buffers as specified by CONFIGURATION. |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
324 CONFIGURATION must be a value previously returned |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
325 by `current-window-configuration'. |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
326 If SET-FRAME-SIZE-P is true, the frame size is also restored. |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
327 Return alist mapping old windows to new windows. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
328 This alist maps the originally captured windows to the windows that correspond |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
329 to them in the restored configuration. It does not include entries for |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
330 windows that have not changed identity." |
1149 | 331 (let ((frame (window-configuration-frame configuration))) |
332 (if (and (frame-live-p frame) | |
333 (not (window-configuration-equal configuration | |
334 (current-window-configuration)))) | |
4674
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
335 (really-set-window-configuration frame configuration set-frame-size-p)))) |
1149 | 336 |
4674
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
337 (defun really-set-window-configuration (frame configuration set-frame-size-p) |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
338 "Set the window configuration CONFIGURATION on live frame FRAME. |
4674
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
339 If SET-FRAME-SIZE-P is true, the frame size is also restored. |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
340 Return alist mapping old windows to new windows." |
1149 | 341 ;; avoid potential temporary problems |
342 (setq window-min-width 0) | |
343 (setq window-min-height 0) | |
344 (setq minibuffer-scroll-window nil) | |
345 | |
346 (frame-reduce-to-one-window frame) | |
4674
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
347 (if set-frame-size-p |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
348 (set-window-configuration-frame-size configuration)) |
2888 | 349 |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
350 ;; avoid setting these if they're already up-to-date |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
351 ;; This also avoids potential inaccuracies in these settings --Mike |
3646 | 352 (when window-configuration-includes-position |
353 (let ((left (window-configuration-frame-left configuration)) | |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
354 (top (window-configuration-frame-top configuration))) |
3646 | 355 (if (not (equal left (frame-property frame 'left))) |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
356 (set-frame-property frame 'left left)) |
3646 | 357 (if (not (equal top (frame-property frame 'top))) |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
358 (set-frame-property frame 'top top)))) |
1149 | 359 |
360 ;; these may have changed because of the delete | |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
361 (set-window-pixel-height (minibuffer-window frame) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
362 (window-configuration-minibuffer-pixel-height configuration)) |
1149 | 363 |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
364 ;; avoid that `set-window-point' will set the buffer's point for |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
365 ;; the selected window |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
366 (select-window (minibuffer-window frame)) |
1149 | 367 |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
368 (let ((window-configuration-current-window nil) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
369 (mapping (list nil))) ; poor man's box |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
370 |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
371 (declare (special window-configuration-current-window)) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
372 (restore-saved-window configuration |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
373 (frame-root-window frame) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
374 (window-configuration-saved-root-window configuration) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
375 'vertical |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
376 mapping) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
377 (if window-configuration-current-window |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
378 (select-window window-configuration-current-window)) |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
379 |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
380 (setq window-min-width (window-configuration-min-width configuration)) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
381 (setq window-min-height (window-configuration-min-height configuration)) |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
382 |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
383 (let ((buffer (window-configuration-current-buffer configuration))) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
384 (if (buffer-live-p buffer) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
385 (set-buffer buffer) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
386 (set-buffer (car (buffer-list))))) |
4674
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
387 ; this resets the window configuration so that the frame is filled |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
388 (if (not set-frame-size-p) |
e95ddfd6a409
In `set-window-configuration', don't restore frame size unconditionally.
Mike Sperber <sperber@deinprogramm.de>
parents:
4673
diff
changeset
|
389 (set-frame-pixel-size frame (frame-pixel-width frame) (frame-pixel-height frame))) |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
390 (car mapping))) |
1149 | 391 |
392 (defun set-window-configuration-frame-size (configuration) | |
393 "Restore the frame size of a window configuration." | |
394 (set-frame-pixel-size | |
395 (window-configuration-frame configuration) | |
396 (window-configuration-frame-pixel-width configuration) | |
397 (window-configuration-frame-pixel-height configuration))) | |
398 | |
399 (defun frame-reduce-to-one-window (frame) | |
400 "Delete all windows except the minibuffer and one other in FRAME." | |
401 (let* ((root-window (frame-root-window frame)) | |
402 (combination-start (or (window-first-hchild root-window) | |
403 (window-first-vchild root-window)))) | |
404 (if combination-start | |
405 (window-reduce-to-one combination-start)))) | |
406 | |
1230 | 407 ;; Note that simply using `delete-other-windows' causes obscure |
408 ;; breakage. --Mike | |
409 | |
1149 | 410 (defun window-reduce-to-one (window) |
411 "Make sure only one subwindow of WINDOW is left." | |
1230 | 412 (let ((window (window-next-child window))) |
413 (while window | |
414 (if (window-live-p window) | |
415 (let ((next (window-next-child window))) | |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
416 (real-delete-window window) |
1230 | 417 (setq window next))))) |
418 (cond | |
419 ((window-first-hchild window) | |
420 (window-reduce-to-one (window-first-hchild window))) | |
421 ((window-first-vchild window) | |
422 (window-reduce-to-one (window-first-vchild window))))) | |
1149 | 423 |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
424 (defun restore-saved-window (configuration window saved-window direction mapping) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
425 "Within CONFIGURATION, restore WINDOW to the state of SAVED-WINDOW. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
426 MAPPING is a one-element list whose element is an old-window-to-new-window |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
427 mapping, which this function will extend." |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
428 (if (not (eq (saved-window-window saved-window) window)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
429 (rplaca mapping |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
430 (cons (cons (saved-window-window saved-window) window) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
431 (car mapping)))) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
432 (cond |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
433 ((and (saved-window-next-child saved-window) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
434 (not (saved-window-minibufferp (saved-window-next-child saved-window)))) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
435 (cond ((eq direction 'vertical) |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
436 (real-split-window window nil nil)) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
437 ((eq direction 'horizontal) |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
438 (real-split-window window nil t))) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
439 (if (not (saved-window-minibufferp saved-window)) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
440 (restore-saved-window-parameters configuration window saved-window)) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
441 (restore-saved-window configuration |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
442 (window-next-child window) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
443 (saved-window-next-child saved-window) |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
444 direction |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
445 mapping)) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
446 ((not (saved-window-minibufferp saved-window)) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
447 (restore-saved-window-parameters configuration window saved-window))) |
1149 | 448 |
1576 | 449 (if (saved-window-first-hchild saved-window) |
450 (restore-saved-window configuration | |
451 window | |
452 (saved-window-first-hchild saved-window) | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
453 'horizontal |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
454 mapping)) |
1576 | 455 (if (saved-window-first-vchild saved-window) |
456 (restore-saved-window configuration | |
457 window | |
458 (saved-window-first-vchild saved-window) | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
459 'vertical |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
460 mapping))) |
1149 | 461 |
462 (defun restore-saved-window-parameters (configuration window saved-window) | |
463 "Restore the window parameters stored in SAVED-WINDOW on WINDOW." | |
1261 | 464 (declare (special window-configuration-current-window)) |
1149 | 465 (let ((buffer (saved-window-buffer saved-window))) |
466 (if (and buffer (buffer-live-p buffer)) | |
467 (progn | |
468 (set-window-buffer window | |
469 (saved-window-buffer saved-window)) | |
470 (set-window-start window | |
1161 | 471 (marker-position (saved-window-start-marker saved-window)) |
472 t) | |
4136 | 473 (if (markerp (saved-window-point-marker saved-window)) |
474 (set-window-point window | |
475 (marker-position (saved-window-point-marker saved-window)))) | |
1149 | 476 (set-marker (mark-marker t buffer) |
477 (marker-position (saved-window-mark-marker saved-window)) | |
478 buffer) | |
479 (if (not (eq buffer (window-configuration-current-buffer configuration))) | |
480 (goto-char (window-point window) buffer))))) | |
481 | |
482 (if (and (not (saved-window-first-hchild saved-window)) | |
483 (not (saved-window-first-vchild saved-window))) | |
484 ;; only set size for non-container windows | |
485 (progn | |
486 ;; If this is the root window, it may be the only window. | |
487 ;; Because of mismatches between actual and reported frame | |
488 ;; size, it may not let us actually set the size of the root | |
489 ;; window to what we want. --Mike | |
490 (if (not (eq window (frame-root-window (window-frame window)))) | |
491 (progn | |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
492 (set-window-pixel-width window |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
493 (saved-window-pixel-width saved-window)) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
494 (set-window-pixel-height window |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
495 (saved-window-pixel-height saved-window)))) |
1149 | 496 (set-window-hscroll window (saved-window-hscroll saved-window)) |
497 (set-modeline-hscroll window | |
498 (saved-window-modeline-hscroll saved-window)) | |
499 (set-window-dedicated-p window (saved-window-dedicatedp saved-window)))) | |
500 | |
501 (if (saved-window-currentp saved-window) | |
502 (setq window-configuration-current-window window)) | |
503 (if (saved-window-minibuffer-scrollp saved-window) | |
504 (setq minibuffer-scroll-window window))) | |
505 | |
506 (defun saved-window-pixel-width (saved-window) | |
507 "Compute the pixel width of SAVED-WINDOW." | |
508 (- (saved-window-pixel-right saved-window) | |
509 (saved-window-pixel-left saved-window))) | |
510 | |
511 (defun saved-window-pixel-height (saved-window) | |
512 "Compute the pixel height of SAVED-WINDOW." | |
513 (- (saved-window-pixel-bottom saved-window) | |
514 (saved-window-pixel-top saved-window))) | |
4673
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
515 |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
516 (defun set-window-pixel-width (window width) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
517 "Set the pixel width of WINDOW." |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
518 (enlarge-window-pixels (- width (window-pixel-width window)) t window)) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
519 |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
520 (defun set-window-pixel-height (window height) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
521 "Set the pixel height of WINDOW." |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
522 (enlarge-window-pixels (- height (window-pixel-height window)) nil window)) |
11d71be1c232
Add `set-window-pixel-{width,height} convenience functions.
Mike Sperber <sperber@deinprogramm.de>
parents:
4445
diff
changeset
|
523 |
428 | 524 |
525 ;; The window-config stack is stored as a list in frame property | |
526 ;; 'window-config-stack, with the most recent element at the front. | |
527 ;; When you pop off an element, the popped off element gets put at the | |
528 ;; front of frame property 'window-config-unpop-stack, so you can | |
529 ;; retrieve it using unpop-window-configuration. | |
530 | |
531 (defcustom window-config-stack-max 16 | |
532 "*Maximum size of window configuration stack. | |
533 Start discarding off end if it gets this big." | |
534 :type 'integer | |
535 :group 'windows) | |
536 | |
537 (defun window-config-stack (&optional frame) | |
538 (or frame (setq frame (selected-frame))) | |
539 (let ((stack (frame-property frame 'window-config-stack))) | |
540 (if stack | |
541 (set-undoable-stack-max stack window-config-stack-max) | |
542 (progn | |
543 (setq stack (make-undoable-stack window-config-stack-max)) | |
544 (set-frame-property frame 'window-config-stack stack))) | |
545 stack)) | |
546 | |
547 (defun push-window-configuration (&optional config) | |
548 "Push the current window configuration onto the window-config stack. | |
549 If CONFIG is specified, push it instead of the current window configuration. | |
550 Each frame has its own window-config stack." | |
551 (interactive) | |
552 (let ((wc (or config (current-window-configuration))) | |
553 (stack (window-config-stack))) | |
554 (if (or (= 0 (undoable-stack-a-length stack)) | |
555 (not (equal (undoable-stack-a-top stack) wc))) | |
556 (undoable-stack-push stack wc)))) | |
557 | |
558 (defun pop-window-configuration () | |
559 "Pop the top window configuration off the window-config stack and set it. | |
560 Before setting the new window configuration, the current window configuration | |
561 is pushed onto the \"unpop\" stack. | |
562 `unpop-window-configuration' undoes what this function does. | |
563 Each frame has its own window-config and \"unpop\" stack." | |
564 (interactive) | |
565 (let ((stack (window-config-stack)) | |
566 (wc (current-window-configuration)) | |
567 popped) | |
568 (condition-case nil | |
569 (progn | |
570 (setq popped (undoable-stack-pop stack)) | |
571 (while (equal popped wc) | |
572 (setq popped (undoable-stack-pop stack))) | |
573 (undoable-stack-push stack wc) | |
574 (undoable-stack-undo stack) | |
575 (set-window-configuration popped) | |
576 popped) | |
577 (trunc-stack-bottom | |
578 (error "Bottom of window config stack"))))) | |
579 | |
580 (defun unpop-window-configuration () | |
581 "Undo the effect of the most recent `pop-window-configuration'. | |
582 This does exactly the inverse of what `pop-window-configuration' does: | |
583 i.e. it pops a window configuration off of the \"unpop\" stack and | |
584 pushes the current window configuration onto the window-config stack. | |
585 Each frame has its own window-config and \"unpop\" stack." | |
586 (interactive) | |
587 (let ((stack (window-config-stack)) | |
588 (wc (current-window-configuration)) | |
589 popped) | |
590 (condition-case nil | |
591 (progn | |
592 (setq popped | |
593 (progn | |
594 (undoable-stack-redo stack) | |
595 (undoable-stack-pop stack))) | |
596 (while (equal popped wc) | |
597 (setq popped | |
598 (progn | |
599 (undoable-stack-redo stack) | |
600 (undoable-stack-pop stack)))) | |
601 (undoable-stack-push stack wc) | |
602 (set-window-configuration popped) | |
603 popped) | |
604 (trunc-stack-bottom | |
605 (error "Top of window config stack"))))) | |
606 | |
607 | |
608 ;;;;;;;;;;;;; display-buffer, moved here from C. Hallelujah. | |
609 | |
442 | 610 (make-variable-buffer-local '__buffer-dedicated-frame) |
611 | |
612 (defun buffer-dedicated-frame (&optional buffer) | |
613 "Return the frame dedicated to this BUFFER, or nil if there is none. | |
614 No argument or nil as argument means use current buffer as BUFFER." | |
615 (let ((buffer (decode-buffer buffer))) | |
616 (let ((frame (symbol-value-in-buffer '__buffer-dedicated-frame buffer))) | |
617 ;; XEmacs addition: if the frame is dead, silently make it go away. | |
618 (when (and (framep frame) (not (frame-live-p frame))) | |
619 (with-current-buffer buffer | |
620 (setq __buffer-dedicated-frame nil)) | |
621 (setq frame nil)) | |
622 frame))) | |
623 | |
624 (defun set-buffer-dedicated-frame (buffer frame) | |
625 "For this BUFFER, set the FRAME dedicated to it. | |
626 FRAME must be a frame or nil." | |
627 (let ((buffer (decode-buffer buffer))) | |
628 (and frame | |
629 (check-argument-type #'frame-live-p frame)) | |
630 (with-current-buffer buffer | |
631 (setq __buffer-dedicated-frame frame)))) | |
632 | |
428 | 633 (defvar display-buffer-function nil |
634 "If non-nil, function to call to handle `display-buffer'. | |
903 | 635 It will receive four args: the same as those to `display-buffer'.") |
428 | 636 |
637 (defvar pre-display-buffer-function nil | |
638 "If non-nil, function that will be called from `display-buffer' | |
903 | 639 as the first action. It will receive four args: the same as those |
428 | 640 to `display-buffer'. |
641 This function may be used to select an appropriate frame for the buffer, | |
642 for example. See also the variable `display-buffer-function', which may | |
643 be used to completely replace the `display-buffer' function. | |
644 If the return value of this function is non-nil, it should be a frame, | |
645 and that frame will be used to display the buffer.") | |
646 | |
647 (defcustom pop-up-frames nil | |
648 "*Non-nil means `display-buffer' should make a separate frame." | |
649 :type 'boolean | |
650 :group 'frames) | |
651 | |
652 (defvar pop-up-frame-function nil | |
653 "Function to call to handle automatic new frame creation. | |
654 It is called with no arguments and should return a newly created frame. | |
655 | |
656 A typical value might be `(lambda () (new-frame pop-up-frame-alist))' | |
657 where `pop-up-frame-alist' would hold the default frame parameters.") | |
658 | |
659 (defcustom special-display-buffer-names nil | |
660 "*List of buffer names that should have their own special frames. | |
661 Displaying a buffer whose name is in this list makes a special frame for it | |
662 using `special-display-function'. | |
663 | |
664 An element of the list can be a cons cell instead of just a string. | |
665 Then the car should be a buffer name, and the cdr specifies frame | |
666 parameters for creating the frame for that buffer. | |
667 More precisely, the cdr is passed as the second argument to | |
668 the function found in `special-display-function', when making that frame. | |
669 See also `special-display-regexps'." | |
670 :type '(repeat (choice :value "" | |
671 (string :tag "Name") | |
672 (cons :menu-tag "Properties" | |
673 :value ("" . nil) | |
674 (string :tag "Name") | |
675 (repeat :tag "Properties" | |
676 (group :inline t | |
677 (symbol :tag "Property") | |
678 (sexp :tag "Value")))))) | |
679 :group 'frames) | |
680 | |
681 (defcustom special-display-regexps nil | |
682 "*List of regexps saying which buffers should have their own special frames. | |
683 If a buffer name matches one of these regexps, it gets its own frame. | |
684 Displaying a buffer whose name is in this list makes a special frame for it | |
685 using `special-display-function'. | |
686 | |
687 An element of the list can be a cons cell instead of just a string. | |
688 Then the car should be the regexp, and the cdr specifies frame | |
689 parameters for creating the frame for buffers that match. | |
690 More precisely, the cdr is passed as the second argument to | |
691 the function found in `special-display-function', when making that frame. | |
692 See also `special-display-buffer-names'." | |
693 :type '(repeat (choice :value "" | |
694 regexp | |
695 (cons :menu-tag "Properties" | |
696 :value ("" . nil) | |
697 regexp | |
698 (repeat :tag "Properties" | |
699 (group :inline t | |
700 (symbol :tag "Property") | |
701 (sexp :tag "Value")))))) | |
702 :group 'frames) | |
703 | |
704 (defvar special-display-function nil | |
705 "Function to call to make a new frame for a special buffer. | |
706 It is called with two arguments, the buffer and optional buffer specific | |
707 data, and should return a window displaying that buffer. | |
708 The default value makes a separate frame for the buffer, | |
709 using `special-display-frame-alist' to specify the frame parameters. | |
710 | |
711 A buffer is special if its is listed in `special-display-buffer-names' | |
712 or matches a regexp in `special-display-regexps'.") | |
713 | |
714 (defcustom same-window-buffer-names nil | |
715 "*List of buffer names that should appear in the selected window. | |
716 Displaying one of these buffers using `display-buffer' or `pop-to-buffer' | |
717 switches to it in the selected window, rather than making it appear | |
718 in some other window. | |
719 | |
720 An element of the list can be a cons cell instead of just a string. | |
721 Then the car must be a string, which specifies the buffer name. | |
722 This is for compatibility with `special-display-buffer-names'; | |
723 the cdr of the cons cell is ignored. | |
724 | |
725 See also `same-window-regexps'." | |
726 :type '(repeat (string :tag "Name")) | |
727 :group 'windows) | |
728 | |
729 (defcustom same-window-regexps nil | |
730 "*List of regexps saying which buffers should appear in the selected window. | |
731 If a buffer name matches one of these regexps, then displaying it | |
732 using `display-buffer' or `pop-to-buffer' switches to it | |
733 in the selected window, rather than making it appear in some other window. | |
734 | |
735 An element of the list can be a cons cell instead of just a string. | |
736 Then the car must be a string, which specifies the buffer name. | |
737 This is for compatibility with `special-display-buffer-names'; | |
738 the cdr of the cons cell is ignored. | |
739 | |
740 See also `same-window-buffer-names'." | |
741 :type '(repeat regexp) | |
742 :group 'windows) | |
743 | |
744 (defcustom pop-up-windows t | |
745 "*Non-nil means display-buffer should make new windows." | |
746 :type 'boolean | |
747 :group 'windows) | |
748 | |
749 (defcustom split-height-threshold 500 | |
750 "*display-buffer would prefer to split the largest window if this large. | |
751 If there is only one window, it is split regardless of this value." | |
752 :type 'integer | |
753 :group 'windows) | |
754 | |
755 (defcustom split-width-threshold 500 | |
756 "*display-buffer would prefer to split the largest window if this large. | |
757 If there is only one window, it is split regardless of this value." | |
758 :type 'integer | |
759 :group 'windows) | |
760 | |
761 ;; Deiconify the frame containing the window WINDOW, then return WINDOW. | |
762 | |
763 (defun display-buffer-1 (window) | |
764 (if (frame-iconified-p (window-frame window)) | |
765 (make-frame-visible (window-frame window))) | |
766 window) | |
767 | |
768 ;; Can you believe that all of this crap was formerly in C? | |
769 ;; Praise Jesus that it's not there any more. | |
770 | |
903 | 771 (defun display-buffer (buffer &optional not-this-window-p override-frame |
772 shrink-to-fit) | |
428 | 773 "Make BUFFER appear in some window on the current frame, but don't select it. |
774 BUFFER can be a buffer or a buffer name. | |
775 If BUFFER is shown already in some window in the current frame, | |
776 just uses that one, unless the window is the selected window and | |
777 NOT-THIS-WINDOW-P is non-nil (interactively, with prefix arg). | |
778 | |
779 If BUFFER has a dedicated frame, display on that frame instead of | |
780 the current frame, unless OVERRIDE-FRAME is non-nil. | |
781 | |
782 If OVERRIDE-FRAME is non-nil, display on that frame instead of | |
783 the current frame (or the dedicated frame). | |
784 | |
903 | 785 If SHRINK-TO-FIT is non-nil and splitting the window is appropriate, give |
786 the new buffer less than half the space if it is small enough to fit. | |
787 | |
428 | 788 If `pop-up-windows' is non-nil, always use the |
789 current frame and create a new window regardless of whether the | |
790 buffer has a dedicated frame, and regardless of whether | |
791 OVERRIDE-FRAME was specified. | |
792 | |
793 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER. | |
794 | |
2590 | 795 If the buffer name is a member of the `same-window-buffer-names' list, |
796 or matches one of the `same-window-regexps' expressions, display the | |
797 buffer in the currently selected window. | |
798 | |
428 | 799 Returns the window displaying BUFFER." |
800 (interactive "BDisplay buffer:\nP") | |
801 | |
802 (let ((wconfig (current-window-configuration)) | |
803 (result | |
804 ;; We just simulate a `return' in C. This function is way ugly | |
805 ;; and does `returns' all over the place and there's no sense | |
806 ;; in trying to rewrite it to be more Lispy. | |
807 (catch 'done | |
1669 | 808 (let (window old-frame target-frame explicit-frame shrink-it) |
428 | 809 (setq old-frame (or (last-nonminibuf-frame) (selected-frame))) |
810 (setq buffer (get-buffer buffer)) | |
811 (check-argument-type 'bufferp buffer) | |
812 | |
813 (setq explicit-frame | |
814 (if pre-display-buffer-function | |
815 (funcall pre-display-buffer-function buffer | |
816 not-this-window-p | |
903 | 817 override-frame |
818 shrink-to-fit))) | |
428 | 819 |
820 ;; Give the user the ability to completely reimplement | |
821 ;; this function via the `display-buffer-function'. | |
822 (if display-buffer-function | |
823 (throw 'done | |
824 (funcall display-buffer-function buffer | |
825 not-this-window-p | |
903 | 826 override-frame |
827 shrink-to-fit))) | |
428 | 828 |
829 ;; If the buffer has a dedicated frame, that takes | |
830 ;; precedence over the current frame, and over what the | |
831 ;; pre-display-buffer-function did. | |
832 (let ((dedi (buffer-dedicated-frame buffer))) | |
833 (if (frame-live-p dedi) (setq explicit-frame dedi))) | |
834 | |
835 ;; if override-frame is supplied, that takes precedence over | |
836 ;; everything. This is gonna look bad if the | |
837 ;; pre-display-buffer-function raised some other frame | |
838 ;; already. | |
839 (if override-frame | |
840 (progn | |
841 (check-argument-type 'frame-live-p override-frame) | |
842 (setq explicit-frame override-frame))) | |
843 | |
844 (setq target-frame | |
845 (or explicit-frame | |
846 (last-nonminibuf-frame) | |
847 (selected-frame))) | |
848 | |
849 ;; If we have switched frames, then set not-this-window-p | |
850 ;; to false. Switching frames means that selected-window | |
851 ;; is no longer the same as it was on entry -- it's the | |
852 ;; selected-window of target_frame instead of old_frame, | |
853 ;; so it's a fine candidate for display. | |
854 (if (not (eq old-frame target-frame)) | |
855 (setq not-this-window-p nil)) | |
856 | |
857 ;; if it's in the selected window, and that's ok, then we're done. | |
858 (if (and (not not-this-window-p) | |
859 (eq buffer (window-buffer (selected-window)))) | |
860 (throw 'done (display-buffer-1 (selected-window)))) | |
861 | |
862 ;; See if the user has specified this buffer should appear | |
863 ;; in the selected window. | |
864 | |
865 (if not-this-window-p | |
866 nil | |
867 | |
868 (if (or (member (buffer-name buffer) same-window-buffer-names) | |
869 (assoc (buffer-name buffer) same-window-buffer-names)) | |
870 (progn | |
871 (switch-to-buffer buffer) | |
872 (throw 'done (display-buffer-1 (selected-window))))) | |
873 | |
874 (let ((tem same-window-regexps)) | |
875 (while tem | |
876 (let ((car (car tem))) | |
877 (if (or | |
878 (and (stringp car) | |
879 (string-match car (buffer-name buffer))) | |
880 (and (consp car) (stringp (car car)) | |
881 (string-match (car car) (buffer-name buffer)))) | |
882 (progn | |
883 (switch-to-buffer buffer) | |
884 (throw 'done (display-buffer-1 | |
885 (selected-window)))))) | |
886 (setq tem (cdr tem))))) | |
887 | |
888 ;; If pop-up-frames, look for a window showing BUFFER on | |
889 ;; any visible or iconified frame. Otherwise search only | |
890 ;; the current frame. | |
891 (if (and (not explicit-frame) | |
892 (or pop-up-frames (not (last-nonminibuf-frame)))) | |
893 (setq target-frame 0)) | |
894 | |
895 ;; Otherwise, find some window that it's already in, and | |
896 ;; return that, unless that window is the selected window | |
897 ;; and that isn't ok. What a contorted mess! | |
898 (setq window (or (if (not explicit-frame) | |
899 ;; search the selected frame | |
900 ;; first if the user didn't | |
901 ;; specify an explicit frame. | |
902 (get-buffer-window buffer nil)) | |
903 (get-buffer-window buffer target-frame))) | |
904 (if (and window | |
905 (or (not not-this-window-p) | |
906 (not (eq window (selected-window))))) | |
907 (throw 'done (display-buffer-1 window))) | |
908 | |
909 ;; Certain buffer names get special handling. | |
910 (if special-display-function | |
911 (progn | |
912 (if (member (buffer-name buffer) | |
913 special-display-buffer-names) | |
914 (throw 'done (funcall special-display-function buffer))) | |
915 | |
916 (let ((tem (assoc (buffer-name buffer) | |
917 special-display-buffer-names))) | |
918 (if tem | |
919 (throw 'done (funcall special-display-function | |
920 buffer (cdr tem))))) | |
921 | |
922 (let ((tem special-display-regexps)) | |
923 (while tem | |
924 (let ((car (car tem))) | |
925 (if (and (stringp car) | |
926 (string-match car (buffer-name buffer))) | |
927 (throw 'done | |
928 (funcall special-display-function buffer))) | |
929 (if (and (consp car) | |
930 (stringp (car car)) | |
931 (string-match (car car) | |
932 (buffer-name buffer))) | |
933 (throw 'done (funcall | |
934 special-display-function buffer | |
935 (cdr car))))) | |
936 (setq tem (cdr tem)))))) | |
937 | |
938 ;; If there are no frames open that have more than a minibuffer, | |
939 ;; we need to create a new frame. | |
940 (if (or pop-up-frames | |
941 (null (last-nonminibuf-frame))) | |
942 (progn | |
943 (setq window (frame-selected-window | |
944 (funcall pop-up-frame-function))) | |
945 (set-window-buffer window buffer) | |
946 (throw 'done (display-buffer-1 window)))) | |
947 | |
948 ;; Otherwise, make it be in some window, splitting if | |
949 ;; appropriate/possible. Do not split a window if we are | |
950 ;; displaying the buffer in a different frame than that which | |
951 ;; was current when we were called. (It is already in a | |
952 ;; different window by virtue of being in another frame.) | |
953 (if (or (and pop-up-windows (eq target-frame old-frame)) | |
954 (eq 'only (frame-property (selected-frame) 'minibuffer)) | |
955 ;; If the current frame is a special display frame, | |
956 ;; don't try to reuse its windows. | |
957 (window-dedicated-p (frame-root-window (selected-frame)))) | |
958 (progn | |
959 (if (eq 'only (frame-property (selected-frame) 'minibuffer)) | |
960 (setq target-frame (last-nonminibuf-frame))) | |
961 | |
962 ;; Don't try to create a window if would get an error with | |
963 ;; height. | |
964 (if (< split-height-threshold (* 2 window-min-height)) | |
965 (setq split-height-threshold (* 2 window-min-height))) | |
966 | |
967 ;; Same with width. | |
968 (if (< split-width-threshold (* 2 window-min-width)) | |
969 (setq split-width-threshold (* 2 window-min-width))) | |
970 | |
971 ;; If the frame we would try to split cannot be split, | |
972 ;; try other frames. | |
973 (if (frame-property (if (null target-frame) | |
974 (selected-frame) | |
975 (last-nonminibuf-frame)) | |
976 'unsplittable) | |
977 (setq window | |
978 ;; Try visible frames first. | |
979 (or (get-largest-window 'visible) | |
980 ;; If that didn't work, try iconified frames. | |
981 (get-largest-window 0) | |
982 (get-largest-window t))) | |
983 (setq window (get-largest-window target-frame))) | |
984 | |
985 ;; If we got a tall enough full-width window that | |
986 ;; can be split, split it. | |
987 (if (and window | |
988 (not (frame-property (window-frame window) | |
989 'unsplittable)) | |
990 (>= (window-height window) split-height-threshold) | |
991 (or (>= (window-width window) | |
992 split-width-threshold) | |
993 (and (window-leftmost-p window) | |
994 (window-rightmost-p window)))) | |
995 (setq window (split-window window)) | |
1669 | 996 (let (upper other) |
428 | 997 (setq window (get-lru-window target-frame)) |
998 ;; If the LRU window is selected, and big enough, | |
999 ;; and can be split, split it. | |
1000 (if (and window | |
1001 (not (frame-property (window-frame window) | |
1002 'unsplittable)) | |
1003 (or (eq window (selected-window)) | |
1004 (not (window-parent window))) | |
1005 (>= (window-height window) | |
1006 (* 2 window-min-height))) | |
1007 (setq window (split-window window))) | |
1008 ;; If get-lru-window returned nil, try other approaches. | |
1009 ;; Try visible frames first. | |
1010 (or window | |
1011 (setq window (or (get-largest-window 'visible) | |
1012 ;; If that didn't work, try | |
1013 ;; iconified frames. | |
1014 (get-largest-window 0) | |
1015 ;; Try invisible frames. | |
1016 (get-largest-window t) | |
1017 ;; As a last resort, make | |
1018 ;; a new frame. | |
1019 (frame-selected-window | |
1020 (funcall | |
1021 pop-up-frame-function))))) | |
1022 ;; If window appears above or below another, | |
1023 ;; even out their heights. | |
1024 (if (window-previous-child window) | |
1025 (setq other (window-previous-child window) | |
1026 upper other)) | |
1027 (if (window-next-child window) | |
1028 (setq other (window-next-child window) | |
1029 upper window)) | |
1030 ;; Check that OTHER and WINDOW are vertically arrayed. | |
1031 (if (and other | |
1032 (not (= (nth 1 (window-pixel-edges other)) | |
1033 (nth 1 (window-pixel-edges window)))) | |
1034 (> (window-pixel-height other) | |
1035 (window-pixel-height window))) | |
1036 (enlarge-window (- (/ (+ (window-height other) | |
1037 (window-height window)) | |
1038 2) | |
1039 (window-height upper)) | |
903 | 1040 nil upper)) |
1669 | 1041 ;; Klaus Berndl <klaus.berndl@sdm.de>: Only in |
1042 ;; this situation we shrink-to-fit but we can do | |
1043 ;; this first after we have displayed buffer in | |
1044 ;; window (s.b. (set-window-buffer window buffer)) | |
1045 (setq shrink-it shrink-to-fit)))) | |
428 | 1046 |
1047 (setq window (get-lru-window target-frame))) | |
1048 | |
1049 ;; Bring the window's previous buffer to the top of the MRU chain. | |
1050 (if (window-buffer window) | |
1051 (save-excursion | |
1052 (save-selected-window | |
1053 (select-window window) | |
1054 (record-buffer (window-buffer window))))) | |
1055 | |
1056 (set-window-buffer window buffer) | |
1057 | |
1669 | 1058 ;; Now window's previous buffer has been brought to the top |
1059 ;; of the MRU chain and window displays buffer - now we can | |
1060 ;; shrink-to-fit if necessary | |
1061 (if shrink-it | |
1062 (shrink-window-if-larger-than-buffer window)) | |
1063 | |
428 | 1064 (display-buffer-1 window))))) |
1065 (or (equal wconfig (current-window-configuration)) | |
1066 (push-window-configuration wconfig)) | |
1067 result)) | |
1068 | |
1069 ;;; window-xemacs.el ends here |