]> code.delx.au - gnu-emacs/blobdiff - lisp/ediff-util.el
(byte-compile-dynamic)
[gnu-emacs] / lisp / ediff-util.el
index b7b39f405e5302dce567d38b1aedb109b478f28b..dff3c6bee6161e3c82cf00b3d7306b8ad1bdbcbf 100644 (file)
@@ -1,7 +1,7 @@
 ;;; ediff-util.el --- the core commands and utilities of ediff
 
 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-;;   2004 Free Software Foundation, Inc.
+;;   2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
 
 
 ;; 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.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;;; Code:
 
-(provide 'ediff-util)
 
 ;; Compiler pacifier
 (defvar ediff-patch-diagnostics)
@@ -49,6 +48,7 @@
 
 (eval-when-compile
   (let ((load-path (cons (expand-file-name ".") load-path)))
+    (provide 'ediff-util) ; to break recursive load cycle
     (or (featurep 'ediff-init)
        (load "ediff-init.el" nil nil 'nosuffix))
     (or (featurep 'ediff-help)
@@ -117,7 +117,13 @@ Commands:
   (kill-all-local-variables)
   (setq major-mode 'ediff-mode)
   (setq mode-name "Ediff")
-  (run-mode-hooks 'ediff-mode-hook))
+  ;; We use run-hooks instead of run-mode-hooks for two reasons.
+  ;; The ediff control buffer is read-only and it is not supposed to be
+  ;; modified by minor modes and such. So, run-mode-hooks doesn't do anything
+  ;; useful here on top of what run-hooks does.
+  ;; Second, changing run-hooks to run-mode-hooks would require an
+  ;; if-statement, since XEmacs doesn't have this. 
+  (run-hooks 'ediff-mode-hook))
 
 
 \f
@@ -228,6 +234,7 @@ to invocation.")
   (define-key ediff-mode-map "#"  nil)
   (define-key ediff-mode-map "#h"  'ediff-toggle-regexp-match)
   (define-key ediff-mode-map "#f"  'ediff-toggle-regexp-match)
+  (define-key ediff-mode-map "#c"  'ediff-toggle-ignore-case)
   (or ediff-word-mode
       (define-key ediff-mode-map "##"  'ediff-toggle-skip-similar))
   (define-key ediff-mode-map "o"   nil)
@@ -323,7 +330,7 @@ to invocation.")
            ediff-word-mode-job (ediff-word-mode-job))
 
       ;; Don't delete variants in case of ediff-buffer-* jobs without asking.
-      ;; This is because u may loose work---dangerous.
+      ;; This is because one may loose work---dangerous.
       (if (string-match "buffer" (symbol-name ediff-job-name))
          (setq ediff-keep-variants t))
 
@@ -361,7 +368,8 @@ to invocation.")
                   (ediff-unique-buffer-name "*ediff-merge" "*")))
            (save-excursion
              (set-buffer buffer-C)
-             (insert-buffer buf)
+             (insert-buffer-substring buf)
+             (goto-char (point-min))
              (funcall (ediff-with-current-buffer buf major-mode))
              (widen) ; merge buffer is always widened
              (add-hook 'local-write-file-hooks 'ediff-set-merge-mode nil t)
@@ -1126,7 +1134,7 @@ of the current buffer."
 ;;       ))
 
 
-(defsubst ediff-file-checked-out-p (file)
+(defun ediff-file-checked-out-p (file)
   (or (not (featurep 'vc-hooks))
       (and (vc-backend file)
           (if (fboundp 'vc-state)
@@ -1136,7 +1144,7 @@ of the current buffer."
             (vc-locking-user file))
           )))
 
-(defsubst ediff-file-checked-in-p (file)
+(defun ediff-file-checked-in-p (file)
   (and (featurep 'vc-hooks)
        ;; CVS files are considered not checked in
        (not (memq (vc-backend file) '(nil CVS)))
@@ -1723,7 +1731,7 @@ With a prefix argument, go forward that many differences."
        (or (>= n ediff-number-of-differences)
            (setq regexp-skip (funcall ediff-skip-diff-region-function n))
            ;; this won't exec if regexp-skip is t
-           (setq non-clash-skip (ediff-merge-region-is-non-clash n)
+           (setq non-clash-skip (ediff-merge-region-is-non-clash-to-skip n)
                  skip-changed
                  (ediff-skip-merge-region-if-changed-from-default-p n))
            (ediff-install-fine-diff-if-necessary n))
@@ -1738,6 +1746,7 @@ With a prefix argument, go forward that many differences."
                     skip-changed
                     ;; skip difference regions that differ in white space
                     (and ediff-ignore-similar-regions
+                         (ediff-merge-region-is-non-clash n)
                          (or (eq (ediff-no-fine-diffs-p n) t)
                              (and (ediff-merge-job)
                                   (eq (ediff-no-fine-diffs-p n) 'C)))
@@ -1748,7 +1757,7 @@ With a prefix argument, go forward that many differences."
          (or (>= n ediff-number-of-differences)
              (setq regexp-skip (funcall ediff-skip-diff-region-function n))
              ;; this won't exec if regexp-skip is t
-             (setq non-clash-skip (ediff-merge-region-is-non-clash n)
+             (setq non-clash-skip (ediff-merge-region-is-non-clash-to-skip n)
                    skip-changed
                    (ediff-skip-merge-region-if-changed-from-default-p n))
              (ediff-install-fine-diff-if-necessary n))
@@ -1772,7 +1781,7 @@ With a prefix argument, go back that many differences."
        (or (< n 0)
            (setq regexp-skip (funcall ediff-skip-diff-region-function n))
            ;; this won't exec if regexp-skip is t
-           (setq non-clash-skip (ediff-merge-region-is-non-clash n)
+           (setq non-clash-skip (ediff-merge-region-is-non-clash-to-skip n)
                  skip-changed
                  (ediff-skip-merge-region-if-changed-from-default-p n))
            (ediff-install-fine-diff-if-necessary n))
@@ -1786,6 +1795,7 @@ With a prefix argument, go back that many differences."
                     skip-changed
                     ;; skip difference regions that differ in white space
                     (and ediff-ignore-similar-regions
+                         (ediff-merge-region-is-non-clash n)
                          (or (eq (ediff-no-fine-diffs-p n) t)
                              (and (ediff-merge-job)
                                   (eq (ediff-no-fine-diffs-p n) 'C)))
@@ -1796,7 +1806,7 @@ With a prefix argument, go back that many differences."
          (or (< n 0)
              (setq regexp-skip (funcall ediff-skip-diff-region-function n))
              ;; this won't exec if regexp-skip is t
-             (setq non-clash-skip (ediff-merge-region-is-non-clash n)
+             (setq non-clash-skip (ediff-merge-region-is-non-clash-to-skip n)
                    skip-changed
                    (ediff-skip-merge-region-if-changed-from-default-p n))
              (ediff-install-fine-diff-if-necessary n))
@@ -2069,7 +2079,7 @@ ARG is a prefix argument.  If nil, copy the current difference region."
          (ediff-clear-fine-differences n))
       ;; Make sure that the message about saving and how to restore is seen
       ;; by the user
-      (message messg))
+      (message "%s" messg))
     ))
 
 ;; Save Nth diff of buffer BUF-TYPE \(A, B, or C\).
@@ -2105,7 +2115,7 @@ ARG is a prefix argument.  If nil, copy the current difference region."
     (if this-buf-n-th-diff-saved
        (if (yes-or-no-p
             (format
-             "You've previously copied diff region %d to buffer %S.  Confirm "
+             "You've previously copied diff region %d to buffer %S.  Confirm? "
              (1+ n) buf-type))
            t
          (error "Quit"))
@@ -2213,18 +2223,18 @@ a regular expression typed in by the user."
            regexp-A
            (read-string
             (format
-             "Ignore A-regions matching this regexp (default \"%s\"): "
+             "Ignore A-regions matching this regexp (default %s): "
              ediff-regexp-hide-A))
            regexp-B
            (read-string
             (format
-             "Ignore B-regions matching this regexp (default \"%s\"): "
+             "Ignore B-regions matching this regexp (default %s): "
              ediff-regexp-hide-B)))
       (if ediff-3way-comparison-job
          (setq regexp-C
                (read-string
                 (format
-                 "Ignore C-regions matching this regexp (default \"%s\"): "
+                 "Ignore C-regions matching this regexp (default %s): "
                  ediff-regexp-hide-C))))
       (if (eq ediff-hide-regexp-connective 'and)
          (setq msg-connective "BOTH"
@@ -2252,18 +2262,18 @@ a regular expression typed in by the user."
            regexp-A
            (read-string
             (format
-             "Focus on A-regions matching this regexp (default \"%s\"): "
+             "Focus on A-regions matching this regexp (default %s): "
              ediff-regexp-focus-A))
            regexp-B
            (read-string
             (format
-             "Focus on B-regions matching this regexp (default \"%s\"): "
+             "Focus on B-regions matching this regexp (default %s): "
              ediff-regexp-focus-B)))
       (if ediff-3way-comparison-job
          (setq regexp-C
                (read-string
                 (format
-                 "Focus on C-regions matching this regexp (default \"%s\"): "
+                 "Focus on C-regions matching this regexp (default %s): "
                  ediff-regexp-focus-C))))
       (if (eq ediff-focus-regexp-connective 'and)
          (setq msg-connective "BOTH"
@@ -2714,7 +2724,7 @@ only if this merge job is part of a group, i.e., was invoked from within
             (format "Another buffer is visiting file %s. Too dangerous to save the merge buffer"
                     file)))
        (beep)
-       (message warn-message)
+       (message "%s" warn-message)
        (with-output-to-temp-buffer ediff-msg-buffer
          (princ "\n\n")
          (princ warn-message)
@@ -3070,7 +3080,7 @@ Hit \\[ediff-recenter] to reset the windows afterward."
        )))
 
 
-(defsubst ediff-highlight-diff (n)
+(defun ediff-highlight-diff (n)
   "Put face on diff N.  Invoked for X displays only."
   (ediff-highlight-diff-in-one-buffer n 'A)
   (ediff-highlight-diff-in-one-buffer n 'B)
@@ -3079,7 +3089,7 @@ Hit \\[ediff-recenter] to reset the windows afterward."
   )
 
 
-(defsubst ediff-unhighlight-diff ()
+(defun ediff-unhighlight-diff ()
   "Remove overlays from buffers A, B, and C."
   (ediff-unhighlight-diff-in-one-buffer 'A)
   (ediff-unhighlight-diff-in-one-buffer 'B)
@@ -3088,7 +3098,7 @@ Hit \\[ediff-recenter] to reset the windows afterward."
   )
 
 ;; delete highlighting overlays, restore faces to their original form
-(defsubst ediff-unhighlight-diffs-totally ()
+(defun ediff-unhighlight-diffs-totally ()
   (ediff-unhighlight-diffs-totally-in-one-buffer 'A)
   (ediff-unhighlight-diffs-totally-in-one-buffer 'B)
   (ediff-unhighlight-diffs-totally-in-one-buffer 'C)
@@ -3164,7 +3174,7 @@ Hit \\[ediff-recenter] to reset the windows afterward."
     (setq f (concat ediff-temp-file-prefix p)
          short-f (concat ediff-temp-file-prefix short-p)
          f (cond (given-file)
-                 ((find-file-name-handler f 'find-file-noselect)
+                 ((find-file-name-handler f 'insert-file-contents)
                   ;; to thwart file handlers in write-region, e.g., if file
                   ;; name ends with .Z or .gz
                   ;; This is needed so that patches produced by ediff will
@@ -3280,7 +3290,7 @@ Hit \\[ediff-recenter] to reset the windows afterward."
            (princ warn-message)
            (princ "\n\n"))
          (if (y-or-n-p
-              (message warn-message))
+              (message "%s" warn-message))
              (with-current-buffer buff
                (save-buffer)
                (kill-buffer (current-buffer)))
@@ -3677,7 +3687,7 @@ Ediff Control Panel to restore highlighting."
            (>= (point) end))))))
 
 
-(defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
+(defun ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
   (ediff-with-current-buffer
       (ediff-with-current-buffer ctrl-buf (ediff-get-buffer buf-type))
     (buffer-substring
@@ -3788,9 +3798,8 @@ Ediff Control Panel to restore highlighting."
                      type ediff-current-diff-overlay-alist))
            (buffer (ediff-get-buffer type))
            (face (face-name
-                  (symbol-value
-                   (ediff-get-symbol-from-alist
-                    type ediff-current-diff-face-alist)))))
+                  (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)
@@ -3937,6 +3946,7 @@ Ediff Control Panel to restore highlighting."
        (ediff-device-type (ediff-device-type))
        varlist salutation buffer-name)
     (setq varlist '(ediff-diff-program ediff-diff-options
+                    ediff-diff3-program ediff-diff3-options
                    ediff-patch-program ediff-patch-options
                    ediff-shell
                    ediff-use-faces
@@ -4292,6 +4302,8 @@ Mail anyway? (y or n) ")
 
 (run-hooks 'ediff-load-hook)
 
+(provide 'ediff-util)
+
 
 ;;; Local Variables:
 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)