209
|
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
|
272
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the
|
209
|
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
|
227
|
38 (defgroup windows nil
|
|
39 "Windows within a frame."
|
|
40 :group 'environment)
|
|
41
|
280
|
42 (defun recenter (n &optional 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
|
209
|
54 (defun backward-other-window (arg &optional all-frames device)
|
|
55 "Select the ARG'th different window on this frame, going backwards.
|
|
56 This is just like calling `other-window' with the arg negated."
|
|
57 (interactive "p")
|
|
58 (other-window (- arg) all-frames device))
|
|
59
|
|
60 (defun windows-of-buffer (&optional buffer)
|
272
|
61 "Return a list of windows that have BUFFER in them.
|
209
|
62 If BUFFER is not specified, the current buffer will be used."
|
|
63 (or (bufferp buffer)
|
|
64 (if (stringp buffer)
|
|
65 (setq buffer (or (get-buffer buffer)
|
|
66 (get-file-buffer buffer)))
|
|
67 (setq buffer (current-buffer))))
|
|
68 (let* ((firstwin (next-window nil nil t))
|
272
|
69 (wind firstwin)
|
209
|
70 (done nil)
|
|
71 window-list)
|
|
72 (while (not done)
|
|
73 (if (eq (window-buffer wind) buffer)
|
|
74 (setq window-list (append window-list (list wind))))
|
|
75 (setq wind (next-window wind nil t))
|
|
76 (setq done (eq wind firstwin)))
|
|
77 window-list))
|
|
78
|
|
79 (defun buffer-in-multiple-windows-p (&optional buffer)
|
|
80 "Return t if BUFFER is in multiple windows.
|
|
81 If BUFFER is not specified, the current buffer will be used."
|
|
82 (setq buffer (or buffer
|
|
83 (get-buffer buffer)
|
|
84 (get-file-buffer buffer)
|
|
85 (current-buffer)))
|
|
86 (> (length (windows-of-buffer buffer)) 1))
|
|
87
|
|
88 (defun window-list (&optional frame minibuf window)
|
|
89 "Return a list of windows on FRAME, beginning with WINDOW.
|
272
|
90 FRAME and WINDOW default to the selected ones.
|
209
|
91 Optional second arg MINIBUF t means count the minibuffer window
|
|
92 even if not active. If MINIBUF is neither t nor nil it means
|
|
93 not to count the minibuffer even if it is active."
|
|
94 (setq window (or window (selected-window))
|
|
95 frame (or frame (selected-frame)))
|
|
96 (if (not (eq (window-frame window) frame))
|
|
97 (error "Window must be on frame."))
|
|
98 (let ((current-frame (selected-frame))
|
|
99 list)
|
|
100 (unwind-protect
|
|
101 (save-window-excursion
|
|
102 (select-frame frame)
|
|
103 (walk-windows
|
|
104 (function (lambda (cur-window)
|
|
105 (if (not (eq window cur-window))
|
|
106 (setq list (cons cur-window list)))))
|
|
107 minibuf)
|
|
108 (setq list (cons window list)))
|
|
109 (select-frame current-frame))))
|
|
110
|
|
111 ;; We used to have set-window-dedicated-p as an obsolete version
|
|
112 ;; of set-window-buffer-dedicated, but it really makes more sense
|
|
113 ;; this way.
|
|
114
|
|
115 (make-obsolete 'set-window-buffer-dedicated 'set-window-dedicated-p)
|
|
116 (defun set-window-buffer-dedicated (window buffer)
|
|
117 "Make WINDOW display BUFFER and be dedicated to that buffer.
|
|
118 Then Emacs will not automatically change which buffer appears in WINDOW.
|
|
119 If BUFFER is nil, make WINDOW not be dedicated (but don't change which
|
|
120 buffer appears in it currently)."
|
|
121 (if (bufferp buffer)
|
|
122 (set-window-buffer window (get-buffer-create buffer)))
|
|
123 (set-window-dedicated-p window (not (null buffer))))
|
|
124
|
|
125
|
|
126 ;; The window-config stack is stored as a list in frame property
|
|
127 ;; 'window-config-stack, with the most recent element at the front.
|
|
128 ;; When you pop off an element, the popped off element gets put at the
|
|
129 ;; front of frame property 'window-config-unpop-stack, so you can
|
|
130 ;; retrieve it using unpop-window-configuration.
|
|
131
|
|
132 (defcustom window-config-stack-max 16
|
|
133 "*Maximum size of window configuration stack.
|
|
134 Start discarding off end if it gets this big."
|
|
135 :type 'integer
|
|
136 :group 'windows)
|
|
137
|
|
138 (defun window-config-stack (&optional frame)
|
|
139 (or frame (setq frame (selected-frame)))
|
|
140 (let ((stack (frame-property frame 'window-config-stack)))
|
|
141 (if stack
|
|
142 (set-undoable-stack-max stack window-config-stack-max)
|
|
143 (progn
|
|
144 (setq stack (make-undoable-stack window-config-stack-max))
|
|
145 (set-frame-property frame 'window-config-stack stack)))
|
|
146 stack))
|
|
147
|
|
148 (defun push-window-configuration (&optional config)
|
|
149 "Push the current window configuration onto the window-config stack.
|
|
150 If CONFIG is specified, push it instead of the current window configuration.
|
|
151 Each frame has its own window-config stack."
|
|
152 (interactive)
|
|
153 (let ((wc (or config (current-window-configuration)))
|
|
154 (stack (window-config-stack)))
|
|
155 (if (or (= 0 (undoable-stack-a-length stack))
|
|
156 (not (equal (undoable-stack-a-top stack) wc)))
|
|
157 (progn
|
|
158 (undoable-stack-push stack wc)
|
|
159 ;; kludge.
|
|
160 (if (featurep 'toolbar)
|
|
161 (set-specifier-dirty-flag default-toolbar))))))
|
|
162
|
|
163 (defun pop-window-configuration ()
|
|
164 "Pop the top window configuration off the window-config stack and set it.
|
|
165 Before setting the new window configuration, the current window configuration
|
|
166 is pushed onto the \"unpop\" stack.
|
|
167 `unpop-window-configuration' undoes what this function does.
|
|
168 Each frame has its own window-config and \"unpop\" stack."
|
|
169 (interactive)
|
|
170 (let ((stack (window-config-stack))
|
|
171 (wc (current-window-configuration))
|
|
172 popped)
|
|
173 (condition-case nil
|
|
174 (progn
|
|
175 (setq popped (undoable-stack-pop stack))
|
|
176 (while (equal popped wc)
|
|
177 (setq popped (undoable-stack-pop stack)))
|
|
178 (undoable-stack-push stack wc)
|
|
179 (undoable-stack-undo stack)
|
|
180 (set-window-configuration popped)
|
|
181 ;; probably not necessary:
|
|
182 (if (featurep 'toolbar)
|
|
183 (set-specifier-dirty-flag default-toolbar))
|
|
184 popped)
|
|
185 (trunc-stack-bottom
|
|
186 (error "Bottom of window config stack")))))
|
|
187
|
|
188 (defun unpop-window-configuration ()
|
|
189 "Undo the effect of the most recent `pop-window-configuration'.
|
|
190 This does exactly the inverse of what `pop-window-configuration' does:
|
|
191 i.e. it pops a window configuration off of the \"unpop\" stack and
|
|
192 pushes the current window configuration onto the window-config stack.
|
|
193 Each frame has its own window-config and \"unpop\" stack."
|
|
194 (interactive)
|
|
195 (let ((stack (window-config-stack))
|
|
196 (wc (current-window-configuration))
|
|
197 popped)
|
|
198 (condition-case nil
|
|
199 (progn
|
|
200 (setq popped
|
|
201 (progn
|
|
202 (undoable-stack-redo stack)
|
|
203 (undoable-stack-pop stack)))
|
|
204 (while (equal popped wc)
|
|
205 (setq popped
|
|
206 (progn
|
|
207 (undoable-stack-redo stack)
|
|
208 (undoable-stack-pop stack))))
|
|
209 (undoable-stack-push stack wc)
|
|
210 (set-window-configuration popped)
|
|
211 ;; probably not necessary:
|
|
212 (if (featurep 'toolbar)
|
|
213 (set-specifier-dirty-flag default-toolbar))
|
|
214 popped)
|
|
215 (trunc-stack-bottom
|
|
216 (error "Top of window config stack")))))
|
|
217
|
|
218
|
|
219 ;;;;;;;;;;;;; display-buffer, moved here from C. Hallelujah.
|
|
220
|
|
221 (defvar display-buffer-function nil
|
|
222 "If non-nil, function to call to handle `display-buffer'.
|
|
223 It will receive three args: the same as those to `display-buffer'.")
|
|
224
|
|
225 (defvar pre-display-buffer-function nil
|
|
226 "If non-nil, function that will be called from `display-buffer'
|
|
227 as the first action. It will receive three args: the same as those
|
|
228 to `display-buffer'.
|
|
229 This function may be used to select an appropriate frame for the buffer,
|
|
230 for example. See also the variable `display-buffer-function', which may
|
|
231 be used to completely replace the `display-buffer' function.
|
|
232 If the return value of this function is non-nil, it should be a frame,
|
|
233 and that frame will be used to display the buffer.")
|
|
234
|
|
235 (defcustom pop-up-frames nil
|
|
236 "*Non-nil means `display-buffer' should make a separate frame."
|
|
237 :type 'boolean
|
|
238 :group 'frames)
|
|
239
|
|
240 (defvar pop-up-frame-function nil
|
|
241 "Function to call to handle automatic new frame creation.
|
|
242 It is called with no arguments and should return a newly created frame.
|
|
243
|
|
244 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
|
|
245 where `pop-up-frame-alist' would hold the default frame parameters.")
|
|
246
|
|
247 (defcustom special-display-buffer-names nil
|
|
248 "*List of buffer names that should have their own special frames.
|
|
249 Displaying a buffer whose name is in this list makes a special frame for it
|
|
250 using `special-display-function'.
|
|
251
|
|
252 An element of the list can be a cons cell instead of just a string.
|
|
253 Then the car should be a buffer name, and the cdr specifies frame
|
|
254 parameters for creating the frame for that buffer.
|
|
255 More precisely, the cdr is passed as the second argument to
|
|
256 the function found in `special-display-function', when making that frame.
|
|
257 See also `special-display-regexps'."
|
|
258 :type '(repeat (choice :value ""
|
|
259 (string :tag "Name")
|
|
260 (cons :menu-tag "Properties"
|
|
261 :value ("" . nil)
|
|
262 (string :tag "Name")
|
|
263 (repeat :tag "Properties"
|
|
264 (group :inline t
|
|
265 (symbol :tag "Property")
|
|
266 (sexp :tag "Value"))))))
|
|
267 :group 'frames)
|
|
268
|
|
269 (defcustom special-display-regexps nil
|
|
270 "*List of regexps saying which buffers should have their own special frames.
|
|
271 If a buffer name matches one of these regexps, it gets its own frame.
|
|
272 Displaying a buffer whose name is in this list makes a special frame for it
|
|
273 using `special-display-function'.
|
|
274
|
|
275 An element of the list can be a cons cell instead of just a string.
|
|
276 Then the car should be the regexp, and the cdr specifies frame
|
|
277 parameters for creating the frame for buffers that match.
|
|
278 More precisely, the cdr is passed as the second argument to
|
|
279 the function found in `special-display-function', when making that frame.
|
|
280 See also `special-display-buffer-names'."
|
|
281 :type '(repeat (choice :value ""
|
|
282 regexp
|
|
283 (cons :menu-tag "Properties"
|
|
284 :value ("" . nil)
|
|
285 regexp
|
|
286 (repeat :tag "Properties"
|
|
287 (group :inline t
|
|
288 (symbol :tag "Property")
|
|
289 (sexp :tag "Value"))))))
|
|
290 :group 'frames)
|
|
291
|
|
292 (defvar special-display-function nil
|
|
293 "Function to call to make a new frame for a special buffer.
|
|
294 It is called with two arguments, the buffer and optional buffer specific
|
|
295 data, and should return a window displaying that buffer.
|
|
296 The default value makes a separate frame for the buffer,
|
|
297 using `special-display-frame-alist' to specify the frame parameters.
|
|
298
|
|
299 A buffer is special if its is listed in `special-display-buffer-names'
|
|
300 or matches a regexp in `special-display-regexps'.")
|
|
301
|
|
302 (defcustom same-window-buffer-names nil
|
|
303 "*List of buffer names that should appear in the selected window.
|
|
304 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
|
|
305 switches to it in the selected window, rather than making it appear
|
|
306 in some other window.
|
|
307
|
|
308 An element of the list can be a cons cell instead of just a string.
|
|
309 Then the car must be a string, which specifies the buffer name.
|
|
310 This is for compatibility with `special-display-buffer-names';
|
|
311 the cdr of the cons cell is ignored.
|
|
312
|
|
313 See also `same-window-regexps'."
|
|
314 :type '(repeat (string :tag "Name"))
|
|
315 :group 'windows)
|
|
316
|
|
317 (defcustom same-window-regexps nil
|
|
318 "*List of regexps saying which buffers should appear in the selected window.
|
|
319 If a buffer name matches one of these regexps, then displaying it
|
|
320 using `display-buffer' or `pop-to-buffer' switches to it
|
|
321 in the selected window, rather than making it appear in some other window.
|
|
322
|
|
323 An element of the list can be a cons cell instead of just a string.
|
|
324 Then the car must be a string, which specifies the buffer name.
|
|
325 This is for compatibility with `special-display-buffer-names';
|
|
326 the cdr of the cons cell is ignored.
|
|
327
|
|
328 See also `same-window-buffer-names'."
|
|
329 :type '(repeat regexp)
|
|
330 :group 'windows)
|
|
331
|
|
332 (defcustom pop-up-windows t
|
|
333 "*Non-nil means display-buffer should make new windows."
|
|
334 :type 'boolean
|
|
335 :group 'windows)
|
|
336
|
|
337 (defcustom split-height-threshold 500
|
|
338 "*display-buffer would prefer to split the largest window if this large.
|
|
339 If there is only one window, it is split regardless of this value."
|
|
340 :type 'integer
|
|
341 :group 'windows)
|
|
342
|
|
343 (defcustom split-width-threshold 500
|
|
344 "*display-buffer would prefer to split the largest window if this large.
|
|
345 If there is only one window, it is split regardless of this value."
|
|
346 :type 'integer
|
|
347 :group 'windows)
|
|
348
|
|
349 ;; Deiconify the frame containing the window WINDOW, then return WINDOW.
|
|
350
|
|
351 (defun display-buffer-1 (window)
|
|
352 (if (frame-iconified-p (window-frame window))
|
|
353 (make-frame-visible (window-frame window)))
|
|
354 window)
|
|
355
|
|
356 ;; Can you believe that all of this crap was formerly in C?
|
|
357 ;; Praise Jesus that it's not there any more.
|
|
358
|
|
359 (defun display-buffer (buffer &optional not-this-window-p override-frame)
|
|
360 "Make BUFFER appear in some window on the current frame, but don't select it.
|
|
361 BUFFER can be a buffer or a buffer name.
|
|
362 If BUFFER is shown already in some window in the current frame,
|
|
363 just uses that one, unless the window is the selected window and
|
|
364 NOT-THIS-WINDOW-P is non-nil (interactively, with prefix arg).
|
|
365
|
|
366 If BUFFER has a dedicated frame, display on that frame instead of
|
|
367 the current frame, unless OVERRIDE-FRAME is non-nil.
|
|
368
|
|
369 If OVERRIDE-FRAME is non-nil, display on that frame instead of
|
|
370 the current frame (or the dedicated frame).
|
|
371
|
|
372 If `pop-up-windows' is non-nil, always use the
|
|
373 current frame and create a new window regardless of whether the
|
|
374 buffer has a dedicated frame, and regardless of whether
|
|
375 OVERRIDE-FRAME was specified.
|
|
376
|
|
377 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
|
|
378
|
|
379 Returns the window displaying BUFFER."
|
|
380 (interactive "BDisplay buffer:\nP")
|
|
381
|
|
382 (let ((wconfig (current-window-configuration))
|
|
383 (result
|
|
384 ;; We just simulate a `return' in C. This function is way ugly
|
|
385 ;; and does `returns' all over the place and there's no sense
|
|
386 ;; in trying to rewrite it to be more Lispy.
|
|
387 (catch 'done
|
|
388 (let (window old-frame target-frame explicit-frame)
|
|
389 (setq old-frame (or (last-nonminibuf-frame) (selected-frame)))
|
|
390 (setq buffer (get-buffer buffer))
|
|
391 (check-argument-type 'bufferp buffer)
|
|
392
|
|
393 (setq explicit-frame
|
|
394 (if pre-display-buffer-function
|
|
395 (funcall pre-display-buffer-function buffer
|
|
396 not-this-window-p
|
|
397 override-frame)))
|
|
398
|
|
399 ;; Give the user the ability to completely reimplement
|
|
400 ;; this function via the `display-buffer-function'.
|
|
401 (if display-buffer-function
|
|
402 (throw 'done
|
|
403 (funcall display-buffer-function buffer
|
|
404 not-this-window-p
|
|
405 override-frame)))
|
|
406
|
|
407 ;; If the buffer has a dedicated frame, that takes
|
|
408 ;; precedence over the current frame, and over what the
|
|
409 ;; pre-display-buffer-function did.
|
|
410 (let ((dedi (buffer-dedicated-frame buffer)))
|
|
411 (if (frame-live-p dedi) (setq explicit-frame dedi)))
|
|
412
|
|
413 ;; if override-frame is supplied, that takes precedence over
|
|
414 ;; everything. This is gonna look bad if the
|
|
415 ;; pre-display-buffer-function raised some other frame
|
|
416 ;; already.
|
|
417 (if override-frame
|
|
418 (progn
|
|
419 (check-argument-type 'frame-live-p override-frame)
|
|
420 (setq explicit-frame override-frame)))
|
|
421
|
|
422 (setq target-frame
|
|
423 (or explicit-frame
|
|
424 (last-nonminibuf-frame)
|
|
425 (selected-frame)))
|
|
426
|
|
427 ;; If we have switched frames, then set not-this-window-p
|
|
428 ;; to false. Switching frames means that selected-window
|
|
429 ;; is no longer the same as it was on entry -- it's the
|
|
430 ;; selected-window of target_frame instead of old_frame,
|
|
431 ;; so it's a fine candidate for display.
|
|
432 (if (not (eq old-frame target-frame))
|
|
433 (setq not-this-window-p nil))
|
272
|
434
|
209
|
435 ;; if it's in the selected window, and that's ok, then we're done.
|
|
436 (if (and (not not-this-window-p)
|
|
437 (eq buffer (window-buffer (selected-window))))
|
|
438 (throw 'done (display-buffer-1 (selected-window))))
|
|
439
|
|
440 ;; See if the user has specified this buffer should appear
|
|
441 ;; in the selected window.
|
272
|
442
|
209
|
443 (if not-this-window-p
|
|
444 nil
|
272
|
445
|
209
|
446 (if (or (member (buffer-name buffer) same-window-buffer-names)
|
|
447 (assoc (buffer-name buffer) same-window-buffer-names))
|
|
448 (progn
|
|
449 (switch-to-buffer buffer)
|
|
450 (throw 'done (display-buffer-1 (selected-window)))))
|
272
|
451
|
209
|
452 (let ((tem same-window-regexps))
|
|
453 (while tem
|
|
454 (let ((car (car tem)))
|
|
455 (if (or
|
|
456 (and (stringp car)
|
|
457 (string-match car (buffer-name buffer)))
|
|
458 (and (consp car) (stringp (car car))
|
|
459 (string-match (car car) (buffer-name buffer))))
|
|
460 (progn
|
|
461 (switch-to-buffer buffer)
|
|
462 (throw 'done (display-buffer-1
|
|
463 (selected-window))))))
|
|
464 (setq tem (cdr tem)))))
|
272
|
465
|
209
|
466 ;; If pop-up-frames, look for a window showing BUFFER on
|
|
467 ;; any visible or iconified frame. Otherwise search only
|
|
468 ;; the current frame.
|
|
469 (if (and (not explicit-frame)
|
|
470 (or pop-up-frames (not (last-nonminibuf-frame))))
|
|
471 (setq target-frame 0))
|
272
|
472
|
209
|
473 ;; Otherwise, find some window that it's already in, and
|
|
474 ;; return that, unless that window is the selected window
|
|
475 ;; and that isn't ok. What a contorted mess!
|
259
|
476 (setq window (or (if (not explicit-frame)
|
|
477 ;; search the selected frame
|
|
478 ;; first if the user didn't
|
|
479 ;; specify an explicit frame.
|
|
480 (get-buffer-window buffer nil))
|
|
481 (get-buffer-window buffer target-frame)))
|
209
|
482 (if (and window
|
|
483 (or (not not-this-window-p)
|
|
484 (not (eq window (selected-window)))))
|
|
485 (throw 'done (display-buffer-1 window)))
|
|
486
|
|
487 ;; Certain buffer names get special handling.
|
|
488 (if special-display-function
|
|
489 (progn
|
|
490 (if (member (buffer-name buffer)
|
|
491 special-display-buffer-names)
|
|
492 (throw 'done (funcall special-display-function buffer)))
|
|
493
|
|
494 (let ((tem (assoc (buffer-name buffer)
|
|
495 special-display-buffer-names)))
|
|
496 (if tem
|
|
497 (throw 'done (funcall special-display-function
|
|
498 buffer (cdr tem)))))
|
|
499
|
|
500 (let ((tem special-display-regexps))
|
|
501 (while tem
|
|
502 (let ((car (car tem)))
|
|
503 (if (and (stringp car)
|
|
504 (string-match car (buffer-name buffer)))
|
|
505 (throw 'done
|
|
506 (funcall special-display-function buffer)))
|
|
507 (if (and (consp car)
|
|
508 (stringp (car car))
|
|
509 (string-match (car car)
|
|
510 (buffer-name buffer)))
|
|
511 (throw 'done (funcall
|
|
512 special-display-function buffer
|
|
513 (cdr car)))))
|
|
514 (setq tem (cdr tem))))))
|
|
515
|
|
516 ;; If there are no frames open that have more than a minibuffer,
|
|
517 ;; we need to create a new frame.
|
|
518 (if (or pop-up-frames
|
|
519 (null (last-nonminibuf-frame)))
|
|
520 (progn
|
|
521 (setq window (frame-selected-window
|
|
522 (funcall pop-up-frame-function)))
|
|
523 (set-window-buffer window buffer)
|
|
524 (throw 'done (display-buffer-1 window))))
|
|
525
|
|
526 ;; Otherwise, make it be in some window, splitting if
|
|
527 ;; appropriate/possible. Do not split a window if we are
|
|
528 ;; displaying the buffer in a different frame than that which
|
|
529 ;; was current when we were called. (It is already in a
|
|
530 ;; different window by virtue of being in another frame.)
|
|
531 (if (or (and pop-up-windows (eq target-frame old-frame))
|
|
532 (eq 'only (frame-property (selected-frame) 'minibuffer))
|
|
533 ;; If the current frame is a special display frame,
|
|
534 ;; don't try to reuse its windows.
|
|
535 (window-dedicated-p (frame-root-window (selected-frame))))
|
|
536 (progn
|
|
537 (if (eq 'only (frame-property (selected-frame) 'minibuffer))
|
|
538 (setq target-frame (last-nonminibuf-frame)))
|
|
539
|
|
540 ;; Don't try to create a window if would get an error with
|
|
541 ;; height.
|
|
542 (if (< split-height-threshold (* 2 window-min-height))
|
|
543 (setq split-height-threshold (* 2 window-min-height)))
|
|
544
|
|
545 ;; Same with width.
|
|
546 (if (< split-width-threshold (* 2 window-min-width))
|
|
547 (setq split-width-threshold (* 2 window-min-width)))
|
|
548
|
|
549 ;; If the frame we would try to split cannot be split,
|
|
550 ;; try other frames.
|
|
551 (if (frame-property (if (null target-frame)
|
|
552 (selected-frame)
|
|
553 (last-nonminibuf-frame))
|
|
554 'unsplittable)
|
|
555 (setq window
|
|
556 ;; Try visible frames first.
|
|
557 (or (get-largest-window 'visible)
|
|
558 ;; If that didn't work, try iconified frames.
|
|
559 (get-largest-window 0)
|
|
560 (get-largest-window t)))
|
|
561 (setq window (get-largest-window target-frame)))
|
|
562
|
|
563 ;; If we got a tall enough full-width window that
|
|
564 ;; can be split, split it.
|
|
565 (if (and window
|
|
566 (not (frame-property (window-frame window)
|
|
567 'unsplittable))
|
|
568 (>= (window-height window) split-height-threshold)
|
|
569 (or (>= (window-width window)
|
|
570 split-width-threshold)
|
|
571 (and (window-leftmost-p window)
|
|
572 (window-rightmost-p window))))
|
|
573 (setq window (split-window window))
|
|
574 (let (upper
|
|
575 ;; lower
|
|
576 other)
|
|
577 (setq window (get-lru-window target-frame))
|
|
578 ;; If the LRU window is selected, and big enough,
|
|
579 ;; and can be split, split it.
|
|
580 (if (and window
|
272
|
581 (not (frame-property (window-frame window)
|
209
|
582 'unsplittable))
|
|
583 (or (eq window (selected-window))
|
|
584 (not (window-parent window)))
|
|
585 (>= (window-height window)
|
|
586 (* 2 window-min-height)))
|
|
587 (setq window (split-window window)))
|
|
588 ;; If get-lru-window returned nil, try other approaches.
|
|
589 ;; Try visible frames first.
|
|
590 (or window
|
|
591 (setq window (or (get-largest-window 'visible)
|
|
592 ;; If that didn't work, try
|
|
593 ;; iconified frames.
|
|
594 (get-largest-window 0)
|
|
595 ;; Try invisible frames.
|
|
596 (get-largest-window t)
|
|
597 ;; As a last resort, make
|
|
598 ;; a new frame.
|
|
599 (frame-selected-window
|
|
600 (funcall
|
|
601 pop-up-frame-function)))))
|
|
602 ;; If window appears above or below another,
|
|
603 ;; even out their heights.
|
|
604 (if (window-previous-child window)
|
|
605 (setq other (window-previous-child window)
|
|
606 ;; lower window
|
|
607 upper other))
|
|
608 (if (window-next-child window)
|
|
609 (setq other (window-next-child window)
|
|
610 ;; lower other
|
|
611 upper window))
|
|
612 ;; Check that OTHER and WINDOW are vertically arrayed.
|
|
613 (if (and other
|
|
614 (not (= (nth 1 (window-pixel-edges other))
|
|
615 (nth 1 (window-pixel-edges window))))
|
|
616 (> (window-pixel-height other)
|
|
617 (window-pixel-height window)))
|
|
618 (enlarge-window (- (/ (+ (window-height other)
|
|
619 (window-height window))
|
|
620 2)
|
|
621 (window-height upper))
|
|
622 nil upper)))))
|
|
623
|
|
624 (setq window (get-lru-window target-frame)))
|
|
625
|
|
626 ;; Bring the window's previous buffer to the top of the MRU chain.
|
|
627 (if (window-buffer window)
|
|
628 (save-excursion
|
|
629 (save-selected-window
|
|
630 (select-window window)
|
|
631 (record-buffer (window-buffer window)))))
|
|
632
|
|
633 (set-window-buffer window buffer)
|
|
634
|
|
635 (display-buffer-1 window)))))
|
|
636 (or (equal wconfig (current-window-configuration))
|
|
637 (push-window-configuration wconfig))
|
|
638 result))
|
|
639
|
|
640 ;;; window-xemacs.el ends here
|