]> code.delx.au - gnu-emacs/blobdiff - lisp/ediff-wind.el
* mail/sendmail.el (send-mail-function):
[gnu-emacs] / lisp / ediff-wind.el
index 8d8334705d22d6cf4948f792b404e6fcc556b565..d206184088c537652a8a931ff749e0fa82407d4c 100644 (file)
@@ -1,15 +1,16 @@
 ;;; ediff-wind.el --- window manipulation utilities
 
-;; Copyright (C) 1994, 95, 96, 97, 2000, 01, 02 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
+;;   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;;; Code:
-        
-(provide 'ediff-wind)
+
 
 ;; Compiler pacifier
 (defvar icon-title-format)
 (defvar top-gutter)
 (defvar frame-icon-title-format)
 (defvar ediff-diff-status)
-(defvar ediff-emacs-p)
+
+;; declare-function does not exist in XEmacs
+(eval-and-compile
+  (unless (fboundp 'declare-function) (defmacro declare-function (&rest  r))))
 
 (eval-when-compile
-  (let ((load-path (cons (expand-file-name ".") load-path)))
-    (or (featurep 'ediff-init)
-       (load "ediff-init.el" nil nil 'nosuffix))
-    (or (featurep 'ediff-util)
-       (load "ediff-util.el" nil nil 'nosuffix))
-    (or (featurep 'ediff-help)
-       (load "ediff-help.el" nil nil 'nosuffix))
-    (or (featurep 'ediff-tbar)
-       ediff-emacs-p
-       (load "ediff-tbar.el" 'noerror nil 'nosuffix))
-    ))
+  (require 'ediff-util)
+  (require 'ediff-help))
 ;; end pacifier
 
 (require 'ediff-init)
 
 ;; be careful with ediff-tbar
-(if ediff-xemacs-p
-    (condition-case nil
-       (require 'ediff-tbar)
-      (error
-       (defun ediff-compute-toolbar-width () 0)))
+(if (featurep 'xemacs)
+    (require 'ediff-tbar)
   (defun ediff-compute-toolbar-width () 0))
 
 (defgroup ediff-window nil
-  "Ediff window manipulation"
+  "Ediff window manipulation."
   :prefix "ediff-"
   :group 'ediff
   :group 'frames)
 
 
-(defcustom ediff-window-setup-function (if (ediff-window-display-p)
-                                       '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',
-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.
+;; Determine which window setup function to use based on current window system.
+(defun ediff-choose-window-setup-function-automatically ()
+  (if (ediff-window-display-p)
+      'ediff-setup-windows-multiframe
+    'ediff-setup-windows-plain))
 
-If you don't like the two functions provided---write your own one.
+(defcustom ediff-window-setup-function (ediff-choose-window-setup-function-automatically)
+  "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', which sets
+the control panel in a separate frame. By default, the appropriate function is
+chosen automatically depending on the current window system.
+However, `ediff-toggle-multiframe' can be used to toggle between the multiframe
+display and the single frame display.
+If the multiframe 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.
+
+If you don't like any of the two provided functions, write your own one.
 The basic guidelines:
     1. It should leave the control buffer current and the control window
        selected.
@@ -94,7 +90,9 @@ The basic guidelines:
        Buffer C may not be used in jobs that compare only two buffers.
 If you plan to do something fancy, take a close look at how the two
 provided functions are written."
-  :type 'function
+  :type '(choice (const :tag "Multi Frame" ediff-setup-windows-multiframe)
+                (const :tag "Single Frame" ediff-setup-windows-plain)
+                (function :tag "Other function"))
   :group 'ediff-window)
 
 ;; indicates if we are in a multiframe setup
@@ -126,25 +124,35 @@ provided functions are written."
 
 
 (defcustom ediff-split-window-function 'split-window-vertically
-  "*The function used to split the main window between buffer-A and buffer-B.
+  "The function used to split the main window between buffer-A and buffer-B.
 You can set it to a horizontal split instead of the default vertical split
 by setting this variable to `split-window-horizontally'.
 You can also have your own function to do fancy splits.
 This variable has no effect when buffer-A/B are shown in different frames.
 In this case, Ediff will use those frames to display these buffers."
-  :type 'function
+  :type '(choice
+         (const :tag "Split vertically" split-window-vertically)
+         (const :tag "Split horizontally" split-window-horizontally)
+         function)
   :group 'ediff-window)
 
 (defcustom ediff-merge-split-window-function 'split-window-horizontally
-  "*The function used to split the main window between buffer-A and buffer-B.
+  "The function used to split the main window between buffer-A and buffer-B.
 You can set it to a vertical split instead of the default horizontal split
 by setting this variable to `split-window-vertically'.
 You can also have your own function to do fancy splits.
 This variable has no effect when buffer-A/B/C are shown in different frames.
 In this case, Ediff will use those frames to display these buffers."
-  :type 'function
+  :type '(choice
+         (const :tag "Split vertically" split-window-vertically)
+         (const :tag "Split horizontally" split-window-horizontally)
+         function)
   :group 'ediff-window)
 
+;; Definitions hidden from the compiler by compat wrappers.
+(declare-function ediff-display-pixel-width "ediff-init")
+(declare-function ediff-display-pixel-height "ediff-init")
+
 (defconst ediff-control-frame-parameters
   (list
    '(name . "Ediff")
@@ -153,9 +161,12 @@ In this case, Ediff will use those frames to display these buffers."
    '(user-position . t)              ; Emacs only
    '(vertical-scroll-bars . nil)  ; Emacs only
    '(scrollbar-width . 0)         ; XEmacs only
+   '(scrollbar-height . 0)        ; XEmacs only
    '(menu-bar-lines . 0)          ; Emacs only
    '(tool-bar-lines . 0)          ; Emacs 21+ only
-   ;; don't lower and auto-raise
+   '(left-fringe    . 0)
+   '(right-fringe   . 0)
+   ;; don't lower but auto-raise
    '(auto-lower . nil)
    '(auto-raise . t)
    '(visibility . nil)
@@ -183,7 +194,7 @@ Used internally---not a user option.")
   "If the user moves mouse more than this many pixels, Ediff won't warp mouse into control window.")
 
 (defcustom ediff-grab-mouse t
-  "*If t, Ediff will always grab the mouse and put it in the control frame.
+  "If t, Ediff will always grab the mouse and put it in the control frame.
 If 'maybe, Ediff will do it sometimes, but not after operations that require
 relatively long time.  If nil, the mouse will be entirely user's
 responsibility."
@@ -199,7 +210,7 @@ of the form \(\(top . <position>\) \(left . <position>\)\)"
   :group 'ediff-window)
 
 (defcustom ediff-control-frame-upward-shift 42
-  "*The upward shift of control frame from the top of buffer A's frame.
+  "The upward shift of control frame from the top of buffer A's frame.
 Measured in pixels.
 This is used by the default control frame positioning function,
 `ediff-make-frame-position'.  This variable is provided for easy
@@ -207,8 +218,8 @@ customization of the default control frame positioning."
   :type 'integer
   :group 'ediff-window)
 
-(defcustom ediff-narrow-control-frame-leftward-shift (if ediff-xemacs-p 7 3)
-  "*The leftward shift of control frame from the right edge of buf A's frame.
+(defcustom ediff-narrow-control-frame-leftward-shift (if (featurep 'xemacs) 7 3)
+  "The leftward shift of control frame from the right edge of buf A's frame.
 Measured in characters.
 This is used by the default control frame positioning function,
 `ediff-make-frame-position' to adjust the position of the control frame
@@ -218,7 +229,7 @@ customization of the default."
   :group 'ediff-window)
 
 (defcustom ediff-wide-control-frame-rightward-shift 7
-  "*The rightward shift of control frame from the left edge of buf A's frame.
+  "The rightward shift of control frame from the left edge of buf A's frame.
 Measured in characters.
 This is used by the default control frame positioning function,
 `ediff-make-frame-position' to adjust the position of the control frame
@@ -250,7 +261,7 @@ the frame used for the wide display.")
 (ediff-defvar-local ediff-control-frame nil "")
 
 (defcustom ediff-prefer-iconified-control-frame nil
-  "*If t, keep control panel iconified when help message is off.
+  "If t, keep control panel iconified when help message is off.
 This has effect only on a windowing system.
 If t, hitting `?' to toggle control panel off iconifies it.
 
@@ -272,39 +283,31 @@ into icons, regardless of the window manager."
          (beep 1))
       (message "Please click on Window %d " wind-number))
     (ediff-read-event) ; discard event
-    (setq wind (ediff-cond-compile-for-xemacs-or-emacs
-               (event-window event) ; xemacs
-               (posn-window (event-start event)) ; emacs
-               )
-         )
-    ))
-      
+    (setq wind (if (featurep 'xemacs)
+                  (event-window event)
+                (posn-window (event-start event))))))
+
 
 ;; Select the lowest window on the frame.
 (defun ediff-select-lowest-window ()
-  (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))))))
-   ))
+  (if (featurep 'xemacs)
+      (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)
+             (setq bottom-edge next-bottom-edge
+                   lowest-window this-window))
+         (select-window this-window)
+         (when (eq last-window this-window)
+           (select-window lowest-window)
+           (setq window-search nil)))))))
 
 
 ;;; Common window setup routines
@@ -319,11 +322,11 @@ into icons, regardless of the window manager."
   (run-hooks 'ediff-before-setup-windows-hook)
   (if (eq (selected-window) (minibuffer-window))
       (other-window 1))
-      
+
   ;; in case user did a no-no on a tty
   (or (ediff-window-display-p)
       (setq ediff-window-setup-function 'ediff-setup-windows-plain))
-  
+
   (or (ediff-keep-window-config control-buffer)
       (funcall
        (ediff-with-current-buffer control-buffer ediff-window-setup-function)
@@ -341,7 +344,7 @@ into icons, regardless of the window manager."
        buffer-A buffer-B buffer-C control-buffer)
     (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)
@@ -354,46 +357,47 @@ into icons, regardless of the window manager."
            ;; this lets us have local versions of ediff-split-window-function
            split-window-function ediff-split-window-function))
     (delete-other-windows)
+    (set-window-dedicated-p (selected-window) nil)
     (split-window-vertically)
     (ediff-select-lowest-window)
     (ediff-setup-control-buffer control-buffer)
-    
+
     ;; go to the upper window and split it betw A, B, and possibly C
     (other-window 1)
     (setq merge-window-lines
          (max 2 (round (* (window-height) merge-window-share))))
     (switch-to-buffer buf-A)
     (setq wind-A (selected-window))
-    
+
     ;; XEmacs used to have a lot of trouble with display
     ;; It did't set things right unless we tell it to sit still
     ;; 19.12 seems ok.
-    ;;(if ediff-xemacs-p (sit-for 0))
-    
+    ;;(if (featurep 'xemacs) (sit-for 0))
+
     (split-window-vertically (max 2 (- (window-height) merge-window-lines)))
     (if (eq (selected-window) wind-A)
        (other-window 1))
     (setq wind-C (selected-window))
     (switch-to-buffer buf-C)
-    
+
     (select-window wind-A)
     (funcall split-window-function)
-                 
+
     (if (eq (selected-window) wind-A)
        (other-window 1))
     (switch-to-buffer buf-B)
     (setq wind-B (selected-window))
-         
+
     (ediff-with-current-buffer control-buffer
       (setq ediff-window-A wind-A
            ediff-window-B wind-B
            ediff-window-C wind-C))
-    
+
     (ediff-select-lowest-window)
     (ediff-setup-control-buffer control-buffer)
     ))
 
-     
+
 ;; This function handles all comparison jobs, including 3way jobs
 (defun ediff-setup-windows-plain-compare (buf-A buf-B buf-C control-buffer)
   ;; skip dedicated and unsplittable frames
@@ -412,11 +416,16 @@ into icons, regardless of the window manager."
            ;; this lets us have local versions of ediff-split-window-function
            split-window-function ediff-split-window-function
            three-way-comparison ediff-3way-comparison-job))
+    ;; if in minibuffer go somewhere else
+    (if (save-match-data
+         (string-match "\*Minibuf-" (buffer-name (window-buffer))))
+       (select-window (next-window nil 'ignore-minibuf)))
     (delete-other-windows)
+    (set-window-dedicated-p (selected-window) nil)
     (split-window-vertically)
     (ediff-select-lowest-window)
     (ediff-setup-control-buffer control-buffer)
-    
+
     ;; go to the upper window and split it betw A, B, and possibly C
     (other-window 1)
     (switch-to-buffer buf-A)
@@ -427,19 +436,19 @@ into icons, regardless of the window manager."
                     (window-height wind-A)
                   (window-width wind-A))
                 3)))
-    
+
     ;; XEmacs used to have a lot of trouble with display
     ;; It did't set things right unless we told it to sit still
     ;; 19.12 seems ok.
-    ;;(if ediff-xemacs-p (sit-for 0))
-    
+    ;;(if (featurep 'xemacs) (sit-for 0))
+
     (funcall split-window-function wind-width-or-height)
-                 
+
     (if (eq (selected-window) wind-A)
        (other-window 1))
     (switch-to-buffer buf-B)
     (setq wind-B (selected-window))
-         
+
     (if three-way-comparison
        (progn
          (funcall split-window-function) ; equally
@@ -447,24 +456,24 @@ into icons, regardless of the window manager."
              (other-window 1))
          (switch-to-buffer buf-C)
          (setq wind-C (selected-window))))
-         
+
     (ediff-with-current-buffer control-buffer
       (setq ediff-window-A wind-A
            ediff-window-B wind-B
            ediff-window-C wind-C))
-    
+
     ;; It is unlikely that we will want to implement 3way window comparison.
     ;; So, only buffers A and B are used here.
     (if ediff-windows-job
        (progn
          (set-window-start wind-A wind-A-start)
          (set-window-start wind-B wind-B-start)))
-  
+
     (ediff-select-lowest-window)
     (ediff-setup-control-buffer control-buffer)
     ))
 
-    
+
 ;; dispatch an appropriate window setup function
 (defun ediff-setup-windows-multiframe (buf-A buf-B buf-C control-buf)
   (ediff-with-current-buffer control-buf
@@ -472,7 +481,7 @@ into icons, regardless of the window manager."
   (if ediff-merge-job
       (ediff-setup-windows-multiframe-merge buf-A buf-B buf-C control-buf)
     (ediff-setup-windows-multiframe-compare buf-A buf-B buf-C control-buf)))
-    
+
 (defun ediff-setup-windows-multiframe-merge (buf-A buf-B buf-C control-buf)
 ;;; Algorithm:
 ;;;   1. Never use frames that have dedicated windows in them---it is bad to
@@ -488,7 +497,7 @@ into icons, regardless of the window manager."
   ;;   Skip dedicated or iconified frames.
   ;;   Unsplittable frames are taken care of later.
   (ediff-skip-unsuitable-frames 'ok-unsplittable)
-  
+
   (let* ((window-min-height 1)
         (wind-A (ediff-get-visible-buffer-window buf-A))
         (wind-B (ediff-get-visible-buffer-window buf-B))
@@ -528,7 +537,7 @@ into icons, regardless of the window manager."
         merge-window-lines
         designated-minibuffer-frame
         done-A done-B done-C)
-    
+
     ;; buf-A on its own
     (if (and (window-live-p wind-A)
             (null use-same-frame) ; implies wind-A is suitable
@@ -539,7 +548,7 @@ into icons, regardless of the window manager."
          (delete-other-windows)
          (setq wind-A (selected-window))
          (setq done-A t)))
-    
+
     ;; buf-B on its own
     (if (and (window-live-p wind-B)
             (null use-same-frame) ; implies wind-B is suitable
@@ -550,7 +559,7 @@ into icons, regardless of the window manager."
          (delete-other-windows)
          (setq wind-B (selected-window))
          (setq done-B t)))
-         
+
     ;; buf-C on its own
     (if (and (window-live-p wind-C)
             (ediff-window-ok-for-display wind-C)
@@ -561,7 +570,7 @@ into icons, regardless of the window manager."
          (delete-other-windows)
          (setq wind-C (selected-window))
          (setq done-C t)))
-    
+
     (if (and use-same-frame-for-AB  ; implies wind A and B are suitable
             (window-live-p wind-A))
        (progn
@@ -569,16 +578,16 @@ into icons, regardless of the window manager."
          (select-window wind-A)
          (delete-other-windows)
          (setq wind-A (selected-window))
-         
+
          (funcall split-window-function)
          (if (eq (selected-window) wind-A)
              (other-window 1))
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
-         
+
          (setq done-A t
                done-B t)))
-    
+
     (if use-same-frame
        (let ((window-min-height 1))
          (if (and (eq frame-A frame-B)
@@ -592,27 +601,27 @@ into icons, regardless of the window manager."
                (max 2 (round (* (window-height) merge-window-share))))
          (switch-to-buffer buf-A)
          (setq wind-A (selected-window))
-         
+
          (split-window-vertically
           (max 2 (- (window-height) merge-window-lines)))
          (if (eq (selected-window) wind-A)
              (other-window 1))
          (setq wind-C (selected-window))
          (switch-to-buffer buf-C)
-         
+
          (select-window wind-A)
-         
+
          (funcall split-window-function)
          (if (eq (selected-window) wind-A)
              (other-window 1))
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
-         
+
          (setq done-A t
                done-B t
                done-C t)
          ))
-    
+
     (or done-A  ; Buf A to be set in its own frame,
              ;;; or it was set before because use-same-frame = 1
        (progn
@@ -633,7 +642,7 @@ into icons, regardless of the window manager."
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
          ))
-    
+
     (or done-C  ; Buf C to be set in its own frame,
              ;;; or it was set before because use-same-frame = 1
        (progn
@@ -644,7 +653,7 @@ into icons, regardless of the window manager."
          (switch-to-buffer buf-C)
          (setq wind-C (selected-window))
          ))
-    
+
     (ediff-with-current-buffer control-buf
       (setq ediff-window-A wind-A
            ediff-window-B wind-B
@@ -652,11 +661,11 @@ into icons, regardless of the window manager."
       (setq frame-A (window-frame ediff-window-A)
            designated-minibuffer-frame
            (window-frame (minibuffer-window frame-A))))
-    
+
     (ediff-setup-control-frame control-buf designated-minibuffer-frame)
     ))
 
-  
+
 ;; Window setup for all comparison jobs, including 3way comparisons
 (defun ediff-setup-windows-multiframe-compare (buf-A buf-B buf-C control-buf)
 ;;; Algorithm:
@@ -670,11 +679,11 @@ into icons, regardless of the window manager."
 ;;;    and the selected frame isn't splittable, we create a new frame and
 ;;;    put both buffers there, event if one of this buffers is visible in
 ;;;    another frame.
-  
+
   ;; Skip dedicated or iconified frames.
   ;; Unsplittable frames are taken care of later.
   (ediff-skip-unsuitable-frames 'ok-unsplittable)
-  
+
   (let* ((window-min-height 1)
         (wind-A (ediff-get-visible-buffer-window buf-A))
         (wind-B (ediff-get-visible-buffer-window buf-B))
@@ -713,7 +722,7 @@ into icons, regardless of the window manager."
         wind-A-start wind-B-start
         designated-minibuffer-frame
         done-A done-B done-C)
-    
+
     (ediff-with-current-buffer control-buf
       (setq wind-A-start (ediff-overlay-start
                          (ediff-get-value-according-to-buffer-type
@@ -721,7 +730,7 @@ into icons, regardless of the window manager."
            wind-B-start (ediff-overlay-start
                          (ediff-get-value-according-to-buffer-type
                           'B ediff-narrow-bounds))))
-    
+
     (if (and (window-live-p wind-A) (null use-same-frame)) ; buf-A on its own
        (progn
          ;; buffer buf-A is seen in live wind-A
@@ -729,7 +738,7 @@ into icons, regardless of the window manager."
          (delete-other-windows)
          (setq wind-A (selected-window))
          (setq done-A t)))
-    
+
     (if (and (window-live-p wind-B) (null use-same-frame)) ; buf B on its own
        (progn
          ;; buffer buf-B is seen in live wind-B
@@ -737,7 +746,7 @@ into icons, regardless of the window manager."
          (delete-other-windows)
          (setq wind-B (selected-window))
          (setq done-B t)))
-         
+
     (if (and (window-live-p wind-C) (null use-same-frame)) ; buf C on its own
        (progn
          ;; buffer buf-C is seen in live wind-C
@@ -745,7 +754,7 @@ into icons, regardless of the window manager."
          (delete-other-windows)
          (setq wind-C (selected-window))
          (setq done-C t)))
-    
+
     (if use-same-frame
        (let (wind-width-or-height) ; this affects 3way setups only
          (if (and (eq frame-A frame-B) (frame-live-p frame-A))
@@ -755,7 +764,7 @@ into icons, regardless of the window manager."
          (delete-other-windows)
          (switch-to-buffer buf-A)
          (setq wind-A (selected-window))
-         
+
          (if three-way-comparison
              (setq wind-width-or-height
                    (/
@@ -763,13 +772,13 @@ into icons, regardless of the window manager."
                         (window-height wind-A)
                       (window-width wind-A))
                     3)))
-         
+
          (funcall split-window-function wind-width-or-height)
          (if (eq (selected-window) wind-A)
              (other-window 1))
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
-         
+
          (if three-way-comparison
              (progn
                (funcall split-window-function) ; equally
@@ -781,7 +790,7 @@ into icons, regardless of the window manager."
                done-B t
                done-C t)
          ))
-    
+
     (or done-A  ; Buf A to be set in its own frame
              ;;; or it was set before because use-same-frame = 1
        (progn
@@ -802,7 +811,7 @@ into icons, regardless of the window manager."
          (switch-to-buffer buf-B)
          (setq wind-B (selected-window))
          ))
-    
+
     (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
@@ -814,23 +823,23 @@ into icons, regardless of the window manager."
              (switch-to-buffer buf-C)
              (setq wind-C (selected-window))
              )))
-    
+
     (ediff-with-current-buffer control-buf
       (setq ediff-window-A wind-A
            ediff-window-B wind-B
            ediff-window-C wind-C)
-      
+
       (setq frame-A (window-frame ediff-window-A)
            designated-minibuffer-frame
            (window-frame (minibuffer-window frame-A))))
-    
+
     ;; It is unlikely that we'll implement a version of ediff-windows that
     ;; would compare 3 windows at once.  So, we don't use buffer C here.
     (if ediff-windows-job
        (progn
          (set-window-start wind-A wind-A-start)
          (set-window-start wind-B wind-B-start)))
-    
+
     (ediff-setup-control-frame control-buf designated-minibuffer-frame)
     ))
 
@@ -838,44 +847,38 @@ 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)
-      (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))
+      (let ((wind-frame (window-frame (selected-window)))
+            seen-windows)
        (while (and (not (memq (selected-window) seen-windows))
                    (or
-                    (ediff-frame-has-dedicated-windows (selected-frame))
-                    (ediff-frame-iconified-p (selected-frame))
+                    (ediff-frame-has-dedicated-windows wind-frame)
+                    (ediff-frame-iconified-p wind-frame)
                     ;; skip small windows
-                    (< (frame-height (selected-frame))
+                    (< (frame-height wind-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)))
+                      (ediff-frame-unsplittable-p wind-frame))))
+         ;; remember history
          (setq seen-windows (cons (selected-window) seen-windows))
          ;; try new window
-         (other-window 1 t))
-       ;;(if (eq (selected-window) last-window)
+         (other-window 1 t)
+         (setq wind-frame (window-frame (selected-window)))
+         )
        (if (memq (selected-window) seen-windows)
-           ;; fed up, no appropriate frame
-           (progn
-             (select-frame (make-frame '((unsplittable)))))))))
+           ;; fed up, no appropriate frames
+           (setq wind-frame (make-frame '((unsplittable)))))
+
+       (select-frame wind-frame)
+       )))
 
 (defun ediff-frame-has-dedicated-windows (frame)
-  (let ((cur-fr (selected-frame))
-       ans)
-    (select-frame frame)
-    (walk-windows 
+  (let (ans)
+    (walk-windows
      (lambda (wind) (if (window-dedicated-p wind)
                        (setq ans t)))
      'ignore-minibuffer
      frame)
-    (select-frame cur-fr)
     ans))
 
 ;; window is ok, if it is only one window on the frame, not counting the
@@ -888,7 +891,7 @@ into icons, regardless of the window manager."
    (or
     ;; only one window
     (eq wind (next-window wind 'ignore-minibuffer (window-frame wind)))
-    ;; none is dedicated
+    ;; none is dedicated (in multiframe setup)
     (not (ediff-frame-has-dedicated-windows (window-frame wind)))
     )))
 
@@ -899,15 +902,13 @@ into icons, regardless of the window manager."
        ctl-frame old-ctl-frame lines
        ;; user-grabbed-mouse
        fheight fwidth adjusted-parameters)
-       
+
     (ediff-with-current-buffer ctl-buffer
-      (ediff-cond-compile-for-xemacs-or-emacs
-       (set-buffer-menubar nil) ; xemacs
-       nil ; emacs
-       )
+      (if (and (featurep 'xemacs) (featurep 'menubar))
+         (set-buffer-menubar nil))
       ;;(setq user-grabbed-mouse (ediff-user-grabbed-mouse))
       (run-hooks 'ediff-before-setup-control-frame-hook))
-  
+
     (setq old-ctl-frame (ediff-with-current-buffer ctl-buffer ediff-control-frame))
     (ediff-with-current-buffer ctl-buffer
       (setq ctl-frame (if (frame-live-p old-ctl-frame)
@@ -916,35 +917,31 @@ into icons, regardless of the window manager."
            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))
-      )
-    
+         (if (and (featurep 'emacs) (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)
     (if (window-dedicated-p (selected-window))
        ()
       (delete-other-windows)
       (switch-to-buffer ctl-buffer))
-      
+
     ;; must be before ediff-setup-control-buffer
     ;; just a precaution--we should be in ctl-buffer already
     (ediff-with-current-buffer ctl-buffer
       (make-local-variable 'frame-title-format)
       (make-local-variable 'frame-icon-title-format)   ; XEmacs
       (make-local-variable 'icon-title-format))        ; Emacs
-    
+
     (ediff-setup-control-buffer ctl-buffer)
     (setq dont-iconify-ctl-frame
          (not (string= ediff-help-message ediff-brief-help-message)))
     (setq deiconify-ctl-frame
          (and (eq this-command 'ediff-toggle-help)
               dont-iconify-ctl-frame))
-    
+
     ;; 1 more line for the modeline
     (setq lines (1+ (count-lines (point-min) (point-max)))
          fheight lines
@@ -957,29 +954,29 @@ into icons, regardless of the window manager."
                 (minibuffer-window
                  designated-minibuffer-frame))
           (cons 'width fwidth)
-          (cons 'height fheight))
-         )
-    (if ediff-use-long-help-message
-       (setq adjusted-parameters
-             (cons '(auto-raise . nil) adjusted-parameters)))
-    
+          (cons 'height fheight)
+          (cons 'user-position t)
+          ))
+
+    ;; adjust autoraise
+    (setq adjusted-parameters
+         (cons (if ediff-use-long-help-message
+                   '(auto-raise . nil)
+                 '(auto-raise . t))
+               adjusted-parameters))
+
     ;; In XEmacs, buffer menubar needs to be killed before frame parameters
     ;; are changed.
     (if (ediff-has-toolbar-support-p)
-       (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
-        )
-      )
-    
+       (when (featurep '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))))
+
     ;; 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
     ;; appears that in the OS/2 port of Emacs, one can't modify frame
@@ -987,28 +984,28 @@ into icons, regardless of the window manager."
     ;; windows-nt.
     (if (memq system-type '(emx windows-nt windows-95))
        (modify-frame-parameters ctl-frame adjusted-parameters))
-      
+
     ;; make or zap toolbar (if not requested)
     (ediff-make-bottom-toolbar ctl-frame)
-    
+
     (goto-char (point-min))
 
     (modify-frame-parameters ctl-frame adjusted-parameters)
     (make-frame-visible ctl-frame)
-    
+
     ;; This works around a bug in 19.25 and earlier.  There, if frame gets
     ;; iconified, the current buffer changes to that of the frame that
     ;; becomes exposed as a result of this iconification.
     ;; So, we make sure the current buffer doesn't change.
     (select-frame ctl-frame)
     (ediff-refresh-control-frame)
-    
+
     (cond ((and ediff-prefer-iconified-control-frame
                (not ctl-frame-iconified-p) (not dont-iconify-ctl-frame))
           (iconify-frame ctl-frame))
          ((or deiconify-ctl-frame (not ctl-frame-iconified-p))
           (raise-frame ctl-frame)))
-    
+
     (set-window-dedicated-p (selected-window) t)
 
     ;; Now move the frame.  We must do it separately due to an obscure bug in
@@ -1016,7 +1013,7 @@ into icons, regardless of the window manager."
     (modify-frame-parameters
      ctl-frame
      (funcall ediff-control-frame-position-function ctl-buffer fwidth fheight))
-      
+
     ;; synchronize so the cursor will move to control frame
     ;; per RMS suggestion
     (if (ediff-window-display-p)
@@ -1031,37 +1028,30 @@ into icons, regardless of the window manager."
        (ediff-reset-mouse ctl-frame
                           (or (eq this-command 'ediff-quit)
                               (not (eq ediff-grab-mouse t)))))
-       
-    (if ediff-xemacs-p
-       (ediff-with-current-buffer ctl-buffer
-         (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)
-         ))
-       
+
+    (when (featurep 'xemacs)
+      (ediff-with-current-buffer ctl-buffer
+       (make-local-hook 'select-frame-hook)
+       (add-hook 'select-frame-hook
+                 'ediff-xemacs-select-frame-hook nil 'local)))
+
     (ediff-with-current-buffer ctl-buffer
-      (run-hooks 'ediff-after-setup-control-frame-hook))
-    ))
+      (run-hooks 'ediff-after-setup-control-frame-hook))))
+
 
-    
 (defun ediff-destroy-control-frame (ctl-buffer)
   (ediff-with-current-buffer ctl-buffer
     (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
        (let ((ctl-frame ediff-control-frame))
-         (ediff-cond-compile-for-xemacs-or-emacs
-          (set-buffer-menubar default-menubar) ; xemacs
-          nil ; emacs
-          )
+         (if (and (featurep 'xemacs) (featurep 'menubar))
+             (set-buffer-menubar default-menubar))
          (setq ediff-control-frame nil)
-         (delete-frame ctl-frame)
-         )))
-  (ediff-skip-unsuitable-frames)
+         (delete-frame ctl-frame))))
+  (if ediff-multiframe
+      (ediff-skip-unsuitable-frames))
   ;;(ediff-reset-mouse nil)
   )
-    
+
 
 ;; finds a good place to clip control frame
 (defun ediff-make-frame-position (ctl-buffer ctl-frame-width ctl-frame-height)
@@ -1074,7 +1064,7 @@ into icons, regardless of the window manager."
           (ctl-frame ediff-control-frame)
           horizontal-adjustment upward-adjustment
           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
       ;; other active control panels.
@@ -1106,16 +1096,16 @@ into icons, regardless of the window manager."
       ;; keep ctl frame within the visible bounds
       (setq ctl-frame-top (max ctl-frame-top 1)
            ctl-frame-left (max ctl-frame-left 1))
-      
+
       (list (cons 'top ctl-frame-top)
            (cons 'left ctl-frame-left))
       )))
-                              
+
 (defun ediff-xemacs-select-frame-hook ()
   (if (and (equal (selected-frame) ediff-control-frame)
           (not ediff-use-long-help-message))
       (raise-frame ediff-control-frame)))
-       
+
 (defun ediff-make-wide-display ()
   "Construct an alist of parameters for the wide display.
 Saves the old frame parameters in `ediff-wide-display-orig-parameters'.
@@ -1132,17 +1122,16 @@ It assumes that it is called from within the control buffer."
          (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)
-    (modify-frame-parameters frame-A (list (cons 'left cw)
-                                                (cons 'width wd)))))
-  
-      
+    (modify-frame-parameters
+     frame-A `((left . ,cw) (width . ,wd) (user-position . t)))))
+
 
 ;; Revise the mode line to display which difference we have selected
 ;; Also resets modelines of buffers A/B, since they may be clobbered by
 ;; anothe invocations of Ediff.
 (defun ediff-refresh-mode-lines ()
   (let (buf-A-state-diff buf-B-state-diff buf-C-state-diff buf-C-state-merge)
-    
+
     (if (ediff-valid-difference-p)
        (setq
         buf-C-state-diff (ediff-get-state-of-diff ediff-current-difference 'C)
@@ -1171,7 +1160,7 @@ It assumes that it is called from within the control buffer."
       (setq buf-A-state-diff ""
            buf-B-state-diff ""
            buf-C-state-diff ""))
-    
+
     ;; control buffer format
     (setq mode-line-format
          (if (ediff-narrow-control-frame-p)
@@ -1184,10 +1173,10 @@ It assumes that it is called from within the control buffer."
            (ediff-make-wide-control-buffer-id)))
     ;; Force mode-line redisplay
     (force-mode-line-update)
-    
+
     (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
        (ediff-refresh-control-frame))
-    
+
     (ediff-with-current-buffer ediff-buffer-A
       (setq ediff-diff-status buf-A-state-diff)
       (ediff-strip-mode-line-format)
@@ -1224,10 +1213,10 @@ It assumes that it is called from within the control buffer."
                            (t ""))
                      mode-line-format))))
     ))
-    
-  
+
+
 (defun ediff-refresh-control-frame ()
-  (if ediff-emacs-p
+  (if (featurep 'emacs)
       ;; set frame/icon titles for Emacs
       (modify-frame-parameters
        ediff-control-frame
@@ -1239,8 +1228,8 @@ It assumes that it is called from within the control buffer."
          frame-icon-title-format (ediff-make-narrow-control-buffer-id))
     ;; force an update of the frame title
     (modify-frame-parameters ediff-control-frame '(()))))
-   
-  
+
+
 (defun ediff-make-narrow-control-buffer-id (&optional skip-name)
   (concat
    (if skip-name
@@ -1259,7 +1248,7 @@ It assumes that it is called from within the control buffer."
   (concat
    (cdr (assoc 'name ediff-control-frame-parameters))
    ediff-control-buffer-suffix))
-                 
+
 (defun ediff-make-wide-control-buffer-id ()
   (cond ((< ediff-current-difference 0)
         (list (format "%%b   At start of %d diffs"
@@ -1277,13 +1266,13 @@ It assumes that it is called from within the control buffer."
 ;; If buff is not live, return nil
 (defun ediff-get-visible-buffer-window (buff)
   (if (ediff-buffer-live-p buff)
-      (if ediff-xemacs-p
+      (if (featurep 'xemacs)
          (get-buffer-window buff t)
        (get-buffer-window buff 'visible))))
-       
+
 
 ;;; Functions to decide when to redraw windows
-  
+
 (defun ediff-keep-window-config (control-buf)
   (and (eq control-buf (current-buffer))
        (/= (buffer-size) 0)
@@ -1292,7 +1281,7 @@ It assumes that it is called from within the control buffer."
               (A-wind ediff-window-A)
               (B-wind ediff-window-B)
               (C-wind ediff-window-C))
-         
+
           (and
            (ediff-window-visible-p A-wind)
            (ediff-window-visible-p B-wind)
@@ -1311,10 +1300,14 @@ It assumes that it is called from within the control buffer."
                             ediff-wide-display-p)))))))
 
 
-;;; Local Variables:
-;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
-;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
-;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
-;;; End:
+(provide 'ediff-wind)
+
+
+;; Local Variables:
+;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
+;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
+;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
+;; End:
 
+;; arch-tag: 73d9a5d7-eed7-4d9c-8b4b-21d5d78eb597
 ;;; ediff-wind.el ends here