Rename `chinese-cns11643-1' to `=cns11643-1'.
[chise/xemacs-chise.git.1] / lisp / window-xemacs.el
index 554ec53..4950427 100644 (file)
@@ -51,11 +51,11 @@ If WINDOW is nil, the selected window is used."
   (when (null n)
     (redraw-frame (window-frame window) t)))
 
   (when (null n)
     (redraw-frame (window-frame window) t)))
 
-(defun backward-other-window (arg &optional all-frames device)
-  "Select the ARG'th different window on this frame, going backwards.
-This is just like calling `other-window' with the arg negated."
+(defun backward-other-window (count &optional which-frames which-devices)
+  "Select the COUNT'th different window on this frame, going backwards.
+This is just like calling `other-window' with COUNT negated."
   (interactive "p")
   (interactive "p")
-  (other-window (- arg) all-frames device))
+  (other-window (- count) which-frames which-devices))
 
 (defalias 'windows-of-buffer 'get-buffer-window-list)
 
 
 (defalias 'windows-of-buffer 'get-buffer-window-list)
 
@@ -191,13 +191,36 @@ Each frame has its own window-config and \"unpop\" stack."
 \f
 ;;;;;;;;;;;;; display-buffer, moved here from C.  Hallelujah.
 
 \f
 ;;;;;;;;;;;;; display-buffer, moved here from C.  Hallelujah.
 
+(make-variable-buffer-local '__buffer-dedicated-frame)
+
+(defun buffer-dedicated-frame (&optional buffer)
+  "Return the frame dedicated to this BUFFER, or nil if there is none.
+No argument or nil as argument means use current buffer as BUFFER."
+  (let ((buffer (decode-buffer buffer)))
+    (let ((frame (symbol-value-in-buffer '__buffer-dedicated-frame buffer)))
+      ;; XEmacs addition: if the frame is dead, silently make it go away.
+      (when (and (framep frame) (not (frame-live-p frame)))
+           (with-current-buffer buffer
+             (setq __buffer-dedicated-frame nil))
+           (setq frame nil))
+      frame)))
+
+(defun set-buffer-dedicated-frame (buffer frame)
+  "For this BUFFER, set the FRAME dedicated to it.
+FRAME must be a frame or nil."
+  (let ((buffer (decode-buffer buffer)))
+    (and frame
+        (check-argument-type #'frame-live-p frame))
+    (with-current-buffer buffer
+      (setq __buffer-dedicated-frame frame))))
+
 (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
@@ -329,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,
@@ -342,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
@@ -367,7 +394,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'.
@@ -375,7 +403,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
@@ -592,7 +621,9 @@ Returns the window displaying BUFFER."
                                                    (window-height window))
                                                 2)
                                              (window-height upper))
                                                    (window-height window))
                                                 2)
                                              (window-height upper))
-                                          nil upper)))))
+                                          nil upper))
+                      (if shrink-to-fit
+                          (shrink-window-if-larger-than-buffer window)))))
 
               (setq window (get-lru-window target-frame)))
 
 
               (setq window (get-lru-window target-frame)))