Mercurial > emacs
annotate lisp/ediff-merg.el @ 31874:8db5d996cfdb
Fix typo in __GNUC_MINOR__.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 25 Sep 2000 14:25:02 +0000 |
parents | 3ec5a485d0ab |
children | 6306740f6938 |
rev | line source |
---|---|
11042 | 1 ;;; ediff-merg.el --- merging utilities |
14169 | 2 |
18054 | 3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
11042 | 4 |
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
14169 | 20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
11042 | 23 |
14169 | 24 ;;; Code: |
11042 | 25 |
18054 | 26 (provide 'ediff-merg) |
27 | |
28 ;; compiler pacifier | |
29 (defvar ediff-window-A) | |
30 (defvar ediff-window-B) | |
31 (defvar ediff-window-C) | |
32 (defvar ediff-merge-window-share) | |
33 (defvar ediff-window-config-saved) | |
34 | |
35 (eval-when-compile | |
36 (let ((load-path (cons (expand-file-name ".") load-path))) | |
37 (or (featurep 'ediff-init) | |
38 (load "ediff-init.el" nil nil 'nosuffix)) | |
39 (or (featurep 'ediff-util) | |
40 (load "ediff-util.el" nil nil 'nosuffix)) | |
41 )) | |
42 ;; end pacifier | |
43 | |
11042 | 44 (require 'ediff-init) |
45 | |
18839 | 46 (defcustom ediff-quit-merge-hook 'ediff-maybe-save-and-delete-merge |
47 "*Hooks to run before quitting a merge job. | |
48 The most common use is to save and delete the merge buffer." | |
49 :type 'hook | |
50 :group 'ediff-merge) | |
51 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
52 |
18054 | 53 (defcustom ediff-default-variant 'combined |
11042 | 54 "*The variant to be used as a default for buffer C in merging. |
18054 | 55 Valid values are the symbols `default-A', `default-B', and `combined'." |
56 :type '(radio (const default-A) (const default-B) (const combined)) | |
57 :group 'ediff-merge) | |
11042 | 58 |
18054 | 59 (defcustom ediff-combination-pattern |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
60 '("<<<<<<< variant A" A ">>>>>>> variant B" B "####### Ancestor" Ancestor "======= end") |
11042 | 61 "*Pattern to be used for combining difference regions in buffers A and B. |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
62 The value must be a list of the form |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
63 (STRING1 bufspec1 STRING2 bufspec2 STRING3 bufspec3 STRING4) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
64 where bufspec is the symbol A, B, or Ancestor. For instance, if the value is |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
65 '(STRING1 A STRING2 Ancestor STRING3 B STRING4) then the |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
66 combined text will look like this: |
11042 | 67 |
68 STRING1 | |
69 diff region from variant A | |
70 STRING2 | |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
71 diff region from the ancestor |
11042 | 72 STRING3 |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
73 diff region from variant B |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
74 STRING4 |
18054 | 75 " |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
76 :type '(choice (list string symbol string symbol string) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
77 (list string symbol string symbol string symbol string)) |
18054 | 78 :group 'ediff-merge) |
11042 | 79 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
80 (defcustom ediff-show-clashes-only nil |
11042 | 81 "*If t, show only those diff regions where both buffers disagree with the ancestor. |
82 This means that regions that have status prefer-A or prefer-B will be | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
83 skiped over. Nil means show all regions." |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
84 :type 'boolean |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
85 :group 'ediff-merge |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
86 ) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
87 (make-variable-buffer-local 'ediff-show-clashes-only) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
88 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
89 (defcustom ediff-skip-merge-regions-that-differ-from-default nil |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
90 "*If t, show only the regions that have not been changed by the user. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
91 A region is considered to have been changed if it is different from the current |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
92 default (`default-A', `default-B', `combined') and it hasn't been marked as |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
93 `prefer-A' or `prefer-B'. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
94 A region is considered to have been changed also when it is marked as |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
95 as `prefer-A', but is different from the corresponding difference region in |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
96 Buffer A or if it is marked as `prefer-B' and is different from the region in |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
97 Buffer B." |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
98 :type 'boolean |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
99 :group 'ediff-merge |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
100 ) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
101 (make-variable-buffer-local 'ediff-skip-merge-regions-that-differ-from-default) |
11042 | 102 |
20003 | 103 ;; If ediff-show-clashes-only, check if there is no clash between the ancestor |
104 ;; and one of the variants. | |
105 (defsubst ediff-merge-region-is-non-clash (n) | |
106 (and ediff-show-clashes-only | |
107 (string-match "prefer" (or (ediff-get-state-of-merge n) "")))) | |
108 | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
109 ;; If ediff-skip-changed-regions, check if the merge region differs from |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
110 ;; the current default. If a region is different from the default, it means |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
111 ;; that the user has made determination as to how to merge for this particular |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
112 ;; region. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
113 (defsubst ediff-skip-merge-region-if-changed-from-default-p (n) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
114 (and ediff-skip-merge-regions-that-differ-from-default |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
115 (ediff-merge-changed-from-default-p n 'prefers-too))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
116 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
117 |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
118 (defun ediff-get-combined-region (n) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
119 (let ((pattern-list ediff-combination-pattern) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
120 (combo-region "") |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
121 (err-msg |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
122 "ediff-combination-pattern: Invalid format. Please consult the documentation") |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
123 diff-region region-delim region-spec) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
124 |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
125 (if (< (length pattern-list) 5) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
126 (error err-msg)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
127 |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
128 (while (> (length pattern-list) 2) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
129 (setq region-delim (nth 0 pattern-list) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
130 region-spec (nth 1 pattern-list)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
131 (or (and (stringp region-delim) (memq region-spec '(A B Ancestor))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
132 (error err-msg)) |
13216
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
133 |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
134 (condition-case err |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
135 (setq combo-region |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
136 (concat combo-region |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
137 region-delim "\n" |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
138 (ediff-get-region-contents |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
139 n region-spec ediff-control-buffer))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
140 (error "")) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
141 (setq pattern-list (cdr (cdr pattern-list))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
142 ) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
143 |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
144 (setq region-delim (nth 0 pattern-list)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
145 (or (stringp region-delim) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
146 (error err-msg)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
147 (setq combo-region (concat combo-region region-delim "\n")) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
148 )) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
149 |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
150 ;;(defsubst ediff-make-combined-diff (regA regB) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
151 ;; (concat (nth 0 ediff-combination-pattern) "\n" |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
152 ;; regA |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
153 ;; (nth 1 ediff-combination-pattern) "\n" |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
154 ;; regB |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
155 ;; (nth 2 ediff-combination-pattern) "\n")) |
13216
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
156 |
11042 | 157 (defsubst ediff-set-state-of-all-diffs-in-all-buffers (ctl-buf) |
158 (let ((n 0)) | |
159 (while (< n ediff-number-of-differences) | |
160 (ediff-set-state-of-diff-in-all-buffers n ctl-buf) | |
161 (setq n (1+ n))))) | |
162 | |
163 (defun ediff-set-state-of-diff-in-all-buffers (n ctl-buf) | |
164 (let ((regA (ediff-get-region-contents n 'A ctl-buf)) | |
165 (regB (ediff-get-region-contents n 'B ctl-buf)) | |
166 (regC (ediff-get-region-contents n 'C ctl-buf))) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
167 (cond ((and (string= regA regB) (string= regA regC)) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
168 (ediff-set-state-of-diff n 'A "=diff(B)") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
169 (ediff-set-state-of-diff n 'B "=diff(C)") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
170 (ediff-set-state-of-diff n 'C "=diff(A)")) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
171 ((string= regA regB) |
11042 | 172 (ediff-set-state-of-diff n 'A "=diff(B)") |
173 (ediff-set-state-of-diff n 'B "=diff(A)") | |
174 (ediff-set-state-of-diff n 'C nil)) | |
175 ((string= regA regC) | |
176 (ediff-set-state-of-diff n 'A "=diff(C)") | |
177 (ediff-set-state-of-diff n 'C "=diff(A)") | |
178 (ediff-set-state-of-diff n 'B nil)) | |
179 ((string= regB regC) | |
180 (ediff-set-state-of-diff n 'C "=diff(B)") | |
181 (ediff-set-state-of-diff n 'B "=diff(C)") | |
182 (ediff-set-state-of-diff n 'A nil)) | |
183 ((string= regC (ediff-get-combined-region n)) | |
184 (ediff-set-state-of-diff n 'A nil) | |
185 (ediff-set-state-of-diff n 'B nil) | |
186 (ediff-set-state-of-diff n 'C "=diff(A+B)")) | |
187 (t (ediff-set-state-of-diff n 'A nil) | |
188 (ediff-set-state-of-diff n 'B nil) | |
189 (ediff-set-state-of-diff n 'C nil))) | |
190 )) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
191 |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
192 (defun ediff-set-merge-mode () |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
193 (normal-mode t) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
194 (remove-hook 'local-write-file-hooks 'ediff-set-merge-mode)) |
13129
9d432c26c3a7
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12167
diff
changeset
|
195 |
11042 | 196 |
197 ;; Go over all diffs starting with DIFF-NUM and copy regions into buffer C | |
198 ;; according to the state of the difference. | |
199 ;; Since ediff-copy-diff refuses to copy identical diff regions, there is | |
200 ;; no need to optimize ediff-do-merge any further. | |
201 ;; | |
202 ;; If re-merging, change state of merge in all diffs starting with | |
203 ;; DIFF-NUM, except those where the state is prefer-* or where it is | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
204 ;; `default-*' or `combined' but the buf C region appears to be modified |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
205 ;; since last set by default. |
11042 | 206 (defun ediff-do-merge (diff-num &optional remerging) |
207 (if (< diff-num 0) (setq diff-num 0)) | |
208 (let ((n diff-num) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
209 ;;(default-state-of-merge (format "%S" ediff-default-variant)) |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
210 do-not-copy state-of-merge) |
11042 | 211 (while (< n ediff-number-of-differences) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
212 (setq do-not-copy nil) ; reset after each cycle |
11042 | 213 (if (= (mod n 10) 0) |
214 (message "%s buffers A & B into C ... region %d of %d" | |
215 (if remerging "Re-merging" "Merging") | |
216 n | |
217 ediff-number-of-differences)) | |
218 | |
219 (setq state-of-merge (ediff-get-state-of-merge n)) | |
220 | |
221 (if remerging | |
222 (let ((reg-A (ediff-get-region-contents n 'A ediff-control-buffer)) | |
223 (reg-B (ediff-get-region-contents n 'B ediff-control-buffer)) | |
224 (reg-C (ediff-get-region-contents n 'C ediff-control-buffer))) | |
225 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
226 ;; if region was edited since it was first set by default |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
227 (if (or (ediff-merge-changed-from-default-p n) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
228 ;; was preferred |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
229 (string-match "prefer" state-of-merge)) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
230 ;; then ignore |
11042 | 231 (setq do-not-copy t)) |
232 | |
233 ;; change state of merge for this diff, if necessary | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
234 (if (and (string-match "\\(default\\|combined\\)" state-of-merge) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
235 (not do-not-copy)) |
11042 | 236 (ediff-set-state-of-merge |
237 n (format "%S" ediff-default-variant))) | |
238 )) | |
239 | |
240 ;; state-of-merge may have changed via ediff-set-state-of-merge, so | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
241 ;; check it once again |
11042 | 242 (setq state-of-merge (ediff-get-state-of-merge n)) |
243 | |
244 (or do-not-copy | |
245 (if (string= state-of-merge "combined") | |
246 ;; use n+1 because ediff-combine-diffs works via user numbering | |
247 ;; of diffs, which is 1+ to what ediff uses internally | |
248 (ediff-combine-diffs (1+ n) 'batch) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
249 (ediff-copy-diff |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
250 n (if (string-match "-A" state-of-merge) 'A 'B) 'C 'batch))) |
11042 | 251 (setq n (1+ n))) |
252 (message "Merging buffers A & B into C ... Done") | |
253 )) | |
254 | |
255 | |
256 (defun ediff-re-merge () | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
257 "Remerge unmodified diff regions using a new default. Start with the current region." |
11042 | 258 (interactive) |
259 (let* ((default-variant-alist | |
260 (list '("default-A") '("default-B") '("combined"))) | |
261 (actual-alist | |
262 (delete (list (symbol-name ediff-default-variant)) | |
263 default-variant-alist))) | |
264 (setq ediff-default-variant | |
265 (intern | |
266 (completing-read | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
267 (format "Current merge default is `%S'. New default: " |
11042 | 268 ediff-default-variant) |
269 actual-alist nil 'must-match))) | |
270 (ediff-do-merge ediff-current-difference 'remerge) | |
271 (ediff-recenter) | |
272 )) | |
273 | |
274 (defun ediff-shrink-window-C (arg) | |
275 "Shrink window C to just one line. | |
276 With a prefix argument, returns window C to its normal size. | |
277 Used only for merging jobs." | |
278 (interactive "P") | |
279 (if (not ediff-merge-job) | |
280 (error "ediff-shrink-window-C can be used only for merging jobs")) | |
281 (cond ((eq arg '-) (setq arg -1)) | |
282 ((not (numberp arg)) (setq arg nil))) | |
283 (cond ((null arg) | |
284 (let ((ediff-merge-window-share | |
285 (if (< (window-height ediff-window-C) 3) | |
286 ediff-merge-window-share 0))) | |
287 (setq ediff-window-config-saved "") ; force redisplay | |
288 (ediff-recenter 'no-rehighlight))) | |
289 ((and (< arg 0) (> (window-height ediff-window-C) 2)) | |
290 (setq ediff-merge-window-share (* ediff-merge-window-share 0.9)) | |
291 (setq ediff-window-config-saved "") ; force redisplay | |
292 (ediff-recenter 'no-rehighlight)) | |
293 ((and (> arg 0) (> (window-height ediff-window-A) 2)) | |
294 (setq ediff-merge-window-share (* ediff-merge-window-share 1.1)) | |
295 (setq ediff-window-config-saved "") ; force redisplay | |
296 (ediff-recenter 'no-rehighlight)))) | |
297 | |
298 | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
299 ;; N here is the user's region number. It is 1+ what Ediff uses internally. |
11042 | 300 (defun ediff-combine-diffs (n &optional batch-invocation) |
301 "Combine Nth diff regions of buffers A and B and place the combination in C. | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
302 N is a prefix argument. If nil, combine the current difference regions. |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
303 Combining is done according to the specifications in variable |
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
304 `ediff-combination-pattern'." |
11042 | 305 (interactive "P") |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
306 (setq n (if (numberp n) (1- n) ediff-current-difference)) |
11042 | 307 |
308 (let (regA regB reg-combined) | |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
309 ;;(setq regA (ediff-get-region-contents n 'A ediff-control-buffer) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
310 ;; regB (ediff-get-region-contents n 'B ediff-control-buffer)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
311 ;;(setq reg-combined (ediff-make-combined-diff regA regB)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
312 (setq reg-combined (ediff-get-combined-region n)) |
11042 | 313 |
314 (ediff-copy-diff n nil 'C batch-invocation reg-combined)) | |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
315 (or batch-invocation (ediff-jump-to-difference (1+ n)))) |
11042 | 316 |
317 | |
318 ;; Checks if the region in buff C looks like a combination of the regions | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
319 ;; in buffers A and B. Return a list (reg-a-beg reg-a-end reg-b-beg reg-b-end) |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
320 ;; These refer to where the delimiters for region A, B, Ancestor start and end |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
321 ;; in buffer C |
11042 | 322 (defun ediff-looks-like-combined-merge (region-num) |
323 (if ediff-merge-job | |
324 (let ((combined (string-match (regexp-quote "(A+B)") | |
325 (or (ediff-get-state-of-diff region-num 'C) | |
326 ""))) | |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
327 (mrgreg-beg (ediff-get-diff-posn 'C 'beg region-num)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
328 (mrgreg-end (ediff-get-diff-posn 'C 'end region-num)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
329 (pattern-list ediff-combination-pattern) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
330 delim reg-beg reg-end delim-regs-list) |
11042 | 331 |
332 (if combined | |
19047 | 333 (ediff-with-current-buffer ediff-buffer-C |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
334 (while pattern-list |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
335 (goto-char mrgreg-beg) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
336 (setq delim (nth 0 pattern-list)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
337 (search-forward delim mrgreg-end 'noerror) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
338 (setq reg-beg (match-beginning 0)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
339 (setq reg-end (match-end 0)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
340 (if (and reg-beg reg-end) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
341 (setq delim-regs-list |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
342 ;; in reverse |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
343 (cons reg-end (cons reg-beg delim-regs-list)))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
344 (if (> (length pattern-list) 1) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
345 (setq pattern-list (cdr (cdr pattern-list))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
346 (setq pattern-list nil)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
347 ))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
348 |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
349 (reverse delim-regs-list) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
350 ))) |
11042 | 351 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
352 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
353 ;; Check if the non-preferred merge has been modified since originally set. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
354 ;; This affects only the regions that are marked as default-A/B or combined. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
355 ;; If PREFERS-TOO is non-nil, then look at the regions marked as prefers-A/B as |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
356 ;; well. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
357 (defun ediff-merge-changed-from-default-p (diff-num &optional prefers-too) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
358 (let ((reg-A (ediff-get-region-contents diff-num 'A ediff-control-buffer)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
359 (reg-B (ediff-get-region-contents diff-num 'B ediff-control-buffer)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
360 (reg-C (ediff-get-region-contents diff-num 'C ediff-control-buffer))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
361 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
362 (setq state-of-merge (ediff-get-state-of-merge diff-num)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
363 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
364 ;; if region was edited since it was first set by default |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
365 (or (and (string= state-of-merge "default-A") |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
366 (not (string= reg-A reg-C))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
367 (and (string= state-of-merge "default-B") |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
368 (not (string= reg-B reg-C))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
369 (and (string= state-of-merge "combined") |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
370 ;;(not (string= (ediff-make-combined-diff reg-A reg-B) reg-C))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
371 (not (string= (ediff-get-combined-region diff-num) reg-C))) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
372 (and prefers-too |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
373 (string= state-of-merge "prefer-A") |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
374 (not (string= reg-A reg-C))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
375 (and prefers-too |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
376 (string= state-of-merge "prefer-B") |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
377 (not (string= reg-B reg-C))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
20206
diff
changeset
|
378 ))) |
11042 | 379 |
380 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
381 ;;; Local Variables: |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
382 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) |
19047 | 383 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1) |
384 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body)) | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
385 ;;; End: |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
386 |
11042 | 387 ;; ediff-merg.el ends here |