Mercurial > emacs
annotate lisp/smerge-mode.el @ 96642:aee1275a4e6e
*** empty log message ***
author | Martin Rudalics <rudalics@gmx.at> |
---|---|
date | Sun, 13 Jul 2008 07:35:15 +0000 |
parents | 4ea0e968c7af |
children | b9de9e7dceed |
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 |
94862 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
4 ;; 2007, 2008 Free Software Foundation, Inc. | |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 |
70292
2b77fa42947f
Update my email address.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
6 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> |
66458
f2be1560adf2
Add 'tools' to file keywords.
Romain Francoise <romain@orebokech.com>
parents:
65658
diff
changeset
|
7 ;; Keywords: tools revision-control merge diff3 cvs conflict |
26776
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 |
94862 | 11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
26776
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 |
94862 | 13 ;; the Free Software Foundation, either version 3 of the License, or |
14 ;; (at your option) any later version. | |
26776
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 |
94862 | 22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 ;;; Commentary: |
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 ;; 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
|
27 ;; 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
|
28 ;; |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 ;; (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
|
30 ;; |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 ;; 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
|
32 ;; 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
|
33 ;; |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 ;; (defun sm-try-smerge () |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 ;; (save-excursion |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;; (goto-char (point-min)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 ;; (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
|
38 ;; (smerge-mode 1)))) |
46899
f00337f04e78
Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41064
diff
changeset
|
39 ;; (add-hook 'find-file-hook 'sm-try-smerge t) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
41 ;;; Todo: |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
42 |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
43 ;; - if requested, ask the user whether he wants to call ediff right away |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
44 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 ;;; Code: |
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 (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
|
48 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 |
63936
1eb58fde25d4
(smerge-mode): Add duplicate defvar near top.
Richard M. Stallman <rms@gnu.org>
parents:
63488
diff
changeset
|
50 ;;; The real definition comes later. |
1eb58fde25d4
(smerge-mode): Add duplicate defvar near top.
Richard M. Stallman <rms@gnu.org>
parents:
63488
diff
changeset
|
51 (defvar smerge-mode) |
1eb58fde25d4
(smerge-mode): Add duplicate defvar near top.
Richard M. Stallman <rms@gnu.org>
parents:
63488
diff
changeset
|
52 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 (defgroup smerge () |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
54 "Minor mode to highlight and resolve diff3 conflicts." |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 :group 'tools |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 :prefix "smerge-") |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 |
47209
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
58 (defcustom smerge-diff-buffer-name "*vc-diff*" |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 "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
|
60 :group 'smerge |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 :type '(choice |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (const "*vc-diff*") |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 (const "*cvs-diff*") |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 (const "*smerge-diff*") |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 string)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 (defcustom smerge-diff-switches |
29207
6c4e371d4efd
(smerge-diff-switches): Don't use list* in defcustom.
Dave Love <fx@gnu.org>
parents:
28248
diff
changeset
|
68 (append '("-d" "-b") |
6c4e371d4efd
(smerge-diff-switches): Don't use list* in defcustom.
Dave Love <fx@gnu.org>
parents:
28248
diff
changeset
|
69 (if (listp diff-switches) diff-switches (list diff-switches))) |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
70 "A list of strings specifying switches to be passed to diff. |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 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
|
72 :group 'smerge |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 :type '(repeat string)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
75 (defcustom smerge-auto-leave t |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
76 "Non-nil means to leave `smerge-mode' when the last conflict is resolved." |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
77 :group 'smerge |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
78 :type 'boolean) |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
79 |
85465
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
80 (defcustom smerge-auto-refine t |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
81 "Automatically highlight changes in detail as the user visits conflicts." |
85478
786d3a985758
* term/x-win.el (x-gtk-stock-map, icon-map-list)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85465
diff
changeset
|
82 :group 'smerge |
85465
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
83 :type 'boolean) |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
84 |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
85 (defface smerge-mine |
61394
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
86 '((((min-colors 88) (background light)) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
87 (:foreground "blue1")) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
88 (((background light)) |
32164
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
89 (:foreground "blue")) |
61394
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
90 (((min-colors 88) (background dark)) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
91 (:foreground "cyan1")) |
32164
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
92 (((background dark)) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
93 (:foreground "cyan"))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 "Face for your code." |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 :group 'smerge) |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
96 ;; backward-compatibility alias |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
97 (put 'smerge-mine-face 'face-alias 'smerge-mine) |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
98 (defvar smerge-mine-face 'smerge-mine) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
100 (defface smerge-other |
32164
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
101 '((((background light)) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
102 (:foreground "darkgreen")) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
103 (((background dark)) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
104 (:foreground "lightgreen"))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 "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
|
106 :group 'smerge) |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
107 ;; backward-compatibility alias |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
108 (put 'smerge-other-face 'face-alias 'smerge-other) |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
109 (defvar smerge-other-face 'smerge-other) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
111 (defface smerge-base |
61394
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
112 '((((min-colors 88) (background light)) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
113 (:foreground "red1")) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61277
diff
changeset
|
114 (((background light)) |
32164
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
115 (:foreground "red")) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
116 (((background dark)) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
117 (:foreground "orange"))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 "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
|
119 :group 'smerge) |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
120 ;; backward-compatibility alias |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
121 (put 'smerge-base-face 'face-alias 'smerge-base) |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
122 (defvar smerge-base-face 'smerge-base) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
124 (defface smerge-markers |
32164
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
125 '((((background light)) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
126 (:background "grey85")) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
127 (((background dark)) |
a3d5adc99010
(smerge-mine-face, smerge-other-face, smerge-base-face, smerge-markers-face):
Miles Bader <miles@gnu.org>
parents:
30868
diff
changeset
|
128 (:background "grey30"))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 "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
|
130 :group 'smerge) |
63205
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
131 ;; backward-compatibility alias |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
132 (put 'smerge-markers-face 'face-alias 'smerge-markers) |
6dde8ad3e1a7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375
Miles Bader <miles@gnu.org>
parents:
61394
diff
changeset
|
133 (defvar smerge-markers-face 'smerge-markers) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
135 (defface smerge-refined-change |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
136 '((t :background "yellow")) |
65131
ebbbce58e84c
(smerge-refined-change): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
65129
diff
changeset
|
137 "Face used for char-based changes shown by `smerge-refine'." |
ebbbce58e84c
(smerge-refined-change): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
65129
diff
changeset
|
138 :group 'smerge) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
139 |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
140 (easy-mmode-defmap smerge-basic-map |
34840
509ed3724af0
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32217
diff
changeset
|
141 `(("n" . smerge-next) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
142 ("p" . smerge-prev) |
47827
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
143 ("r" . smerge-resolve) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 ("a" . smerge-keep-all) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 ("b" . smerge-keep-base) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
146 ("o" . smerge-keep-other) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147 ("m" . smerge-keep-mine) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
148 ("E" . smerge-ediff) |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
149 ("C" . smerge-combine-with-next) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
150 ("R" . smerge-refine) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 ("\C-m" . smerge-keep-current) |
34840
509ed3724af0
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32217
diff
changeset
|
152 ("=" . ,(make-sparse-keymap "Diff")) |
509ed3724af0
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32217
diff
changeset
|
153 ("=<" "base-mine" . smerge-diff-base-mine) |
509ed3724af0
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32217
diff
changeset
|
154 ("=>" "base-other" . smerge-diff-base-other) |
509ed3724af0
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32217
diff
changeset
|
155 ("==" "mine-other" . smerge-diff-mine-other)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
156 "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
|
157 |
34840
509ed3724af0
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32217
diff
changeset
|
158 (defcustom smerge-command-prefix "\C-c^" |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 "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
|
160 :group 'smerge |
94846
1a6e4ea4e517
(smerge-command-prefix): Fix custom type.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
94678
diff
changeset
|
161 :type '(choice (const :tag "ESC" "\e") |
1a6e4ea4e517
(smerge-command-prefix): Fix custom type.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
94678
diff
changeset
|
162 (const :tag "C-c ^" "\C-c^" ) |
1a6e4ea4e517
(smerge-command-prefix): Fix custom type.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
94678
diff
changeset
|
163 (const :tag "none" "") |
1a6e4ea4e517
(smerge-command-prefix): Fix custom type.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
94678
diff
changeset
|
164 string)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
165 |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
166 (easy-mmode-defmap smerge-mode-map |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
167 `((,smerge-command-prefix . ,smerge-basic-map)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168 "Keymap for `smerge-mode'.") |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
170 (defvar smerge-check-cache nil) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
171 (make-variable-buffer-local 'smerge-check-cache) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
172 (defun smerge-check (n) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
173 (condition-case nil |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
174 (let ((state (cons (point) (buffer-modified-tick)))) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
175 (unless (equal (cdr smerge-check-cache) state) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
176 (smerge-match-conflict) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
177 (setq smerge-check-cache (cons (match-data) state))) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
178 (nth (* 2 n) (car smerge-check-cache))) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
179 (error nil))) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
180 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181 (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
|
182 "Menu for `smerge-mode'." |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183 '("SMerge" |
30358 | 184 ["Next" smerge-next :help "Go to next conflict"] |
30868
f7b06560383b
(smerge-mode-menu): Doc fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30358
diff
changeset
|
185 ["Previous" smerge-prev :help "Go to previous conflict"] |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
186 "--" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
187 ["Keep All" smerge-keep-all :help "Keep all three versions" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
188 :active (smerge-check 1)] |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
189 ["Keep Current" smerge-keep-current :help "Use current (at point) version" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
190 :active (and (smerge-check 1) (> (smerge-get-current) 0))] |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
191 "--" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
192 ["Revert to Base" smerge-keep-base :help "Revert to base version" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
193 :active (smerge-check 2)] |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
194 ["Keep Other" smerge-keep-other :help "Keep `other' version" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
195 :active (smerge-check 3)] |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
196 ["Keep Yours" smerge-keep-mine :help "Keep your version" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
197 :active (smerge-check 1)] |
30358 | 198 "--" |
199 ["Diff Base/Mine" smerge-diff-base-mine | |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
200 :help "Diff `base' and `mine' for current conflict" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
201 :active (smerge-check 2)] |
30358 | 202 ["Diff Base/Other" smerge-diff-base-other |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
203 :help "Diff `base' and `other' for current conflict" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
204 :active (smerge-check 2)] |
30358 | 205 ["Diff Mine/Other" smerge-diff-mine-other |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
206 :help "Diff `mine' and `other' for current conflict" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
207 :active (smerge-check 1)] |
30358 | 208 "--" |
209 ["Invoke Ediff" smerge-ediff | |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
210 :help "Use Ediff to resolve the conflicts" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
211 :active (smerge-check 1)] |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
212 ["Auto Resolve" smerge-resolve |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
213 :help "Try auto-resolution heuristics" |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
214 :active (smerge-check 1)] |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
215 ["Combine" smerge-combine-with-next |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
216 :help "Combine current conflict with next" |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
217 :active (smerge-check 1)] |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 )) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
219 |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
220 (easy-menu-define smerge-context-menu nil |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
221 "Context menu for mine area in `smerge-mode'." |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
222 '(nil |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
223 ["Keep Current" smerge-keep-current :help "Use current (at point) version"] |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
224 ["Kill Current" smerge-kill-current :help "Remove current (at point) version"] |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
225 ["Keep All" smerge-keep-all :help "Keep all three versions"] |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
226 "---" |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
227 ["More..." (popup-menu smerge-mode-menu) :help "Show full SMerge mode menu"] |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
228 )) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
229 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
230 (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
|
231 '((smerge-find-conflict |
35564
b546ef3b2284
(smerge-font-lock-keywords): Relax submatch 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34855
diff
changeset
|
232 (1 smerge-mine-face prepend t) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
233 (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
|
234 (3 smerge-other-face prepend t) |
34840
509ed3724af0
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32217
diff
changeset
|
235 ;; FIXME: `keep' doesn't work right with syntactic fontification. |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
236 (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
|
237 (4 nil t t) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
238 (5 nil t t))) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
239 "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
|
240 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
241 (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
|
242 (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
|
243 (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
|
244 (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
|
245 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
246 (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
|
247 "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
|
248 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
|
249 - `diff3-E' |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
250 - `diff3-A'") |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
251 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
252 ;; Compiler pacifiers |
52779
3bc7b9f71e34
Previous change was bogus. Something odd in pcl-cvs...
Dave Love <fx@gnu.org>
parents:
52778
diff
changeset
|
253 (defvar font-lock-mode) |
3bc7b9f71e34
Previous change was bogus. Something odd in pcl-cvs...
Dave Love <fx@gnu.org>
parents:
52778
diff
changeset
|
254 (defvar font-lock-keywords) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
255 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
256 ;;;; |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
257 ;;;; Actual code |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
258 ;;;; |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
259 |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
260 ;; Define smerge-next and smerge-prev |
85465
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
261 (easy-mmode-define-navigation smerge smerge-begin-re "conflict" nil nil |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
262 (if smerge-auto-refine |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
263 (condition-case nil (smerge-refine) (error nil)))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
264 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
265 (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
|
266 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
267 (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
|
268 (unless (match-end n) |
63488
31f53cf94303
(smerge-ensure-match): Don't use `format' on `error' arguments.
Juanma Barranquero <lekktu@gmail.com>
parents:
63205
diff
changeset
|
269 (error "No `%s'" (aref smerge-match-names n)))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
270 |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
271 (defun smerge-auto-leave () |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
272 (when (and smerge-auto-leave |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
273 (save-excursion (goto-char (point-min)) |
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
274 (not (re-search-forward smerge-begin-re nil t)))) |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
275 (when (and (listp buffer-undo-list) smerge-mode) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
276 (push (list 'apply 'smerge-mode 1) buffer-undo-list)) |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
277 (smerge-mode -1))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47827
diff
changeset
|
278 |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
279 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
280 (defun smerge-keep-all () |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
281 "Concatenate all versions." |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
282 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
283 (smerge-match-conflict) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
284 (let ((mb2 (or (match-beginning 2) (point-max))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
285 (me2 (or (match-end 2) (point-min)))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
286 (delete-region (match-end 3) (match-end 0)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
287 (delete-region (max me2 (match-end 1)) (match-beginning 3)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
288 (if (and (match-end 2) (/= (match-end 1) (match-end 3))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
289 (delete-region (match-end 1) (match-beginning 2))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
290 (delete-region (match-beginning 0) (min (match-beginning 1) mb2)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
291 (smerge-auto-leave))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
292 |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
293 (defun smerge-keep-n (n) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
294 (smerge-remove-props (match-beginning 0) (match-end 0)) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
295 ;; We used to use replace-match, but that did not preserve markers so well. |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
296 (delete-region (match-end n) (match-end 0)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
297 (delete-region (match-beginning 0) (match-beginning n))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
298 |
47209
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
299 (defun smerge-combine-with-next () |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
300 "Combine the current conflict with the next one." |
91813
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
301 ;; `smerge-auto-combine' relies on the finish position (at the beginning |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
302 ;; of the closing marker). |
47209
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
303 (interactive) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
304 (smerge-match-conflict) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
305 (let ((ends nil)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
306 (dolist (i '(3 2 1 0)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
307 (push (if (match-end i) (copy-marker (match-end i) t)) ends)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
308 (setq ends (apply 'vector ends)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
309 (goto-char (aref ends 0)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
310 (if (not (re-search-forward smerge-begin-re nil t)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
311 (error "No next conflict") |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
312 (smerge-match-conflict) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
313 (let ((match-data (mapcar (lambda (m) (if m (copy-marker m))) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
314 (match-data)))) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
315 ;; First copy the in-between text in each alternative. |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
316 (dolist (i '(1 2 3)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
317 (when (aref ends i) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
318 (goto-char (aref ends i)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
319 (insert-buffer-substring (current-buffer) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
320 (aref ends 0) (car match-data)))) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
321 (delete-region (aref ends 0) (car match-data)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
322 ;; Then move the second conflict's alternatives into the first. |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
323 (dolist (i '(1 2 3)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
324 (set-match-data match-data) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
325 (when (and (aref ends i) (match-end i)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
326 (goto-char (aref ends i)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
327 (insert-buffer-substring (current-buffer) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
328 (match-beginning i) (match-end i)))) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
329 (delete-region (car match-data) (cadr match-data)) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
330 ;; Free the markers. |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
331 (dolist (m match-data) (if m (move-marker m nil))) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
332 (mapc (lambda (m) (if m (move-marker m nil))) ends))))) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
333 |
91813
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
334 (defvar smerge-auto-combine-max-separation 2 |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
335 "Max number of lines between conflicts that should be combined.") |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
336 |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
337 (defun smerge-auto-combine () |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
338 "Automatically combine conflicts that are near each other." |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
339 (interactive) |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
340 (save-excursion |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
341 (goto-char (point-min)) |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
342 (while (smerge-find-conflict) |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
343 ;; 2 is 1 (default) + 1 (the begin markers). |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
344 (while (save-excursion |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
345 (smerge-find-conflict |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
346 (line-beginning-position |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
347 (+ 2 smerge-auto-combine-max-separation)))) |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
348 (forward-line -1) ;Go back inside the conflict. |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
349 (smerge-combine-with-next) |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
350 (forward-line 1) ;Move past the end of the conflict. |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
351 )))) |
ca1e1298a3d8
(smerge-auto-combine-max-separation): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87785
diff
changeset
|
352 |
47827
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
353 (defvar smerge-resolve-function |
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
354 (lambda () (error "Don't know how to resolve")) |
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
355 "Mode-specific merge function. |
78572
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
356 The function is called with zero or one argument (non-nil if the resolution |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
357 function should only apply safe heuristics) and with the match data set |
47827
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
358 according to `smerge-match-conflict'.") |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
359 (add-to-list 'debug-ignored-errors "Don't know how to resolve") |
47827
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
360 |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
361 (defvar smerge-text-properties |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
362 `(help-echo "merge conflict: mouse-3 shows a menu" |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
363 ;; mouse-face highlight |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
364 keymap (keymap (down-mouse-3 . smerge-popup-context-menu)))) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
365 |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
366 (defun smerge-remove-props (beg end) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
367 (remove-overlays beg end 'smerge 'refine) |
65658
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
368 (remove-overlays beg end 'smerge 'conflict) |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
369 ;; Now that we use overlays rather than text-properties, this function |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
370 ;; does not cause refontification any more. It can be seen very clearly |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
371 ;; in buffers where jit-lock-contextually is not t, in which case deleting |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
372 ;; the "<<<<<<< foobar" leading line leaves the rest of the conflict |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
373 ;; highlighted as if it were still a valid conflict. Note that in many |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
374 ;; important cases (such as the previous example) we're actually called |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
375 ;; during font-locking so inhibit-modification-hooks is non-nil, so we |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
376 ;; can't just modify the buffer and expect font-lock to be triggered as in: |
5bde6d4759d6
(smerge-remove-props): Cause re-highlighting of the whole conflict.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65379
diff
changeset
|
377 ;; (put-text-property beg end 'smerge-force-highlighting nil) |
76397
e9b063d17531
(smerge-remove-props): Don't mark the buffer modified.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
378 (let ((modified (buffer-modified-p))) |
e9b063d17531
(smerge-remove-props): Don't mark the buffer modified.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
379 (remove-text-properties beg end '(fontified nil)) |
e9b063d17531
(smerge-remove-props): Don't mark the buffer modified.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
380 (restore-buffer-modified-p modified))) |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
381 |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
382 (defun smerge-popup-context-menu (event) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
383 "Pop up the Smerge mode context menu under mouse." |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
384 (interactive "e") |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
385 (if (and smerge-mode |
54872
367886fbcfd9
(smerge-popup-context-menu): Use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54527
diff
changeset
|
386 (save-excursion (posn-set-point (event-end event)) (smerge-check 1))) |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
387 (progn |
54872
367886fbcfd9
(smerge-popup-context-menu): Use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54527
diff
changeset
|
388 (posn-set-point (event-end event)) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
389 (smerge-match-conflict) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
390 (let ((i (smerge-get-current)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
391 o) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
392 (if (<= i 0) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
393 ;; Out of range |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
394 (popup-menu smerge-mode-menu) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
395 ;; Install overlay. |
55258
04a44f089cc1
(smerge-diff-switches): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
54904
diff
changeset
|
396 (setq o (make-overlay (match-beginning i) (match-end i))) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
397 (unwind-protect |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
398 (progn |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
399 (overlay-put o 'face 'highlight) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
400 (sit-for 0) ;Display the new highlighting. |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
401 (popup-menu smerge-context-menu)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
402 ;; Delete overlay. |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
403 (delete-overlay o))))) |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
404 ;; There's no conflict at point, the text-props are just obsolete. |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
405 (save-excursion |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
406 (let ((beg (re-search-backward smerge-end-re nil t)) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
407 (end (re-search-forward smerge-begin-re nil t))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
408 (smerge-remove-props (or beg (point-min)) (or end (point-max))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
409 (push event unread-command-events))))) |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
410 |
93445
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
411 (defun smerge-apply-resolution-patch (buf m0b m0e m3b m3e &optional m2b) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
412 "Replace the conflict with a bunch of subconflicts. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
413 BUF contains a plain diff between match-1 and match-3." |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
414 (let ((line 1) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
415 (textbuf (current-buffer)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
416 (name1 (progn (goto-char m0b) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
417 (buffer-substring (+ (point) 8) (line-end-position)))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
418 (name2 (when m2b (goto-char m2b) (forward-line -1) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
419 (buffer-substring (+ (point) 8) (line-end-position)))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
420 (name3 (progn (goto-char m0e) (forward-line -1) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
421 (buffer-substring (+ (point) 8) (line-end-position))))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
422 (smerge-remove-props m0b m0e) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
423 (delete-region m3e m0e) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
424 (delete-region m0b m3b) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
425 (setq m3b m0b) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
426 (setq m3e (- m3e (- m3b m0b))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
427 (goto-char m3b) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
428 (with-current-buffer buf |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
429 (goto-char (point-min)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
430 (while (not (eobp)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
431 (if (not (looking-at "\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?\\([acd]\\)\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?$")) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
432 (error "Unexpected patch hunk header: %s" |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
433 (buffer-substring (point) (line-end-position))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
434 (let* ((op (char-after (match-beginning 3))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
435 (startline (+ (string-to-number (match-string 1)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
436 ;; No clue why this is the way it is, but line |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
437 ;; numbers seem to be off-by-one for `a' ops. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
438 (if (eq op ?a) 1 0))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
439 (endline (if (eq op ?a) startline |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
440 (1+ (if (match-end 2) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
441 (string-to-number (match-string 2)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
442 startline)))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
443 (lines (- endline startline)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
444 (otherlines (cond |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
445 ((eq op ?d) nil) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
446 ((null (match-end 5)) 1) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
447 (t (- (string-to-number (match-string 5)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
448 (string-to-number (match-string 4)) -1)))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
449 othertext) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
450 (forward-line 1) ;Skip header. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
451 (forward-line lines) ;Skip deleted text. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
452 (if (eq op ?c) (forward-line 1)) ;Skip separator. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
453 (setq othertext |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
454 (if (null otherlines) "" |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
455 (let ((pos (point))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
456 (dotimes (i otherlines) (delete-char 2) (forward-line 1)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
457 (buffer-substring pos (point))))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
458 (with-current-buffer textbuf |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
459 (forward-line (- startline line)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
460 (insert "<<<<<<< " name1 "\n" othertext |
94884
4ea0e968c7af
(smerge-apply-resolution-patch): Don't pass nil to `insert'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94865
diff
changeset
|
461 (if name2 (concat "||||||| " name2 "\n") "") |
93445
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
462 "=======\n") |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
463 (forward-line lines) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
464 (insert ">>>>>>> " name3 "\n") |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
465 (setq line endline)))))))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
466 |
78572
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
467 (defun smerge-resolve (&optional safe) |
47827
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
468 "Resolve the conflict at point intelligently. |
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
469 This relies on mode-specific knowledge and thus only works in |
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
470 some major modes. Uses `smerge-resolve-function' to do the actual work." |
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
471 (interactive) |
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
472 (smerge-match-conflict) |
65379
66ed969ca7cc
(smerge-resolve): Pass args to smerge-remove-props.
Richard M. Stallman <rms@gnu.org>
parents:
65131
diff
changeset
|
473 (smerge-remove-props (match-beginning 0) (match-end 0)) |
93445
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
474 (let ((md (match-data)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
475 (m0b (match-beginning 0)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
476 (m1b (match-beginning 1)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
477 (m2b (match-beginning 2)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
478 (m3b (match-beginning 3)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
479 (m0e (match-end 0)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
480 (m1e (match-end 1)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
481 (m2e (match-end 2)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
482 (m3e (match-end 3)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
483 (buf (generate-new-buffer " *smerge*")) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
484 m b o) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
485 (unwind-protect |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
486 (progn |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
487 (cond |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
488 ;; Trivial diff3 -A non-conflicts. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
489 ((and (eq (match-end 1) (match-end 3)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
490 (eq (match-beginning 1) (match-beginning 3))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
491 (smerge-keep-n 3)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
492 ;; Mode-specific conflict resolution. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
493 ((condition-case nil |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
494 (atomic-change-group |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
495 (if safe |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
496 (funcall smerge-resolve-function safe) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
497 (funcall smerge-resolve-function)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
498 t) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
499 (error nil)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
500 ;; Nothing to do: the resolution function has done it already. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
501 nil) |
93983
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
502 ;; Non-conflict. |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
503 ((and (eq m1e m3e) (eq m1b m3b)) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
504 (set-match-data md) (smerge-keep-n 3)) |
93445
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
505 ;; Refine a 2-way conflict using "diff -b". |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
506 ;; In case of a 3-way conflict with an empty base |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
507 ;; (i.e. 2 conflicting additions), we do the same, presuming |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
508 ;; that the 2 additions should be somehow merged rather |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
509 ;; than concatenated. |
93983
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
510 ((let ((lines (count-lines m3b m3e))) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
511 (setq m (make-temp-file "smm")) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
512 (write-region m1b m1e m nil 'silent) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
513 (setq o (make-temp-file "smo")) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
514 (write-region m3b m3e o nil 'silent) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
515 (not (or (eq m1b m1e) (eq m3b m3e) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
516 (and (not (zerop (call-process diff-command |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
517 nil buf nil "-b" o m))) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
518 ;; TODO: We don't know how to do the refinement |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
519 ;; if there's a non-empty ancestor and m1 and m3 |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
520 ;; aren't just plain equal. |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
521 m2b (not (eq m2b m2e))) |
93445
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
522 (with-current-buffer buf |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
523 (goto-char (point-min)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
524 ;; Make sure there's some refinement. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
525 (looking-at |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
526 (concat "1," (number-to-string lines) "c")))))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
527 (smerge-apply-resolution-patch buf m0b m0e m3b m3e m2b)) |
93983
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
528 ;; "Mere whitespace changes" conflicts. |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
529 ((when m2e |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
530 (setq b (make-temp-file "smb")) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
531 (write-region m2b m2e b nil 'silent) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
532 (with-current-buffer buf (erase-buffer)) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
533 ;; Only minor whitespace changes made locally. |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
534 ;; BEWARE: pass "-c" 'cause the output is reused in the next test. |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
535 (zerop (call-process diff-command nil buf nil "-bc" b m))) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
536 (set-match-data md) |
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
537 (smerge-keep-n 3)) |
93445
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
538 ;; Try "diff -b BASE MINE | patch OTHER". |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
539 ((when (and (not safe) m2e b |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
540 ;; If the BASE is empty, this would just concatenate |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
541 ;; the two, which is rarely right. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
542 (not (eq m2b m2e))) |
93983
955774916817
(smerge-apply-resolution-patch): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93445
diff
changeset
|
543 ;; BEWARE: we're using here the patch of the previous test. |
93445
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
544 (with-current-buffer buf |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
545 (zerop (call-process-region |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
546 (point-min) (point-max) "patch" t nil nil |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
547 "-r" "/dev/null" "--no-backup-if-mismatch" |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
548 "-fl" o)))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
549 (save-restriction |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
550 (narrow-to-region m0b m0e) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
551 (smerge-remove-props m0b m0e) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
552 (insert-file-contents o nil nil nil t))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
553 ;; Try "diff -b BASE OTHER | patch MINE". |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
554 ((when (and (not safe) m2e b |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
555 ;; If the BASE is empty, this would just concatenate |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
556 ;; the two, which is rarely right. |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
557 (not (eq m2b m2e))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
558 (write-region m3b m3e o nil 'silent) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
559 (call-process diff-command nil buf nil "-bc" b o) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
560 (with-current-buffer buf |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
561 (zerop (call-process-region |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
562 (point-min) (point-max) "patch" t nil nil |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
563 "-r" "/dev/null" "--no-backup-if-mismatch" |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
564 "-fl" m)))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
565 (save-restriction |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
566 (narrow-to-region m0b m0e) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
567 (smerge-remove-props m0b m0e) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
568 (insert-file-contents m nil nil nil t))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
569 (t |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
570 (error "Don't know how to resolve")))) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
571 (if (buffer-name buf) (kill-buffer buf)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
572 (if m (delete-file m)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
573 (if b (delete-file b)) |
87b6e6f4a207
(smerge-apply-resolution-patch): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93442
diff
changeset
|
574 (if o (delete-file o)))) |
47827
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
575 (smerge-auto-leave)) |
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
576 |
78572
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
577 (defun smerge-resolve-all () |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
578 "Perform automatic resolution on all conflicts." |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
579 (interactive) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
580 (save-excursion |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
581 (goto-char (point-min)) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
582 (while (re-search-forward smerge-begin-re nil t) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
583 (condition-case nil |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
584 (progn |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
585 (smerge-match-conflict) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
586 (smerge-resolve 'safe)) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
587 (error nil))))) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
588 |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
589 (defun smerge-batch-resolve () |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
590 ;; command-line-args-left is what is left of the command line. |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
591 (if (not noninteractive) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
592 (error "`smerge-batch-resolve' is to be used only with -batch")) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
593 (while command-line-args-left |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
594 (let ((file (pop command-line-args-left))) |
85465
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
595 (if (string-match "\\.rej\\'" file) |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
596 ;; .rej files should never contain diff3 markers, on the other hand, |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
597 ;; in Arch, .rej files are sometimes used to indicate that the |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
598 ;; main file has diff3 markers. So you can pass **/*.rej and |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
599 ;; it will DTRT. |
b9fe84d8ca5a
(smerge-auto-refine): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85443
diff
changeset
|
600 (setq file (substring file 0 (match-beginning 0)))) |
78572
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
601 (message "Resolving conflicts in %s..." file) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
602 (when (file-readable-p file) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
603 (with-current-buffer (find-file-noselect file) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
604 (smerge-resolve-all) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
605 (save-buffer) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
606 (kill-buffer (current-buffer))))))) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
607 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
608 (defun smerge-keep-base () |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
609 "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
|
610 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
611 (smerge-match-conflict) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
612 (smerge-ensure-match 2) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
613 (smerge-keep-n 2) |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
614 (smerge-auto-leave)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
615 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
616 (defun smerge-keep-other () |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
617 "Use \"other\" version." |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
618 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
619 (smerge-match-conflict) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
620 ;;(smerge-ensure-match 3) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
621 (smerge-keep-n 3) |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
622 (smerge-auto-leave)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
623 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
624 (defun smerge-keep-mine () |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
625 "Keep your version." |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
626 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
627 (smerge-match-conflict) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
628 ;;(smerge-ensure-match 1) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
629 (smerge-keep-n 1) |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
630 (smerge-auto-leave)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
631 |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
632 (defun smerge-get-current () |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
633 (let ((i 3)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
634 (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
|
635 (< (point) (match-beginning i)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
636 (>= (point) (match-end i))) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
637 (decf i)) |
54332
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
638 i)) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
639 |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
640 (defun smerge-keep-current () |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
641 "Use the current (under the cursor) version." |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
642 (interactive) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
643 (smerge-match-conflict) |
118715eba3b3
(smerge-check-cache, smerge-check): New var and fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52779
diff
changeset
|
644 (let ((i (smerge-get-current))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
645 (if (<= i 0) (error "Not inside a version") |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
646 (smerge-keep-n i) |
28248
108ba8d61036
(smerge-auto-leave): New function and variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26776
diff
changeset
|
647 (smerge-auto-leave)))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
648 |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
649 (defun smerge-kill-current () |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
650 "Remove the current (under the cursor) version." |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
651 (interactive) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
652 (smerge-match-conflict) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
653 (let ((i (smerge-get-current))) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
654 (if (<= i 0) (error "Not inside a version") |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
655 (let ((left nil)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
656 (dolist (n '(3 2 1)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
657 (if (and (match-end n) (/= (match-end n) (match-end i))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
658 (push n left))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
659 (if (and (cdr left) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
660 (/= (match-end (car left)) (match-end (cadr left)))) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
661 (ding) ;We don't know how to do that. |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
662 (smerge-keep-n (car left)) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
663 (smerge-auto-leave)))))) |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
664 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
665 (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
|
666 "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
|
667 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
668 (smerge-diff 2 1)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
669 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
670 (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
|
671 "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
|
672 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
673 (smerge-diff 2 3)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
674 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
675 (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
|
676 "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
|
677 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
678 (smerge-diff 1 3)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
679 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
680 (defun smerge-match-conflict () |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
681 "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
|
682 The submatches contain: |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
683 0: the whole conflict. |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
684 1: your code. |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
685 2: the base code. |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
686 3: other code. |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
687 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
|
688 (save-excursion |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
689 (condition-case nil |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
690 (let* ((orig-point (point)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
691 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
692 (_ (forward-line 1)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
693 (_ (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
|
694 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
695 (start (match-beginning 0)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
696 (mine-start (match-end 0)) |
47827
9d7b63dcf005
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47821
diff
changeset
|
697 (filename (or (match-string 1) "")) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
698 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
699 (_ (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
|
700 (_ (assert (< orig-point (match-end 0)))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47827
diff
changeset
|
701 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
702 (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
|
703 (end (match-end 0)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
704 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
705 (_ (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
|
706 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
707 (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
|
708 (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
|
709 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
710 base-start base-end) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
711 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
712 ;; 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
|
713 (cond |
54903
922f49230ff5
(smerge-match-conflict): Try to do something sensible
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54872
diff
changeset
|
714 ((save-excursion |
922f49230ff5
(smerge-match-conflict): Try to do something sensible
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54872
diff
changeset
|
715 (goto-char mine-start) |
54904
a23bbf466906
(smerge-match-conflict): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54903
diff
changeset
|
716 (re-search-forward smerge-begin-re end t)) |
54903
922f49230ff5
(smerge-match-conflict): Try to do something sensible
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54872
diff
changeset
|
717 ;; There's a nested conflict and we're after the the beginning |
922f49230ff5
(smerge-match-conflict): Try to do something sensible
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54872
diff
changeset
|
718 ;; of the outer one but before the beginning of the inner one. |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
719 ;; Of course, maybe this is not a nested conflict but in that |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
720 ;; case it can only be something nastier that we don't know how |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
721 ;; to handle, so may as well arbitrarily decide to treat it as |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
722 ;; a nested conflict. --Stef |
54903
922f49230ff5
(smerge-match-conflict): Try to do something sensible
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54872
diff
changeset
|
723 (error "There is a nested conflict")) |
922f49230ff5
(smerge-match-conflict): Try to do something sensible
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54872
diff
changeset
|
724 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
725 ((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
|
726 ;; a 3-parts conflict |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
727 (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
|
728 (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
|
729 (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
|
730 (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
|
731 |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
732 ((string= filename (file-name-nondirectory |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
733 (or buffer-file-name ""))) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
734 ;; a 2-parts conflict |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
735 (set (make-local-variable 'smerge-conflict-style) 'diff3-E)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
736 |
54402
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
737 ((and (not base-start) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
738 (or (eq smerge-conflict-style 'diff3-A) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
739 (equal filename "ANCESTOR") |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
740 (string-match "\\`[.0-9]+\\'" filename))) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
741 ;; a same-diff conflict |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
742 (setq base-start mine-start) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
743 (setq base-end mine-end) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
744 (setq mine-start other-start) |
8bf3846fc7dd
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
54332
diff
changeset
|
745 (setq mine-end other-end))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47827
diff
changeset
|
746 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
747 (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
|
748 mine-start mine-end |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
749 base-start base-end |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
750 other-start other-end |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
751 (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
|
752 (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
|
753 t) |
41064
cdd9ef6f603d
(smerge-match-conflict): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38611
diff
changeset
|
754 (search-failed (error "Point not in conflict region"))))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
755 |
76397
e9b063d17531
(smerge-remove-props): Don't mark the buffer modified.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
756 (add-to-list 'debug-ignored-errors "Point not in conflict region") |
e9b063d17531
(smerge-remove-props): Don't mark the buffer modified.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
757 |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
758 (defun smerge-conflict-overlay (pos) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
759 "Return the conflict overlay at POS if any." |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
760 (let ((ols (overlays-at pos)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
761 conflict) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
762 (dolist (ol ols) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
763 (if (and (eq (overlay-get ol 'smerge) 'conflict) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
764 (> (overlay-end ol) pos)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
765 (setq conflict ol))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
766 conflict)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
767 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
768 (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
|
769 "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
|
770 The submatches are the same as in `smerge-match-conflict'. |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
771 Returns non-nil if a match is found between point and LIMIT. |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
772 Point is moved to the end of the conflict." |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
773 (let ((found nil) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
774 (pos (point)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
775 conflict) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
776 ;; First check to see if point is already inside a conflict, using |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
777 ;; the conflict overlays. |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
778 (while (and (not found) (setq conflict (smerge-conflict-overlay pos))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
779 ;; Check the overlay's validity and kill it if it's out of date. |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
780 (condition-case nil |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
781 (progn |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
782 (goto-char (overlay-start conflict)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
783 (smerge-match-conflict) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
784 (goto-char (match-end 0)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
785 (if (<= (point) pos) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
786 (error "Matching backward!") |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
787 (setq found t))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
788 (error (smerge-remove-props |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
789 (overlay-start conflict) (overlay-end conflict)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
790 (goto-char pos)))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
791 ;; If we're not already inside a conflict, look for the next conflict |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
792 ;; and add/update its overlay. |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
793 (while (and (not found) (re-search-forward smerge-begin-re limit t)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
794 (condition-case nil |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
795 (progn |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
796 (smerge-match-conflict) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
797 (goto-char (match-end 0)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
798 (let ((conflict (smerge-conflict-overlay (1- (point))))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
799 (if conflict |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
800 ;; Update its location, just in case it got messed up. |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
801 (move-overlay conflict (match-beginning 0) (match-end 0)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
802 (setq conflict (make-overlay (match-beginning 0) (match-end 0) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
803 nil 'front-advance nil)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
804 (overlay-put conflict 'evaporate t) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
805 (overlay-put conflict 'smerge 'conflict) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
806 (let ((props smerge-text-properties)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
807 (while props |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
808 (overlay-put conflict (pop props) (pop props)))))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
809 (setq found t)) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
810 (error nil))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
811 found)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
812 |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
813 ;;; Refined change highlighting |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
814 |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
815 (defvar smerge-refine-forward-function 'smerge-refine-forward |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
816 "Function used to determine an \"atomic\" element. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
817 You can set it to `forward-char' to get char-level granularity. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
818 Its behavior has mainly two restrictions: |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
819 - if this function encounters a newline, it's important that it stops right |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
820 after the newline. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
821 This only matters if `smerge-refine-ignore-whitespace' is nil. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
822 - it needs to be unaffected by changes performed by the `preproc' argument |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
823 to `smerge-refine-subst'. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
824 This only matters if `smerge-refine-weight-hack' is nil.") |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
825 |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
826 (defvar smerge-refine-ignore-whitespace t |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
827 "If non-nil,Indicate that smerge-refine should try to ignore change in whitespace.") |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
828 |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
829 (defvar smerge-refine-weight-hack t |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
830 "If non-nil, pass to diff as many lines as there are chars in the region. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
831 I.e. each atomic element (e.g. word) will be copied as many times (on different |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
832 lines) as it has chars. This has 2 advantages: |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
833 - if `diff' tries to minimize the number *lines* (rather than chars) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
834 added/removed, this adjust the weights so that adding/removing long |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
835 symbols is considered correspondingly more costly. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
836 - `smerge-refine-forward-function' only needs to be called when chopping up |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
837 the regions, and `forward-char' can be used afterwards. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
838 It has the following disadvantages: |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
839 - cannot use `diff -w' because the weighting causes added spaces in a line |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
840 to be represented as added copies of some line, so `diff -w' can't do the |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
841 right thing any more. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
842 - may in degenerate cases take a 1KB input region and turn it into a 1MB |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
843 file to pass to diff.") |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
844 |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
845 (defun smerge-refine-forward (n) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
846 (let ((case-fold-search nil) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
847 (re "[[:upper:]]?[[:lower:]]+\\|[[:upper:]]+\\|[[:digit:]]+\\|.\\|\n")) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
848 (when (and smerge-refine-ignore-whitespace |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
849 ;; smerge-refine-weight-hack causes additional spaces to |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
850 ;; appear as additional lines as well, so even if diff ignore |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
851 ;; whitespace changes, it'll report added/removed lines :-( |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
852 (not smerge-refine-weight-hack)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
853 (setq re (concat "[ \t]*\\(?:" re "\\)"))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
854 (dotimes (i n) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
855 (unless (looking-at re) (error "Smerge refine internal error")) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
856 (goto-char (match-end 0))))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
857 |
85099
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
858 (defun smerge-refine-chopup-region (beg end file &optional preproc) |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
859 "Chopup the region into small elements, one per line. |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
860 Save the result into FILE. |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
861 If non-nil, PREPROC is called with no argument in a buffer that contains |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
862 a copy of the text, just before chopping it up. It can be used to replace |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
863 chars to try and eliminate some spurious differences." |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
864 ;; We used to chop up char-by-char rather than word-by-word like ediff |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
865 ;; does. It had the benefit of simplicity and very fine results, but it |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
866 ;; often suffered from problem that diff would find correlations where |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
867 ;; there aren't any, so the resulting "change" didn't make much sense. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
868 ;; You can still get this behavior by setting |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
869 ;; `smerge-refine-forward-function' to `forward-char'. |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
870 (let ((buf (current-buffer))) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
871 (with-temp-buffer |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
872 (insert-buffer-substring buf beg end) |
85099
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
873 (when preproc (goto-char (point-min)) (funcall preproc)) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
874 (when smerge-refine-ignore-whitespace |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
875 ;; It doesn't make much of a difference for diff-fine-highlight |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
876 ;; because we still have the _/+/</>/! prefix anyway. Can still be |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
877 ;; useful in other circumstances. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
878 (subst-char-in-region (point-min) (point-max) ?\n ?\s)) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
879 (goto-char (point-min)) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
880 (while (not (eobp)) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
881 (funcall smerge-refine-forward-function 1) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
882 (let ((s (if (prog2 (forward-char -1) (bolp) (forward-char 1)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
883 nil |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
884 (buffer-substring (line-beginning-position) (point))))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
885 ;; We add \n after each char except after \n, so we get |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
886 ;; one line per text char, where each line contains |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
887 ;; just one char, except for \n chars which are |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
888 ;; represented by the empty line. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
889 (unless (eq (char-before) ?\n) (insert ?\n)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
890 ;; HACK ALERT!! |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
891 (if smerge-refine-weight-hack |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
892 (dotimes (i (1- (length s))) (insert s "\n"))))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
893 (unless (bolp) (error "Smerge refine internal error")) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
894 (let ((coding-system-for-write 'emacs-mule)) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
895 (write-region (point-min) (point-max) file nil 'nomessage))))) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
896 |
85099
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
897 (defun smerge-refine-highlight-change (buf beg match-num1 match-num2 props) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
898 (with-current-buffer buf |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
899 (goto-char beg) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
900 (let* ((startline (- (string-to-number match-num1) 1)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
901 (beg (progn (funcall (if smerge-refine-weight-hack |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
902 'forward-char |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
903 smerge-refine-forward-function) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
904 startline) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
905 (point))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
906 (end (progn (funcall (if smerge-refine-weight-hack |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
907 'forward-char |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
908 smerge-refine-forward-function) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
909 (if match-num2 |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
910 (- (string-to-number match-num2) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
911 startline) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
912 1)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
913 (point)))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
914 (when smerge-refine-ignore-whitespace |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
915 (skip-chars-backward " \t\n" beg) (setq end (point)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
916 (goto-char beg) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
917 (skip-chars-forward " \t\n" end) (setq beg (point))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
918 (when (> end beg) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
919 (let ((ol (make-overlay |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
920 beg end nil |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
921 ;; Make them tend to shrink rather than spread when editing. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
922 'front-advance nil))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
923 (overlay-put ol 'evaporate t) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
924 (dolist (x props) (overlay-put ol (car x) (cdr x))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
925 ol))))) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
926 |
85099
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
927 (defun smerge-refine-subst (beg1 end1 beg2 end2 props &optional preproc) |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
928 "Show fine differences in the two regions BEG1..END1 and BEG2..END2. |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
929 PROPS is an alist of properties to put (via overlays) on the changes. |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
930 If non-nil, PREPROC is called with no argument in a buffer that contains |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
931 a copy of a region, just before preparing it to for `diff'. It can be used to |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
932 replace chars to try and eliminate some spurious differences." |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
933 (let* ((buf (current-buffer)) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
934 (pos (point)) |
85099
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
935 (file1 (make-temp-file "diff1")) |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
936 (file2 (make-temp-file "diff2"))) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
937 ;; Chop up regions into smaller elements and save into files. |
85099
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
938 (smerge-refine-chopup-region beg1 end1 file1 preproc) |
ccdbfad065e3
(smerge-refine-chopup-region): Add `preproc' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78572
diff
changeset
|
939 (smerge-refine-chopup-region beg2 end2 file2 preproc) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
940 |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
941 ;; Call diff on those files. |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
942 (unwind-protect |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
943 (with-temp-buffer |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
944 (let ((coding-system-for-read 'emacs-mule)) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
945 (call-process diff-command nil t nil |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
946 (if (and smerge-refine-ignore-whitespace |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
947 (not smerge-refine-weight-hack)) |
85965
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
948 ;; Pass -a so diff treats it as a text file even |
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
949 ;; if it contains \0 and such. |
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
950 ;; Pass -d so as to get the smallest change, but |
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
951 ;; also and more importantly because otherwise it |
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
952 ;; may happen that diff doesn't behave like |
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
953 ;; smerge-refine-weight-hack expects it to. |
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
954 ;; See http://thread.gmane.org/gmane.emacs.devel/82685. |
ac6bbbd64b2f
(smerge-refine-subst): Pass "-d" to diff.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85478
diff
changeset
|
955 "-awd" "-ad") |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
956 file1 file2)) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
957 ;; Process diff's output. |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
958 (goto-char (point-min)) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
959 (let ((last1 nil) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
960 (last2 nil)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
961 (while (not (eobp)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
962 (if (not (looking-at "\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?\\([acd]\\)\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?$")) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
963 (error "Unexpected patch hunk header: %s" |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
964 (buffer-substring (point) (line-end-position)))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
965 (let ((op (char-after (match-beginning 3))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
966 (m1 (match-string 1)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
967 (m2 (match-string 2)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
968 (m4 (match-string 4)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
969 (m5 (match-string 5))) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
970 (when (memq op '(?d ?c)) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
971 (setq last1 |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
972 (smerge-refine-highlight-change buf beg1 m1 m2 props))) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
973 (when (memq op '(?a ?c)) |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
974 (setq last2 |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
975 (smerge-refine-highlight-change buf beg2 m4 m5 props)))) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
976 (forward-line 1) ;Skip hunk header. |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
977 (and (re-search-forward "^[0-9]" nil 'move) ;Skip hunk body. |
85443
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
978 (goto-char (match-beginning 0)))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
979 ;; (assert (or (null last1) (< (overlay-start last1) end1))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
980 ;; (assert (or (null last2) (< (overlay-start last2) end2))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
981 (if smerge-refine-weight-hack |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
982 (progn |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
983 ;; (assert (or (null last1) (<= (overlay-end last1) end1))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
984 ;; (assert (or (null last2) (<= (overlay-end last2) end2))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
985 ) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
986 ;; smerge-refine-forward-function when calling in chopup may |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
987 ;; have stopped because it bumped into EOB whereas in |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
988 ;; smerge-refine-weight-hack it may go a bit further. |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
989 (if (and last1 (> (overlay-end last1) end1)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
990 (move-overlay last1 (overlay-start last1) end1)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
991 (if (and last2 (> (overlay-end last2) end2)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
992 (move-overlay last2 (overlay-start last2) end2)) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
993 ))) |
13cb05eb9f29
Add word-granularity refinement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85099
diff
changeset
|
994 (goto-char pos) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
995 (delete-file file1) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
996 (delete-file file2)))) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
997 |
93442
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
998 (defun smerge-refine (&optional part) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
999 "Highlight the words of the conflict that are different. |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1000 For 3-way conflicts, highlights only 2 of the 3 parts. |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1001 A numeric argument PART can be used to specify which 2 parts; |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1002 repeating the command will highlight other 2 parts." |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1003 (interactive |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1004 (if (integerp current-prefix-arg) (list current-prefix-arg) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1005 (smerge-match-conflict) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1006 (let* ((prop (get-text-property (match-beginning 0) 'smerge-refine-part)) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1007 (part (if (and (consp prop) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1008 (eq (buffer-chars-modified-tick) (car prop))) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1009 (cdr prop)))) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1010 ;; If already highlighted, cycle. |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1011 (list (if (integerp part) (1+ (mod part 3))))))) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1012 |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1013 (if (and (integerp part) (or (< part 1) (> part 3))) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1014 (error "No conflict part nb %s" part)) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
1015 (smerge-match-conflict) |
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
1016 (remove-overlays (match-beginning 0) (match-end 0) 'smerge 'refine) |
93442
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1017 ;; Ignore `part' if not applicable, and default it if not provided. |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1018 (setq part (cond ((null (match-end 2)) 2) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1019 ((eq (match-end 1) (match-end 3)) 1) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1020 ((integerp part) part) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1021 (t 2))) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1022 (let ((n1 (if (eq part 1) 2 1)) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1023 (n2 (if (eq part 3) 2 3))) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1024 (smerge-ensure-match n1) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1025 (smerge-ensure-match n2) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1026 (put-text-property (match-beginning 0) (1+ (match-beginning 0)) |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1027 'smerge-refine-part |
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1028 (cons (buffer-chars-modified-tick) part)) |
87767
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1029 (smerge-refine-subst (match-beginning n1) (match-end n1) |
93442
a6d8268a0da6
(smerge-refine): Allow highlighting other subparts in 3-way conflicts.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91813
diff
changeset
|
1030 (match-beginning n2) (match-end n2) |
87767
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1031 '((smerge . refine) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1032 (face . smerge-refined-change))))) |
65129
8303172e4c68
(smerge-remove-props): Make the args non-optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65067
diff
changeset
|
1033 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1034 (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
|
1035 (smerge-match-conflict) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1036 (smerge-ensure-match n1) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1037 (smerge-ensure-match n2) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1038 (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
|
1039 (name2 (aref smerge-match-names n2)) |
41064
cdd9ef6f603d
(smerge-match-conflict): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38611
diff
changeset
|
1040 ;; Read them before the match-data gets clobbered. |
cdd9ef6f603d
(smerge-match-conflict): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38611
diff
changeset
|
1041 (beg1 (match-beginning n1)) |
cdd9ef6f603d
(smerge-match-conflict): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38611
diff
changeset
|
1042 (end1 (match-end n1)) |
cdd9ef6f603d
(smerge-match-conflict): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38611
diff
changeset
|
1043 (beg2 (match-beginning n2)) |
cdd9ef6f603d
(smerge-match-conflict): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38611
diff
changeset
|
1044 (end2 (match-end n2)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1045 (file1 (make-temp-file "smerge1")) |
32217
44f7f2635fec
(smerge-diff): Setup the buffer's default-directory
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32164
diff
changeset
|
1046 (file2 (make-temp-file "smerge2")) |
44f7f2635fec
(smerge-diff): Setup the buffer's default-directory
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32164
diff
changeset
|
1047 (dir default-directory) |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1048 (file (if buffer-file-name (file-relative-name buffer-file-name))) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1049 ;; We would want to use `emacs-mule-unix' for read&write, but we |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1050 ;; bump into problems with the coding-system used by diff to write |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1051 ;; the file names and the time stamps in the header. |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1052 ;; `buffer-file-coding-system' is not always correct either, but if |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1053 ;; the OS/user uses only one coding-system, then it works. |
41064
cdd9ef6f603d
(smerge-match-conflict): Fix typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38611
diff
changeset
|
1054 (coding-system-for-read buffer-file-coding-system)) |
47209
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1055 (write-region beg1 end1 file1 nil 'nomessage) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1056 (write-region beg2 end2 file2 nil 'nomessage) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1057 (unwind-protect |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1058 (with-current-buffer (get-buffer-create smerge-diff-buffer-name) |
32217
44f7f2635fec
(smerge-diff): Setup the buffer's default-directory
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32164
diff
changeset
|
1059 (setq default-directory dir) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1060 (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
|
1061 (erase-buffer) |
47209
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1062 (let ((status |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1063 (apply 'call-process diff-command nil t nil |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1064 (append smerge-diff-switches |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1065 (list "-L" (concat name1 "/" file) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1066 "-L" (concat name2 "/" file) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1067 file1 file2))))) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1068 (if (eq status 0) (insert "No differences found.\n")))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1069 (goto-char (point-min)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1070 (diff-mode) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1071 (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
|
1072 (delete-file file1) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1073 (delete-file file2)))) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1074 |
47209
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1075 ;; compiler pacifiers |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1076 (defvar smerge-ediff-windows) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1077 (defvar smerge-ediff-buf) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1078 (defvar ediff-buffer-A) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1079 (defvar ediff-buffer-B) |
f06f993cfd92
(smerge-diff-buffer-name): Default to *vc-diff*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46899
diff
changeset
|
1080 (defvar ediff-buffer-C) |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1081 (defvar ediff-ancestor-buffer) |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1082 (defvar ediff-quit-hook) |
86234
860a7a8e779e
* progmodes/octave-mod.el (inferior-octave-send-list-and-digest):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85965
diff
changeset
|
1083 (declare-function ediff-cleanup-mess "ediff-util" nil) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1084 |
47821
45dcf3407814
(smerge-ediff): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47756
diff
changeset
|
1085 ;;;###autoload |
47756
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1086 (defun smerge-ediff (&optional name-mine name-other name-base) |
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1087 "Invoke ediff to resolve the conflicts. |
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1088 NAME-MINE, NAME-OTHER, and NAME-BASE, if non-nil, are used for the |
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1089 buffer names." |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1090 (interactive) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1091 (let* ((buf (current-buffer)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1092 (mode major-mode) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1093 ;;(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
|
1094 (config (current-window-configuration)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1095 (filename (file-name-nondirectory buffer-file-name)) |
47756
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1096 (mine (generate-new-buffer |
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1097 (or name-mine (concat "*" filename " MINE*")))) |
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1098 (other (generate-new-buffer |
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1099 (or name-other (concat "*" filename " OTHER*")))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1100 base) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1101 (with-current-buffer mine |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1102 (buffer-disable-undo) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1103 (insert-buffer-substring buf) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1104 (goto-char (point-min)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1105 (while (smerge-find-conflict) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1106 (when (match-beginning 2) (setq base t)) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
1107 (smerge-keep-n 1)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1108 (buffer-enable-undo) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1109 (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
|
1110 (funcall mode)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1111 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1112 (with-current-buffer other |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1113 (buffer-disable-undo) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1114 (insert-buffer-substring buf) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1115 (goto-char (point-min)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1116 (while (smerge-find-conflict) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
1117 (smerge-keep-n 3)) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1118 (buffer-enable-undo) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1119 (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
|
1120 (funcall mode)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47827
diff
changeset
|
1121 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1122 (when base |
47756
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1123 (setq base (generate-new-buffer |
b2c9ea334a34
(smerge-ediff): Add name-{mine,other,base} args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47209
diff
changeset
|
1124 (or name-base (concat "*" filename " BASE*")))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1125 (with-current-buffer base |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1126 (buffer-disable-undo) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1127 (insert-buffer-substring buf) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1128 (goto-char (point-min)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1129 (while (smerge-find-conflict) |
54527
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
1130 (if (match-end 2) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
1131 (smerge-keep-n 2) |
192fc783e115
(smerge-mode-menu): Fix activate pred for resolve.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54410
diff
changeset
|
1132 (delete-region (match-beginning 0) (match-end 0)))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1133 (buffer-enable-undo) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1134 (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
|
1135 (funcall mode))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47827
diff
changeset
|
1136 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1137 ;; 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
|
1138 ;; Fire up ediff. |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1139 (set-buffer |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1140 (if base |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1141 (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
|
1142 ;; 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
|
1143 (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
|
1144 ;; nil 'ediff-merge-revisions buffer-file-name))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47827
diff
changeset
|
1145 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1146 ;; 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
|
1147 ;; 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
|
1148 (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
|
1149 (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
|
1150 (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
|
1151 (lambda () |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1152 (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
|
1153 (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
|
1154 (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
|
1155 (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
|
1156 (buf smerge-ediff-buf) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1157 (windows smerge-ediff-windows)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1158 (ediff-cleanup-mess) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1159 (with-current-buffer buf |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1160 (erase-buffer) |
64637
a975a8beec7f
(smerge-ediff): Use insert-buffer-substring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64091
diff
changeset
|
1161 (insert-buffer-substring buffer-C) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1162 (kill-buffer buffer-A) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1163 (kill-buffer buffer-B) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1164 (kill-buffer buffer-C) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1165 (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
|
1166 (set-window-configuration windows) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1167 (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
|
1168 (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
|
1169 |
87767
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1170 (defun smerge-makeup-conflict (pt1 pt2 pt3 &optional pt4) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1171 "Insert diff3 markers to make a new conflict. |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1172 Uses point and mark for 2 of the relevant positions and previous marks |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1173 for the other ones. |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1174 By default, makes up a 2-way conflict, |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1175 with a \\[universal-argument] prefix, makes up a 3-way conflict." |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1176 (interactive |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1177 (list (point) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1178 (mark) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1179 (progn (pop-mark) (mark)) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1180 (when current-prefix-arg (pop-mark) (mark)))) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1181 ;; Start from the end so as to avoid problems with pos-changes. |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1182 (destructuring-bind (pt1 pt2 pt3 &optional pt4) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1183 (sort (list* pt1 pt2 pt3 (if pt4 (list pt4))) '>=) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1184 (goto-char pt1) (beginning-of-line) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1185 (insert ">>>>>>> OTHER\n") |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1186 (goto-char pt2) (beginning-of-line) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1187 (insert "=======\n") |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1188 (goto-char pt3) (beginning-of-line) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1189 (when pt4 |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1190 (insert "||||||| BASE\n") |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1191 (goto-char pt4) (beginning-of-line)) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1192 (insert "<<<<<<< MINE\n")) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1193 (if smerge-mode nil (smerge-mode 1)) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1194 (smerge-refine)) |
90318261ac4d
(smerge-refine): Also work on "same change conflicts".
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87743
diff
changeset
|
1195 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1196 |
78572
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1197 (defconst smerge-parsep-re |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1198 (concat smerge-begin-re "\\|" smerge-end-re "\\|" |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1199 smerge-base-re "\\|" smerge-other-re "\\|")) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1200 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1201 ;;;###autoload |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1202 (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
|
1203 "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
|
1204 \\{smerge-mode-map}" |
61277
7fa982932904
(smerge-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents:
55258
diff
changeset
|
1205 :group 'smerge :lighter " SMerge" |
38611
7f82c0bbe525
(smerge-mode): Check if `font-lock-mode' is bound
Gerd Moellmann <gerd@gnu.org>
parents:
37674
diff
changeset
|
1206 (when (and (boundp 'font-lock-mode) font-lock-mode) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1207 (save-excursion |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1208 (if smerge-mode |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1209 (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
|
1210 (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
|
1211 (goto-char (point-min)) |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1212 (while (smerge-find-conflict) |
34842
f05ec8dfc452
(smerge-basic-map): Use `=' rather than `d'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34840
diff
changeset
|
1213 (save-excursion |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1214 (font-lock-fontify-region (match-beginning 0) (match-end 0) nil))))) |
78572
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1215 (if (string-match (regexp-quote smerge-parsep-re) paragraph-separate) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1216 (unless smerge-mode |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1217 (set (make-local-variable 'paragraph-separate) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1218 (replace-match "" t t paragraph-separate))) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1219 (when smerge-mode |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1220 (set (make-local-variable 'paragraph-separate) |
5b92bb6e6570
(smerge-resolve): New arg `safe'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78236
diff
changeset
|
1221 (concat smerge-parsep-re paragraph-separate)))) |
65067
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1222 (unless smerge-mode |
52de8046c483
(smerge-basic-map): Bind smerge-combine-with-next.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
1223 (smerge-remove-props (point-min) (point-max)))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1224 |
87743
c2a952d12e21
* smerge-mode.el (smerge-auto): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87649
diff
changeset
|
1225 ;;;###autoload |
87785
8f1628da223f
* smerge-mode.el (smerge-start-session): Rename from smerge-auto.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87767
diff
changeset
|
1226 (defun smerge-start-session () |
87743
c2a952d12e21
* smerge-mode.el (smerge-auto): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87649
diff
changeset
|
1227 "Turn on `smerge-mode' and move point to first conflict marker. |
c2a952d12e21
* smerge-mode.el (smerge-auto): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87649
diff
changeset
|
1228 If no conflict maker is found, turn off `smerge-mode'." |
c2a952d12e21
* smerge-mode.el (smerge-auto): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87649
diff
changeset
|
1229 (smerge-mode 1) |
c2a952d12e21
* smerge-mode.el (smerge-auto): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87649
diff
changeset
|
1230 (condition-case nil |
94865
f413ee341af0
(smerge-start-session): Revert unintended change in revision 1.69.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
94862
diff
changeset
|
1231 (unless (looking-at smerge-begin-re) |
f413ee341af0
(smerge-start-session): Revert unintended change in revision 1.69.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
94862
diff
changeset
|
1232 (smerge-next)) |
87743
c2a952d12e21
* smerge-mode.el (smerge-auto): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87649
diff
changeset
|
1233 (error (smerge-auto-leave)))) |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1234 |
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1235 (provide 'smerge-mode) |
52401 | 1236 |
54903
922f49230ff5
(smerge-match-conflict): Try to do something sensible
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54872
diff
changeset
|
1237 ;; arch-tag: 605c8d1e-e43d-4943-a6f3-1bcc4333e690 |
26776
142d6aa7c470
New file. Provides a simple minor-mode for files containing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1238 ;;; smerge-mode.el ends here |