]> code.delx.au - gnu-emacs/blobdiff - lisp/ediff-wind.el
(report_file_error): String pointer args now point to
[gnu-emacs] / lisp / ediff-wind.el
index 9ae1673250d01724f4772f1b879a2a59efbc5d88..8d8334705d22d6cf4948f792b404e6fcc556b565 100644 (file)
@@ -1,8 +1,8 @@
 ;;; ediff-wind.el --- window manipulation utilities
 
-;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 95, 96, 97, 2000, 01, 02 Free Software Foundation, Inc.
 
-;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
 
 ;; This file is part of GNU Emacs.
 
@@ -21,6 +21,8 @@
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
 ;;; Code:
         
 (provide 'ediff-wind)
@@ -34,6 +36,7 @@
 (defvar left-toolbar-width)
 (defvar right-toolbar-width)
 (defvar default-menubar)
+(defvar top-gutter)
 (defvar frame-icon-title-format)
 (defvar ediff-diff-status)
 (defvar ediff-emacs-p)
@@ -73,8 +76,8 @@
                                        'ediff-setup-windows-multiframe
                                      'ediff-setup-windows-plain)
   "*Function called to set up windows.
-Ediff provides a choice of two functions: ediff-setup-windows-plain, for
-doing everything in one frame, and ediff-setup-windows-multiframe,
+Ediff provides a choice of two functions: `ediff-setup-windows-plain', for
+doing everything in one frame, and `ediff-setup-windows-multiframe',
 which sets the control panel in a separate frame.  Also, if the latter
 function detects that one of the buffers A/B is seen in some other frame,
 it will try to keep that buffer in that frame.
@@ -82,9 +85,9 @@ it will try to keep that buffer in that frame.
 If you don't like the two functions provided---write your own one.
 The basic guidelines:
     1. It should leave the control buffer current and the control window
-       selected. 
-    2. It should set ediff-window-A, ediff-window-B, ediff-window-C,
-       and ediff-control-window to contain window objects that display
+       selected.
+    2. It should set `ediff-window-A', `ediff-window-B', `ediff-window-C',
+       and `ediff-control-window' to contain window objects that display
        the corresponding buffers.
     3. It should accept the following arguments:
        buffer-A, buffer-B, buffer-C, control-buffer
@@ -143,7 +146,7 @@ In this case, Ediff will use those frames to display these buffers."
   :group 'ediff-window)
 
 (defconst ediff-control-frame-parameters
-  (list 
+  (list
    '(name . "Ediff")
    ;;'(unsplittable . t)
    '(minibuffer . nil)
@@ -151,6 +154,7 @@ In this case, Ediff will use those frames to display these buffers."
    '(vertical-scroll-bars . nil)  ; Emacs only
    '(scrollbar-width . 0)         ; XEmacs only
    '(menu-bar-lines . 0)          ; Emacs only
+   '(tool-bar-lines . 0)          ; Emacs 21+ only
    ;; don't lower and auto-raise
    '(auto-lower . nil)
    '(auto-raise . t)
@@ -229,7 +233,7 @@ customization of the default."
 ;; t means Ediff is using wide display
 (ediff-defvar-local ediff-wide-display-p nil "")
 ;; keeps frame config for toggling wide display
-(ediff-defvar-local ediff-wide-display-orig-parameters nil 
+(ediff-defvar-local ediff-wide-display-orig-parameters nil
   "Frame parameters to be restored when the user wants to toggle the wide
 display off.")
 (ediff-defvar-local ediff-wide-display-frame nil
@@ -268,35 +272,39 @@ into icons, regardless of the window manager."
          (beep 1))
       (message "Please click on Window %d " wind-number))
     (ediff-read-event) ; discard event
-    (setq wind (if ediff-xemacs-p
-                  (event-window event)
-                (posn-window (event-start event))))
+    (setq wind (ediff-cond-compile-for-xemacs-or-emacs
+               (event-window event) ; xemacs
+               (posn-window (event-start event)) ; emacs
+               )
+         )
     ))
       
 
 ;; Select the lowest window on the frame.
 (defun ediff-select-lowest-window ()
-  (if ediff-xemacs-p
-      (select-window (frame-lowest-window))
-    (let* ((lowest-window (selected-window))
-          (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
-          (last-window (save-excursion
-                         (other-window -1) (selected-window)))
-          (window-search t))
-      (while window-search
-       (let* ((this-window (next-window))
-              (next-bottom-edge
-               (car (cdr (cdr (cdr (window-edges this-window)))))))
-         (if (< bottom-edge next-bottom-edge)
-             (progn
-               (setq bottom-edge next-bottom-edge)
-               (setq lowest-window this-window)))
-         
-         (select-window this-window)
-         (if (eq last-window this-window)
-             (progn
-               (select-window lowest-window)
-               (setq window-search nil))))))))
+  (ediff-cond-compile-for-xemacs-or-emacs
+   (select-window (frame-lowest-window)) ; xemacs
+   ;; emacs
+   (let* ((lowest-window (selected-window))
+         (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
+         (last-window (save-excursion
+                        (other-window -1) (selected-window)))
+         (window-search t))
+     (while window-search
+       (let* ((this-window (next-window))
+             (next-bottom-edge
+              (car (cdr (cdr (cdr (window-edges this-window)))))))
+        (if (< bottom-edge next-bottom-edge)
+            (progn
+              (setq bottom-edge next-bottom-edge)
+              (setq lowest-window this-window)))
+        
+        (select-window this-window)
+        (if (eq last-window this-window)
+            (progn
+              (select-window lowest-window)
+              (setq window-search nil))))))
+   ))
 
 
 ;;; Common window setup routines
@@ -317,7 +325,7 @@ into icons, regardless of the window manager."
       (setq ediff-window-setup-function 'ediff-setup-windows-plain))
   
   (or (ediff-keep-window-config control-buffer)
-      (funcall 
+      (funcall
        (ediff-with-current-buffer control-buffer ediff-window-setup-function)
        buffer-A buffer-B buffer-C control-buffer))
   (run-hooks 'ediff-after-setup-windows-hook))
@@ -331,14 +339,14 @@ into icons, regardless of the window manager."
   (if ediff-merge-job
       (ediff-setup-windows-plain-merge
        buffer-A buffer-B buffer-C control-buffer)
-    (ediff-setup-windows-plain-compare 
+    (ediff-setup-windows-plain-compare
      buffer-A buffer-B buffer-C control-buffer)))
      
 (defun ediff-setup-windows-plain-merge (buf-A buf-B buf-C control-buffer)
   ;; skip dedicated and unsplittable frames
   (ediff-destroy-control-frame control-buffer)
   (let ((window-min-height 1)
-       split-window-function 
+       split-window-function
        merge-window-share merge-window-lines
        wind-A wind-B wind-C)
     (ediff-with-current-buffer control-buffer
@@ -351,7 +359,7 @@ into icons, regardless of the window manager."
     (ediff-setup-control-buffer control-buffer)
     
     ;; go to the upper window and split it betw A, B, and possibly C
-    (other-window 1) 
+    (other-window 1)
     (setq merge-window-lines
          (max 2 (round (* (window-height) merge-window-share))))
     (switch-to-buffer buf-A)
@@ -363,7 +371,7 @@ into icons, regardless of the window manager."
     ;;(if ediff-xemacs-p (sit-for 0))
     
     (split-window-vertically (max 2 (- (window-height) merge-window-lines)))
-    (if (eq (selected-window) wind-A) 
+    (if (eq (selected-window) wind-A)
        (other-window 1))
     (setq wind-C (selected-window))
     (switch-to-buffer buf-C)
@@ -410,7 +418,7 @@ into icons, regardless of the window manager."
     (ediff-setup-control-buffer control-buffer)
     
     ;; go to the upper window and split it betw A, B, and possibly C
-    (other-window 1) 
+    (other-window 1)
     (switch-to-buffer buf-A)
     (setq wind-A (selected-window))
     (if three-way-comparison
@@ -470,14 +478,14 @@ into icons, regardless of the window manager."
 ;;;   1. Never use frames that have dedicated windows in them---it is bad to
 ;;;      destroy dedicated windows.
 ;;;   2. If A and B are in the same frame but C's frame is different--- use one
-;;;      frame for A and B and use a separate frame for C. 
+;;;      frame for A and B and use a separate frame for C.
 ;;;   3. If C's frame is non-existent, then: if the first suitable
 ;;;      non-dedicated frame  is different from A&B's, then use it for C.
 ;;;      Otherwise, put A,B, and C in one frame.
 ;;;   4. If buffers A, B, C are is separate frames, use them to display these
 ;;;      buffers.
 
-  ;;   Skip dedicated or iconified frames. 
+  ;;   Skip dedicated or iconified frames.
   ;;   Unsplittable frames are taken care of later.
   (ediff-skip-unsuitable-frames 'ok-unsplittable)
   
@@ -489,10 +497,10 @@ into icons, regardless of the window manager."
         (frame-B (if wind-B (window-frame wind-B)))
         (frame-C (if wind-C (window-frame wind-C)))
         ;; on wide display, do things in one frame
-        (force-one-frame 
+        (force-one-frame
          (ediff-with-current-buffer control-buf ediff-wide-display-p))
         ;; this lets us have local versions of ediff-split-window-function
-        (split-window-function 
+        (split-window-function
          (ediff-with-current-buffer control-buf ediff-split-window-function))
         (orig-wind (selected-window))
         (orig-frame (selected-frame))
@@ -556,14 +564,14 @@ into icons, regardless of the window manager."
     
     (if (and use-same-frame-for-AB  ; implies wind A and B are suitable
             (window-live-p wind-A))
-       (progn 
+       (progn
          ;; wind-A must already be displaying buf-A
          (select-window wind-A)
          (delete-other-windows)
          (setq wind-A (selected-window))
          
          (funcall split-window-function)
-         (if (eq (selected-window) wind-A) 
+         (if (eq (selected-window) wind-A)
              (other-window 1))
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
@@ -587,7 +595,7 @@ into icons, regardless of the window manager."
          
          (split-window-vertically
           (max 2 (- (window-height) merge-window-lines)))
-         (if (eq (selected-window) wind-A) 
+         (if (eq (selected-window) wind-A)
              (other-window 1))
          (setq wind-C (selected-window))
          (switch-to-buffer buf-C)
@@ -595,7 +603,7 @@ into icons, regardless of the window manager."
          (select-window wind-A)
          
          (funcall split-window-function)
-         (if (eq (selected-window) wind-A) 
+         (if (eq (selected-window) wind-A)
              (other-window 1))
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
@@ -652,7 +660,7 @@ into icons, regardless of the window manager."
 ;; Window setup for all comparison jobs, including 3way comparisons
 (defun ediff-setup-windows-multiframe-compare (buf-A buf-B buf-C control-buf)
 ;;; Algorithm:
-;;;    If a buffer is seen in a frame, use that frame for that buffer.  
+;;;    If a buffer is seen in a frame, use that frame for that buffer.
 ;;;    If it is not seen, use the current frame.
 ;;;    If both buffers are not seen, they share the current frame.  If one
 ;;;    of the buffers is not seen, it is placed in the current frame (where
@@ -677,10 +685,10 @@ into icons, regardless of the window manager."
         (ctl-frame-exists-p (ediff-with-current-buffer control-buf
                               (frame-live-p ediff-control-frame)))
         ;; on wide display, do things in one frame
-        (force-one-frame 
+        (force-one-frame
          (ediff-with-current-buffer control-buf ediff-wide-display-p))
         ;; this lets us have local versions of ediff-split-window-function
-        (split-window-function 
+        (split-window-function
          (ediff-with-current-buffer control-buf ediff-split-window-function))
         (three-way-comparison
          (ediff-with-current-buffer control-buf ediff-3way-comparison-job))
@@ -702,7 +710,7 @@ into icons, regardless of the window manager."
                             (and (not (frame-live-p frame-A))
                                  (or ctl-frame-exists-p
                                      (eq frame-B (selected-frame))))))
-        wind-A-start wind-B-start 
+        wind-A-start wind-B-start
         designated-minibuffer-frame
         done-A done-B done-C)
     
@@ -757,7 +765,7 @@ into icons, regardless of the window manager."
                     3)))
          
          (funcall split-window-function wind-width-or-height)
-         (if (eq (selected-window) wind-A) 
+         (if (eq (selected-window) wind-A)
              (other-window 1))
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
@@ -776,7 +784,7 @@ into icons, regardless of the window manager."
     
     (or done-A  ; Buf A to be set in its own frame
              ;;; or it was set before because use-same-frame = 1
-       (progn  
+       (progn
          ;; Buf-A was not set up yet as it wasn't visible,
          ;; and use-same-frame = nil
          (select-window orig-wind)
@@ -786,7 +794,7 @@ into icons, regardless of the window manager."
          ))
     (or done-B  ; Buf B to be set in its own frame
              ;;; or it was set before because use-same-frame = 1
-       (progn  
+       (progn
          ;; Buf-B was not set up yet as it wasn't visible,
          ;; and use-same-frame = nil
          (select-window orig-wind)
@@ -798,7 +806,7 @@ into icons, regardless of the window manager."
     (if three-way-comparison
        (or done-C  ; Buf C to be set in its own frame
                  ;;; or it was set before because use-same-frame = 1
-           (progn  
+           (progn
              ;; Buf-C was not set up yet as it wasn't visible,
              ;; and use-same-frame = nil
              (select-window orig-wind)
@@ -830,25 +838,30 @@ into icons, regardless of the window manager."
 ;; create a new splittable frame if none is found
 (defun ediff-skip-unsuitable-frames (&optional ok-unsplittable)
   (if (ediff-window-display-p)
-      (let (last-window)
-       (while (and (not (eq (selected-window) last-window))
+      ;;(let (last-window)
+      (let (seen-windows)
+       ;; (memq ... seen-windows) has quadratic behavior,
+       ;; but (eq ... last-window) runs into an emacs bug where next-window
+       ;; gets stuck in a loop if the only frame is the minibuffer.
+       ;;
+       ;;(while (and (not (eq (selected-window) last-window))
+       (while (and (not (memq (selected-window) seen-windows))
                    (or
                     (ediff-frame-has-dedicated-windows (selected-frame))
                     (ediff-frame-iconified-p (selected-frame))
-                    ;; skip small frames
-                    (< (frame-height (selected-frame))
-                       (* 3 window-min-height))
                     ;; skip small windows
-                    (< (window-height (selected-window))
+                    (< (frame-height (selected-frame))
                        (* 3 window-min-height))
                     (if ok-unsplittable
                         nil
                       (ediff-frame-unsplittable-p (selected-frame)))))
          ;; remember where started
-         (or last-window (setq last-window (selected-window)))
+         ;;(or last-window (setq last-window (selected-window)))
+         (setq seen-windows (cons (selected-window) seen-windows))
          ;; try new window
          (other-window 1 t))
-       (if (eq (selected-window) last-window)
+       ;;(if (eq (selected-window) last-window)
+       (if (memq (selected-window) seen-windows)
            ;; fed up, no appropriate frame
            (progn
              (select-frame (make-frame '((unsplittable)))))))))
@@ -872,7 +885,7 @@ into icons, regardless of the window manager."
 (defun ediff-window-ok-for-display (wind)
   (and
    (window-live-p wind)
-   (or 
+   (or
     ;; only one window
     (eq wind (next-window wind 'ignore-minibuffer (window-frame wind)))
     ;; none is dedicated
@@ -883,12 +896,15 @@ into icons, regardless of the window manager."
 (defun ediff-setup-control-frame (ctl-buffer designated-minibuffer-frame)
   (let ((window-min-height 1)
        ctl-frame-iconified-p dont-iconify-ctl-frame deiconify-ctl-frame
-       ctl-frame old-ctl-frame lines 
+       ctl-frame old-ctl-frame lines
        ;; user-grabbed-mouse
-       fheight fwidth adjusted-parameters) 
+       fheight fwidth adjusted-parameters)
        
     (ediff-with-current-buffer ctl-buffer
-      (if ediff-xemacs-p (set-buffer-menubar nil))
+      (ediff-cond-compile-for-xemacs-or-emacs
+       (set-buffer-menubar nil) ; xemacs
+       nil ; emacs
+       )
       ;;(setq user-grabbed-mouse (ediff-user-grabbed-mouse))
       (run-hooks 'ediff-before-setup-control-frame-hook))
   
@@ -897,7 +913,16 @@ into icons, regardless of the window manager."
       (setq ctl-frame (if (frame-live-p old-ctl-frame)
                          old-ctl-frame
                        (make-frame ediff-control-frame-parameters))
-           ediff-control-frame ctl-frame))
+           ediff-control-frame ctl-frame)
+      ;; protect against undefined face-attribute
+      (condition-case nil
+         (ediff-cond-compile-for-xemacs-or-emacs
+          nil ; xemacs
+          (when (face-attribute 'mode-line :box)
+            (set-face-attribute 'mode-line ctl-frame :box nil))
+          )
+       (error))
+      )
     
     (setq ctl-frame-iconified-p (ediff-frame-iconified-p ctl-frame))
     (select-frame ctl-frame)
@@ -916,7 +941,7 @@ into icons, regardless of the window manager."
     (ediff-setup-control-buffer ctl-buffer)
     (setq dont-iconify-ctl-frame
          (not (string= ediff-help-message ediff-brief-help-message)))
-    (setq deiconify-ctl-frame 
+    (setq deiconify-ctl-frame
          (and (eq this-command 'ediff-toggle-help)
               dont-iconify-ctl-frame))
     
@@ -939,16 +964,21 @@ into icons, regardless of the window manager."
              (cons '(auto-raise . nil) adjusted-parameters)))
     
     ;; In XEmacs, buffer menubar needs to be killed before frame parameters
-    ;; are changed. 
+    ;; are changed.
     (if (ediff-has-toolbar-support-p)
-       (progn
-         (set-specifier top-toolbar-height (list ctl-frame 2))
-         (sit-for 0)
-         (set-specifier top-toolbar-height (list ctl-frame 0))
-         ;;(set-specifier bottom-toolbar-height (list ctl-frame 0))
-         (set-specifier left-toolbar-width (list ctl-frame 0))
-         (set-specifier right-toolbar-width (list ctl-frame 0))
-         ))
+       (ediff-cond-compile-for-xemacs-or-emacs
+        (progn ; xemacs
+          (if (ediff-has-gutter-support-p)
+              (set-specifier top-gutter (list ctl-frame nil)))
+          (sit-for 0)
+          (set-specifier top-toolbar-height (list ctl-frame 0))
+          ;;(set-specifier bottom-toolbar-height (list ctl-frame 0))
+          (set-specifier left-toolbar-width (list ctl-frame 0))
+          (set-specifier right-toolbar-width (list ctl-frame 0))
+          )
+        nil ; emacs
+        )
+      )
     
     ;; Under OS/2 (emx) we have to call modify frame parameters twice, in order
     ;; to make sure that at least once we do it for non-iconified frame.  If
@@ -1004,8 +1034,12 @@ into icons, regardless of the window manager."
        
     (if ediff-xemacs-p
        (ediff-with-current-buffer ctl-buffer
-         (make-local-hook 'select-frame-hook)
-         (add-hook 'select-frame-hook 'ediff-xemacs-select-frame-hook nil t)
+         (ediff-cond-compile-for-xemacs-or-emacs
+          (make-local-hook 'select-frame-hook) ; xemacs
+          nil     ; emacs
+          )
+         (add-hook
+          'select-frame-hook 'ediff-xemacs-select-frame-hook nil 'local)
          ))
        
     (ediff-with-current-buffer ctl-buffer
@@ -1017,8 +1051,10 @@ into icons, regardless of the window manager."
   (ediff-with-current-buffer ctl-buffer
     (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
        (let ((ctl-frame ediff-control-frame))
-         (if ediff-xemacs-p
-             (set-buffer-menubar default-menubar))
+         (ediff-cond-compile-for-xemacs-or-emacs
+          (set-buffer-menubar default-menubar) ; xemacs
+          nil ; emacs
+          )
          (setq ediff-control-frame nil)
          (delete-frame ctl-frame)
          )))
@@ -1037,7 +1073,7 @@ into icons, regardless of the window manager."
           (frame-A-width (frame-width frame-A))
           (ctl-frame ediff-control-frame)
           horizontal-adjustment upward-adjustment
-          ctl-frame-top ctl-frame-left) 
+          ctl-frame-top ctl-frame-left)
       
       ;; Multiple control frames are clipped based on the value of
       ;; ediff-control-buffer-number.  This is done in order not to obscure
@@ -1087,12 +1123,12 @@ The frame to be resized is kept in `ediff-wide-display-frame'.
 This function modifies only the left margin and the width of the display.
 It assumes that it is called from within the control buffer."
   (if (not (fboundp 'ediff-display-pixel-width))
-      (error "Can't determine display width."))
+      (error "Can't determine display width"))
   (let* ((frame-A (window-frame ediff-window-A))
         (frame-A-params (frame-parameters frame-A))
         (cw (ediff-frame-char-width frame-A))
         (wd (- (/ (ediff-display-pixel-width) cw) 5)))
-    (setq ediff-wide-display-orig-parameters 
+    (setq ediff-wide-display-orig-parameters
          (list (cons 'left (max 0 (eval (cdr (assoc 'left frame-A-params)))))
                (cons 'width (cdr (assoc 'width frame-A-params))))
          ediff-wide-display-frame frame-A)
@@ -1126,7 +1162,7 @@ It assumes that it is called from within the control buffer."
                                      (if buf-C-state-merge
                                          (concat " " buf-C-state-merge)
                                        "")
-                                     (if (ediff-get-state-of-ancestor 
+                                     (if (ediff-get-state-of-ancestor
                                           ediff-current-difference)
                                          " AncestorEmpty"
                                        "")
@@ -1142,7 +1178,7 @@ It assumes that it is called from within the control buffer."
              (list "   " mode-line-buffer-identification)
            (list "-- " mode-line-buffer-identification "        Quick Help")))
     ;; control buffer id
-    (setq mode-line-buffer-identification 
+    (setq mode-line-buffer-identification
          (if (ediff-narrow-control-frame-p)
              (ediff-make-narrow-control-buffer-id 'skip-name)
            (ediff-make-wide-control-buffer-id)))
@@ -1210,7 +1246,7 @@ It assumes that it is called from within the control buffer."
    (if skip-name
        " "
      (ediff-make-base-title))
-   (cond ((< ediff-current-difference 0) 
+   (cond ((< ediff-current-difference 0)
          (format " _/%d" ediff-number-of-differences))
         ((>= ediff-current-difference ediff-number-of-differences)
          (format " $/%d" ediff-number-of-differences))