*** empty log message ***
[bpt/emacs.git] / lisp / ediff-init.el
index de8bed9..b701ae6 100644 (file)
@@ -21,6 +21,8 @@
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
 ;;; Code:
 
 ;; Start compiler pacifier
@@ -443,11 +445,11 @@ set local variables that determine how the display looks like."
   :type 'hook
   :group 'ediff-hook)
 
-(defcustom ediff-suspend-hook (list 'ediff-default-suspend-function)
+(defcustom ediff-suspend-hook nil
   "*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)
+(defcustom ediff-quit-hook nil
   "*Hooks to run in the Ediff control buffer after finishing Ediff."
   :type 'hook
   :group 'ediff-hook)
@@ -519,6 +521,11 @@ See the documentation string of `ediff-focus-on-regexp-matches' for details.")
 ;; where some buffer-objects may be missing.
 (ediff-defvar-local ediff-killed-diffs-alist nil "")
 
+;; Syntax table to use in ediff-forward-word-function
+;; This is chosen by a heuristic. The important thing is for all buffers to
+;; have the same syntax table. Which is not too important.
+(ediff-defvar-local ediff-syntax-table nil "")
+
 
 ;; Highlighting
 (defcustom ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
@@ -707,6 +714,22 @@ appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
   :type 'symbol
   :group 'ediff)
 
+(defcustom ediff-coding-system-for-read 'raw-text
+  "*The coding system for read to use when running the diff program as a subprocess. 
+In most cases, the default will do. However, under certain circumstances in
+Windows NT/98/95 you might need to use something like 'raw-text-dos here.
+So, if the output that your diff program sends to Emacs contains extra ^M's,
+you might need to experiment here, if the default or 'raw-text-dos doesn't
+work."
+  :type 'symbol
+  :group 'ediff)
+
+(defcustom ediff-coding-system-for-write 'no-conversion
+  "*The coding system for write to use when writing out difference regions
+to temp files when Ediff needs to find fine differences."
+  :type 'symbol
+  :group 'ediff)
+
 
 (if ediff-xemacs-p
     (progn
@@ -1152,6 +1175,9 @@ this variable represents.")
 (put 'ediff-fine-diff-face-Ancestor 'ediff-help-echo
      "A `refinement' of the current difference region")
 
+(add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
+(add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
+
 
 ;;; Overlays
 
@@ -1164,7 +1190,7 @@ this variable represents.")
 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
   "Overlay for the current difference region in the ancestor buffer.")
 
-;; Compute priority of ediff overlay.
+;; Compute priority of a current ediff overlay.
 (defun ediff-highest-priority (start end buffer)
   (let ((pos (max 1 (1- start)))
        ovr-list)
@@ -1174,13 +1200,24 @@ this variable represents.")
        (while (< pos (min (point-max) (1+ end)))
          (setq ovr-list (append (overlays-at pos) ovr-list))
          (setq pos (next-overlay-change pos)))
-       (1+ (apply '+
-                  (mapcar (lambda (ovr)
-                            (if ovr
-                                (or (ediff-overlay-get ovr 'priority) 0)
-                              0))
-                          ovr-list)
-                  ))
+       (+ 1 ediff-shadow-overlay-priority
+          (apply 'max
+                 (cons
+                  1
+                  (mapcar
+                   (lambda (ovr)
+                     (if (and ovr
+                              ;; exclude ediff overlays from priority
+                              ;; calculation, or else priority will keep
+                              ;; increasing
+                              (null (ediff-overlay-get ovr 'ediff))
+                              (null (ediff-overlay-get ovr 'ediff-diff-num)))
+                         ;; use the overlay priority or 0
+                         (or (ediff-overlay-get ovr 'priority) 0)
+                       0))
+                   ovr-list)
+                  )
+                 ))
        ))))
 
 
@@ -1271,13 +1308,16 @@ This default should work without changes."
 
 ;;; In-line functions
 
-(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))))))
+;; If file-remote-p is defined (as in XEmacs, use it. Otherwise, check
+;; if find-file-name-handler is defined for 'file-local-copy
+(defun ediff-file-remote-p (file-name)
+  (or (and (fboundp 'file-remote-p) (file-remote-p file-name))
+      (find-file-name-handler file-name 'file-local-copy)))
+
+;; File for which we can get attributes, such as size or date
+(defun ediff-listable-file (file-name)
+  (let ((handler (find-file-name-handler file-name 'file-local-copy)))
+    (or (null handler) (eq handler 'dired-handler-fn))))
 
 
 (defsubst ediff-frame-unsplittable-p (frame)
@@ -1661,6 +1701,18 @@ Checks if overlay's buffer exists."
 (defsubst ediff-nonempty-string-p (string)
   (and (stringp string) (not (string= string ""))))
 
+(unless (fboundp 'subst-char-in-string)
+  (defun subst-char-in-string (fromchar tochar string &optional inplace)
+    "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
+Unless optional argument INPLACE is non-nil, return a new string."
+    (let ((i (length string))
+         (newstr (if inplace string (copy-sequence string))))
+      (while (> i 0)
+       (setq i (1- i))
+       (if (eq (aref newstr i) fromchar)
+           (aset newstr i tochar)))
+      newstr)))
+
 (defun ediff-abbrev-jobname (jobname)
   (cond ((eq jobname 'ediff-directories)
         "Compare two directories")
@@ -1683,17 +1735,9 @@ Checks if overlay's buffer exists."
        ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
         "Merge dir versions via ancestors")
        (t
-        (let* ((str (substring (symbol-name jobname) 6))
-               (len (length str))
-               (pos 0))
-          (while (< pos len)
-            (if (= pos 0)
-                (aset str pos (upcase (aref str pos))))
-            (if (= (aref str pos) ?-)
-                (aset str pos ?\ ))
-            (setq pos (1+ pos)))
-          str))))
-
+        (capitalize
+         (subst-char-in-string ?- ?\  (substring (symbol-name jobname) 6))))
+       ))
 
 
 (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
@@ -1725,9 +1769,10 @@ Checks if overlay's buffer exists."
       (apply 'message string args)))
 
 (defun ediff-file-attributes (filename attr-number)
-  (if (ediff-file-remote-p filename)
-      -1
-    (nth attr-number (file-attributes filename))))
+  (if (ediff-listable-file filename)
+      (nth attr-number (file-attributes filename))
+    -1)
+  )
 
 (defsubst ediff-file-size (filename)
   (ediff-file-attributes filename 7))
@@ -1741,6 +1786,24 @@ Checks if overlay's buffer exists."
     fname))
 
 
+(if (fboundp 'with-syntax-table)
+    (fset 'ediff-with-syntax-table 'with-syntax-table)
+  ;; stolen from subr.el in emacs 21
+  (defmacro ediff-with-syntax-table (table &rest body)
+    (let ((old-table (make-symbol "table"))
+         (old-buffer (make-symbol "buffer")))
+      `(let ((,old-table (syntax-table))
+            (,old-buffer (current-buffer)))
+        (unwind-protect
+            (progn
+              (set-syntax-table (copy-syntax-table ,table))
+              ,@body)
+          (save-current-buffer
+            (set-buffer ,old-buffer)
+            (set-syntax-table ,old-table)))))))
+
+
+
 ;;; Local Variables:
 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
@@ -1749,5 +1812,4 @@ Checks if overlay's buffer exists."
 
 (provide 'ediff-init)
 
-
-;;; ediff-init.el  ends here
+;;; ediff-init.el ends here