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