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
|
1149
|
110 (defstruct saved-window
|
|
111 currentp minibufferp minibuffer-scrollp
|
|
112 buffer mark-marker
|
|
113 start-marker
|
|
114 point-marker
|
|
115 pixel-left pixel-top pixel-right pixel-bottom
|
|
116 hscroll modeline-hscroll
|
|
117 dedicatedp
|
|
118 first-hchild first-vchild next-child)
|
|
119
|
|
120 (defstruct window-configuration
|
|
121 frame
|
2872
|
122 frame-top frame-left
|
1149
|
123 frame-pixel-width frame-pixel-height
|
|
124 current-buffer
|
|
125 minibuffer-pixel-height
|
|
126 min-width min-height
|
|
127 saved-root-window)
|
|
128
|
|
129 (defun window-configuration-equal (conf-1 conf-2)
|
|
130 "Returns a boolean indicating whether the two given configurations
|
|
131 are identical."
|
|
132 (or (eq conf-1 conf-2)
|
|
133 (and (eq (window-configuration-frame conf-1)
|
|
134 (window-configuration-frame conf-2))
|
|
135 (= (window-configuration-frame-pixel-width conf-1)
|
|
136 (window-configuration-frame-pixel-width conf-2))
|
|
137 (= (window-configuration-frame-pixel-height conf-1)
|
|
138 (window-configuration-frame-pixel-height conf-2))
|
2885
|
139 (equal (window-configuration-frame-top conf-1)
|
|
140 (window-configuration-frame-top conf-2))
|
|
141 (equal (window-configuration-frame-left conf-1)
|
|
142 (window-configuration-frame-left conf-2))
|
1149
|
143 (eq (window-configuration-current-buffer conf-1)
|
|
144 (window-configuration-current-buffer conf-2))
|
|
145 (saved-window-equal (window-configuration-saved-root-window conf-1)
|
|
146 (window-configuration-saved-root-window conf-2)))))
|
|
147
|
|
148 (defun saved-window-equal (saved-1 saved-2)
|
|
149 "Returns a boolean indicating whether the two given saved windows
|
|
150 are identical."
|
|
151 (or (eq saved-1 saved-2)
|
|
152 (and (eq (saved-window-currentp saved-1)
|
|
153 (saved-window-currentp saved-2))
|
|
154 (eq (saved-window-minibuffer-scrollp saved-1)
|
|
155 (saved-window-minibuffer-scrollp saved-2))
|
|
156 (eq (saved-window-buffer saved-1)
|
|
157 (saved-window-buffer saved-2))
|
|
158 (equal (saved-window-mark-marker saved-1)
|
|
159 (saved-window-mark-marker saved-2))
|
|
160 (or (and (saved-window-currentp saved-1)
|
|
161 (saved-window-currentp saved-2))
|
|
162 (equal (saved-window-start-marker saved-1)
|
|
163 (saved-window-start-marker saved-2)))
|
|
164 (or (and (saved-window-currentp saved-1)
|
|
165 (saved-window-currentp saved-2))
|
|
166 (equal (saved-window-point-marker saved-1)
|
|
167 (saved-window-point-marker saved-2)))
|
|
168 (= (saved-window-pixel-left saved-1)
|
|
169 (saved-window-pixel-left saved-2))
|
|
170 (= (saved-window-pixel-top saved-1)
|
|
171 (saved-window-pixel-top saved-2))
|
|
172 (= (saved-window-pixel-right saved-1)
|
|
173 (saved-window-pixel-right saved-2))
|
|
174 (= (saved-window-pixel-bottom saved-1)
|
|
175 (saved-window-pixel-bottom saved-2))
|
|
176 (= (saved-window-hscroll saved-1)
|
|
177 (saved-window-hscroll saved-2))
|
1387
|
178 (equal (saved-window-modeline-hscroll saved-1)
|
|
179 (saved-window-modeline-hscroll saved-2))
|
1149
|
180 (eq (saved-window-dedicatedp saved-1)
|
|
181 (saved-window-dedicatedp saved-2))
|
|
182 (maybe-saved-window-equal (saved-window-first-hchild saved-1)
|
|
183 (saved-window-first-hchild saved-2))
|
|
184 (maybe-saved-window-equal (saved-window-first-vchild saved-1)
|
|
185 (saved-window-first-vchild saved-2))
|
|
186 (maybe-saved-window-equal (saved-window-next-child saved-1)
|
|
187 (saved-window-next-child saved-2)))))
|
|
188
|
|
189 (defun maybe-saved-window-equal (maybe-saved-1 maybe-saved-2)
|
|
190 "Returns a boolean indicating whether the two given saved windows
|
|
191 or NILs are identical."
|
|
192 (cond
|
|
193 ((and (not maybe-saved-1) (not maybe-saved-2)) t)
|
|
194 ((not maybe-saved-1) (not maybe-saved-2))
|
|
195 ((not maybe-saved-2) (not maybe-saved-1))
|
|
196 (t (saved-window-equal maybe-saved-1 maybe-saved-2))))
|
|
197
|
|
198 (defun current-window-configuration (&optional frame)
|
|
199 "Return an object representing the current window configuration of FRAME.
|
|
200 If FRAME is nil or omitted, use the selected frame.
|
|
201 This describes the number of windows, their sizes and current buffers,
|
|
202 and for each window on FRAME the displayed buffer, where display
|
|
203 starts, and the positions of point and mark.
|
|
204 An exception is made for point in the current buffer:
|
|
205 its value is -not- saved."
|
|
206 (let ((frame (or frame (selected-frame))))
|
|
207 ;; The original C code used complicated but still incomplete logic
|
|
208 ;; to decide if and how to restore the size of the minibuffer. It
|
|
209 ;; goes something like this:
|
|
210 ; (let ((real-font-height
|
|
211 ; (font-height (face-font 'default) frame))
|
|
212 ; (minibuffer-height
|
|
213 ; (if (and (minibuffer-window frame)
|
|
214 ; (not (frame-minibuffer-only-p frame)))
|
|
215 ; (window-pixel-height (minibuffer-window frame))
|
|
216 ; 0)))
|
|
217 ; ...)
|
|
218
|
|
219 (make-window-configuration
|
|
220 :frame frame
|
2885
|
221 :frame-top (frame-property frame 'top)
|
|
222 :frame-left (frame-property frame 'left)
|
1149
|
223 :frame-pixel-width (frame-pixel-width frame)
|
|
224 :frame-pixel-height (frame-pixel-height frame)
|
|
225 :current-buffer (current-buffer)
|
|
226 :min-width window-min-width :min-height window-min-height
|
|
227 :minibuffer-pixel-height (window-pixel-height (minibuffer-window frame))
|
|
228 ;; this tries to do what the old code did:
|
|
229 ; :minibuffer-height (if (zerop (% minibuffer-height real-font-height))
|
|
230 ; (- (/ minibuffer-height real-font-height)) ; lines
|
|
231 ; minibuffer-height) ; pixels
|
|
232 :saved-root-window (root-window->saved-window (frame-root-window frame)))))
|
|
233
|
|
234 (defun root-window->saved-window (window)
|
|
235 "Converts a root window into a tree of saved-window structures."
|
|
236 (let ((buffer (window-buffer window))
|
|
237 (edges (window-pixel-edges window)))
|
|
238 (let ((left (nth 0 edges))
|
|
239 (top (nth 1 edges))
|
|
240 (right (nth 2 edges))
|
|
241 (bottom (nth 3 edges)))
|
|
242 (let ((saved-window
|
|
243 (make-saved-window
|
|
244 :currentp (eq window (selected-window (window-frame window)))
|
|
245 :minibufferp (eq window (minibuffer-window (window-frame window)))
|
|
246 :minibuffer-scrollp (eq window minibuffer-scroll-window)
|
|
247 :buffer buffer
|
|
248 :pixel-left left :pixel-top top :pixel-right right :pixel-bottom bottom
|
|
249 :hscroll (window-hscroll window)
|
|
250 :modeline-hscroll (modeline-hscroll window)
|
|
251 :dedicatedp (window-dedicated-p window)
|
|
252 :first-hchild (if (window-first-hchild window)
|
|
253 (root-window->saved-window (window-first-hchild window))
|
|
254 nil)
|
|
255 :first-vchild (if (window-first-vchild window)
|
|
256 (root-window->saved-window (window-first-vchild window))
|
|
257 nil)
|
|
258 :next-child (if (window-next-child window)
|
|
259 (root-window->saved-window (window-next-child window))
|
|
260 nil))))
|
|
261 (if buffer
|
|
262 (progn
|
|
263 (let ((marker (make-marker)))
|
|
264 (set-marker marker (window-start window) buffer)
|
|
265 (setf (saved-window-start-marker saved-window) marker))
|
|
266 (let ((marker (make-marker)))
|
|
267 (if (eq window (selected-window))
|
|
268 (set-marker marker (point buffer) buffer)
|
|
269 (set-marker marker (window-point window) buffer))
|
|
270 (setf (saved-window-point-marker saved-window) marker))
|
|
271 (setf (saved-window-mark-marker saved-window)
|
|
272 (copy-marker (mark-marker t buffer)))))
|
|
273 saved-window))))
|
|
274
|
|
275 (defun set-window-configuration (configuration)
|
|
276 "Set the configuration of windows and buffers as specified by CONFIGURATION.
|
|
277 CONFIGURATION must be a value previously returned
|
|
278 by `current-window-configuration'."
|
|
279 (let ((frame (window-configuration-frame configuration)))
|
|
280 (if (and (frame-live-p frame)
|
|
281 (not (window-configuration-equal configuration
|
|
282 (current-window-configuration))))
|
|
283 (really-set-window-configuration frame configuration))))
|
|
284
|
|
285 (defun really-set-window-configuration (frame configuration)
|
|
286 "Set the window configuration CONFIGURATION on live frame FRAME."
|
|
287 ;; avoid potential temporary problems
|
|
288 (setq window-min-width 0)
|
|
289 (setq window-min-height 0)
|
|
290 (setq minibuffer-scroll-window nil)
|
|
291
|
|
292 (frame-reduce-to-one-window frame)
|
|
293 (set-window-configuration-frame-size configuration)
|
2872
|
294 (set-frame-property frame 'left (window-configuration-frame-left configuration))
|
|
295 (set-frame-property frame 'top (window-configuration-frame-top configuration))
|
1149
|
296
|
|
297 ;; these may have changed because of the delete
|
|
298 (let ((root-window (frame-root-window frame)))
|
|
299 (enlarge-window-pixels
|
|
300 (- (window-configuration-minibuffer-pixel-height configuration)
|
|
301 (window-pixel-height (minibuffer-window frame)))
|
|
302 nil
|
|
303 (minibuffer-window frame))
|
|
304
|
|
305 ;; avoid that `set-window-point' will set the buffer's point for
|
|
306 ;; the selected window
|
|
307 (select-window (minibuffer-window frame))
|
|
308
|
|
309 (let ((window-configuration-current-window nil))
|
1261
|
310 (declare (special window-configuration-current-window))
|
1149
|
311 (restore-saved-window configuration
|
|
312 root-window
|
|
313 (window-configuration-saved-root-window configuration)
|
|
314 'vertical)
|
|
315 (if window-configuration-current-window
|
|
316 (select-window window-configuration-current-window))))
|
|
317
|
|
318 (setq window-min-width (window-configuration-min-width configuration))
|
|
319 (setq window-min-height (window-configuration-min-height configuration))
|
|
320
|
2227
|
321 (let ((buffer (window-configuration-current-buffer configuration)))
|
|
322 (if (buffer-live-p buffer)
|
|
323 (set-buffer buffer)
|
|
324 (set-buffer (car (buffer-list))))))
|
1149
|
325
|
|
326 (defun set-window-configuration-frame-size (configuration)
|
|
327 "Restore the frame size of a window configuration."
|
|
328 (set-frame-pixel-size
|
|
329 (window-configuration-frame configuration)
|
|
330 (window-configuration-frame-pixel-width configuration)
|
|
331 (window-configuration-frame-pixel-height configuration)))
|
|
332
|
|
333 (defun frame-reduce-to-one-window (frame)
|
|
334 "Delete all windows except the minibuffer and one other in FRAME."
|
|
335 (let* ((root-window (frame-root-window frame))
|
|
336 (combination-start (or (window-first-hchild root-window)
|
|
337 (window-first-vchild root-window))))
|
|
338 (if combination-start
|
|
339 (window-reduce-to-one combination-start))))
|
|
340
|
1230
|
341 ;; Note that simply using `delete-other-windows' causes obscure
|
|
342 ;; breakage. --Mike
|
|
343
|
1149
|
344 (defun window-reduce-to-one (window)
|
|
345 "Make sure only one subwindow of WINDOW is left."
|
1230
|
346 (let ((window (window-next-child window)))
|
|
347 (while window
|
|
348 (if (window-live-p window)
|
|
349 (let ((next (window-next-child window)))
|
|
350 (delete-window window)
|
|
351 (setq window next)))))
|
|
352 (cond
|
|
353 ((window-first-hchild window)
|
|
354 (window-reduce-to-one (window-first-hchild window)))
|
|
355 ((window-first-vchild window)
|
|
356 (window-reduce-to-one (window-first-vchild window)))))
|
1149
|
357
|
|
358 (defun restore-saved-window (configuration window saved-window direction)
|
|
359 "Within CONFIGURATION, restore WINDOW to the state of SAVED-WINDOW."
|
1576
|
360 (and (saved-window-next-child saved-window)
|
|
361 (not (saved-window-minibufferp (saved-window-next-child saved-window)))
|
|
362 (progn
|
|
363 (cond ((eq direction 'vertical)
|
|
364 (split-window window nil nil))
|
|
365 ((eq direction 'horizontal)
|
|
366 (split-window window nil t)))
|
|
367 (restore-saved-window configuration
|
|
368 (window-next-child window)
|
|
369 (saved-window-next-child saved-window)
|
|
370 direction)))
|
1149
|
371
|
1576
|
372 (if (saved-window-first-hchild saved-window)
|
|
373 (restore-saved-window configuration
|
|
374 window
|
|
375 (saved-window-first-hchild saved-window)
|
|
376 'horizontal))
|
|
377 (if (saved-window-first-vchild saved-window)
|
|
378 (restore-saved-window configuration
|
|
379 window
|
|
380 (saved-window-first-vchild saved-window)
|
|
381 'vertical))
|
1149
|
382
|
|
383 (if (not (saved-window-minibufferp saved-window))
|
|
384 (restore-saved-window-parameters configuration window saved-window)))
|
|
385
|
|
386 (defun restore-saved-window-parameters (configuration window saved-window)
|
|
387 "Restore the window parameters stored in SAVED-WINDOW on WINDOW."
|
1261
|
388 (declare (special window-configuration-current-window))
|
1149
|
389 (let ((buffer (saved-window-buffer saved-window)))
|
|
390 (if (and buffer (buffer-live-p buffer))
|
|
391 (progn
|
|
392 (set-window-buffer window
|
|
393 (saved-window-buffer saved-window))
|
|
394 (set-window-start window
|
1161
|
395 (marker-position (saved-window-start-marker saved-window))
|
|
396 t)
|
1149
|
397 (set-window-point window
|
|
398 (marker-position (saved-window-point-marker saved-window)))
|
|
399 (set-marker (mark-marker t buffer)
|
|
400 (marker-position (saved-window-mark-marker saved-window))
|
|
401 buffer)
|
|
402 (if (not (eq buffer (window-configuration-current-buffer configuration)))
|
|
403 (goto-char (window-point window) buffer)))))
|
|
404
|
|
405 (if (and (not (saved-window-first-hchild saved-window))
|
|
406 (not (saved-window-first-vchild saved-window)))
|
|
407 ;; only set size for non-container windows
|
|
408 (progn
|
|
409 ;; If this is the root window, it may be the only window.
|
|
410 ;; Because of mismatches between actual and reported frame
|
|
411 ;; size, it may not let us actually set the size of the root
|
|
412 ;; window to what we want. --Mike
|
|
413 (if (not (eq window (frame-root-window (window-frame window))))
|
|
414 (progn
|
|
415 (enlarge-window-pixels (- (saved-window-pixel-width saved-window)
|
|
416 (window-pixel-width window))
|
|
417 t
|
|
418 window)
|
|
419 (enlarge-window-pixels (- (saved-window-pixel-height saved-window)
|
|
420 (window-pixel-height window))
|
|
421 nil
|
|
422 window)))
|
|
423 (set-window-hscroll window (saved-window-hscroll saved-window))
|
|
424 (set-modeline-hscroll window
|
|
425 (saved-window-modeline-hscroll saved-window))
|
|
426 (set-window-dedicated-p window (saved-window-dedicatedp saved-window))))
|
|
427
|
|
428 (if (saved-window-currentp saved-window)
|
|
429 (setq window-configuration-current-window window))
|
|
430 (if (saved-window-minibuffer-scrollp saved-window)
|
|
431 (setq minibuffer-scroll-window window)))
|
|
432
|
|
433 (defun saved-window-pixel-width (saved-window)
|
|
434 "Compute the pixel width of SAVED-WINDOW."
|
|
435 (- (saved-window-pixel-right saved-window)
|
|
436 (saved-window-pixel-left saved-window)))
|
|
437
|
|
438 (defun saved-window-pixel-height (saved-window)
|
|
439 "Compute the pixel height of SAVED-WINDOW."
|
|
440 (- (saved-window-pixel-bottom saved-window)
|
|
441 (saved-window-pixel-top saved-window)))
|
428
|
442
|
|
443 ;; The window-config stack is stored as a list in frame property
|
|
444 ;; 'window-config-stack, with the most recent element at the front.
|
|
445 ;; When you pop off an element, the popped off element gets put at the
|
|
446 ;; front of frame property 'window-config-unpop-stack, so you can
|
|
447 ;; retrieve it using unpop-window-configuration.
|
|
448
|
|
449 (defcustom window-config-stack-max 16
|
|
450 "*Maximum size of window configuration stack.
|
|
451 Start discarding off end if it gets this big."
|
|
452 :type 'integer
|
|
453 :group 'windows)
|
|
454
|
|
455 (defun window-config-stack (&optional frame)
|
|
456 (or frame (setq frame (selected-frame)))
|
|
457 (let ((stack (frame-property frame 'window-config-stack)))
|
|
458 (if stack
|
|
459 (set-undoable-stack-max stack window-config-stack-max)
|
|
460 (progn
|
|
461 (setq stack (make-undoable-stack window-config-stack-max))
|
|
462 (set-frame-property frame 'window-config-stack stack)))
|
|
463 stack))
|
|
464
|
|
465 (defun push-window-configuration (&optional config)
|
|
466 "Push the current window configuration onto the window-config stack.
|
|
467 If CONFIG is specified, push it instead of the current window configuration.
|
|
468 Each frame has its own window-config stack."
|
|
469 (interactive)
|
|
470 (let ((wc (or config (current-window-configuration)))
|
|
471 (stack (window-config-stack)))
|
|
472 (if (or (= 0 (undoable-stack-a-length stack))
|
|
473 (not (equal (undoable-stack-a-top stack) wc)))
|
|
474 (undoable-stack-push stack wc))))
|
|
475
|
|
476 (defun pop-window-configuration ()
|
|
477 "Pop the top window configuration off the window-config stack and set it.
|
|
478 Before setting the new window configuration, the current window configuration
|
|
479 is pushed onto the \"unpop\" stack.
|
|
480 `unpop-window-configuration' undoes what this function does.
|
|
481 Each frame has its own window-config and \"unpop\" stack."
|
|
482 (interactive)
|
|
483 (let ((stack (window-config-stack))
|
|
484 (wc (current-window-configuration))
|
|
485 popped)
|
|
486 (condition-case nil
|
|
487 (progn
|
|
488 (setq popped (undoable-stack-pop stack))
|
|
489 (while (equal popped wc)
|
|
490 (setq popped (undoable-stack-pop stack)))
|
|
491 (undoable-stack-push stack wc)
|
|
492 (undoable-stack-undo stack)
|
|
493 (set-window-configuration popped)
|
|
494 popped)
|
|
495 (trunc-stack-bottom
|
|
496 (error "Bottom of window config stack")))))
|
|
497
|
|
498 (defun unpop-window-configuration ()
|
|
499 "Undo the effect of the most recent `pop-window-configuration'.
|
|
500 This does exactly the inverse of what `pop-window-configuration' does:
|
|
501 i.e. it pops a window configuration off of the \"unpop\" stack and
|
|
502 pushes the current window configuration onto the window-config stack.
|
|
503 Each frame has its own window-config and \"unpop\" stack."
|
|
504 (interactive)
|
|
505 (let ((stack (window-config-stack))
|
|
506 (wc (current-window-configuration))
|
|
507 popped)
|
|
508 (condition-case nil
|
|
509 (progn
|
|
510 (setq popped
|
|
511 (progn
|
|
512 (undoable-stack-redo stack)
|
|
513 (undoable-stack-pop stack)))
|
|
514 (while (equal popped wc)
|
|
515 (setq popped
|
|
516 (progn
|
|
517 (undoable-stack-redo stack)
|
|
518 (undoable-stack-pop stack))))
|
|
519 (undoable-stack-push stack wc)
|
|
520 (set-window-configuration popped)
|
|
521 popped)
|
|
522 (trunc-stack-bottom
|
|
523 (error "Top of window config stack")))))
|
|
524
|
|
525
|
|
526 ;;;;;;;;;;;;; display-buffer, moved here from C. Hallelujah.
|
|
527
|
442
|
528 (make-variable-buffer-local '__buffer-dedicated-frame)
|
|
529
|
|
530 (defun buffer-dedicated-frame (&optional buffer)
|
|
531 "Return the frame dedicated to this BUFFER, or nil if there is none.
|
|
532 No argument or nil as argument means use current buffer as BUFFER."
|
|
533 (let ((buffer (decode-buffer buffer)))
|
|
534 (let ((frame (symbol-value-in-buffer '__buffer-dedicated-frame buffer)))
|
|
535 ;; XEmacs addition: if the frame is dead, silently make it go away.
|
|
536 (when (and (framep frame) (not (frame-live-p frame)))
|
|
537 (with-current-buffer buffer
|
|
538 (setq __buffer-dedicated-frame nil))
|
|
539 (setq frame nil))
|
|
540 frame)))
|
|
541
|
|
542 (defun set-buffer-dedicated-frame (buffer frame)
|
|
543 "For this BUFFER, set the FRAME dedicated to it.
|
|
544 FRAME must be a frame or nil."
|
|
545 (let ((buffer (decode-buffer buffer)))
|
|
546 (and frame
|
|
547 (check-argument-type #'frame-live-p frame))
|
|
548 (with-current-buffer buffer
|
|
549 (setq __buffer-dedicated-frame frame))))
|
|
550
|
428
|
551 (defvar display-buffer-function nil
|
|
552 "If non-nil, function to call to handle `display-buffer'.
|
903
|
553 It will receive four args: the same as those to `display-buffer'.")
|
428
|
554
|
|
555 (defvar pre-display-buffer-function nil
|
|
556 "If non-nil, function that will be called from `display-buffer'
|
903
|
557 as the first action. It will receive four args: the same as those
|
428
|
558 to `display-buffer'.
|
|
559 This function may be used to select an appropriate frame for the buffer,
|
|
560 for example. See also the variable `display-buffer-function', which may
|
|
561 be used to completely replace the `display-buffer' function.
|
|
562 If the return value of this function is non-nil, it should be a frame,
|
|
563 and that frame will be used to display the buffer.")
|
|
564
|
|
565 (defcustom pop-up-frames nil
|
|
566 "*Non-nil means `display-buffer' should make a separate frame."
|
|
567 :type 'boolean
|
|
568 :group 'frames)
|
|
569
|
|
570 (defvar pop-up-frame-function nil
|
|
571 "Function to call to handle automatic new frame creation.
|
|
572 It is called with no arguments and should return a newly created frame.
|
|
573
|
|
574 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
|
|
575 where `pop-up-frame-alist' would hold the default frame parameters.")
|
|
576
|
|
577 (defcustom special-display-buffer-names nil
|
|
578 "*List of buffer names that should have their own special frames.
|
|
579 Displaying a buffer whose name is in this list makes a special frame for it
|
|
580 using `special-display-function'.
|
|
581
|
|
582 An element of the list can be a cons cell instead of just a string.
|
|
583 Then the car should be a buffer name, and the cdr specifies frame
|
|
584 parameters for creating the frame for that buffer.
|
|
585 More precisely, the cdr is passed as the second argument to
|
|
586 the function found in `special-display-function', when making that frame.
|
|
587 See also `special-display-regexps'."
|
|
588 :type '(repeat (choice :value ""
|
|
589 (string :tag "Name")
|
|
590 (cons :menu-tag "Properties"
|
|
591 :value ("" . nil)
|
|
592 (string :tag "Name")
|
|
593 (repeat :tag "Properties"
|
|
594 (group :inline t
|
|
595 (symbol :tag "Property")
|
|
596 (sexp :tag "Value"))))))
|
|
597 :group 'frames)
|
|
598
|
|
599 (defcustom special-display-regexps nil
|
|
600 "*List of regexps saying which buffers should have their own special frames.
|
|
601 If a buffer name matches one of these regexps, it gets its own frame.
|
|
602 Displaying a buffer whose name is in this list makes a special frame for it
|
|
603 using `special-display-function'.
|
|
604
|
|
605 An element of the list can be a cons cell instead of just a string.
|
|
606 Then the car should be the regexp, and the cdr specifies frame
|
|
607 parameters for creating the frame for buffers that match.
|
|
608 More precisely, the cdr is passed as the second argument to
|
|
609 the function found in `special-display-function', when making that frame.
|
|
610 See also `special-display-buffer-names'."
|
|
611 :type '(repeat (choice :value ""
|
|
612 regexp
|
|
613 (cons :menu-tag "Properties"
|
|
614 :value ("" . nil)
|
|
615 regexp
|
|
616 (repeat :tag "Properties"
|
|
617 (group :inline t
|
|
618 (symbol :tag "Property")
|
|
619 (sexp :tag "Value"))))))
|
|
620 :group 'frames)
|
|
621
|
|
622 (defvar special-display-function nil
|
|
623 "Function to call to make a new frame for a special buffer.
|
|
624 It is called with two arguments, the buffer and optional buffer specific
|
|
625 data, and should return a window displaying that buffer.
|
|
626 The default value makes a separate frame for the buffer,
|
|
627 using `special-display-frame-alist' to specify the frame parameters.
|
|
628
|
|
629 A buffer is special if its is listed in `special-display-buffer-names'
|
|
630 or matches a regexp in `special-display-regexps'.")
|
|
631
|
|
632 (defcustom same-window-buffer-names nil
|
|
633 "*List of buffer names that should appear in the selected window.
|
|
634 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
|
|
635 switches to it in the selected window, rather than making it appear
|
|
636 in some other window.
|
|
637
|
|
638 An element of the list can be a cons cell instead of just a string.
|
|
639 Then the car must be a string, which specifies the buffer name.
|
|
640 This is for compatibility with `special-display-buffer-names';
|
|
641 the cdr of the cons cell is ignored.
|
|
642
|
|
643 See also `same-window-regexps'."
|
|
644 :type '(repeat (string :tag "Name"))
|
|
645 :group 'windows)
|
|
646
|
|
647 (defcustom same-window-regexps nil
|
|
648 "*List of regexps saying which buffers should appear in the selected window.
|
|
649 If a buffer name matches one of these regexps, then displaying it
|
|
650 using `display-buffer' or `pop-to-buffer' switches to it
|
|
651 in the selected window, rather than making it appear in some other window.
|
|
652
|
|
653 An element of the list can be a cons cell instead of just a string.
|
|
654 Then the car must be a string, which specifies the buffer name.
|
|
655 This is for compatibility with `special-display-buffer-names';
|
|
656 the cdr of the cons cell is ignored.
|
|
657
|
|
658 See also `same-window-buffer-names'."
|
|
659 :type '(repeat regexp)
|
|
660 :group 'windows)
|
|
661
|
|
662 (defcustom pop-up-windows t
|
|
663 "*Non-nil means display-buffer should make new windows."
|
|
664 :type 'boolean
|
|
665 :group 'windows)
|
|
666
|
|
667 (defcustom split-height-threshold 500
|
|
668 "*display-buffer would prefer to split the largest window if this large.
|
|
669 If there is only one window, it is split regardless of this value."
|
|
670 :type 'integer
|
|
671 :group 'windows)
|
|
672
|
|
673 (defcustom split-width-threshold 500
|
|
674 "*display-buffer would prefer to split the largest window if this large.
|
|
675 If there is only one window, it is split regardless of this value."
|
|
676 :type 'integer
|
|
677 :group 'windows)
|
|
678
|
|
679 ;; Deiconify the frame containing the window WINDOW, then return WINDOW.
|
|
680
|
|
681 (defun display-buffer-1 (window)
|
|
682 (if (frame-iconified-p (window-frame window))
|
|
683 (make-frame-visible (window-frame window)))
|
|
684 window)
|
|
685
|
|
686 ;; Can you believe that all of this crap was formerly in C?
|
|
687 ;; Praise Jesus that it's not there any more.
|
|
688
|
903
|
689 (defun display-buffer (buffer &optional not-this-window-p override-frame
|
|
690 shrink-to-fit)
|
428
|
691 "Make BUFFER appear in some window on the current frame, but don't select it.
|
|
692 BUFFER can be a buffer or a buffer name.
|
|
693 If BUFFER is shown already in some window in the current frame,
|
|
694 just uses that one, unless the window is the selected window and
|
|
695 NOT-THIS-WINDOW-P is non-nil (interactively, with prefix arg).
|
|
696
|
|
697 If BUFFER has a dedicated frame, display on that frame instead of
|
|
698 the current frame, unless OVERRIDE-FRAME is non-nil.
|
|
699
|
|
700 If OVERRIDE-FRAME is non-nil, display on that frame instead of
|
|
701 the current frame (or the dedicated frame).
|
|
702
|
903
|
703 If SHRINK-TO-FIT is non-nil and splitting the window is appropriate, give
|
|
704 the new buffer less than half the space if it is small enough to fit.
|
|
705
|
428
|
706 If `pop-up-windows' is non-nil, always use the
|
|
707 current frame and create a new window regardless of whether the
|
|
708 buffer has a dedicated frame, and regardless of whether
|
|
709 OVERRIDE-FRAME was specified.
|
|
710
|
|
711 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
|
|
712
|
2590
|
713 If the buffer name is a member of the `same-window-buffer-names' list,
|
|
714 or matches one of the `same-window-regexps' expressions, display the
|
|
715 buffer in the currently selected window.
|
|
716
|
428
|
717 Returns the window displaying BUFFER."
|
|
718 (interactive "BDisplay buffer:\nP")
|
|
719
|
|
720 (let ((wconfig (current-window-configuration))
|
|
721 (result
|
|
722 ;; We just simulate a `return' in C. This function is way ugly
|
|
723 ;; and does `returns' all over the place and there's no sense
|
|
724 ;; in trying to rewrite it to be more Lispy.
|
|
725 (catch 'done
|
1669
|
726 (let (window old-frame target-frame explicit-frame shrink-it)
|
428
|
727 (setq old-frame (or (last-nonminibuf-frame) (selected-frame)))
|
|
728 (setq buffer (get-buffer buffer))
|
|
729 (check-argument-type 'bufferp buffer)
|
|
730
|
|
731 (setq explicit-frame
|
|
732 (if pre-display-buffer-function
|
|
733 (funcall pre-display-buffer-function buffer
|
|
734 not-this-window-p
|
903
|
735 override-frame
|
|
736 shrink-to-fit)))
|
428
|
737
|
|
738 ;; Give the user the ability to completely reimplement
|
|
739 ;; this function via the `display-buffer-function'.
|
|
740 (if display-buffer-function
|
|
741 (throw 'done
|
|
742 (funcall display-buffer-function buffer
|
|
743 not-this-window-p
|
903
|
744 override-frame
|
|
745 shrink-to-fit)))
|
428
|
746
|
|
747 ;; If the buffer has a dedicated frame, that takes
|
|
748 ;; precedence over the current frame, and over what the
|
|
749 ;; pre-display-buffer-function did.
|
|
750 (let ((dedi (buffer-dedicated-frame buffer)))
|
|
751 (if (frame-live-p dedi) (setq explicit-frame dedi)))
|
|
752
|
|
753 ;; if override-frame is supplied, that takes precedence over
|
|
754 ;; everything. This is gonna look bad if the
|
|
755 ;; pre-display-buffer-function raised some other frame
|
|
756 ;; already.
|
|
757 (if override-frame
|
|
758 (progn
|
|
759 (check-argument-type 'frame-live-p override-frame)
|
|
760 (setq explicit-frame override-frame)))
|
|
761
|
|
762 (setq target-frame
|
|
763 (or explicit-frame
|
|
764 (last-nonminibuf-frame)
|
|
765 (selected-frame)))
|
|
766
|
|
767 ;; If we have switched frames, then set not-this-window-p
|
|
768 ;; to false. Switching frames means that selected-window
|
|
769 ;; is no longer the same as it was on entry -- it's the
|
|
770 ;; selected-window of target_frame instead of old_frame,
|
|
771 ;; so it's a fine candidate for display.
|
|
772 (if (not (eq old-frame target-frame))
|
|
773 (setq not-this-window-p nil))
|
|
774
|
|
775 ;; if it's in the selected window, and that's ok, then we're done.
|
|
776 (if (and (not not-this-window-p)
|
|
777 (eq buffer (window-buffer (selected-window))))
|
|
778 (throw 'done (display-buffer-1 (selected-window))))
|
|
779
|
|
780 ;; See if the user has specified this buffer should appear
|
|
781 ;; in the selected window.
|
|
782
|
|
783 (if not-this-window-p
|
|
784 nil
|
|
785
|
|
786 (if (or (member (buffer-name buffer) same-window-buffer-names)
|
|
787 (assoc (buffer-name buffer) same-window-buffer-names))
|
|
788 (progn
|
|
789 (switch-to-buffer buffer)
|
|
790 (throw 'done (display-buffer-1 (selected-window)))))
|
|
791
|
|
792 (let ((tem same-window-regexps))
|
|
793 (while tem
|
|
794 (let ((car (car tem)))
|
|
795 (if (or
|
|
796 (and (stringp car)
|
|
797 (string-match car (buffer-name buffer)))
|
|
798 (and (consp car) (stringp (car car))
|
|
799 (string-match (car car) (buffer-name buffer))))
|
|
800 (progn
|
|
801 (switch-to-buffer buffer)
|
|
802 (throw 'done (display-buffer-1
|
|
803 (selected-window))))))
|
|
804 (setq tem (cdr tem)))))
|
|
805
|
|
806 ;; If pop-up-frames, look for a window showing BUFFER on
|
|
807 ;; any visible or iconified frame. Otherwise search only
|
|
808 ;; the current frame.
|
|
809 (if (and (not explicit-frame)
|
|
810 (or pop-up-frames (not (last-nonminibuf-frame))))
|
|
811 (setq target-frame 0))
|
|
812
|
|
813 ;; Otherwise, find some window that it's already in, and
|
|
814 ;; return that, unless that window is the selected window
|
|
815 ;; and that isn't ok. What a contorted mess!
|
|
816 (setq window (or (if (not explicit-frame)
|
|
817 ;; search the selected frame
|
|
818 ;; first if the user didn't
|
|
819 ;; specify an explicit frame.
|
|
820 (get-buffer-window buffer nil))
|
|
821 (get-buffer-window buffer target-frame)))
|
|
822 (if (and window
|
|
823 (or (not not-this-window-p)
|
|
824 (not (eq window (selected-window)))))
|
|
825 (throw 'done (display-buffer-1 window)))
|
|
826
|
|
827 ;; Certain buffer names get special handling.
|
|
828 (if special-display-function
|
|
829 (progn
|
|
830 (if (member (buffer-name buffer)
|
|
831 special-display-buffer-names)
|
|
832 (throw 'done (funcall special-display-function buffer)))
|
|
833
|
|
834 (let ((tem (assoc (buffer-name buffer)
|
|
835 special-display-buffer-names)))
|
|
836 (if tem
|
|
837 (throw 'done (funcall special-display-function
|
|
838 buffer (cdr tem)))))
|
|
839
|
|
840 (let ((tem special-display-regexps))
|
|
841 (while tem
|
|
842 (let ((car (car tem)))
|
|
843 (if (and (stringp car)
|
|
844 (string-match car (buffer-name buffer)))
|
|
845 (throw 'done
|
|
846 (funcall special-display-function buffer)))
|
|
847 (if (and (consp car)
|
|
848 (stringp (car car))
|
|
849 (string-match (car car)
|
|
850 (buffer-name buffer)))
|
|
851 (throw 'done (funcall
|
|
852 special-display-function buffer
|
|
853 (cdr car)))))
|
|
854 (setq tem (cdr tem))))))
|
|
855
|
|
856 ;; If there are no frames open that have more than a minibuffer,
|
|
857 ;; we need to create a new frame.
|
|
858 (if (or pop-up-frames
|
|
859 (null (last-nonminibuf-frame)))
|
|
860 (progn
|
|
861 (setq window (frame-selected-window
|
|
862 (funcall pop-up-frame-function)))
|
|
863 (set-window-buffer window buffer)
|
|
864 (throw 'done (display-buffer-1 window))))
|
|
865
|
|
866 ;; Otherwise, make it be in some window, splitting if
|
|
867 ;; appropriate/possible. Do not split a window if we are
|
|
868 ;; displaying the buffer in a different frame than that which
|
|
869 ;; was current when we were called. (It is already in a
|
|
870 ;; different window by virtue of being in another frame.)
|
|
871 (if (or (and pop-up-windows (eq target-frame old-frame))
|
|
872 (eq 'only (frame-property (selected-frame) 'minibuffer))
|
|
873 ;; If the current frame is a special display frame,
|
|
874 ;; don't try to reuse its windows.
|
|
875 (window-dedicated-p (frame-root-window (selected-frame))))
|
|
876 (progn
|
|
877 (if (eq 'only (frame-property (selected-frame) 'minibuffer))
|
|
878 (setq target-frame (last-nonminibuf-frame)))
|
|
879
|
|
880 ;; Don't try to create a window if would get an error with
|
|
881 ;; height.
|
|
882 (if (< split-height-threshold (* 2 window-min-height))
|
|
883 (setq split-height-threshold (* 2 window-min-height)))
|
|
884
|
|
885 ;; Same with width.
|
|
886 (if (< split-width-threshold (* 2 window-min-width))
|
|
887 (setq split-width-threshold (* 2 window-min-width)))
|
|
888
|
|
889 ;; If the frame we would try to split cannot be split,
|
|
890 ;; try other frames.
|
|
891 (if (frame-property (if (null target-frame)
|
|
892 (selected-frame)
|
|
893 (last-nonminibuf-frame))
|
|
894 'unsplittable)
|
|
895 (setq window
|
|
896 ;; Try visible frames first.
|
|
897 (or (get-largest-window 'visible)
|
|
898 ;; If that didn't work, try iconified frames.
|
|
899 (get-largest-window 0)
|
|
900 (get-largest-window t)))
|
|
901 (setq window (get-largest-window target-frame)))
|
|
902
|
|
903 ;; If we got a tall enough full-width window that
|
|
904 ;; can be split, split it.
|
|
905 (if (and window
|
|
906 (not (frame-property (window-frame window)
|
|
907 'unsplittable))
|
|
908 (>= (window-height window) split-height-threshold)
|
|
909 (or (>= (window-width window)
|
|
910 split-width-threshold)
|
|
911 (and (window-leftmost-p window)
|
|
912 (window-rightmost-p window))))
|
|
913 (setq window (split-window window))
|
1669
|
914 (let (upper other)
|
428
|
915 (setq window (get-lru-window target-frame))
|
|
916 ;; If the LRU window is selected, and big enough,
|
|
917 ;; and can be split, split it.
|
|
918 (if (and window
|
|
919 (not (frame-property (window-frame window)
|
|
920 'unsplittable))
|
|
921 (or (eq window (selected-window))
|
|
922 (not (window-parent window)))
|
|
923 (>= (window-height window)
|
|
924 (* 2 window-min-height)))
|
|
925 (setq window (split-window window)))
|
|
926 ;; If get-lru-window returned nil, try other approaches.
|
|
927 ;; Try visible frames first.
|
|
928 (or window
|
|
929 (setq window (or (get-largest-window 'visible)
|
|
930 ;; If that didn't work, try
|
|
931 ;; iconified frames.
|
|
932 (get-largest-window 0)
|
|
933 ;; Try invisible frames.
|
|
934 (get-largest-window t)
|
|
935 ;; As a last resort, make
|
|
936 ;; a new frame.
|
|
937 (frame-selected-window
|
|
938 (funcall
|
|
939 pop-up-frame-function)))))
|
|
940 ;; If window appears above or below another,
|
|
941 ;; even out their heights.
|
|
942 (if (window-previous-child window)
|
|
943 (setq other (window-previous-child window)
|
|
944 upper other))
|
|
945 (if (window-next-child window)
|
|
946 (setq other (window-next-child window)
|
|
947 upper window))
|
|
948 ;; Check that OTHER and WINDOW are vertically arrayed.
|
|
949 (if (and other
|
|
950 (not (= (nth 1 (window-pixel-edges other))
|
|
951 (nth 1 (window-pixel-edges window))))
|
|
952 (> (window-pixel-height other)
|
|
953 (window-pixel-height window)))
|
|
954 (enlarge-window (- (/ (+ (window-height other)
|
|
955 (window-height window))
|
|
956 2)
|
|
957 (window-height upper))
|
903
|
958 nil upper))
|
1669
|
959 ;; Klaus Berndl <klaus.berndl@sdm.de>: Only in
|
|
960 ;; this situation we shrink-to-fit but we can do
|
|
961 ;; this first after we have displayed buffer in
|
|
962 ;; window (s.b. (set-window-buffer window buffer))
|
|
963 (setq shrink-it shrink-to-fit))))
|
428
|
964
|
|
965 (setq window (get-lru-window target-frame)))
|
|
966
|
|
967 ;; Bring the window's previous buffer to the top of the MRU chain.
|
|
968 (if (window-buffer window)
|
|
969 (save-excursion
|
|
970 (save-selected-window
|
|
971 (select-window window)
|
|
972 (record-buffer (window-buffer window)))))
|
|
973
|
|
974 (set-window-buffer window buffer)
|
|
975
|
1669
|
976 ;; Now window's previous buffer has been brought to the top
|
|
977 ;; of the MRU chain and window displays buffer - now we can
|
|
978 ;; shrink-to-fit if necessary
|
|
979 (if shrink-it
|
|
980 (shrink-window-if-larger-than-buffer window))
|
|
981
|
428
|
982 (display-buffer-1 window)))))
|
|
983 (or (equal wconfig (current-window-configuration))
|
|
984 (push-window-configuration wconfig))
|
|
985 result))
|
|
986
|
|
987 ;;; window-xemacs.el ends here
|