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