]> code.delx.au - gnu-emacs/blobdiff - lisp/ediff-merg.el
(coding-system-list): Moved to mule.el.
[gnu-emacs] / lisp / ediff-merg.el
index 3280861efdf263b330d0c7cde718e39d2e1f21f7..188d67ebcaf77eb73818e6fa4fa06d4757c43a8a 100644 (file)
@@ -1,5 +1,6 @@
 ;;; ediff-merg.el --- merging utilities
-;;; 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:
+
+(provide 'ediff-merg)
 
+;; compiler pacifier
+(defvar ediff-window-A)
+(defvar ediff-window-B)
+(defvar ediff-window-C)
+(defvar ediff-merge-window-share)
+(defvar ediff-window-config-saved)
+
+(eval-when-compile
+  (let ((load-path (cons (expand-file-name ".") load-path)))
+    (or (featurep 'ediff-init)
+       (load "ediff-init.el" nil nil 'nosuffix))
+    (or (featurep 'ediff-util)
+       (load "ediff-util.el" nil nil 'nosuffix))
+    ))
+;; end pacifier
 
 (require 'ediff-init)
 
-(defvar ediff-default-variant 'default-A
+(defcustom ediff-quit-merge-hook 'ediff-maybe-save-and-delete-merge
+  "*Hooks to run before quitting a merge job.
+The most common use is to save and delete the merge buffer."
+  :type 'hook
+  :group 'ediff-merge)
+
+
+(defcustom ediff-default-variant 'combined
   "*The variant to be used as a default for buffer C in merging.
-Valid values are the symbols `default-A', `default-B', and `combined'.")
+Valid values are the symbols `default-A', `default-B', and `combined'."
+  :type '(radio (const default-A) (const default-B) (const combined))
+  :group 'ediff-merge)
 
-(defvar ediff-combination-pattern 
-  '("#ifdef NEW /* variant A */" "#else /* variant B */" "#endif /* NEW */")
+(defcustom ediff-combination-pattern 
+  '("<<<<<<<<<<<<<< variant A" ">>>>>>>>>>>>>> variant B" "======= end of combination")
   "*Pattern to be used for combining difference regions in buffers A and B.
 The value is (STRING1 STRING2 STRING3). The combined text will look like this:
 
@@ -36,13 +66,21 @@ diff region from variant A
 STRING2
 diff region from variant B
 STRING3
-")
+"
+  :type '(list string string string)
+  :group 'ediff-merge)
 
 (ediff-defvar-local ediff-show-clashes-only  nil
   "*If t, show only those diff regions where both buffers disagree with the ancestor.
 This means that regions that have status prefer-A or prefer-B will be
 skiped over. Nil means show all regions.")
 
+;; If ediff-show-clashes-only, check if there is no clash between the ancestor
+;; and one of the variants.
+(defsubst ediff-merge-region-is-non-clash (n)
+  (and ediff-show-clashes-only
+       (string-match "prefer" (or (ediff-get-state-of-merge n) ""))))
+
        
 (defsubst ediff-get-combined-region (n)
   (concat (nth 0 ediff-combination-pattern) "\n"
@@ -50,7 +88,14 @@ skiped over. Nil means show all regions.")
          (nth 1 ediff-combination-pattern) "\n"
          (ediff-get-region-contents n 'B ediff-control-buffer)
          (nth 2 ediff-combination-pattern) "\n"))
-    
+
+(defsubst ediff-make-combined-diff (regA regB)
+  (concat (nth 0 ediff-combination-pattern) "\n"
+         regA
+         (nth 1 ediff-combination-pattern) "\n"
+         regB
+         (nth 2 ediff-combination-pattern) "\n"))
+
 (defsubst ediff-set-state-of-all-diffs-in-all-buffers (ctl-buf)
   (let ((n 0))
     (while (< n ediff-number-of-differences)
@@ -87,7 +132,6 @@ skiped over. Nil means show all regions.")
     ))
     
 (defun ediff-set-merge-mode ()
-  ;; by Stig@hackvan.com
   (normal-mode t)
   (remove-hook 'local-write-file-hooks 'ediff-set-merge-mode))
 
@@ -104,9 +148,10 @@ skiped over. Nil means show all regions.")
 (defun ediff-do-merge (diff-num &optional remerging)
   (if (< diff-num 0) (setq diff-num 0))
   (let ((n diff-num)
-       (default-state-of-merge (format "%S" ediff-default-variant))
+       ;;(default-state-of-merge (format "%S" ediff-default-variant))
        do-not-copy state-of-merge)
     (while (< n ediff-number-of-differences)
+      (setq do-not-copy nil) ; reset after each cycle
       (if (= (mod n 10) 0)
          (message "%s buffers A & B into C ... region %d of %d"
                   (if remerging "Re-merging" "Merging")
@@ -120,9 +165,9 @@ skiped over. Nil means show all regions.")
                (reg-B (ediff-get-region-contents n 'B ediff-control-buffer))
                (reg-C (ediff-get-region-contents n 'C ediff-control-buffer)))
                
-                   ;;; was edited since first set by default
+           ;; if region was edited since it was first set by default
            (if (or (and (string= state-of-merge "default-A")
-                     (not (string= reg-A reg-C)))
+                        (not (string= reg-A reg-C)))
                    ;; was edited since first set by default
                    (and (string= state-of-merge "default-B")
                         (not (string= reg-B reg-C)))
@@ -130,7 +175,7 @@ skiped over. Nil means show all regions.")
                    (and (string= state-of-merge "combined")
                         (not (string=
                               (ediff-make-combined-diff reg-A reg-B) reg-C)))
-                   ;; was prefered--ignore
+                   ;; was preferred--ignore
                    (string-match "prefer" state-of-merge))
                (setq do-not-copy t))
                
@@ -203,9 +248,11 @@ Used only for merging jobs."
 ;; N here is the user's region number. It is 1+ what Ediff uses internally.
 (defun ediff-combine-diffs (n &optional batch-invocation)
   "Combine Nth diff regions of buffers A and B and place the combination in C.
-Combining is done using the list in variable `ediff-combination-pattern'."
+N is a prefix argument. If nil, combine the current difference regions.
+Combining is done according to the specifications in variable
+`ediff-combination-pattern'."
   (interactive "P")
-  (setq n (if n (1- n) ediff-current-difference))
+  (setq n (if (numberp n) (1- n) ediff-current-difference))
   
   (let (regA regB reg-combined)
     (setq regA (ediff-get-region-contents n 'A ediff-control-buffer)
@@ -214,15 +261,8 @@ Combining is done using the list in variable `ediff-combination-pattern'."
     (setq reg-combined (ediff-make-combined-diff regA regB))
     
     (ediff-copy-diff n nil 'C batch-invocation reg-combined))
-    (or batch-invocation (ediff-recenter)))
+    (or batch-invocation (ediff-jump-to-difference (1+ n))))
     
-(defsubst ediff-make-combined-diff (regA regB)
-  (concat (nth 0 ediff-combination-pattern) "\n"
-         regA
-         (nth 1 ediff-combination-pattern) "\n"
-         regB
-         (nth 2 ediff-combination-pattern) "\n"))
-
 
 ;; Checks if the region in buff C looks like a combination of the regions
 ;; in buffers A and B. Returns a list (reg-a-beg reg-a-end reg-b-beg reg-b-end)
@@ -240,7 +280,7 @@ Combining is done using the list in variable `ediff-combination-pattern'."
            reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end)
        
        (if combined
-           (ediff-eval-in-buffer ediff-buffer-C
+           (ediff-with-current-buffer ediff-buffer-C
              (goto-char reg-beg)
              (search-forward pat1 reg-end 'noerror)
              (setq reg-a-beg (match-beginning 0))
@@ -257,6 +297,10 @@ Combining is done using the list in variable `ediff-combination-pattern'."
        )))
   
 
-(provide 'ediff-merg)
+;;; 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:
 
 ;; ediff-merg.el ends here