(msdos-face-setup): Register standard colors in
[bpt/emacs.git] / lisp / ediff-init.el
index 4190019..fc91c7b 100644 (file)
@@ -1,5 +1,6 @@
 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
-;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
+
+;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
 
 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
 
 ;; 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, 675 Mass Ave, Cambridge, MA 02139, USA.
-
+;; 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.
+
+;;; Code:
+
+;; Start compiler pacifier
+(defvar ediff-metajob-name)
+(defvar ediff-meta-buffer)
+(defvar pm-color-alist)
+(defvar ediff-grab-mouse)
+(defvar ediff-mouse-pixel-position)
+(defvar ediff-mouse-pixel-threshold)
+(defvar ediff-whitespace)
+(defvar ediff-multiframe)
+(defvar ediff-use-toolbar-p)
+
+(and noninteractive
+     (eval-when-compile
+        (load "ange-ftp" 'noerror)))
+;; end pacifier
 
 ;; Is it XEmacs?
 (defconst ediff-xemacs-p (string-match "XEmacs" emacs-version))
 ;; Is it Emacs?
 (defconst ediff-emacs-p (not ediff-xemacs-p))
+
+(defvar ediff-force-faces nil
+  "If t, Ediff will think that it is running on a display that supports faces.
+This is provided as a temporary relief for users of face-capable displays
+that Ediff doesn't know about.")
+
 ;; Are we running as a window application or on a TTY?
 (defsubst ediff-device-type ()
   (if ediff-emacs-p
       window-system
     (device-type (selected-device))))
+
 ;; in XEmacs: device-type is tty on tty and stream in batch.
-(defsubst ediff-window-display-p ()
-  (and (ediff-device-type) (not (memq (ediff-device-type) '(tty stream)))))
+(defun ediff-window-display-p ()
+  (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))
+
+;; test if supports faces
+(defun ediff-has-face-support-p ()
+  (cond ((ediff-window-display-p))
+       (ediff-force-faces)
+       (ediff-emacs-p (memq (ediff-device-type) '(pc)))
+       (ediff-xemacs-p (memq (ediff-device-type) '(tty pc)))))
+
+(defun ediff-has-toolbar-support-p ()
+  (and ediff-xemacs-p
+       (featurep 'toolbar)
+       (console-on-window-system-p)))
+
+(defun ediff-use-toolbar-p ()
+  (and (ediff-has-toolbar-support-p)   ;Can it do it ?
+       (boundp 'ediff-use-toolbar-p)
+       ediff-use-toolbar-p))           ;Does the user want it ?
+
+;; Defines SYMBOL as an advertised local variable.  
+;; Performs a defvar, then executes `make-variable-buffer-local' on
+;; the variable.  Also sets the `permanent-local' property,
+;; so that `kill-all-local-variables' (called by major-mode setting
+;; commands) won't destroy Ediff control variables.
+;; 
+;; Plagiarised from `emerge-defvar-local' for XEmacs.
+(defmacro ediff-defvar-local (var value doc) 
+  (` (progn
+       (defvar (, var) (, value) (, doc))
+       (make-variable-buffer-local '(, var))
+       (put '(, var) 'permanent-local t))))
+    
+
+
+;; Variables that control each Ediff session---local to the control buffer.
+
+;; Mode variables
+;; The buffer in which the A variant is stored.
+(ediff-defvar-local ediff-buffer-A nil "")
+;; The buffer in which the B variant is stored.
+(ediff-defvar-local ediff-buffer-B nil "")
+;; The buffer in which the C variant is stored.
+(ediff-defvar-local ediff-buffer-C nil "")
+;; Ancestor buffer
+(ediff-defvar-local ediff-ancestor-buffer nil "")
+;; The Ediff control buffer
+(ediff-defvar-local ediff-control-buffer nil "")
+
+
+;; Association between buff-type and ediff-buffer-*
+(defconst ediff-buffer-alist
+  '((?A . ediff-buffer-A)
+    (?B . ediff-buffer-B)
+    (?C . ediff-buffer-C)))
 
 ;;; Macros
 (defmacro ediff-odd-p (arg)
           ((memq (, arg) '(?c ?C)) 'C)
           )
   ))
+
+
+;; A-list is supposed to be of the form (A . symb) (B . symb)...)
+;; where the first part of any association is a buffer type and the second is
+;; an appropriate symbol. Given buffer-type, this function returns the
+;; symbol. This is used to avoid using `intern'
+(defsubst ediff-get-symbol-from-alist (buf-type alist)
+  (cdr (assoc buf-type alist)))
   
+(defconst ediff-difference-vector-alist
+  '((A . ediff-difference-vector-A)
+    (B . ediff-difference-vector-B)
+    (C . ediff-difference-vector-C)
+    (Ancestor . ediff-difference-vector-Ancestor)))
+
 (defmacro ediff-get-difference (n buf-type)
   (` (aref
       (symbol-value
-       (intern (format "ediff-difference-vector-%S" (, buf-type)))) (, n))))
+       (ediff-get-symbol-from-alist
+       (, buf-type) ediff-difference-vector-alist))
+      (, n))))
   
-;; tell if it has been previously determined that the region has
+;; Tell if it has been previously determined that the region has
 ;; no diffs other than the white space and newlines
 ;; The argument, N, is the diff region number used by Ediff to index the
 ;; diff vector. It is 1 less than the number seen by the user.
+;; Returns:
+;;             t  if the diffs are whitespace in all buffers
+;;             'A (in 3-buf comparison only) if there are only whitespace
+;;                diffs in bufs B and C
+;;             'B (in 3-buf comparison only) if there are only whitespace
+;;                diffs in bufs A and C
+;;             'C (in 3-buf comparison only) if there are only whitespace
+;;                diffs in bufs A and B
 ;;
 ;; A difference vector has the form:
 ;; [diff diff diff ...]
   (` (ediff-get-fine-diff-vector-from-diff-record
       (ediff-get-difference (, n) (, buf-type)))))
   
-  
-;; Defines SYMBOL as an advertised local variable.  
-;; Performs a defvar, then executes `make-variable-buffer-local' on
-;; the variable.  Also sets the `permanent-local' property,
-;; so that `kill-all-local-variables' (called by major-mode setting
-;; commands) won't destroy Ediff control variables.
-;; 
-;; Plagiarised from `emerge-defvar-local' for XEmacs.
-(defmacro ediff-defvar-local (var value doc) 
-  (` (progn
-       (defvar (, var) (, value) (, doc))
-       (make-variable-buffer-local '(, var))
-       (put '(, var) 'permanent-local t))))
-    
-;; Macro to switch to BUFFER, evaluate FORMS, returns to original buffer.
-;; Differs from `save-excursion' in that it doesn't save the point and mark.
-;; This is essentially `emerge-eval-in-buffer' with the test for live buffers."
-(defmacro ediff-eval-in-buffer (buffer &rest forms)
-  (` (let ((StartBuffer (current-buffer)))
-       (if (ediff-buffer-live-p (, buffer))
-          (unwind-protect
-              (progn
-                (set-buffer (, buffer))
-                (,@ forms))
-            (set-buffer StartBuffer))
-        (or (eq this-command 'ediff-quit)
-            (error
-             "You've killed an essential Ediff buffer---Please quit Ediff"))
-        ))))
-        
+;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
+;; Doesn't save the point and mark.
+;; This is `with-current-buffer' with the added test for live buffers."
+(defmacro ediff-with-current-buffer (buffer &rest body)
+  (` (if (ediff-buffer-live-p (, buffer))
+       (save-current-buffer
+        (set-buffer (, buffer))
+        (,@ body))
+     (or (eq this-command 'ediff-quit)
+        (error ediff-KILLED-VITAL-BUFFER))
+     )))
+     
 
 (defsubst ediff-multiframe-setup-p ()
   (and (ediff-window-display-p) ediff-multiframe))
        '(ediff-directory-revisions 
          ediff-merge-directory-revisions
          ediff-merge-directory-revisions-with-ancestor)))
-;; metajob involving only one directory
-(defsubst ediff-dir1-metajob (&optional metajob)
+(defsubst ediff-patch-metajob (&optional metajob)
+  (memq (or metajob ediff-metajob-name)
+       '(ediff-multifile-patch)))
+;; metajob involving only one group of files, such as multipatch or directory
+;; revision
+(defsubst ediff-one-filegroup-metajob (&optional metajob)
   (or (ediff-revision-metajob metajob)
+      (ediff-patch-metajob metajob)
       ;; add more here
       ))
 (defsubst ediff-collect-diffs-metajob (&optional metajob)
-  (or (ediff-revision-metajob metajob)
-      (memq ediff-metajob-name
-           '(ediff-directories
-             ;; add more here
-             ediff-directory-revisions))))
+  (memq (or metajob ediff-metajob-name)
+       '(ediff-directories
+         ediff-directory-revisions
+         ediff-merge-directories
+         ediff-merge-directories-with-ancestor
+         ediff-merge-directory-revisions
+         ediff-merge-directory-revisions-with-ancestor
+         ;; add more here
+         )))
+(defsubst ediff-merge-metajob (&optional metajob)
+  (memq (or metajob ediff-metajob-name)
+       '(ediff-merge-directories
+         ediff-merge-directories-with-ancestor
+         ediff-merge-directory-revisions
+         ediff-merge-directory-revisions-with-ancestor
+         ediff-merge-filegroups-with-ancestor 
+         ;; add more here
+         )))
+
 (defsubst ediff-metajob3 (&optional metajob)
   (memq (or metajob ediff-metajob-name)
        '(ediff-merge-directories-with-ancestor
   (memq (or metajob ediff-metajob-name)
        '(ediff-directories3 ediff-filegroups3)))
 
-(defsubst ediff-barf-if-not-control-buffer (&optional meta-buf)
-  (or (eq (if meta-buf ediff-meta-buffer ediff-control-buffer)
-         (current-buffer))
+;; with no argument, checks if we are in ediff-control-buffer
+;; with argument, checks if we are in ediff-meta-buffer
+(defun ediff-in-control-buffer-p (&optional meta-buf-p)
+  (and (boundp 'ediff-control-buffer)
+       (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
+          (current-buffer))))
+
+(defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
+  (or (ediff-in-control-buffer-p meta-buf-p)
       (error "%S: This command runs in Ediff Control Buffer only!"
             this-command)))
 
+(defgroup ediff-highlighting nil
+  "Hilighting of difference regions in Ediff"
+  :prefix "ediff-"
+  :group 'ediff)
+
+(defgroup ediff-merge nil
+  "Merging utilities"
+  :prefix "ediff-"
+  :group 'ediff)
+
+(defgroup ediff-hook nil
+  "Hooks called by Ediff"
+  :prefix "ediff-"
+  :group 'ediff)
 
 ;; Hook variables
 
-(defvar ediff-before-setup-windows-hook nil
+(defcustom ediff-before-setup-windows-hook nil
   "*Hooks to run before Ediff sets its window configuration. 
 This can be used to save the previous window config, which can be restored
-on ediff-quit or ediff-suspend.") 
-(defvar ediff-after-setup-windows-hook nil
+on ediff-quit or ediff-suspend."
+  :type 'hook
+  :group 'ediff-hook) 
+(defcustom ediff-after-setup-windows-hook nil
   "*Hooks to run after Ediff sets its window configuration. 
-This can be used to set up control window or icon in a desired place.")
-(defvar ediff-before-setup-control-frame-hook nil
+This can be used to set up control window or icon in a desired place."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-before-setup-control-frame-hook nil
   "*Hooks run before setting up the frame to display Ediff Control Panel.
 Can be used to change control frame parameters to position it where it
-is desirable.")
-(defvar ediff-after-setup-control-frame-hook nil
+is desirable."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-after-setup-control-frame-hook nil
   "*Hooks run after setting up the frame to display Ediff Control Panel.
-Can be used to move the frame where it is desired.")
-(defvar ediff-startup-hook nil
-  "*Hooks to run in the control buffer after Ediff has been set up.")
-(defvar ediff-select-hook nil
-  "*Hooks to run after a difference has been selected.")
-(defvar ediff-unselect-hook nil
-  "*Hooks to run after a difference has been unselected.")
-(defvar ediff-prepare-buffer-hook  nil
-  "*Hooks called after buffers A, B, and C are set up.")
-(defvar ediff-load-hook nil
-  "*Hook run after Ediff is loaded.  Can be used to change defaults.")
+Can be used to move the frame where it is desired."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-startup-hook nil
+  "*Hooks to run in the control buffer after Ediff has been set up."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-select-hook nil
+  "*Hooks to run after a difference has been selected."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-unselect-hook nil
+  "*Hooks to run after a difference has been unselected."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-prepare-buffer-hook  nil
+  "*Hooks called after buffers A, B, and C are set up."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-load-hook nil
+  "*Hook run after Ediff is loaded.  Can be used to change defaults."
+  :type 'hook
+  :group 'ediff-hook)
   
-(defvar ediff-mode-hook nil
+(defcustom ediff-mode-hook nil
   "*Hook run just after ediff-mode is set up in the control buffer. 
 This is done before any windows or frames are created. One can use it to
-set local variables that determine how the display looks like.")
-(defvar ediff-keymap-setup-hook nil
-  "*Hook run just after the default bindings in Ediff keymap are set up.")
+set local variables that determine how the display looks like."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-keymap-setup-hook nil
+  "*Hook run just after the default bindings in Ediff keymap are set up."
+  :type 'hook
+  :group 'ediff-hook)
   
-(defvar ediff-display-help-hook nil
-  "*Hooks run after preparing the help message.")
-
-(defvar ediff-suspend-hook (list 'ediff-default-suspend-function)
-  "*Hooks to run in the Ediff control buffer when Ediff is suspended.")
-(defvar ediff-quit-hook (list 'ediff-cleanup-mess)
-  "*Hooks to run in the Ediff control buffer after finishing Ediff.") 
-(defvar ediff-cleanup-hook nil
+(defcustom ediff-display-help-hook nil
+  "*Hooks run after preparing the help message."
+  :type 'hook
+  :group 'ediff-hook)
+
+(defcustom ediff-suspend-hook (list 'ediff-default-suspend-function)
+  "*Hooks to run in the Ediff control buffer when Ediff is suspended."
+  :type 'hook
+  :group 'ediff-hook)
+(defcustom ediff-quit-hook (list 'ediff-cleanup-mess)
+  "*Hooks to run in the Ediff control buffer after finishing Ediff."
+  :type 'hook
+  :group 'ediff-hook) 
+(defcustom ediff-cleanup-hook nil
   "*Hooks to run on exiting Ediff but before killing the control buffer.
 This is a place to do various cleanups, such as deleting the variant buffers.
-Ediff provides a function, `ediff-janitor', as one such possible hook.")
-
-
-;; Help messages
-
-(defconst ediff-long-help-message-head
-  "   Moving around     |     Toggling features     |       Manipulations
-=====================|===========================|============================="
-  "The head of the full help message.")
-(defconst ediff-long-help-message-tail
-  "=====================|===========================|=============================
-    R -show registry |                           |  M   -show session group
-    D -diff output   |     E -browse Ediff manual|  G   -send bug report   
-    i -status info   |     ? -help off           |  z/q -suspend/quit
--------------------------------------------------------------------------------
-X,Y (x,y)  on the left are meta-symbols for the keys  A,B,C (a,b,c).
-X,Y on the right are meta-symbols for buffers A,B,C.
-A,B,C on the right denote the working buffers A,B,C, respectively."
-  "The tail of the full-help message.")
-
-(defconst ediff-long-help-message-compare3
-  "
-p,DEL -previous diff |     | -vert/horiz split   | xy -copy buf X's region to Y
-n,SPC -next diff     |     h -hiliting           | rx -restore buf X's old diff
-    j -jump to diff  |     @ -auto-refinement    |  * -refine current region
-   gx -goto X's point|                           |  ! -update diff regions
-  C-l -recenter      |    ## -ignore whitespace  |
-  v/V -scroll up/dn  | #f/#h -focus/hide regions | wx -save buf X
-  </> -scroll lt/rt  |     X -read-only in buf X | wd -save diff output
-                     |     m -wide display       |  ~ -rotate buffers
-"
-  "Help message usually used for 3-way comparison.
-Normally, not a user option. See `ediff-help-message' for details.")
-  
-(defconst ediff-long-help-message-compare2
-  "
-p,DEL -previous diff |     | -vert/horiz split   |a/b -copy A/B's region to B/A
-n,SPC -next diff     |     h -hiliting           | rx -restore buf X's old diff
-    j -jump to diff  |     @ -auto-refinement    |  * -refine current region
-   gx -goto X's point|                           |  ! -update diff regions
-  C-l -recenter      |    ## -ignore whitespace  |
-  v/V -scroll up/dn  | #f/#h -focus/hide regions | wx -save buf X
-  </> -scroll lt/rt  |     X -read-only in buf X | wd -save diff output
-                     |     m -wide display       |  ~ -swap buffers
-"
-  "Help message usually used for 2-way comparison.
-Normally, not a user option. See `ediff-help-message' for details.")
-  
-(defconst ediff-long-help-message-narrow2
-  "
-p,DEL -previous diff |     | -vert/horiz split   |a/b -copy A/B's region to B/A
-n,SPC -next diff     |     h -hiliting           | rx -restore buf X's old diff
-    j -jump to diff  |     @ -auto-refinement    |  * -refine current region
-   gx -goto X's point|     % -narrow/widen buffs |  ! -update diff regions
-  C-l -recenter      |    ## -ignore whitespace  |
-  v/V -scroll up/dn  | #f/#h -focus/hide regions | wx -save buf X
-  </> -scroll lt/rt  |     X -read-only in buf X | wd -save diff output
-                     |     m -wide display       |  ~ -swap buffers
-"
-  "Help message when comparing windows or regions line-by-line.
-Normally, not a user option. See `ediff-help-message' for details.")
-  
-(defconst ediff-long-help-message-word-mode
-  "
-p,DEL -previous diff |     | -vert/horiz split   | xy -copy buf X's region to Y
-n,SPC -next diff     |     h -hiliting           | rx -restore buf X's old diff
-    j -jump to diff  |                           |                   
-   gx -goto X's point|     % -narrow/widen buffs |  ! -recompute diffs
-  C-l -recenter      |                           |
-  v/V -scroll up/dn  | #f/#h -focus/hide regions | wx -save buf X
-  </> -scroll lt/rt  |     X -read-only in buf X | wd -save diff output
-                     |     m -wide display       |  ~ -swap buffers
-"
-  "Help message when comparing windows or regions word-by-word.
-Normally, not a user option. See `ediff-help-message' for details.")
-  
-(defconst ediff-long-help-message-merge
-  "
-p,DEL -previous diff |     | -vert/horiz split   |  x -copy buf X's region to C
-n,SPC -next diff     |     h -hiliting           |  r -restore buf C's old diff
-    j -jump to diff  |     @ -auto-refinement    |  * -refine current region
-   gx -goto X's point|    ## -ignore whitespace  |  ! -update diff regions
-  C-l -recenter      | #f/#h -focus/hide regions |  + -combine diff regions
-  v/V -scroll up/dn  |     X -read-only in buf X | wx -save buf X
-  </> -scroll lt/rt  |     m -wide display       | wd -save diff output
-    / -ancestor buff |     s -shrink window C    |  ~ -swap buffers
-                     |     $ -show clashes only  |  & -merge w/new default
-"
-  "Help message during merging.
-Normally, not a user option. See `ediff-help-message' for details.")
-
-;; The actual long help message.
-(ediff-defvar-local ediff-long-help-message ""
-  "Normally, not a user option. See `ediff-help-message' for details.")
-  
-(defconst ediff-brief-message-string
-  "  ? - help  "
-  "Contents of the brief help message.")
-;; The actual brief help message
-(ediff-defvar-local ediff-brief-help-message ""
-  "Normally, not a user option. See `ediff-help-message' for details.")
-  
-(ediff-defvar-local ediff-brief-help-message-function nil
-  "The brief help message that the user can customize.
-If the user sets this to a parameter-less function, Ediff will use it to
-produce the brief help message. This function must return a string.")
-(ediff-defvar-local ediff-long-help-message-function nil
-  "The long help message that the user can customize.
-See `ediff-brief-help-message-function' for more.")
-
-(defvar ediff-prefer-long-help-message nil
-  "*If t, Ediff starts with a long help message. Short help msg otherwise.")
-
-;; The actual help message.
-(ediff-defvar-local ediff-help-message ""
-  "The actual help message.
-Normally, the user shouldn't touch this. However, if you want Ediff to
-start up with different help messages for different jobs, you can change
-the value of this variable and the variables `ediff-help-message-*' in
-`ediff-startup-hook'.") 
+Ediff provides a function, `ediff-janitor', as one such possible hook."
+  :type 'hook
+  :group 'ediff-hook)
+
+;; Error messages
+(defconst ediff-KILLED-VITAL-BUFFER
+  "You have killed a vital Ediff buffer---you must leave Ediff now!")
+(defconst ediff-NO-DIFFERENCES
+  "Sorry, comparison of identical variants is not what I am made for...")
+(defconst ediff-BAD-DIFF-NUMBER
+  ;; %S stands for this-command, %d - diff number, %d - max diff
+  "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
+(defconst ediff-BAD-INFO (format "
+*** The Info file for Ediff, a part of the standard distribution
+*** of %sEmacs, does not seem to be properly installed.
+*** 
+*** Please contact your system administrator. "
+                                (if ediff-xemacs-p "X" "")))
  
 ;; Selective browsing
 
@@ -449,45 +499,49 @@ See the documentation string of `ediff-focus-on-regexp-matches' for details.")
 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
   
   
-(defvar ediff-ange-ftp-ftp-name (if ediff-xemacs-p
-                                   'ange-ftp-ftp-path
-                                 'ange-ftp-ftp-name)
-  "Function ange-ftp uses to find out if file is remote.")
-  
+;;; Copying difference regions between buffers.    
 
-;; Copying difference regions between buffers.    
-(ediff-defvar-local ediff-killed-diffs-alist nil
-  "A list of killed diffs. 
-A diff is saved here if it is replaced by a diff
-from another buffer.  This alist has the form:
-\((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
-where some buffer-objects may be missing.")
+;; A list of killed diffs. 
+;; A diff is saved here if it is replaced by a diff
+;; from another buffer.  This alist has the form:
+;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
+;; where some buffer-objects may be missing.
+(ediff-defvar-local ediff-killed-diffs-alist nil "")
 
 
 ;; Highlighting
-;;(defvar ediff-before-flag-bol (if ediff-emacs-p "->>\n" (make-glyph "->>\n"))
-(defvar ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
-  "*Flag placed above the highlighted block of differences. 
-Must end with newline.")
-;;(defvar ediff-after-flag-eol  (if ediff-emacs-p "<<-\n" (make-glyph "<<-"))
-(defvar ediff-after-flag-eol  (if ediff-xemacs-p (make-glyph "<<-") "<<-")
-  "*Flag placed below the highlighted block of differences.
-Must end with newline.")
-
-(defvar ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>")
-  "*Like ediff-before-flag, used when a difference starts in mid-line.")
-(defvar ediff-after-flag-mol  (if ediff-xemacs-p (make-glyph "<<-") "<<-")
-  "*Like ediff-after-flag, used when a difference starts in mid-line.")
+(defcustom ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
+  "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
+  :type 'string
+  :tag  "Region before-flag at beginning of line"
+  :group 'ediff)
+
+(defcustom ediff-after-flag-eol  (if ediff-xemacs-p (make-glyph "<<-") "<<-")
+  "*Flag placed after a highlighted block of differences, if block ends at end of a line."
+  :type 'string
+  :tag  "Region after-flag at end of line"
+  :group 'ediff)
+
+(defcustom ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>")
+  "*Flag placed before a highlighted block of differences, if block starts in mid-line."
+  :type 'string
+  :tag  "Region before-flag in the middle of line"
+  :group 'ediff)
+(defcustom ediff-after-flag-mol  (if ediff-xemacs-p (make-glyph "<<-") "<<-")
+  "*Flag placed after a highlighted block of differences, if block ends in mid-line."
+  :type 'string
+  :tag  "Region after-flag in the middle of line"
+  :group 'ediff)
 
   
-(ediff-defvar-local ediff-use-faces t 
-  "If t, differences are highlighted using faces on a window system.
-If nil, they are highlighted using ASCII flags, ediff-before-flag
+(ediff-defvar-local ediff-use-faces t "") 
+(defcustom ediff-use-faces t 
+  "If t, differences are highlighted using faces, if device supports faces.
+If nil, differences are highlighted using ASCII flags, ediff-before-flag
 and ediff-after-flag.  On a non-window system, differences are always
-highlighted using ASCII flags.
-This variable can be set either in .emacs or toggled interactively.
-Use `setq-default' if setting it in .emacs")
-
+highlighted using ASCII flags."
+  :type 'boolean
+  :group 'ediff-highlighting)
 
 ;; this indicates that diff regions are word-size, so fine diffs are
 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
@@ -516,38 +570,27 @@ Use `setq-default' if setting it in .emacs")
 (ediff-defvar-local ediff-quit-widened t
   "*Non-nil means: when finished, Ediff widens buffers A/B.
 Actually, Ediff restores the scope of visibility that existed at startup.")
-(defvar ediff-keep-variants t
-  "*Nil means that non-modified variant buffers should be removed after some
-interrogation.
-Supplying a prefix agument to the quit command `q' temporarily reverses the
-meaning of this variable.")
 
-(ediff-defvar-local ediff-highlight-all-diffs t
+(defcustom ediff-keep-variants t
+  "*Nil means that non-modified variant buffers should be removed at the end of the session after some interrogation.
+Supplying a prefix argument to the quit command `q' temporarily reverses the
+meaning of this variable."
+  :type 'boolean
+  :group 'ediff)
+
+(ediff-defvar-local ediff-highlight-all-diffs t "")
+(defcustom ediff-highlight-all-diffs t
   "If nil, only the selected differences are highlighted.
-This variable can be set either in .emacs or toggled interactively, using
-ediff-toggle-hilit. Use `setq-default' to set it.") 
+Otherwise, all difference regions are highlighted, but the selected region is
+shown in brighter colors."
+  :type 'boolean
+  :group 'ediff-highlighting)
 
 ;; A var local to each control panel buffer.  Indicates highlighting style
 ;; in effect for this buffer: `face', `ascii', nil -- temporarily
 ;; unhighlighted, `off' -- turned off \(on a dumb terminal only\).
 (ediff-defvar-local ediff-highlighting-style nil "")
 
-
-;; Variables that control each Ediff session.  They are local to the
-;; control buffer. 
-
-;; Mode variables
-;; The buffer in which the A variant is stored.
-(ediff-defvar-local ediff-buffer-A nil "")
-;; The buffer in which the B variant is stored.
-(ediff-defvar-local ediff-buffer-B nil "")
-;; The buffer in which the C variant is stored.
-(ediff-defvar-local ediff-buffer-C nil "")
-;; Ancestor buffer
-(ediff-defvar-local ediff-ancestor-buffer nil "")
-;; The control buffer of ediff.
-(ediff-defvar-local ediff-control-buffer nil "")
-
   
 ;; The suffix of the control buffer name.
 (ediff-defvar-local ediff-control-buffer-suffix nil "")
@@ -564,10 +607,17 @@ ediff-toggle-hilit. Use `setq-default' to set it.")
 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
 ;; The original values of ediff-protected-variables for buffer Ancestor
 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
+
+;; association between buff-type and ediff-buffer-values-orig-*
+(defconst ediff-buffer-values-orig-alist
+  '((A . ediff-buffer-values-orig-A)
+    (B . ediff-buffer-values-orig-B)
+    (C . ediff-buffer-values-orig-C)
+    (Ancestor . ediff-buffer-values-orig-Ancestor)))
+
 ;; Buffer-local variables to be saved then restored during Ediff sessions
-;; Buffer-local variables to be saved then restored during Ediff sessions
-(defconst ediff-protected-variables '(buffer-read-only 
-                                     synchronize-minibuffers
+(defconst ediff-protected-variables '(
+                                     ;;buffer-read-only 
                                      mode-line-format))
 
 ;; Vector of differences between the variants.  Each difference is
@@ -589,6 +639,12 @@ ediff-toggle-hilit. Use `setq-default' to set it.")
 (ediff-defvar-local ediff-difference-vector-B nil "")
 (ediff-defvar-local ediff-difference-vector-C nil "")
 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
+;; A-list of diff vector types associated with buffer types
+(defconst ediff-difference-vector-alist
+  '((A . ediff-difference-vector-A)
+    (B . ediff-difference-vector-B)
+    (C . ediff-difference-vector-C)
+    (Ancestor . ediff-difference-vector-Ancestor)))
 
 ;; [ status status status ...]
 ;; Each status: [state-of-merge state-of-ancestor]
@@ -631,12 +687,14 @@ ediff-toggle-hilit. Use `setq-default' to set it.")
 ;; Priority of non-selected overlays.
 (defvar ediff-shadow-overlay-priority  100 "")
 
-(defvar ediff-version-control-package 'vc
+(defcustom ediff-version-control-package 'vc
   "Version control package used.
-Currently, Ediff supports vc.el, rcs.el, and generic-sc.el. The standard Emacs
-interface to RCS, CVS, SCCS, etc., is vc.el. However, some people find the
-other two packages more convenient. Set this variable `rcs' or `generic-sc' if
-you are such a person.")
+Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
+standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
+people find the other two packages more convenient. Set this variable to the
+appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
+  :type 'symbol
+  :group 'ediff)
 
 
 (if ediff-xemacs-p
@@ -644,16 +702,11 @@ you are such a person.")
       (fset 'ediff-read-event (symbol-function 'next-command-event))
       (fset 'ediff-overlayp (symbol-function 'extentp))
       (fset 'ediff-make-overlay (symbol-function 'make-extent))
-      (fset 'ediff-delete-overlay (symbol-function 'delete-extent))
-      (fset 'ediff-overlay-buffer (symbol-function 'extent-buffer))
-      (fset 'ediff-overlay-get (symbol-function 'extent-property)))
+      (fset 'ediff-delete-overlay (symbol-function 'delete-extent)))
   (fset 'ediff-read-event (symbol-function 'read-event))
   (fset 'ediff-overlayp (symbol-function 'overlayp))
-  (fset 'ediff-overlayp (symbol-function 'overlayp))
   (fset 'ediff-make-overlay (symbol-function 'make-overlay))
-  (fset 'ediff-delete-overlay (symbol-function 'delete-overlay))
-  (fset 'ediff-overlay-buffer (symbol-function 'overlay-buffer))
-  (fset 'ediff-overlay-get (symbol-function 'overlay-get)))
+  (fset 'ediff-delete-overlay (symbol-function 'delete-overlay)))
   
 ;; Check the current version against the major and minor version numbers
 ;; using op: cur-vers op major.minor If emacs-major-version or
@@ -683,30 +736,6 @@ you are such a person.")
          ((memq op '(< <=)) t))))
   
   
-;;;; warn if it is a wrong version of emacs
-;;(if (or (ediff-check-version '< 19 29 'emacs)
-;;     (ediff-check-version '< 19 12 'xemacs))
-;;    (progn
-;;      (with-output-to-temp-buffer ediff-msg-buffer
-;;     (switch-to-buffer ediff-msg-buffer)
-;;     (insert
-;;      (format "
-;;
-;;This version of Ediff requires 
-;;
-;;\t Emacs 19.29 and higher
-;;\t OR
-;;\t XEmacs 19.12 and higher
-;;
-;;It is unlikely to work under Emacs version %s
-;;that you are using... " emacs-version))
-;;     (if noninteractive
-;;         ()
-;;       (beep 1)
-;;       (beep 1)
-;;       (insert "\n\nType any key to continue...")
-;;       (ediff-read-event)))
-;;      (kill-buffer ediff-msg-buffer)))
 
 ;; A fix for NeXT Step
 ;; Should probably be eliminated in later versions.
@@ -725,35 +754,55 @@ you are such a person.")
     (eq (device-class (selected-device)) 'color)))
 
   
-(if (ediff-window-display-p)
+(if (ediff-has-face-support-p)
     (if ediff-xemacs-p
        (progn
-         (fset 'ediff-display-pixel-width
-               (symbol-function 'device-pixel-width))
-         (fset 'ediff-display-pixel-height
-               (symbol-function 'device-pixel-height))
          (fset 'ediff-valid-color-p (symbol-function 'valid-color-name-p))
          (fset 'ediff-get-face (symbol-function 'get-face)))
       ;; Temporary fix for OS/2 port of Emacs
       ;; pm-win.el in PM-Emacs should be fixed.
-      (fset 'ediff-display-pixel-width 
-           (symbol-function 'x-display-pixel-width))
-      (fset 'ediff-display-pixel-height
-           (symbol-function 'x-display-pixel-height))
       (if (eq (ediff-device-type) 'pm)
          (fset 'ediff-valid-color-p 
                (function (lambda (color) (assoc color pm-color-alist))))
        (fset 'ediff-valid-color-p (symbol-function 'x-color-defined-p)))
       (fset 'ediff-get-face (symbol-function 'internal-get-face))))
+
+(if (ediff-window-display-p)
+    (if ediff-xemacs-p
+       (progn
+         (fset 'ediff-display-pixel-width
+               (symbol-function 'device-pixel-width))
+         (fset 'ediff-display-pixel-height
+               (symbol-function 'device-pixel-height)))
+      (fset 'ediff-display-pixel-width 
+           (symbol-function 'x-display-pixel-width))
+      (fset 'ediff-display-pixel-height
+           (symbol-function 'x-display-pixel-height))))
       
+;; A-list of current-diff-overlay symbols asssociated with buf types
+(defconst ediff-current-diff-overlay-alist
+  '((A . ediff-current-diff-overlay-A)
+    (B . ediff-current-diff-overlay-B)
+    (C . ediff-current-diff-overlay-C)
+    (Ancestor . ediff-current-diff-overlay-Ancestor)))
+  
+;; A-list of current-diff-face-* symbols asssociated with buf types
+(defconst ediff-current-diff-face-alist
+  '((A . ediff-current-diff-face-A)
+    (B . ediff-current-diff-face-B)
+    (C . ediff-current-diff-face-C)
+    (Ancestor . ediff-current-diff-face-Ancestor)))
+  
 
 (defun ediff-make-current-diff-overlay (type)
-  (if (ediff-window-display-p)
-      (let ((overlay (intern (format "ediff-current-diff-overlay-%S" type)))
+  (if (ediff-has-face-support-p)
+      (let ((overlay (ediff-get-symbol-from-alist
+                     type ediff-current-diff-overlay-alist))
            (buffer (ediff-get-buffer type))
            (face (face-name
                   (symbol-value
-                   (intern (format "ediff-current-diff-face-%S" type))))))
+                   (ediff-get-symbol-from-alist
+                    type ediff-current-diff-face-alist)))))
        (set overlay
             (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer))
        (ediff-set-overlay-face (symbol-value overlay) face)
@@ -769,274 +818,311 @@ you are such a person.")
   (let ((is-current (ediff-overlay-get extent 'ediff))
        (face (ediff-overlay-get extent 'face))
        (diff-num (ediff-overlay-get extent 'ediff-diff-num))
-       face-help help-msg)
+       face-help)
 
     ;; This happens only for refinement overlays
     (setq face-help (and face (get face 'ediff-help-echo)))
 
-    (setq help-msg
-         (cond ((and is-current diff-num) ; current diff region
-                (format "Difference region %S -- current" (1+ diff-num)))
-               (face-help) ; refinement of current diff region
-               (diff-num ; non-current
-                (format "Difference region %S -- non-current" (1+ diff-num)))
-               (t ""))))) ; none
-
-(defun ediff-set-face (ground face color)
-  "Set face foreground/background."
-  (if (ediff-window-display-p)
-      (if (ediff-valid-color-p color)
-         (if (eq ground 'foreground)
-             (set-face-foreground face color)
-           (set-face-background face color))
-       (cond ((memq face
-                    '(ediff-current-diff-face-A
-                      ediff-current-diff-face-B
-                      ediff-current-diff-face-C
-                      ediff-current-diff-face-Ancestor))
-              (copy-face 'highlight face))
-             ((memq face
-                    '(ediff-fine-diff-face-A
-                      ediff-fine-diff-face-B
-                      ediff-fine-diff-face-C
-                      ediff-fine-diff-face-Ancestor))
-              (copy-face 'secondary-selection face)
-              (set-face-underline-p face t))
-             ((memq face
-                    '(ediff-even-diff-face-A
-                      ediff-odd-diff-face-A 
-                      ediff-even-diff-face-B ediff-odd-diff-face-B
-                      ediff-even-diff-face-C ediff-odd-diff-face-C
-                      ediff-even-diff-face-Ancestor
-                      ediff-odd-diff-face-Ancestor))
-              (copy-face 'secondary-selection face))))
+    (cond ((and is-current diff-num) ; current diff region
+          (format "Difference region %S -- current" (1+ diff-num)))
+         (face-help) ; refinement of current diff region
+         (diff-num ; non-current
+          (format "Difference region %S -- non-current" (1+ diff-num)))
+         (t ""))   ; none
     ))
-      
-(add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-A)
-(defvar ediff-current-diff-face-A
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-current-diff-face-A)
-       (or (face-differs-from-default-p 'ediff-current-diff-face-A)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face
-                   'foreground 'ediff-current-diff-face-A "firebrick")
-                  (ediff-set-face
-                   'background 'ediff-current-diff-face-A "pale green"))
-                 (t
-                  (if ediff-xemacs-p
-                      (copy-face 'modeline 'ediff-current-diff-face-A)
-                    (copy-face 'highlight 'ediff-current-diff-face-A))
-                  )))
-       'ediff-current-diff-face-A))
-  "Face for highlighting the selected difference in buffer A.")
-
-(add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-B)
-(defvar ediff-current-diff-face-B
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-current-diff-face-B)
-       (or (face-differs-from-default-p 'ediff-current-diff-face-B)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face
-                   'foreground 'ediff-current-diff-face-B "DarkOrchid")
-                  (ediff-set-face
-                   'background 'ediff-current-diff-face-B "Yellow"))
-                 (t 
-                  (if ediff-xemacs-p
-                      (copy-face 'modeline 'ediff-current-diff-face-B)
-                    (copy-face 'highlight 'ediff-current-diff-face-B))
-                  )))
-       'ediff-current-diff-face-B))
-  "Face for highlighting the selected difference in buffer B.")
-    
 
-(add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-C)
-(defvar ediff-current-diff-face-C
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-current-diff-face-C)
-       (or (face-differs-from-default-p 'ediff-current-diff-face-C)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face
-                   'foreground 'ediff-current-diff-face-C "Navy")
-                  (ediff-set-face
-                   'background 'ediff-current-diff-face-C "Pink"))
-                 (t 
-                  (if ediff-xemacs-p
-                      (copy-face 'modeline 'ediff-current-diff-face-C)
-                    (copy-face 'highlight 'ediff-current-diff-face-C))
-                  )))
-       'ediff-current-diff-face-C))
-  "Face for highlighting the selected difference in buffer C.")
-
-(add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-Ancestor)
-(defvar ediff-current-diff-face-Ancestor
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-current-diff-face-Ancestor)
-       (or (face-differs-from-default-p 'ediff-current-diff-face-Ancestor)
-           (copy-face 
-            'ediff-current-diff-face-C 'ediff-current-diff-face-Ancestor))))
-  "Face for highlighting the selected difference in the ancestor buffer.")
-
-(add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-A)
-(defvar ediff-fine-diff-face-A
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-fine-diff-face-A)
-       (or (face-differs-from-default-p 'ediff-fine-diff-face-A)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face 'foreground 'ediff-fine-diff-face-A
-                                  "Navy")
-                  (ediff-set-face 'background 'ediff-fine-diff-face-A
-                                  "sky blue"))
-                 (t (set-face-underline-p 'ediff-fine-diff-face-A t))))
-       'ediff-fine-diff-face-A))
-  "Face for highlighting the refinement of the selected diff in buffer A.")
-
-(add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-B)
-(defvar ediff-fine-diff-face-B
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-fine-diff-face-B)
-       (or (face-differs-from-default-p 'ediff-fine-diff-face-B)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face 'foreground 'ediff-fine-diff-face-B "Black")
-                  (ediff-set-face 'background 'ediff-fine-diff-face-B "cyan"))
-                 (t (set-face-underline-p 'ediff-fine-diff-face-B t))))
-       'ediff-fine-diff-face-B))
-  "Face for highlighting the refinement of the selected diff in buffer B.")
-    
-(add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-C)
-(defvar ediff-fine-diff-face-C
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-fine-diff-face-C)
-       (or (face-differs-from-default-p 'ediff-fine-diff-face-C)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face 'foreground 'ediff-fine-diff-face-C "black")
-                  (ediff-set-face
-                   'background 'ediff-fine-diff-face-C "Turquoise"))
-                 (t (set-face-underline-p 'ediff-fine-diff-face-C t))))
-       'ediff-fine-diff-face-C))
-  "Face for highlighting the refinement of the selected diff in buffer C.")
-
-(add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-Ancestor)
-(defvar ediff-fine-diff-face-Ancestor
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-fine-diff-face-Ancestor)
-       (or (face-differs-from-default-p 'ediff-fine-diff-face-Ancestor)
-           (copy-face
-            'ediff-fine-diff-face-C 'ediff-fine-diff-face-Ancestor))))
-  "Face highlighting refinements of the selected diff in ancestor buffer.
-Presently, this is not used, as difference regions are not refined in the
-ancestor buffer.")
-    
-(add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-A)
-(defvar ediff-even-diff-face-A
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-even-diff-face-A)
-       (or (face-differs-from-default-p 'ediff-even-diff-face-A)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face
-                   'foreground 'ediff-even-diff-face-A "black")
-                  (ediff-set-face
-                   'background 'ediff-even-diff-face-A "light grey"))
-                 (t 
-                  (copy-face 'italic 'ediff-even-diff-face-A))))
-       'ediff-even-diff-face-A))
-  "Face used to highlight even-numbered differences in buffer A.")
+
+(defun ediff-set-face-pixmap (face pixmap)
+  "Set face pixmap on a monochrome display."
+  (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
+      (condition-case nil
+         (set-face-background-pixmap face pixmap)
+       (error
+        (message "Pixmap not found for %S: %s" (face-name face) pixmap)
+        (sit-for 1)))))
+
+(defun ediff-hide-face (face)
+  (if (and (ediff-has-face-support-p) ediff-emacs-p)
+      (add-to-list 'facemenu-unlisted-faces face)))
       
-(add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-B)
-(defvar ediff-even-diff-face-B
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-even-diff-face-B)
-       (or (face-differs-from-default-p 'ediff-even-diff-face-B)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face
-                   'foreground 'ediff-even-diff-face-B "White")
-                  (ediff-set-face
-                   'background 'ediff-even-diff-face-B "Gray"))
-                 (t 
-                  (copy-face 'italic 'ediff-even-diff-face-B))))
-       'ediff-even-diff-face-B))
-  "Face used to highlight even-numbered differences in buffer B.")
-    
-(add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-C)
-(defvar ediff-even-diff-face-C
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-even-diff-face-C)
-       (or (face-differs-from-default-p 'ediff-even-diff-face-C)
-           (copy-face 'ediff-even-diff-face-A 'ediff-even-diff-face-C))
-       'ediff-even-diff-face-C))
-  "Face used to highlight even-numbered differences in buffer C.")
-
-(add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-Ancestor)
-(defvar ediff-even-diff-face-Ancestor
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-even-diff-face-Ancestor)
-       (or (face-differs-from-default-p 'ediff-even-diff-face-Ancestor)
-           (copy-face 'ediff-even-diff-face-C 'ediff-even-diff-face-Ancestor))
-       'ediff-even-diff-face-Ancestor))
-  "Face highlighting even-numbered differences in the ancestor buffer.")
+
+
+(defface ediff-current-diff-face-A
+  '((((class color)) (:foreground "firebrick" :background "pale green"))
+    (t (:inverse-video t)))
+  "Face for highlighting the selected difference in buffer A."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-current-diff-face-A 'ediff-current-diff-face-A
+  "Face for highlighting the selected difference in buffer A.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-current-diff-face-A'
+this variable represents.")
+(ediff-hide-face 'ediff-current-diff-face-A)
+;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
+;; This means that some user customization may be trashed.
+(if (and ediff-xemacs-p
+        (ediff-has-face-support-p)
+        (not (ediff-color-display-p))) 
+    (copy-face 'modeline 'ediff-current-diff-face-A))
+
+
+
+(defface ediff-current-diff-face-B
+  '((((class color)) (:foreground "DarkOrchid" :background "Yellow"))
+    (t (:inverse-video t)))
+  "Face for highlighting the selected difference in buffer B."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-current-diff-face-B 'ediff-current-diff-face-B
+  "Face for highlighting the selected difference in buffer B.
+ this variable. Instead, use the customization
+widget to customize the actual face `ediff-current-diff-face-B'
+this variable represents.")
+(ediff-hide-face 'ediff-current-diff-face-B)
+;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
+;; This means that some user customization may be trashed.
+(if (and ediff-xemacs-p
+        (ediff-has-face-support-p)
+        (not (ediff-color-display-p))) 
+    (copy-face 'modeline 'ediff-current-diff-face-B))
+
+
+(defface ediff-current-diff-face-C
+  '((((class color)) (:foreground "Navy" :background "Pink"))
+    (t (:inverse-video t)))
+  "Face for highlighting the selected difference in buffer C."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-current-diff-face-C 'ediff-current-diff-face-C
+  "Face for highlighting the selected difference in buffer C.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-current-diff-face-C'
+this variable represents.")
+(ediff-hide-face 'ediff-current-diff-face-C)
+;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
+;; This means that some user customization may be trashed.
+(if (and ediff-xemacs-p
+        (ediff-has-face-support-p)
+        (not (ediff-color-display-p))) 
+    (copy-face 'modeline 'ediff-current-diff-face-C))
+
+
+(defface ediff-current-diff-face-Ancestor
+  '((((class color)) (:foreground "Black" :background "VioletRed"))
+    (t (:inverse-video t)))
+  "Face for highlighting the selected difference in buffer Ancestor."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-face-Ancestor
+  "Face for highlighting the selected difference in buffer Ancestor.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-current-diff-face-Ancestor'
+this variable represents.")
+(ediff-hide-face 'ediff-current-diff-face-Ancestor)
+;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
+;; This means that some user customization may be trashed.
+(if (and ediff-xemacs-p
+        (ediff-has-face-support-p)
+        (not (ediff-color-display-p))) 
+    (copy-face 'modeline 'ediff-current-diff-face-Ancestor))
+
+
+(defface ediff-fine-diff-face-A
+  '((((class color)) (:foreground "Navy" :background "sky blue"))
+    (t (:underline t :stipple "gray3")))
+  "Face for highlighting the refinement of the selected diff in buffer A."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-fine-diff-face-A 'ediff-fine-diff-face-A
+  "Face for highlighting the fine differences in buffer A.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-fine-diff-face-A'
+this variable represents.")
+(ediff-hide-face 'ediff-fine-diff-face-A)
+
+(defface ediff-fine-diff-face-B
+  '((((class color)) (:foreground "Black" :background "cyan"))
+    (t (:underline t :stipple "gray3")))
+  "Face for highlighting the refinement of the selected diff in buffer B."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-fine-diff-face-B 'ediff-fine-diff-face-B
+  "Face for highlighting the fine differences in buffer B.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-fine-diff-face-B'
+this variable represents.")
+(ediff-hide-face 'ediff-fine-diff-face-B)
+
+(defface ediff-fine-diff-face-C
+  '((((class color)) (:foreground "Black" :background "Turquoise"))
+    (t (:underline t :stipple "gray3")))
+  "Face for highlighting the refinement of the selected diff in buffer C."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-fine-diff-face-C 'ediff-fine-diff-face-C
+  "Face for highlighting the fine differences in buffer C.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-fine-diff-face-C'
+this variable represents.")
+(ediff-hide-face 'ediff-fine-diff-face-C)
+
+(defface ediff-fine-diff-face-Ancestor
+  '((((class color)) (:foreground "Black" :background "Green"))
+    (t (:underline t :stipple "gray3")))
+  "Face for highlighting the refinement of the selected diff in the ancestor buffer.
+At present, this face is not used and no fine differences are computed for the
+ancestor buffer."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-face-Ancestor
+  "Face for highlighting the fine differences in buffer Ancestor.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-fine-diff-face-Ancestor'
+this variable represents.")
+(ediff-hide-face 'ediff-fine-diff-face-Ancestor)
+
+(defface ediff-even-diff-face-A
+  '((((class color)) (:foreground "Black" :background "light grey"))
+    (t (:italic t :stipple "stipple")))
+  "Face for highlighting even-numbered non-current differences in buffer A."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-even-diff-face-A 'ediff-even-diff-face-A
+  "Face for highlighting even-numbered non-current differences in buffer A.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-even-diff-face-A'
+this variable represents.")
+(ediff-hide-face 'ediff-even-diff-face-A)
+
+(defface ediff-even-diff-face-B
+  '((((class color)) (:foreground "White" :background "Grey"))
+    (t (:italic t :stipple "stipple")))
+  "Face for highlighting even-numbered non-current differences in buffer B."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-even-diff-face-B 'ediff-even-diff-face-B
+  "Face for highlighting even-numbered non-current differences in buffer B.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-even-diff-face-B'
+this variable represents.")
+(ediff-hide-face 'ediff-even-diff-face-B)
+
+(defface ediff-even-diff-face-C
+  '((((class color)) (:foreground "Black" :background "light grey"))
+    (t (:italic t :stipple "stipple")))
+  "Face for highlighting even-numbered non-current differences in buffer C."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-even-diff-face-C 'ediff-even-diff-face-C
+  "Face for highlighting even-numbered non-current differences in buffer C.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-even-diff-face-C'
+this variable represents.")
+(ediff-hide-face 'ediff-even-diff-face-C)
+
+(defface ediff-even-diff-face-Ancestor
+  '((((class color)) (:foreground "White" :background "Grey"))
+    (t (:italic t :stipple "stipple")))
+  "Face for highlighting even-numbered non-current differences in the ancestor buffer."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-face-Ancestor
+  "Face for highlighting even-numbered non-current differences in buffer Ancestor.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-even-diff-face-Ancestor'
+this variable represents.")
+(ediff-hide-face 'ediff-even-diff-face-Ancestor)
+
+;; Association between buffer types and even-diff-face symbols
+(defconst ediff-even-diff-face-alist
+  '((A . ediff-even-diff-face-A)
+    (B . ediff-even-diff-face-B)
+    (C . ediff-even-diff-face-C)
+    (Ancestor . ediff-even-diff-face-Ancestor)))
+
+(defface ediff-odd-diff-face-A
+  '((((class color)) (:foreground "White" :background "Grey"))
+    (t (:italic t :stipple "gray1")))
+  "Face for highlighting odd-numbered non-current differences in buffer A."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-odd-diff-face-A 'ediff-odd-diff-face-A
+  "Face for highlighting odd-numbered non-current differences in buffer A.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-odd-diff-face-A'
+this variable represents.")
+(ediff-hide-face 'ediff-odd-diff-face-A)
+
+
+(defface ediff-odd-diff-face-B
+  '((((class color)) (:foreground "Black" :background "light grey"))
+    (t (:italic t :stipple "gray1")))
+  "Face for highlighting odd-numbered non-current differences in buffer B."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-odd-diff-face-B 'ediff-odd-diff-face-B
+  "Face for highlighting odd-numbered non-current differences in buffer B.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-odd-diff-face-B'
+this variable represents.")
+(ediff-hide-face 'ediff-odd-diff-face-B)
+
+(defface ediff-odd-diff-face-C
+  '((((class color)) (:foreground "White" :background "Grey"))
+    (t (:italic t :stipple "gray1")))
+  "Face for highlighting odd-numbered non-current differences in buffer C."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-odd-diff-face-C 'ediff-odd-diff-face-C
+  "Face for highlighting odd-numbered non-current differences in buffer C.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-odd-diff-face-C'
+this variable represents.")
+(ediff-hide-face 'ediff-odd-diff-face-C)
+
+(defface ediff-odd-diff-face-Ancestor
+  '((((class color)) (:foreground "Black" :background "light grey"))
+    (t (:italic t :stipple "gray1")))
+  "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
+  :group 'ediff-highlighting)
+;; An internal variable. Ediff takes the face from here. When unhighlighting,
+;; this variable is set to nil, then again to the appropriate face.
+(defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-face-Ancestor
+  "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
+DO NOT CHANGE this variable. Instead, use the customization
+widget to customize the actual face object `ediff-odd-diff-face-Ancestor'
+this variable represents.")
+(ediff-hide-face 'ediff-odd-diff-face-Ancestor)
+
+;; Association between buffer types and odd-diff-face symbols
+(defconst ediff-odd-diff-face-alist
+  '((A . ediff-odd-diff-face-A)
+    (B . ediff-odd-diff-face-B)
+    (C . ediff-odd-diff-face-C)
+    (Ancestor . ediff-odd-diff-face-Ancestor)))
   
-(add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-A)
-(defvar ediff-odd-diff-face-A
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-odd-diff-face-A)
-       (or (face-differs-from-default-p 'ediff-odd-diff-face-A)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face
-                   'foreground 'ediff-odd-diff-face-A "White")
-                  (ediff-set-face
-                   'background 'ediff-odd-diff-face-A "Gray"))
-                 (t 
-                  (copy-face 'italic 'ediff-odd-diff-face-A))))
-       'ediff-odd-diff-face-A))
-  "Face used to highlight odd-numbered differences in buffer A.")
-      
-(add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-B)
-(defvar ediff-odd-diff-face-B
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-odd-diff-face-B)
-       (or (face-differs-from-default-p 'ediff-odd-diff-face-B)
-           (cond ((ediff-color-display-p)
-                  (ediff-set-face
-                   'foreground 'ediff-odd-diff-face-B "Black")
-                  (ediff-set-face
-                   'background 'ediff-odd-diff-face-B "light grey"))
-                 (t 
-                  (copy-face 'italic 'ediff-odd-diff-face-B))))
-       'ediff-odd-diff-face-B))
-  "Face used to highlight odd-numbered differences in buffer B.")
-    
-(add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-C)
-(defvar ediff-odd-diff-face-C
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-odd-diff-face-C)
-       (or (face-differs-from-default-p 'ediff-odd-diff-face-C)
-           (copy-face 'ediff-odd-diff-face-A 'ediff-odd-diff-face-C))
-       'ediff-odd-diff-face-C))
-  "Face used to highlight odd-numbered differences in buffer C.")
-
-(add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-Ancestor )
-(defvar ediff-odd-diff-face-Ancestor 
-  (if (ediff-window-display-p)
-      (progn
-       (make-face 'ediff-odd-diff-face-Ancestor)
-       (or (face-differs-from-default-p 'ediff-odd-diff-face-Ancestor)
-           (copy-face 'ediff-odd-diff-face-C 'ediff-odd-diff-face-Ancestor))
-       'ediff-odd-diff-face-Ancestor))
-  "Face used to highlight even-numbered differences in the ancestor buffer.")
+;; A-list of fine-diff face symbols associated with buffer types
+(defconst ediff-fine-diff-face-alist
+  '((A . ediff-fine-diff-face-A)
+    (B . ediff-fine-diff-face-B)
+    (C . ediff-fine-diff-face-C)
+    (Ancestor . ediff-fine-diff-face-Ancestor)))
 
 ;; Help echo
 (put 'ediff-fine-diff-face-A 'ediff-help-echo
@@ -1059,14 +1145,14 @@ ancestor buffer.")
   "Overlay for the current difference region in buffer C.")
 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
   "Overlay for the current difference region in the ancestor buffer.")
-  
+
 ;; Compute priority of ediff overlay.
 (defun ediff-highest-priority (start end buffer)
   (let ((pos (max 1 (1- start)))
        ovr-list)
     (if ediff-xemacs-p
        (1+ ediff-shadow-overlay-priority)
-      (ediff-eval-in-buffer buffer
+      (ediff-with-current-buffer buffer
        (while (< pos (min (point-max) (1+ end)))
          (setq ovr-list (append (overlays-at pos) ovr-list))
          (setq pos (next-overlay-change pos)))
@@ -1087,64 +1173,79 @@ If nil, Ediff tries to deduce the function from the binding of C-x C-q.
 Normally, this is the `toggle-read-only' function, but, if version
 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
 
+(defcustom ediff-make-buffers-readonly-at-startup nil
+  "*Make all variant buffers read-only when Ediff starts up.
+This property can be toggled interactively."
+  :type 'boolean
+  :group 'ediff)
+
 
 ;;; Misc
 
 ;; if nil, this silences some messages
 (defconst ediff-verbose-p t)
+
+(defcustom ediff-autostore-merges  'group-jobs-only
+  "*Save the results of merge jobs automatically.
+Nil means don't save automatically. t means always save. Anything but nil or t
+means save automatically only if the merge job is part of a group of jobs, such
+as `ediff-merge-directory' or `ediff-merge-directory-revisions'."
+  :type '(choice (const nil) (const t)
+                (other :tag "group-jobs-only" group-jobs-only))
+  :group 'ediff-merge)
+(make-variable-buffer-local 'ediff-autostore-merges)
+
+;; file where the result of the merge is to be saved. used internally
+(ediff-defvar-local ediff-merge-store-file nil "")
   
-(defvar ediff-no-emacs-help-in-control-buffer nil
+(defcustom ediff-no-emacs-help-in-control-buffer nil
   "*Non-nil means C-h should not invoke Emacs help in control buffer.
-Instead, C-h jumps to previous difference.")
+Instead, C-h would jump to previous difference."
+  :type 'boolean
+  :group 'ediff)
   
-(defvar ediff-temp-file-prefix
-  (let ((env (or (getenv "TMPDIR")
-                (getenv "TMP")
-                (getenv "TEMP")))
-       d)
-    (setq d (if (and env (> (length env) 0))
-               env
-             (if (memq system-type '(vax-vms axp-vms))
-                 "SYS$SCRATCH:"
-               "/tmp")))
-    ;; The following is to make sure we get something to which we can
-    ;; add directory levels on VMS.
-    (setq d (file-name-as-directory (directory-file-name d)))
-    )
+(defcustom ediff-temp-file-prefix
+  (file-name-as-directory temporary-file-directory)
   "*Prefix to put on Ediff temporary file names.
-Do not start with `~/' or `~user-name/'.")  
-
-(defvar ediff-temp-file-mode 384       ; u=rw only
-  "*Mode for Ediff temporary files.")
+Do not start with `~/' or `~USERNAME/'."
+  :type 'string
+  :group 'ediff)
+
+(defcustom ediff-temp-file-mode 384    ; u=rw only
+  "*Mode for Ediff temporary files."
+  :type 'integer
+  :group 'ediff)
   
 ;; Metacharacters that have to be protected from the shell when executing
 ;; a diff/diff3 command.
-(defvar ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
-  "Characters that must be quoted with \\ when used in a shell command line.
-More precisely, a regexp to match any one such character.")
+(defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
+  "Regexp that matches characters that must be quoted with `\\' in shell command line.
+This default should work without changes."
+  :type 'string
+  :group 'ediff)
+
+;; needed to simulate frame-char-width in XEmacs.
+(defvar ediff-H-glyph (if ediff-xemacs-p (make-glyph "H")))
 
   
-(ediff-defvar-local ediff-temp-file-A nil
-  "Temporary file used for refining difference regions in buffer A.")
-(ediff-defvar-local ediff-temp-file-B nil
-  "Temporary file used for refining difference regions in buffer B.")
-(ediff-defvar-local ediff-temp-file-C nil
-  "Temporary file used for refining difference regions in buffer C.")
+;; Temporary file used for refining difference regions in buffer A.
+(ediff-defvar-local ediff-temp-file-A nil "")
+;; Temporary file used for refining difference regions in buffer B.
+(ediff-defvar-local ediff-temp-file-B nil "")
+;; Temporary file used for refining difference regions in buffer C.
+(ediff-defvar-local ediff-temp-file-C nil "")
+
 
 ;;; In-line functions
 
-(defsubst ediff-file-remote-p (file-name)
-  (if (fboundp ediff-ange-ftp-ftp-name)
-      (funcall ediff-ange-ftp-ftp-name file-name)))
-
-;;(defun ediff-frame-has-menubar ()
-;;  (and (ediff-window-display-p)
-;;       (if ediff-xemacs-p
-;;        current-menubar
-;;      (let ((lines (cdr (assq 'menu-bar-lines
-;;                              (frame-parameters (selected-frame))))))
-;;        (or (eq lines t) (and (numberp lines) (< 0 lines))))
-;;      )))
+(or (fboundp 'ediff-file-remote-p) ; user supplied his own function: use it
+    (defun ediff-file-remote-p (file-name)
+      (car (cond ((featurep 'efs-auto) (efs-ftp-path file-name))
+                ((fboundp 'file-remote-p) (file-remote-p file-name))
+                (t (require 'ange-ftp)
+                   ;; Can happen only in Emacs, since XEmacs has file-remote-p
+                   (ange-ftp-ftp-name file-name))))))
+
     
 (defsubst ediff-frame-unsplittable-p (frame)
   (cdr (assq 'unsplittable (frame-parameters frame))))
@@ -1160,6 +1261,108 @@ More precisely, a regexp to match any one such character.")
   "Kill buffer BUF if it exists."
   (if (ediff-buffer-live-p buf)
       (kill-buffer (get-buffer buf))))
+
+(defsubst ediff-background-face (buf-type dif-num)
+  ;; The value of dif-num is always 1- the one that user sees.
+  ;; This is why even face is used when dif-num is odd.
+  (ediff-get-symbol-from-alist
+   buf-type (if (ediff-odd-p dif-num)
+               ediff-even-diff-face-alist
+             ediff-odd-diff-face-alist)
+   ))
+
+
+;; activate faces on diff regions in buffer
+(defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
+  (let ((diff-vector 
+        (eval (ediff-get-symbol-from-alist
+               buf-type ediff-difference-vector-alist)))
+       overl diff-num)
+    (mapcar (function
+            (lambda (rec)
+              (setq overl (ediff-get-diff-overlay-from-diff-record rec)
+                    diff-num (ediff-overlay-get overl 'ediff-diff-num))
+              (if (ediff-overlay-buffer overl)
+                  ;; only if overlay is alive
+                  (ediff-set-overlay-face
+                   overl
+                   (if (not unhighlight)
+                       (ediff-background-face buf-type diff-num))))
+              ))
+           diff-vector)))
+
+
+;; activate faces on diff regions in all buffers
+(defun ediff-paint-background-regions (&optional unhighlight)
+  (ediff-paint-background-regions-in-one-buffer
+   'A unhighlight)
+  (ediff-paint-background-regions-in-one-buffer
+   'B unhighlight)
+  (ediff-paint-background-regions-in-one-buffer
+   'C unhighlight)
+  (ediff-paint-background-regions-in-one-buffer
+   'Ancestor unhighlight))
+
+(defun ediff-highlight-diff-in-one-buffer (n buf-type)
+  (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
+      (let* ((buff (ediff-get-buffer buf-type))
+            (last (ediff-with-current-buffer buff (point-max)))
+            (begin (ediff-get-diff-posn buf-type 'beg n))
+            (end (ediff-get-diff-posn buf-type 'end n))
+            (xtra (if (equal begin end) 1 0))
+            (end-hilit (min last (+ end xtra)))
+            (current-diff-overlay 
+             (symbol-value
+              (ediff-get-symbol-from-alist
+               buf-type ediff-current-diff-overlay-alist))))
+       
+       (if ediff-xemacs-p
+           (ediff-move-overlay current-diff-overlay begin end-hilit)
+         (ediff-move-overlay current-diff-overlay begin end-hilit buff))
+       (ediff-overlay-put current-diff-overlay 'priority  
+                          (ediff-highest-priority begin end-hilit buff))
+       (ediff-overlay-put current-diff-overlay 'ediff-diff-num n)
+       
+       ;; unhighlight the background overlay for diff n so it won't
+       ;; interfere with the current diff overlay
+       (ediff-set-overlay-face (ediff-get-diff-overlay n buf-type) nil)
+       )))
+
+
+(defun ediff-unhighlight-diff-in-one-buffer (buf-type)
+  (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
+      (let ((current-diff-overlay 
+            (symbol-value
+             (ediff-get-symbol-from-alist
+              buf-type ediff-current-diff-overlay-alist)))
+           (overlay
+            (ediff-get-diff-overlay ediff-current-difference buf-type))
+           )
+    
+       (ediff-move-overlay current-diff-overlay 1 1)
+       
+       ;; rehighlight the overlay in the background of the
+       ;; current difference region
+       (ediff-set-overlay-face
+        overlay
+        (if (and (ediff-has-face-support-p)
+                 ediff-use-faces ediff-highlight-all-diffs)
+            (ediff-background-face buf-type ediff-current-difference)))
+       )))
+
+(defun ediff-unhighlight-diffs-totally-in-one-buffer (buf-type)
+  (ediff-unselect-and-select-difference -1)
+  (if (and (ediff-has-face-support-p) ediff-use-faces)
+      (let* ((inhibit-quit t)
+            (current-diff-overlay-var
+             (ediff-get-symbol-from-alist
+              buf-type ediff-current-diff-overlay-alist))
+            (current-diff-overlay (symbol-value current-diff-overlay-var)))
+       (ediff-paint-background-regions 'unhighlight)
+       (if (ediff-overlayp current-diff-overlay)
+           (ediff-delete-overlay current-diff-overlay))
+       (set current-diff-overlay-var nil)
+       )))
       
 
 (defsubst ediff-highlight-diff (n)
@@ -1187,14 +1390,6 @@ More precisely, a regexp to match any one such character.")
   (ediff-unhighlight-diffs-totally-in-one-buffer 'Ancestor)
   )
 
-(defsubst ediff-background-face (buf-type dif-num)
-  ;; The value of dif-num is always 1- the one that user sees.
-  ;; This is why even face is used when dif-num is odd.
-  (intern (format (if (ediff-odd-p dif-num)
-                     "ediff-even-diff-face-%S"
-                   "ediff-odd-diff-face-%S")
-                 buf-type)))
-    
       
 ;; arg is a record for a given diff in a difference vector
 ;; this record is itself a vector
@@ -1283,7 +1478,7 @@ More precisely, a regexp to match any one such character.")
            ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
            ;; sessions that are not part of a group (this is done in
            ;; ediff-recenter). The condition below affects only terminating
-           ;; sessions in session groups (in whhich case mouse is warped into
+           ;; sessions in session groups (in which case mouse is warped into
            ;; a meta buffer).
            (and (eq ediff-grab-mouse 'maybe)
                 (memq this-command '(ediff-quit ediff-update-diffs)))
@@ -1293,10 +1488,9 @@ More precisely, a regexp to match any one such character.")
 (defsubst ediff-spy-after-mouse ()
   (setq ediff-mouse-pixel-position (mouse-pixel-position)))
 
-;; This is actually not easy to find out since emacs and xemacs behave
-;; differently when mouse is not in any frame. Also, this is sensitive to
-;; when the user grabbed mouse.
-;; Not used for now.
+;; It is not easy to find out when the user grabs the mouse, since emacs and
+;; xemacs behave differently when mouse is not in any frame. Also, this is
+;; sensitive to when the user grabbed mouse.  Not used for now.
 (defun ediff-user-grabbed-mouse ()
   (if ediff-mouse-pixel-position
       (cond ((not (eq (car ediff-mouse-pixel-position)
@@ -1307,20 +1501,73 @@ More precisely, a regexp to match any one such character.")
                  (cdr (cdr (mouse-pixel-position))))
             (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
                                  (car (cdr (mouse-pixel-position)))))
-                         ediff-mouse-pixel-threshhold)
+                         ediff-mouse-pixel-threshold)
                       (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
                                  (cdr (cdr (mouse-pixel-position)))))
-                         ediff-mouse-pixel-threshhold))))
+                         ediff-mouse-pixel-threshold))))
            (t nil))))
     
 (defsubst ediff-frame-char-height (frame)
   (if ediff-xemacs-p
-      (/ (frame-pixel-height frame) (frame-height frame))
+      (glyph-height ediff-H-glyph (selected-window frame))
     (frame-char-height frame)))
     
+;; Some overlay functions
+
+(defsubst ediff-overlay-start (overl)
+  (if (ediff-overlayp overl)
+      (if ediff-emacs-p
+         (overlay-start overl)
+       (extent-start-position overl))))
+       
+(defsubst ediff-overlay-end  (overl)
+  (if (ediff-overlayp overl)
+      (if ediff-emacs-p
+         (overlay-end overl)
+       (extent-end-position overl))))
 
 (defsubst ediff-empty-overlay-p (overl)
   (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
+
+;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
+;; dead. Otherwise, works like extent-buffer
+(defun ediff-overlay-buffer (overl)
+  (if ediff-emacs-p
+      (overlay-buffer overl)
+    (and (extent-live-p overl) (extent-object overl))))
+
+;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
+;; dead. Otherwise, like extent-property
+(defun ediff-overlay-get (overl property)
+  (if ediff-emacs-p
+      (overlay-get overl property)
+    (and (extent-live-p overl) (extent-property overl property))))
+
+
+;; These two functions are here because XEmacs refuses to
+;; handle overlays whose buffers were deleted.
+(defun ediff-move-overlay (overlay beg end &optional buffer)
+  "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
+Checks if overlay's buffer exists before actually doing the move."
+  (let ((buf (and overlay (ediff-overlay-buffer overlay))))
+    (if (ediff-buffer-live-p buf)
+       (if ediff-xemacs-p
+           (set-extent-endpoints overlay beg end)
+         (move-overlay overlay beg end buffer))
+      ;; buffer's dead
+      (if overlay
+         (ediff-delete-overlay overlay)))))
+         
+(defun ediff-overlay-put (overlay prop value)
+  "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
+Checks if overlay's buffer exists."
+  (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
+      (if ediff-xemacs-p
+         (set-extent-property overlay prop value)
+       (overlay-put overlay prop value))
+    (ediff-delete-overlay overlay)))
+
+;; Some diff region tests
   
 ;; t if diff region is empty.
 ;; In case of buffer C, t also if it is not a 3way
@@ -1340,7 +1587,7 @@ More precisely, a regexp to match any one such character.")
       (ediff-empty-diff-region-p n buf-type)
       (let ((beg (ediff-get-diff-posn buf-type 'beg n))
            (end (ediff-get-diff-posn buf-type 'end n)))
-       (ediff-eval-in-buffer (ediff-get-buffer buf-type)
+       (ediff-with-current-buffer (ediff-get-buffer buf-type)
          (save-excursion
            (goto-char beg)
            (skip-chars-forward ediff-whitespace)
@@ -1348,7 +1595,7 @@ More precisely, a regexp to match any one such character.")
            
 ;; temporarily uses DIR to abbreviate file name
 ;; if DIR is nil, use default-directory
-(defsubst ediff-abbreviate-file-name (file &optional dir)
+(defun ediff-abbreviate-file-name (file &optional dir)
   (cond ((stringp dir)
         (let ((directory-abbrev-alist (list (cons dir ""))))
           (abbreviate-file-name file)))
@@ -1415,8 +1662,8 @@ More precisely, a regexp to match any one such character.")
 
     
 (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
-  (ediff-eval-in-buffer 
-      (ediff-eval-in-buffer ctrl-buf (ediff-get-buffer buf-type))
+  (ediff-with-current-buffer 
+      (ediff-with-current-buffer ctrl-buf (ediff-get-buffer buf-type))
     (buffer-substring
      (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf))
      (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf)))))
@@ -1441,6 +1688,29 @@ More precisely, a regexp to match any one such character.")
 (defsubst ediff-message-if-verbose (string &rest args)
   (if ediff-verbose-p
       (apply 'message string args)))
+
+(defun ediff-file-attributes (filename attr-number)
+  (if (ediff-file-remote-p filename)
+      -1
+    (nth attr-number (file-attributes filename))))
+
+(defsubst ediff-file-size (filename)
+  (ediff-file-attributes filename 7))
+(defsubst ediff-file-modtime (filename)
+  (ediff-file-attributes filename 5))
+
+
+(defun ediff-convert-standard-filename (fname)
+  (if (fboundp 'convert-standard-filename)
+      (convert-standard-filename fname)
+    fname))
+
+
+;;; 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-init)