;;; 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:
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"
))
(defun ediff-set-merge-mode ()
- ;; by Stig@hackvan.com
(normal-mode t)
(remove-hook 'local-write-file-hooks 'ediff-set-merge-mode))
(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")
(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)))
;; 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)
(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))))
;; Checks if the region in buff C looks like a combination of the regions
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))
)))
-(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