]> code.delx.au - gnu-emacs/blob - lisp/smerge-mode.el
(replace-regexp-in-string): Doc fix.
[gnu-emacs] / lisp / smerge-mode.el
1 ;;; smerge-mode.el --- Minor mode to resolve diff3 conflicts
2
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005 Free Software Foundation, Inc.
5
6 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
7 ;; Keywords: revision-control merge diff3 cvs conflict
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; Provides a lightweight alternative to emerge/ediff.
29 ;; To use it, simply add to your .emacs the following lines:
30 ;;
31 ;; (autoload 'smerge-mode "smerge-mode" nil t)
32 ;;
33 ;; you can even have it turned on automatically with the following
34 ;; piece of code in your .emacs:
35 ;;
36 ;; (defun sm-try-smerge ()
37 ;; (save-excursion
38 ;; (goto-char (point-min))
39 ;; (when (re-search-forward "^<<<<<<< " nil t)
40 ;; (smerge-mode 1))))
41 ;; (add-hook 'find-file-hook 'sm-try-smerge t)
42
43 ;;; Todo:
44
45 ;; - if requested, ask the user whether he wants to call ediff right away
46
47 ;;; Code:
48
49 (eval-when-compile (require 'cl))
50
51
52 ;;; The real definition comes later.
53 (defvar smerge-mode)
54
55 (defgroup smerge ()
56 "Minor mode to resolve diff3 conflicts."
57 :group 'tools
58 :prefix "smerge-")
59
60 (defcustom smerge-diff-buffer-name "*vc-diff*"
61 "Buffer name to use for displaying diffs."
62 :group 'smerge
63 :type '(choice
64 (const "*vc-diff*")
65 (const "*cvs-diff*")
66 (const "*smerge-diff*")
67 string))
68
69 (defcustom smerge-diff-switches
70 (append '("-d" "-b")
71 (if (listp diff-switches) diff-switches (list diff-switches)))
72 "*A list of strings specifying switches to be passed to diff.
73 Used in `smerge-diff-base-mine' and related functions."
74 :group 'smerge
75 :type '(repeat string))
76
77 (defcustom smerge-auto-leave t
78 "*Non-nil means to leave `smerge-mode' when the last conflict is resolved."
79 :group 'smerge
80 :type 'boolean)
81
82 (defface smerge-mine
83 '((((min-colors 88) (background light))
84 (:foreground "blue1"))
85 (((background light))
86 (:foreground "blue"))
87 (((min-colors 88) (background dark))
88 (:foreground "cyan1"))
89 (((background dark))
90 (:foreground "cyan")))
91 "Face for your code."
92 :group 'smerge)
93 ;; backward-compatibility alias
94 (put 'smerge-mine-face 'face-alias 'smerge-mine)
95 (defvar smerge-mine-face 'smerge-mine)
96
97 (defface smerge-other
98 '((((background light))
99 (:foreground "darkgreen"))
100 (((background dark))
101 (:foreground "lightgreen")))
102 "Face for the other code."
103 :group 'smerge)
104 ;; backward-compatibility alias
105 (put 'smerge-other-face 'face-alias 'smerge-other)
106 (defvar smerge-other-face 'smerge-other)
107
108 (defface smerge-base
109 '((((min-colors 88) (background light))
110 (:foreground "red1"))
111 (((background light))
112 (:foreground "red"))
113 (((background dark))
114 (:foreground "orange")))
115 "Face for the base code."
116 :group 'smerge)
117 ;; backward-compatibility alias
118 (put 'smerge-base-face 'face-alias 'smerge-base)
119 (defvar smerge-base-face 'smerge-base)
120
121 (defface smerge-markers
122 '((((background light))
123 (:background "grey85"))
124 (((background dark))
125 (:background "grey30")))
126 "Face for the conflict markers."
127 :group 'smerge)
128 ;; backward-compatibility alias
129 (put 'smerge-markers-face 'face-alias 'smerge-markers)
130 (defvar smerge-markers-face 'smerge-markers)
131
132 (easy-mmode-defmap smerge-basic-map
133 `(("n" . smerge-next)
134 ("p" . smerge-prev)
135 ("r" . smerge-resolve)
136 ("a" . smerge-keep-all)
137 ("b" . smerge-keep-base)
138 ("o" . smerge-keep-other)
139 ("m" . smerge-keep-mine)
140 ("E" . smerge-ediff)
141 ("\C-m" . smerge-keep-current)
142 ("=" . ,(make-sparse-keymap "Diff"))
143 ("=<" "base-mine" . smerge-diff-base-mine)
144 ("=>" "base-other" . smerge-diff-base-other)
145 ("==" "mine-other" . smerge-diff-mine-other))
146 "The base keymap for `smerge-mode'.")
147
148 (defcustom smerge-command-prefix "\C-c^"
149 "Prefix for `smerge-mode' commands."
150 :group 'smerge
151 :type '(choice (string "\e") (string "\C-c^") (string "") string))
152
153 (easy-mmode-defmap smerge-mode-map
154 `((,smerge-command-prefix . ,smerge-basic-map))
155 "Keymap for `smerge-mode'.")
156
157 (defvar smerge-check-cache nil)
158 (make-variable-buffer-local 'smerge-check-cache)
159 (defun smerge-check (n)
160 (condition-case nil
161 (let ((state (cons (point) (buffer-modified-tick))))
162 (unless (equal (cdr smerge-check-cache) state)
163 (smerge-match-conflict)
164 (setq smerge-check-cache (cons (match-data) state)))
165 (nth (* 2 n) (car smerge-check-cache)))
166 (error nil)))
167
168 (easy-menu-define smerge-mode-menu smerge-mode-map
169 "Menu for `smerge-mode'."
170 '("SMerge"
171 ["Next" smerge-next :help "Go to next conflict"]
172 ["Previous" smerge-prev :help "Go to previous conflict"]
173 "--"
174 ["Keep All" smerge-keep-all :help "Keep all three versions"
175 :active (smerge-check 1)]
176 ["Keep Current" smerge-keep-current :help "Use current (at point) version"
177 :active (and (smerge-check 1) (> (smerge-get-current) 0))]
178 "--"
179 ["Revert to Base" smerge-keep-base :help "Revert to base version"
180 :active (smerge-check 2)]
181 ["Keep Other" smerge-keep-other :help "Keep `other' version"
182 :active (smerge-check 3)]
183 ["Keep Yours" smerge-keep-mine :help "Keep your version"
184 :active (smerge-check 1)]
185 "--"
186 ["Diff Base/Mine" smerge-diff-base-mine
187 :help "Diff `base' and `mine' for current conflict"
188 :active (smerge-check 2)]
189 ["Diff Base/Other" smerge-diff-base-other
190 :help "Diff `base' and `other' for current conflict"
191 :active (smerge-check 2)]
192 ["Diff Mine/Other" smerge-diff-mine-other
193 :help "Diff `mine' and `other' for current conflict"
194 :active (smerge-check 1)]
195 "--"
196 ["Invoke Ediff" smerge-ediff
197 :help "Use Ediff to resolve the conflicts"
198 :active (smerge-check 1)]
199 ["Auto Resolve" smerge-resolve
200 :help "Try auto-resolution heuristics"
201 :active (smerge-check 1)]
202 ["Combine" smerge-combine-with-next
203 :help "Combine current conflict with next"
204 :active (smerge-check 1)]
205 ))
206
207 (easy-menu-define smerge-context-menu nil
208 "Context menu for mine area in `smerge-mode'."
209 '(nil
210 ["Keep Current" smerge-keep-current :help "Use current (at point) version"]
211 ["Kill Current" smerge-kill-current :help "Remove current (at point) version"]
212 ["Keep All" smerge-keep-all :help "Keep all three versions"]
213 "---"
214 ["More..." (popup-menu smerge-mode-menu) :help "Show full SMerge mode menu"]
215 ))
216
217 (defconst smerge-font-lock-keywords
218 '((smerge-find-conflict
219 (1 smerge-mine-face prepend t)
220 (2 smerge-base-face prepend t)
221 (3 smerge-other-face prepend t)
222 ;; FIXME: `keep' doesn't work right with syntactic fontification.
223 (0 smerge-markers-face keep)
224 (4 nil t t)
225 (5 nil t t)))
226 "Font lock patterns for `smerge-mode'.")
227
228 (defconst smerge-begin-re "^<<<<<<< \\(.*\\)\n")
229 (defconst smerge-end-re "^>>>>>>> .*\n")
230 (defconst smerge-base-re "^||||||| .*\n")
231 (defconst smerge-other-re "^=======\n")
232
233 (defvar smerge-conflict-style nil
234 "Keep track of which style of conflict is in use.
235 Can be nil if the style is undecided, or else:
236 - `diff3-E'
237 - `diff3-A'")
238
239 ;; Compiler pacifiers
240 (defvar font-lock-mode)
241 (defvar font-lock-keywords)
242
243 ;;;;
244 ;;;; Actual code
245 ;;;;
246
247 ;; Define smerge-next and smerge-prev
248 (easy-mmode-define-navigation smerge smerge-begin-re "conflict")
249
250 (defconst smerge-match-names ["conflict" "mine" "base" "other"])
251
252 (defun smerge-ensure-match (n)
253 (unless (match-end n)
254 (error "No `%s'" (aref smerge-match-names n))))
255
256 (defun smerge-auto-leave ()
257 (when (and smerge-auto-leave
258 (save-excursion (goto-char (point-min))
259 (not (re-search-forward smerge-begin-re nil t))))
260 (smerge-mode -1)))
261
262
263 (defun smerge-keep-all ()
264 "Concatenate all versions."
265 (interactive)
266 (smerge-match-conflict)
267 (let ((mb2 (or (match-beginning 2) (point-max)))
268 (me2 (or (match-end 2) (point-min))))
269 (delete-region (match-end 3) (match-end 0))
270 (delete-region (max me2 (match-end 1)) (match-beginning 3))
271 (if (and (match-end 2) (/= (match-end 1) (match-end 3)))
272 (delete-region (match-end 1) (match-beginning 2)))
273 (delete-region (match-beginning 0) (min (match-beginning 1) mb2))
274 (smerge-auto-leave)))
275
276 (defun smerge-keep-n (n)
277 ;; We used to use replace-match, but that did not preserve markers so well.
278 (delete-region (match-end n) (match-end 0))
279 (delete-region (match-beginning 0) (match-beginning n)))
280
281 (defun smerge-combine-with-next ()
282 "Combine the current conflict with the next one."
283 (interactive)
284 (smerge-match-conflict)
285 (let ((ends nil))
286 (dolist (i '(3 2 1 0))
287 (push (if (match-end i) (copy-marker (match-end i) t)) ends))
288 (setq ends (apply 'vector ends))
289 (goto-char (aref ends 0))
290 (if (not (re-search-forward smerge-begin-re nil t))
291 (error "No next conflict")
292 (smerge-match-conflict)
293 (let ((match-data (mapcar (lambda (m) (if m (copy-marker m)))
294 (match-data))))
295 ;; First copy the in-between text in each alternative.
296 (dolist (i '(1 2 3))
297 (when (aref ends i)
298 (goto-char (aref ends i))
299 (insert-buffer-substring (current-buffer)
300 (aref ends 0) (car match-data))))
301 (delete-region (aref ends 0) (car match-data))
302 ;; Then move the second conflict's alternatives into the first.
303 (dolist (i '(1 2 3))
304 (set-match-data match-data)
305 (when (and (aref ends i) (match-end i))
306 (goto-char (aref ends i))
307 (insert-buffer-substring (current-buffer)
308 (match-beginning i) (match-end i))))
309 (delete-region (car match-data) (cadr match-data))
310 ;; Free the markers.
311 (dolist (m match-data) (if m (move-marker m nil)))
312 (mapc (lambda (m) (if m (move-marker m nil))) ends)))))
313
314 (defvar smerge-resolve-function
315 (lambda () (error "Don't know how to resolve"))
316 "Mode-specific merge function.
317 The function is called with no argument and with the match data set
318 according to `smerge-match-conflict'.")
319
320 (defvar smerge-text-properties
321 `(help-echo "merge conflict: mouse-3 shows a menu"
322 ;; mouse-face highlight
323 keymap (keymap (down-mouse-3 . smerge-popup-context-menu))))
324
325 (defun smerge-remove-props (&optional beg end)
326 (remove-text-properties
327 (or beg (match-beginning 0))
328 (or end (match-end 0))
329 smerge-text-properties))
330
331 (defun smerge-popup-context-menu (event)
332 "Pop up the Smerge mode context menu under mouse."
333 (interactive "e")
334 (if (and smerge-mode
335 (save-excursion (posn-set-point (event-end event)) (smerge-check 1)))
336 (progn
337 (posn-set-point (event-end event))
338 (smerge-match-conflict)
339 (let ((i (smerge-get-current))
340 o)
341 (if (<= i 0)
342 ;; Out of range
343 (popup-menu smerge-mode-menu)
344 ;; Install overlay.
345 (setq o (make-overlay (match-beginning i) (match-end i)))
346 (unwind-protect
347 (progn
348 (overlay-put o 'face 'highlight)
349 (sit-for 0) ;Display the new highlighting.
350 (popup-menu smerge-context-menu))
351 ;; Delete overlay.
352 (delete-overlay o)))))
353 ;; There's no conflict at point, the text-props are just obsolete.
354 (save-excursion
355 (let ((beg (re-search-backward smerge-end-re nil t))
356 (end (re-search-forward smerge-begin-re nil t)))
357 (smerge-remove-props (or beg (point-min)) (or end (point-max)))
358 (push event unread-command-events)))))
359
360 (defun smerge-resolve ()
361 "Resolve the conflict at point intelligently.
362 This relies on mode-specific knowledge and thus only works in
363 some major modes. Uses `smerge-resolve-function' to do the actual work."
364 (interactive)
365 (smerge-match-conflict)
366 (smerge-remove-props)
367 (cond
368 ;; Trivial diff3 -A non-conflicts.
369 ((and (eq (match-end 1) (match-end 3))
370 (eq (match-beginning 1) (match-beginning 3)))
371 ;; FIXME: Add "if [ diff -b MINE OTHER ]; then select OTHER; fi"
372 (smerge-keep-n 3))
373 ((and (match-end 2)
374 ;; FIXME: Add "diff -b BASE MINE | patch OTHER".
375 ;; FIXME: Add "diff -b BASE OTHER | patch MINE".
376 nil)
377 )
378 ((and (not (match-end 2))
379 ;; FIXME: Add "diff -b"-based refinement.
380 nil)
381 )
382 (t
383 ;; Mode-specific conflict resolution.
384 (funcall smerge-resolve-function)))
385 (smerge-auto-leave))
386
387 (defun smerge-keep-base ()
388 "Revert to the base version."
389 (interactive)
390 (smerge-match-conflict)
391 (smerge-ensure-match 2)
392 (smerge-remove-props)
393 (smerge-keep-n 2)
394 (smerge-auto-leave))
395
396 (defun smerge-keep-other ()
397 "Use \"other\" version."
398 (interactive)
399 (smerge-match-conflict)
400 ;;(smerge-ensure-match 3)
401 (smerge-remove-props)
402 (smerge-keep-n 3)
403 (smerge-auto-leave))
404
405 (defun smerge-keep-mine ()
406 "Keep your version."
407 (interactive)
408 (smerge-match-conflict)
409 ;;(smerge-ensure-match 1)
410 (smerge-remove-props)
411 (smerge-keep-n 1)
412 (smerge-auto-leave))
413
414 (defun smerge-get-current ()
415 (let ((i 3))
416 (while (or (not (match-end i))
417 (< (point) (match-beginning i))
418 (>= (point) (match-end i)))
419 (decf i))
420 i))
421
422 (defun smerge-keep-current ()
423 "Use the current (under the cursor) version."
424 (interactive)
425 (smerge-match-conflict)
426 (let ((i (smerge-get-current)))
427 (if (<= i 0) (error "Not inside a version")
428 (smerge-remove-props)
429 (smerge-keep-n i)
430 (smerge-auto-leave))))
431
432 (defun smerge-kill-current ()
433 "Remove the current (under the cursor) version."
434 (interactive)
435 (smerge-match-conflict)
436 (let ((i (smerge-get-current)))
437 (if (<= i 0) (error "Not inside a version")
438 (smerge-remove-props)
439 (let ((left nil))
440 (dolist (n '(3 2 1))
441 (if (and (match-end n) (/= (match-end n) (match-end i)))
442 (push n left)))
443 (if (and (cdr left)
444 (/= (match-end (car left)) (match-end (cadr left))))
445 (ding) ;We don't know how to do that.
446 (smerge-keep-n (car left))
447 (smerge-auto-leave))))))
448
449 (defun smerge-diff-base-mine ()
450 "Diff 'base' and 'mine' version in current conflict region."
451 (interactive)
452 (smerge-diff 2 1))
453
454 (defun smerge-diff-base-other ()
455 "Diff 'base' and 'other' version in current conflict region."
456 (interactive)
457 (smerge-diff 2 3))
458
459 (defun smerge-diff-mine-other ()
460 "Diff 'mine' and 'other' version in current conflict region."
461 (interactive)
462 (smerge-diff 1 3))
463
464 (defun smerge-match-conflict ()
465 "Get info about the conflict. Puts the info in the `match-data'.
466 The submatches contain:
467 0: the whole conflict.
468 1: your code.
469 2: the base code.
470 3: other code.
471 An error is raised if not inside a conflict."
472 (save-excursion
473 (condition-case nil
474 (let* ((orig-point (point))
475
476 (_ (forward-line 1))
477 (_ (re-search-backward smerge-begin-re))
478
479 (start (match-beginning 0))
480 (mine-start (match-end 0))
481 (filename (or (match-string 1) ""))
482
483 (_ (re-search-forward smerge-end-re))
484 (_ (assert (< orig-point (match-end 0))))
485
486 (other-end (match-beginning 0))
487 (end (match-end 0))
488
489 (_ (re-search-backward smerge-other-re start))
490
491 (mine-end (match-beginning 0))
492 (other-start (match-end 0))
493
494 base-start base-end)
495
496 ;; handle the various conflict styles
497 (cond
498 ((save-excursion
499 (goto-char mine-start)
500 (re-search-forward smerge-begin-re end t))
501 ;; There's a nested conflict and we're after the the beginning
502 ;; of the outer one but before the beginning of the inner one.
503 (error "There is a nested conflict"))
504
505 ((re-search-backward smerge-base-re start t)
506 ;; a 3-parts conflict
507 (set (make-local-variable 'smerge-conflict-style) 'diff3-A)
508 (setq base-end mine-end)
509 (setq mine-end (match-beginning 0))
510 (setq base-start (match-end 0)))
511
512 ((string= filename (file-name-nondirectory
513 (or buffer-file-name "")))
514 ;; a 2-parts conflict
515 (set (make-local-variable 'smerge-conflict-style) 'diff3-E))
516
517 ((and (not base-start)
518 (or (eq smerge-conflict-style 'diff3-A)
519 (equal filename "ANCESTOR")
520 (string-match "\\`[.0-9]+\\'" filename)))
521 ;; a same-diff conflict
522 (setq base-start mine-start)
523 (setq base-end mine-end)
524 (setq mine-start other-start)
525 (setq mine-end other-end)))
526
527 (let ((inhibit-read-only t)
528 (inhibit-modification-hooks t)
529 (m (buffer-modified-p)))
530 (unwind-protect
531 (add-text-properties start end smerge-text-properties)
532 (restore-buffer-modified-p m)))
533
534 (store-match-data (list start end
535 mine-start mine-end
536 base-start base-end
537 other-start other-end
538 (when base-start (1- base-start)) base-start
539 (1- other-start) other-start))
540 t)
541 (search-failed (error "Point not in conflict region")))))
542
543 (defun smerge-find-conflict (&optional limit)
544 "Find and match a conflict region. Intended as a font-lock MATCHER.
545 The submatches are the same as in `smerge-match-conflict'.
546 Returns non-nil if a match is found between the point and LIMIT.
547 The point is moved to the end of the conflict."
548 (when (re-search-forward smerge-begin-re limit t)
549 (condition-case err
550 (progn
551 (smerge-match-conflict)
552 (goto-char (match-end 0)))
553 (error (smerge-find-conflict limit)))))
554
555 (defun smerge-diff (n1 n2)
556 (smerge-match-conflict)
557 (smerge-ensure-match n1)
558 (smerge-ensure-match n2)
559 (let ((name1 (aref smerge-match-names n1))
560 (name2 (aref smerge-match-names n2))
561 ;; Read them before the match-data gets clobbered.
562 (beg1 (match-beginning n1))
563 (end1 (match-end n1))
564 (beg2 (match-beginning n2))
565 (end2 (match-end n2))
566 (file1 (make-temp-file "smerge1"))
567 (file2 (make-temp-file "smerge2"))
568 (dir default-directory)
569 (file (file-relative-name buffer-file-name))
570 (coding-system-for-read buffer-file-coding-system))
571 (write-region beg1 end1 file1 nil 'nomessage)
572 (write-region beg2 end2 file2 nil 'nomessage)
573 (unwind-protect
574 (with-current-buffer (get-buffer-create smerge-diff-buffer-name)
575 (setq default-directory dir)
576 (let ((inhibit-read-only t))
577 (erase-buffer)
578 (let ((status
579 (apply 'call-process diff-command nil t nil
580 (append smerge-diff-switches
581 (list "-L" (concat name1 "/" file)
582 "-L" (concat name2 "/" file)
583 file1 file2)))))
584 (if (eq status 0) (insert "No differences found.\n"))))
585 (goto-char (point-min))
586 (diff-mode)
587 (display-buffer (current-buffer) t))
588 (delete-file file1)
589 (delete-file file2))))
590
591 ;; compiler pacifiers
592 (defvar smerge-ediff-windows)
593 (defvar smerge-ediff-buf)
594 (defvar ediff-buffer-A)
595 (defvar ediff-buffer-B)
596 (defvar ediff-buffer-C)
597
598 ;;;###autoload
599 (defun smerge-ediff (&optional name-mine name-other name-base)
600 "Invoke ediff to resolve the conflicts.
601 NAME-MINE, NAME-OTHER, and NAME-BASE, if non-nil, are used for the
602 buffer names."
603 (interactive)
604 (let* ((buf (current-buffer))
605 (mode major-mode)
606 ;;(ediff-default-variant 'default-B)
607 (config (current-window-configuration))
608 (filename (file-name-nondirectory buffer-file-name))
609 (mine (generate-new-buffer
610 (or name-mine (concat "*" filename " MINE*"))))
611 (other (generate-new-buffer
612 (or name-other (concat "*" filename " OTHER*"))))
613 base)
614 (with-current-buffer mine
615 (buffer-disable-undo)
616 (insert-buffer-substring buf)
617 (goto-char (point-min))
618 (while (smerge-find-conflict)
619 (when (match-beginning 2) (setq base t))
620 (smerge-keep-n 1))
621 (buffer-enable-undo)
622 (set-buffer-modified-p nil)
623 (funcall mode))
624
625 (with-current-buffer other
626 (buffer-disable-undo)
627 (insert-buffer-substring buf)
628 (goto-char (point-min))
629 (while (smerge-find-conflict)
630 (smerge-keep-n 3))
631 (buffer-enable-undo)
632 (set-buffer-modified-p nil)
633 (funcall mode))
634
635 (when base
636 (setq base (generate-new-buffer
637 (or name-base (concat "*" filename " BASE*"))))
638 (with-current-buffer base
639 (buffer-disable-undo)
640 (insert-buffer-substring buf)
641 (goto-char (point-min))
642 (while (smerge-find-conflict)
643 (if (match-end 2)
644 (smerge-keep-n 2)
645 (delete-region (match-beginning 0) (match-end 0))))
646 (buffer-enable-undo)
647 (set-buffer-modified-p nil)
648 (funcall mode)))
649
650 ;; the rest of the code is inspired from vc.el
651 ;; Fire up ediff.
652 (set-buffer
653 (if base
654 (ediff-merge-buffers-with-ancestor mine other base)
655 ;; nil 'ediff-merge-revisions-with-ancestor buffer-file-name)
656 (ediff-merge-buffers mine other)))
657 ;; nil 'ediff-merge-revisions buffer-file-name)))
658
659 ;; Ediff is now set up, and we are in the control buffer.
660 ;; Do a few further adjustments and take precautions for exit.
661 (set (make-local-variable 'smerge-ediff-windows) config)
662 (set (make-local-variable 'smerge-ediff-buf) buf)
663 (set (make-local-variable 'ediff-quit-hook)
664 (lambda ()
665 (let ((buffer-A ediff-buffer-A)
666 (buffer-B ediff-buffer-B)
667 (buffer-C ediff-buffer-C)
668 (buffer-Ancestor ediff-ancestor-buffer)
669 (buf smerge-ediff-buf)
670 (windows smerge-ediff-windows))
671 (ediff-cleanup-mess)
672 (with-current-buffer buf
673 (erase-buffer)
674 (insert-buffer-substring buffer-C)
675 (kill-buffer buffer-A)
676 (kill-buffer buffer-B)
677 (kill-buffer buffer-C)
678 (when (bufferp buffer-Ancestor) (kill-buffer buffer-Ancestor))
679 (set-window-configuration windows)
680 (message "Conflict resolution finished; you may save the buffer")))))
681 (message "Please resolve conflicts now; exit ediff when done")))
682
683
684 ;;;###autoload
685 (define-minor-mode smerge-mode
686 "Minor mode to simplify editing output from the diff3 program.
687 \\{smerge-mode-map}"
688 :group 'smerge :lighter " SMerge"
689 (when (and (boundp 'font-lock-mode) font-lock-mode)
690 (set (make-local-variable 'font-lock-multiline) t)
691 (save-excursion
692 (if smerge-mode
693 (font-lock-add-keywords nil smerge-font-lock-keywords 'append)
694 (font-lock-remove-keywords nil smerge-font-lock-keywords))
695 (goto-char (point-min))
696 (while (smerge-find-conflict)
697 (save-excursion
698 (font-lock-fontify-region (match-beginning 0) (match-end 0) nil))))))
699
700
701 (provide 'smerge-mode)
702
703 ;; arch-tag: 605c8d1e-e43d-4943-a6f3-1bcc4333e690
704 ;;; smerge-mode.el ends here