(U+4E2E-itaiji-007): New character; use `<-denotational' for U+4E2E.
[chise/xemacs-chise.git.1] / lisp / window-xemacs.el
index 6fb0abd..4af7720 100644 (file)
@@ -216,11 +216,11 @@ FRAME must be a frame or nil."
 
 (defvar display-buffer-function nil
   "If non-nil, function to call to handle `display-buffer'.
 
 (defvar display-buffer-function nil
   "If non-nil, function to call to handle `display-buffer'.
-It will receive three args: the same as those to `display-buffer'.")
+It will receive four args: the same as those to `display-buffer'.")
 
 (defvar pre-display-buffer-function nil
   "If non-nil, function that will be called from `display-buffer'
 
 (defvar pre-display-buffer-function nil
   "If non-nil, function that will be called from `display-buffer'
-as the first action.  It will receive three args: the same as those
+as the first action.  It will receive four args: the same as those
 to `display-buffer'.
 This function may be used to select an appropriate frame for the buffer,
 for example.  See also the variable `display-buffer-function', which may
 to `display-buffer'.
 This function may be used to select an appropriate frame for the buffer,
 for example.  See also the variable `display-buffer-function', which may
@@ -352,7 +352,8 @@ If there is only one window, it is split regardless of this value."
 ;; Can you believe that all of this crap was formerly in C?
 ;; Praise Jesus that it's not there any more.
 
 ;; Can you believe that all of this crap was formerly in C?
 ;; Praise Jesus that it's not there any more.
 
-(defun display-buffer (buffer &optional not-this-window-p override-frame)
+(defun display-buffer (buffer &optional not-this-window-p override-frame
+                             shrink-to-fit)
   "Make BUFFER appear in some window on the current frame, but don't select it.
 BUFFER can be a buffer or a buffer name.
 If BUFFER is shown already in some window in the current frame,
   "Make BUFFER appear in some window on the current frame, but don't select it.
 BUFFER can be a buffer or a buffer name.
 If BUFFER is shown already in some window in the current frame,
@@ -365,6 +366,9 @@ the current frame, unless OVERRIDE-FRAME is non-nil.
 If OVERRIDE-FRAME is non-nil, display on that frame instead of
 the current frame (or the dedicated frame).
 
 If OVERRIDE-FRAME is non-nil, display on that frame instead of
 the current frame (or the dedicated frame).
 
+If SHRINK-TO-FIT is non-nil and splitting the window is appropriate, give
+the new buffer less than half the space if it is small enough to fit.
+
 If `pop-up-windows' is non-nil, always use the
 current frame and create a new window regardless of whether the
 buffer has a dedicated frame, and regardless of whether
 If `pop-up-windows' is non-nil, always use the
 current frame and create a new window regardless of whether the
 buffer has a dedicated frame, and regardless of whether
@@ -372,6 +376,10 @@ OVERRIDE-FRAME was specified.
 
 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
 
 
 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
 
+If the buffer name is a member of the `same-window-buffer-names' list,
+or matches one of the `same-window-regexps' expressions, display the
+buffer in the currently selected window.
+
 Returns the window displaying BUFFER."
   (interactive "BDisplay buffer:\nP")
 
 Returns the window displaying BUFFER."
   (interactive "BDisplay buffer:\nP")
 
@@ -381,7 +389,7 @@ Returns the window displaying BUFFER."
         ;; and does `returns' all over the place and there's no sense
         ;; in trying to rewrite it to be more Lispy.
         (catch 'done
         ;; and does `returns' all over the place and there's no sense
         ;; in trying to rewrite it to be more Lispy.
         (catch 'done
-          (let (window old-frame target-frame explicit-frame)
+          (let (window old-frame target-frame explicit-frame shrink-it)
             (setq old-frame (or (last-nonminibuf-frame) (selected-frame)))
             (setq buffer (get-buffer buffer))
             (check-argument-type 'bufferp buffer)
             (setq old-frame (or (last-nonminibuf-frame) (selected-frame)))
             (setq buffer (get-buffer buffer))
             (check-argument-type 'bufferp buffer)
@@ -390,7 +398,8 @@ Returns the window displaying BUFFER."
                   (if pre-display-buffer-function
                       (funcall pre-display-buffer-function buffer
                                not-this-window-p
                   (if pre-display-buffer-function
                       (funcall pre-display-buffer-function buffer
                                not-this-window-p
-                               override-frame)))
+                               override-frame
+                               shrink-to-fit)))
 
             ;; Give the user the ability to completely reimplement
             ;; this function via the `display-buffer-function'.
 
             ;; Give the user the ability to completely reimplement
             ;; this function via the `display-buffer-function'.
@@ -398,7 +407,8 @@ Returns the window displaying BUFFER."
                 (throw 'done
                        (funcall display-buffer-function buffer
                                 not-this-window-p
                 (throw 'done
                        (funcall display-buffer-function buffer
                                 not-this-window-p
-                                override-frame)))
+                                override-frame
+                                shrink-to-fit)))
 
             ;; If the buffer has a dedicated frame, that takes
             ;; precedence over the current frame, and over what the
 
             ;; If the buffer has a dedicated frame, that takes
             ;; precedence over the current frame, and over what the
@@ -567,9 +577,7 @@ Returns the window displaying BUFFER."
                                (and (window-leftmost-p window)
                                     (window-rightmost-p window))))
                       (setq window (split-window window))
                                (and (window-leftmost-p window)
                                     (window-rightmost-p window))))
                       (setq window (split-window window))
-                    (let (upper
-;;                        lower
-                          other)
+                    (let (upper other)
                       (setq window (get-lru-window target-frame))
                       ;; If the LRU window is selected, and big enough,
                       ;; and can be split, split it.
                       (setq window (get-lru-window target-frame))
                       ;; If the LRU window is selected, and big enough,
                       ;; and can be split, split it.
@@ -599,11 +607,9 @@ Returns the window displaying BUFFER."
                       ;; even out their heights.
                       (if (window-previous-child window)
                           (setq other (window-previous-child window)
                       ;; even out their heights.
                       (if (window-previous-child window)
                           (setq other (window-previous-child window)
-;;                              lower window
                                 upper other))
                       (if (window-next-child window)
                           (setq other (window-next-child window)
                                 upper other))
                       (if (window-next-child window)
                           (setq other (window-next-child window)
-;;                              lower other
                                 upper window))
                       ;; Check that OTHER and WINDOW are vertically arrayed.
                       (if (and other
                                 upper window))
                       ;; Check that OTHER and WINDOW are vertically arrayed.
                       (if (and other
@@ -615,7 +621,12 @@ Returns the window displaying BUFFER."
                                                    (window-height window))
                                                 2)
                                              (window-height upper))
                                                    (window-height window))
                                                 2)
                                              (window-height upper))
-                                          nil upper)))))
+                                          nil upper))
+                       ;; Klaus Berndl <klaus.berndl@sdm.de>: Only in
+                       ;; this situation we shrink-to-fit but we can do
+                       ;; this first after we have displayed buffer in
+                       ;; window (s.b. (set-window-buffer window buffer))
+                       (setq shrink-it shrink-to-fit))))
 
               (setq window (get-lru-window target-frame)))
 
 
               (setq window (get-lru-window target-frame)))
 
@@ -628,6 +639,12 @@ Returns the window displaying BUFFER."
 
             (set-window-buffer window buffer)
 
 
             (set-window-buffer window buffer)
 
+             ;; Now window's previous buffer has been brought to the top
+             ;; of the MRU chain and window displays buffer - now we can
+             ;; shrink-to-fit if necessary
+             (if shrink-it
+                 (shrink-window-if-larger-than-buffer window))
+
             (display-buffer-1 window)))))
     (or (equal wconfig (current-window-configuration))
        (push-window-configuration wconfig))
             (display-buffer-1 window)))))
     (or (equal wconfig (current-window-configuration))
        (push-window-configuration wconfig))