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