annotate lisp/smerge-mode.el @ 28177:ff69c2cd80c1

(cvs-strings->string): Rename replace-regexps-in-string.
author Dave Love <fx@gnu.org>
date Fri, 17 Mar 2000 10:07:00 +0000
parents 142d6aa7c470
children 108ba8d61036
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26776
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; smerge-mode.el --- Minor mode to resolve diff3 conflicts
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
4
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Keywords: merge diff3 cvs conflict
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7 ;; Revision: $Id$
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14 ;; any later version.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19 ;; GNU General Public License for more details.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26 ;;; Commentary:
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28 ;; Provides a lightweight alternative to emerge/ediff.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 ;; To use it, simply add to your .emacs the following lines:
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30 ;;
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 ;; (autoload 'smerge-mode "smerge-mode" nil t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 ;;
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33 ;; you can even have it turned on automatically with the following
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;; piece of code in your .emacs:
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35 ;;
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 ;; (defun sm-try-smerge ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 ;; (save-excursion
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 ;; (goto-char (point-min))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 ;; (when (re-search-forward "^<<<<<<< " nil t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40 ;; (smerge-mode 1))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41 ;; (add-hook 'find-file-hooks 'sm-try-smerge t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
42
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43 ;;; Code:
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
45 (eval-when-compile (require 'cl))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
48 (defgroup smerge ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 "Minor mode to resolve diff3 conflicts."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50 :group 'tools
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 :prefix "smerge-")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 (defcustom smerge-diff-buffer-name "*smerge-diff*"
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 "Buffer name to use for displaying diffs."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 :group 'smerge
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 :type '(choice
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 (const "*vc-diff*")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 (const "*cvs-diff*")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 (const "*smerge-diff*")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 string))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62 (defcustom smerge-diff-switches
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63 (list* "-d" "-b"
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64 (if (listp diff-switches) diff-switches (list diff-switches)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65 "*A list of strings specifying switches to be be passed to diff.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 Used in `smerge-diff-base-mine' and related functions."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 :group 'smerge
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 :type '(repeat string))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 (defface smerge-mine-face
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71 '((t (:foreground "blue")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 "Face for your code."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 :group 'smerge)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 (defvar smerge-mine-face 'smerge-mine-face)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 (defface smerge-other-face
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 '((t (:foreground "darkgreen")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 "Face for the other code."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 :group 'smerge)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 (defvar smerge-other-face 'smerge-other-face)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 (defface smerge-base-face
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 '((t (:foreground "red")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 "Face for the base code."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 :group 'smerge)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 (defvar smerge-base-face 'smerge-base-face)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 (defface smerge-markers-face
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 '((t (:background "grey85")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 "Face for the conflict markers."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 :group 'smerge)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 (defvar smerge-markers-face 'smerge-markers-face)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 (defmacro smerge-defmap (var bindings &optional doc)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 `(defvar ,var
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 (let ((m (make-sparse-keymap)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 (dolist (b ,bindings)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 (if (equal (car b) "")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99 (set-keymap-parent m (cdr b))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100 (define-key m (car b) (cdr b))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 m)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 ,doc))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104 (smerge-defmap smerge-basic-keymap
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 '(("n" . smerge-next)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106 ("p" . smerge-prev)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
107 ("a" . smerge-keep-all)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108 ("b" . smerge-keep-base)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 ("o" . smerge-keep-other)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110 ("m" . smerge-keep-mine)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
111 ("E" . smerge-ediff)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112 ("\C-m" . smerge-keep-current)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
113 ("<" . smerge-diff-base-mine)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
114 (">" . smerge-diff-base-other)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
115 ("=" . smerge-diff-mine-other))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 "The base keymap for `smerge-mode'.")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 (fset 'smerge-basic-keymap smerge-basic-keymap)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 (defcustom smerge-command-prefix "\e"
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120 "Prefix for `smerge-mode' commands."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121 :group 'smerge
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 :type '(choice (string "\e") (string "C-x^") (string "") string))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
123
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
124 (smerge-defmap smerge-mode-map
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 `((,smerge-command-prefix . smerge-basic-keymap))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126 "Keymap for `smerge-mode'.")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
128 (easy-menu-define smerge-mode-menu smerge-mode-map
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
129 "Menu for `smerge-mode'."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
130 '("SMerge"
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
131 ["Invoke Ediff" smerge-ediff t]
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
132 ))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
133
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
134 (defconst smerge-font-lock-keywords
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
135 '((smerge-find-conflict
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
136 (1 smerge-mine-face prepend)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
137 (2 smerge-base-face prepend t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
138 (3 smerge-other-face prepend t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
139 (0 smerge-markers-face keep)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
140 (4 nil t t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
141 (5 nil t t)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
142 "Font lock patterns for `smerge-mode'.")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
143
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
144 (defconst smerge-begin-re "^<<<<<<< \\(.*\\)\n")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145 (defconst smerge-end-re "^>>>>>>> .*\n")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
146 (defconst smerge-base-re "^||||||| .*\n")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147 (defconst smerge-other-re "^=======\n")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
148
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
149 (defvar smerge-conflict-style nil
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
150 "Keep track of which style of conflict is in use.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
151 Can be nil if the style is undecided, or else:
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
152 - `diff3-E'
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
153 - `diff3-A'")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
154
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
155 ;; Compiler pacifiers
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
156 (defvar font-lock-mode nil)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
157 (defvar font-lock-keywords nil)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
158 (eval-when-compile
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
159 (unless (fboundp 'font-lock-fontify-region)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160 (autoload 'font-lock-fontify-region "font-lock")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
161
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162 ;;;;
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163 ;;;; Actual code
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 ;;;;
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 (defun smerge-next (&optional count)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 "Go to the next COUNT'th conflict."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 (unless count (setq count 1))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 (if (< count 0) (smerge-prev (- count))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 (if (looking-at smerge-begin-re) (incf count))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 (unless (re-search-forward smerge-begin-re nil t count)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 (error "No next conflict"))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 (goto-char (match-beginning 0))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176 (defun smerge-prev (&optional count)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 "Go to the previous COUNT'th conflict."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 (unless count (setq count 1))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
180 (if (< count 0) (smerge-next (- count))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 (unless (re-search-backward smerge-begin-re nil t count)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 (error "No previous conflict"))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184 (defconst smerge-match-names ["conflict" "mine" "base" "other"])
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186 (defun smerge-ensure-match (n)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 (unless (match-end n)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
188 (error (format "No `%s'" (aref smerge-match-names n)))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
190 (defun smerge-keep-all ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191 "Keep all three versions.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
192 Convenient for the kind of conflicts that can arise in ChangeLog files."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
194 (smerge-match-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195 (replace-match (concat (or (match-string 1) "")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
196 (or (match-string 2) "")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 (or (match-string 3) ""))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
198 t t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
200 (defun smerge-keep-base ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201 "Revert to the base version."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
202 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 (smerge-match-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
204 (smerge-ensure-match 2)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 (replace-match (match-string 2) t t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
206
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207 (defun smerge-keep-other ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
208 "Use \"other\" version."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
209 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
210 (smerge-match-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
211 ;;(smerge-ensure-match 3)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
212 (replace-match (match-string 3) t t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
213
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
214 (defun smerge-keep-mine ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
215 "Keep your version."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
216 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
217 (smerge-match-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
218 ;;(smerge-ensure-match 1)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
219 (replace-match (match-string 1) t t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
220
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
221 (defun smerge-keep-current ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
222 "Use the current (under the cursor) version."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
223 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
224 (smerge-match-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
225 (let ((i 3))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
226 (while (or (not (match-end i))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
227 (< (point) (match-beginning i))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
228 (>= (point) (match-end i)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
229 (decf i))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
230 (if (<= i 0) (error "Not inside a version")
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
231 (replace-match (match-string i) t t))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
232
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233 (defun smerge-diff-base-mine ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
234 "Diff 'base' and 'mine' version in current conflict region."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
235 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236 (smerge-diff 2 1))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
238 (defun smerge-diff-base-other ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
239 "Diff 'base' and 'other' version in current conflict region."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
240 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
241 (smerge-diff 2 3))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
243 (defun smerge-diff-mine-other ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
244 "Diff 'mine' and 'other' version in current conflict region."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
245 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
246 (smerge-diff 1 3))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
247
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
248 (defun smerge-match-conflict ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249 "Get info about the conflict. Puts the info in the `match-data'.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
250 The submatches contain:
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
251 0: the whole conflict.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
252 1: your code.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
253 2: the base code.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
254 3: other code.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
255 An error is raised if not inside a conflict."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
256 (save-excursion
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
257 (condition-case nil
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
258 (let* ((orig-point (point))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
259
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
260 (_ (forward-line 1))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
261 (_ (re-search-backward smerge-begin-re))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263 (start (match-beginning 0))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
264 (mine-start (match-end 0))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
265 (filename (match-string 1))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
266
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
267 (_ (re-search-forward smerge-end-re))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
268 (_ (assert (< orig-point (match-end 0))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
269
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
270 (other-end (match-beginning 0))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
271 (end (match-end 0))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
273 (_ (re-search-backward smerge-other-re start))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
274
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
275 (mine-end (match-beginning 0))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
276 (other-start (match-end 0))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
277
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
278 base-start base-end)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
279
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
280 ;; handle the various conflict styles
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
281 (cond
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
282 ((re-search-backward smerge-base-re start t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
283 ;; a 3-parts conflict
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
284 (set (make-local-variable 'smerge-conflict-style) 'diff3-A)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
285 (setq base-end mine-end)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
286 (setq mine-end (match-beginning 0))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
287 (setq base-start (match-end 0)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
289 ((string= filename (file-name-nondirectory
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
290 (or buffer-file-name "")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
291 ;; a 2-parts conflict
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
292 (set (make-local-variable 'smerge-conflict-style) 'diff3-E))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
293
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294 ((and (not base-start)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295 (or (eq smerge-conflict-style 'diff3-A)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
296 (string-match "^[.0-9]+\\'" filename)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
297 ;; a same-diff conflict
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
298 (setq base-start mine-start)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299 (setq base-end mine-end)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (setq mine-start other-start)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
301 (setq mine-end other-end)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
302
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
303 (store-match-data (list start end
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 mine-start mine-end
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
305 base-start base-end
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306 other-start other-end
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
307 (when base-start (1- base-start)) base-start
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
308 (1- other-start) other-start))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309 t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (error "Point not in conflict region"))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
311
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
312 (defun smerge-find-conflict (&optional limit)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
313 "Find and match a conflict region. Intended as a font-lock MATCHER.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
314 The submatches are the same as in `smerge-match-conflict'.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
315 Returns non-nil if a match is found between the point and LIMIT.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
316 The point is moved to the end of the conflict."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
317 (when (re-search-forward smerge-begin-re limit t)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
318 (ignore-errors
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
319 (smerge-match-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
320 (goto-char (match-end 0)))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
322 (defun smerge-diff (n1 n2)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
323 (smerge-match-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
324 (smerge-ensure-match n1)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
325 (smerge-ensure-match n2)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
326 (let ((name1 (aref smerge-match-names n1))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
327 (name2 (aref smerge-match-names n2))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 (file1 (make-temp-file "smerge1"))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (file2 (make-temp-file "smerge2")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
330 (write-region (match-beginning n1) (match-end n1) file1)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
331 (write-region (match-beginning n2) (match-end n2) file2)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332 (unwind-protect
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 (with-current-buffer (get-buffer-create smerge-diff-buffer-name)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334 (let ((inhibit-read-only t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 (erase-buffer)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
336 (apply 'call-process diff-command nil t nil
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
337 (append smerge-diff-switches
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338 (list "-L" name1 "-L" name2 file1 file2))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
339 (goto-char (point-min))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
340 (diff-mode)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341 (display-buffer (current-buffer) t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342 (delete-file file1)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 (delete-file file2))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345 (eval-when-compile
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
346 ;; compiler pacifiers
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
347 (defvar smerge-ediff-windows)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
348 (defvar smerge-ediff-buf)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
349 (defvar ediff-buffer-A)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
350 (defvar ediff-buffer-B)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
351 (defvar ediff-buffer-C)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
352 (unless (fboundp 'ediff-cleanup-mess)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
353 (autoload 'ediff-cleanup-mess "ediff-util")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
354
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
355 (defun smerge-ediff ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
356 "Invoke ediff to resolve the conflicts."
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
357 (interactive)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
358 (let* ((buf (current-buffer))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359 (mode major-mode)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
360 ;;(ediff-default-variant 'default-B)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
361 (config (current-window-configuration))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
362 (filename (file-name-nondirectory buffer-file-name))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
363 (mine (generate-new-buffer (concat "*" filename " MINE*")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
364 (other (generate-new-buffer (concat "*" filename " OTHER*")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
365 base)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
366 (with-current-buffer mine
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
367 (buffer-disable-undo)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
368 (insert-buffer-substring buf)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
369 (goto-char (point-min))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
370 (while (smerge-find-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371 (when (match-beginning 2) (setq base t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
372 (replace-match (match-string 1) t t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
373 (buffer-enable-undo)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
374 (set-buffer-modified-p nil)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
375 (funcall mode))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
376
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
377 (with-current-buffer other
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
378 (buffer-disable-undo)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
379 (insert-buffer-substring buf)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
380 (goto-char (point-min))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
381 (while (smerge-find-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382 (replace-match (match-string 3) t t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
383 (buffer-enable-undo)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
384 (set-buffer-modified-p nil)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385 (funcall mode))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
386
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
387 (when base
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 (setq base (generate-new-buffer (concat "*" filename " BASE*")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 (with-current-buffer base
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
390 (buffer-disable-undo)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
391 (insert-buffer-substring buf)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
392 (goto-char (point-min))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 (while (smerge-find-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
394 (replace-match (or (match-string 2) "") t t))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395 (buffer-enable-undo)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
396 (set-buffer-modified-p nil)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
397 (funcall mode)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
398
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399 ;; the rest of the code is inspired from vc.el
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
400 ;; Fire up ediff.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
401 (set-buffer
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
402 (if base
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
403 (ediff-merge-buffers-with-ancestor mine other base)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404 ;; nil 'ediff-merge-revisions-with-ancestor buffer-file-name)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405 (ediff-merge-buffers mine other)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 ;; nil 'ediff-merge-revisions buffer-file-name)))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
407
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
408 ;; Ediff is now set up, and we are in the control buffer.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
409 ;; Do a few further adjustments and take precautions for exit.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
410 (set (make-local-variable 'smerge-ediff-windows) config)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
411 (set (make-local-variable 'smerge-ediff-buf) buf)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
412 (set (make-local-variable 'ediff-quit-hook)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
413 (lambda ()
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
414 (let ((buffer-A ediff-buffer-A)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
415 (buffer-B ediff-buffer-B)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
416 (buffer-C ediff-buffer-C)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
417 (buffer-Ancestor ediff-ancestor-buffer)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
418 (buf smerge-ediff-buf)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
419 (windows smerge-ediff-windows))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
420 (ediff-cleanup-mess)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
421 (with-current-buffer buf
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
422 (erase-buffer)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
423 (insert-buffer buffer-C)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
424 (kill-buffer buffer-A)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
425 (kill-buffer buffer-B)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
426 (kill-buffer buffer-C)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
427 (when (bufferp buffer-Ancestor) (kill-buffer buffer-Ancestor))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
428 (set-window-configuration windows)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
429 (message "Conflict resolution finished; you may save the buffer")))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
430 (message "Please resolve conflicts now; exit ediff when done")))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
431
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
432
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
433 ;;;###autoload
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
434 (define-minor-mode smerge-mode
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
435 "Minor mode to simplify editing output from the diff3 program.
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
436 \\{smerge-mode-map}"
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
437 nil " SMerge" nil
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
438 (when font-lock-mode
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
439 (save-excursion
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440 (if smerge-mode
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441 (font-lock-add-keywords nil smerge-font-lock-keywords 'append)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442 (font-lock-remove-keywords nil smerge-font-lock-keywords))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
443 (goto-char (point-min))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
444 (while (smerge-find-conflict)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
445 (font-lock-fontify-region (match-beginning 0) (match-end 0) nil)))))
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
446
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
447
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448 (provide 'smerge-mode)
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
450 ;;; Change Log:
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451 ;; $Log$
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
452
142d6aa7c470 New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
453 ;;; smerge-mode.el ends here