changeset 78572:5b92bb6e6570

(smerge-resolve): New arg `safe'. (smerge-resolve-all, smerge-batch-resolve): New function. (smerge-refine): Make sure `diff' returns the expected result. (smerge-parsep-re): New const. (smerge-mode): Use it to adjust paragraph-separate.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 16 Aug 2007 20:04:36 +0000
parents fd7a34f481ad
children 2fc1b1c43abd
files lisp/ChangeLog lisp/smerge-mode.el
diffstat 2 files changed, 52 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Aug 16 14:20:37 2007 +0000
+++ b/lisp/ChangeLog	Thu Aug 16 20:04:36 2007 +0000
@@ -1,5 +1,11 @@
 2007-08-16  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* smerge-mode.el (smerge-resolve): New arg `safe'.
+	(smerge-resolve-all, smerge-batch-resolve): New function.
+	(smerge-refine): Make sure `diff' returns the expected result.
+	(smerge-parsep-re): New const.
+	(smerge-mode): Use it to adjust paragraph-separate.
+
 	* progmodes/perl-mode.el (perl-font-lock-syntactic-keywords):
 	Correctly match / regexp matchers as first char on a line when
 	fontifying only that line.
--- a/lisp/smerge-mode.el	Thu Aug 16 14:20:37 2007 +0000
+++ b/lisp/smerge-mode.el	Thu Aug 16 20:04:36 2007 +0000
@@ -324,7 +324,8 @@
 (defvar smerge-resolve-function
   (lambda () (error "Don't know how to resolve"))
   "Mode-specific merge function.
-The function is called with no argument and with the match data set
+The function is called with zero or one argument (non-nil if the resolution
+function should only apply safe heuristics) and with the match data set
 according to `smerge-match-conflict'.")
 (add-to-list 'debug-ignored-errors "Don't know how to resolve")
 
@@ -378,7 +379,7 @@
 	(smerge-remove-props (or beg (point-min)) (or end (point-max)))
 	(push event unread-command-events)))))
 
-(defun smerge-resolve ()
+(defun smerge-resolve (&optional safe)
   "Resolve the conflict at point intelligently.
 This relies on mode-specific knowledge and thus only works in
 some major modes.  Uses `smerge-resolve-function' to do the actual work."
@@ -393,8 +394,10 @@
    ;; Mode-specific conflict resolution.
    ((condition-case nil
         (atomic-change-group
-         (funcall smerge-resolve-function)
-         t)
+          (if safe
+              (funcall smerge-resolve-function safe)
+            (funcall smerge-resolve-function))
+          t)
       (error nil))
     ;; Nothing to do: the resolution function has done it already.
     nil)
@@ -412,6 +415,31 @@
     (error "Don't know how to resolve")))
   (smerge-auto-leave))
 
+(defun smerge-resolve-all ()
+  "Perform automatic resolution on all conflicts."
+  (interactive)
+  (save-excursion
+    (goto-char (point-min))
+    (while (re-search-forward smerge-begin-re nil t)
+      (condition-case nil
+          (progn
+            (smerge-match-conflict)
+            (smerge-resolve 'safe))
+        (error nil)))))
+
+(defun smerge-batch-resolve ()
+  ;; command-line-args-left is what is left of the command line.
+  (if (not noninteractive)
+      (error "`smerge-batch-resolve' is to be used only with -batch"))
+  (while command-line-args-left
+    (let ((file (pop command-line-args-left)))
+      (message "Resolving conflicts in %s..." file)
+      (when (file-readable-p file)
+        (with-current-buffer (find-file-noselect file)
+          (smerge-resolve-all)
+          (save-buffer)
+          (kill-buffer (current-buffer)))))))
+
 (defun smerge-keep-base ()
   "Revert to the base version."
   (interactive)
@@ -677,7 +705,9 @@
     (unwind-protect
         (with-temp-buffer
           (let ((coding-system-for-read 'emacs-mule))
-            (call-process diff-command nil t nil file1 file2))
+            ;; Don't forget -a to make sure diff treats it as a text file
+            ;; even if it contains \0 and such.
+            (call-process diff-command nil t nil "-a" file1 file2))
           ;; Process diff's output.
           (goto-char (point-min))
           (while (not (eobp))
@@ -831,6 +861,10 @@
     (message "Please resolve conflicts now; exit ediff when done")))
 
 
+(defconst smerge-parsep-re
+  (concat smerge-begin-re "\\|" smerge-end-re "\\|"
+          smerge-base-re "\\|" smerge-other-re "\\|"))
+
 ;;;###autoload
 (define-minor-mode smerge-mode
   "Minor mode to simplify editing output from the diff3 program.
@@ -845,6 +879,13 @@
       (while (smerge-find-conflict)
 	(save-excursion
 	  (font-lock-fontify-region (match-beginning 0) (match-end 0) nil)))))
+  (if (string-match (regexp-quote smerge-parsep-re) paragraph-separate)
+      (unless smerge-mode
+        (set (make-local-variable 'paragraph-separate)
+             (replace-match "" t t paragraph-separate)))
+    (when smerge-mode
+        (set (make-local-variable 'paragraph-separate)
+             (concat smerge-parsep-re paragraph-separate))))
   (unless smerge-mode
     (smerge-remove-props (point-min) (point-max))))