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