Mercurial > emacs
annotate lisp/ediff-merg.el @ 20047:735f0cdfc5b9
(winner-change-fun): Don't use pushnew.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 15 Oct 1997 22:41:09 +0000 |
parents | 9bc6a4017c8c |
children | f44ff2c52fac |
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 (defgroup ediff-merge nil | |
29 "Merging utilities" | |
30 :prefix "ediff-" | |
31 :group 'ediff) | |
32 | |
33 | |
34 ;; compiler pacifier | |
35 (defvar ediff-window-A) | |
36 (defvar ediff-window-B) | |
37 (defvar ediff-window-C) | |
38 (defvar ediff-merge-window-share) | |
39 (defvar ediff-window-config-saved) | |
40 | |
41 (eval-when-compile | |
42 (let ((load-path (cons (expand-file-name ".") load-path))) | |
43 (or (featurep 'ediff-init) | |
44 (load "ediff-init.el" nil nil 'nosuffix)) | |
45 (or (featurep 'ediff-util) | |
46 (load "ediff-util.el" nil nil 'nosuffix)) | |
47 )) | |
48 ;; end pacifier | |
49 | |
11042 | 50 (require 'ediff-init) |
51 | |
18839 | 52 (defcustom ediff-quit-merge-hook 'ediff-maybe-save-and-delete-merge |
53 "*Hooks to run before quitting a merge job. | |
54 The most common use is to save and delete the merge buffer." | |
55 :type 'hook | |
56 :group 'ediff-merge) | |
57 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
58 |
18054 | 59 (defcustom ediff-default-variant 'combined |
11042 | 60 "*The variant to be used as a default for buffer C in merging. |
18054 | 61 Valid values are the symbols `default-A', `default-B', and `combined'." |
62 :type '(radio (const default-A) (const default-B) (const combined)) | |
63 :group 'ediff-merge) | |
11042 | 64 |
18054 | 65 (defcustom ediff-combination-pattern |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
66 '("<<<<<<<<<<<<<< variant A" ">>>>>>>>>>>>>> variant B" "======= end of combination") |
11042 | 67 "*Pattern to be used for combining difference regions in buffers A and B. |
68 The value is (STRING1 STRING2 STRING3). The combined text will look like this: | |
69 | |
70 STRING1 | |
71 diff region from variant A | |
72 STRING2 | |
73 diff region from variant B | |
74 STRING3 | |
18054 | 75 " |
76 :type '(list string string string) | |
77 :group 'ediff-merge) | |
11042 | 78 |
79 (ediff-defvar-local ediff-show-clashes-only nil | |
80 "*If t, show only those diff regions where both buffers disagree with the ancestor. | |
81 This means that regions that have status prefer-A or prefer-B will be | |
82 skiped over. Nil means show all regions.") | |
83 | |
20003 | 84 ;; If ediff-show-clashes-only, check if there is no clash between the ancestor |
85 ;; and one of the variants. | |
86 (defsubst ediff-merge-region-is-non-clash (n) | |
87 (and ediff-show-clashes-only | |
88 (string-match "prefer" (or (ediff-get-state-of-merge n) "")))) | |
89 | |
11042 | 90 |
91 (defsubst ediff-get-combined-region (n) | |
92 (concat (nth 0 ediff-combination-pattern) "\n" | |
93 (ediff-get-region-contents n 'A ediff-control-buffer) | |
94 (nth 1 ediff-combination-pattern) "\n" | |
95 (ediff-get-region-contents n 'B ediff-control-buffer) | |
96 (nth 2 ediff-combination-pattern) "\n")) | |
13216
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
97 |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
98 (defsubst ediff-make-combined-diff (regA regB) |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
99 (concat (nth 0 ediff-combination-pattern) "\n" |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
100 regA |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
101 (nth 1 ediff-combination-pattern) "\n" |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
102 regB |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
103 (nth 2 ediff-combination-pattern) "\n")) |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
104 |
11042 | 105 (defsubst ediff-set-state-of-all-diffs-in-all-buffers (ctl-buf) |
106 (let ((n 0)) | |
107 (while (< n ediff-number-of-differences) | |
108 (ediff-set-state-of-diff-in-all-buffers n ctl-buf) | |
109 (setq n (1+ n))))) | |
110 | |
111 (defun ediff-set-state-of-diff-in-all-buffers (n ctl-buf) | |
112 (let ((regA (ediff-get-region-contents n 'A ctl-buf)) | |
113 (regB (ediff-get-region-contents n 'B ctl-buf)) | |
114 (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
|
115 (cond ((and (string= regA regB) (string= regA regC)) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
116 (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
|
117 (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
|
118 (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
|
119 ((string= regA regB) |
11042 | 120 (ediff-set-state-of-diff n 'A "=diff(B)") |
121 (ediff-set-state-of-diff n 'B "=diff(A)") | |
122 (ediff-set-state-of-diff n 'C nil)) | |
123 ((string= regA regC) | |
124 (ediff-set-state-of-diff n 'A "=diff(C)") | |
125 (ediff-set-state-of-diff n 'C "=diff(A)") | |
126 (ediff-set-state-of-diff n 'B nil)) | |
127 ((string= regB regC) | |
128 (ediff-set-state-of-diff n 'C "=diff(B)") | |
129 (ediff-set-state-of-diff n 'B "=diff(C)") | |
130 (ediff-set-state-of-diff n 'A nil)) | |
131 ((string= regC (ediff-get-combined-region n)) | |
132 (ediff-set-state-of-diff n 'A nil) | |
133 (ediff-set-state-of-diff n 'B nil) | |
134 (ediff-set-state-of-diff n 'C "=diff(A+B)")) | |
135 (t (ediff-set-state-of-diff n 'A nil) | |
136 (ediff-set-state-of-diff n 'B nil) | |
137 (ediff-set-state-of-diff n 'C nil))) | |
138 )) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
139 |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
140 (defun ediff-set-merge-mode () |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
141 ;; by Stig@hackvan.com |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
142 (normal-mode t) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
143 (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
|
144 |
11042 | 145 |
146 ;; Go over all diffs starting with DIFF-NUM and copy regions into buffer C | |
147 ;; according to the state of the difference. | |
148 ;; Since ediff-copy-diff refuses to copy identical diff regions, there is | |
149 ;; no need to optimize ediff-do-merge any further. | |
150 ;; | |
151 ;; If re-merging, change state of merge in all diffs starting with | |
152 ;; 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
|
153 ;; `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
|
154 ;; since last set by default. |
11042 | 155 (defun ediff-do-merge (diff-num &optional remerging) |
156 (if (< diff-num 0) (setq diff-num 0)) | |
157 (let ((n diff-num) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
158 ;;(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
|
159 do-not-copy state-of-merge) |
11042 | 160 (while (< n ediff-number-of-differences) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
161 (setq do-not-copy nil) ; reset after each cycle |
11042 | 162 (if (= (mod n 10) 0) |
163 (message "%s buffers A & B into C ... region %d of %d" | |
164 (if remerging "Re-merging" "Merging") | |
165 n | |
166 ediff-number-of-differences)) | |
167 | |
168 (setq state-of-merge (ediff-get-state-of-merge n)) | |
169 | |
170 (if remerging | |
171 (let ((reg-A (ediff-get-region-contents n 'A ediff-control-buffer)) | |
172 (reg-B (ediff-get-region-contents n 'B ediff-control-buffer)) | |
173 (reg-C (ediff-get-region-contents n 'C ediff-control-buffer))) | |
174 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
175 ;; if region was edited since it was first set by default |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
176 (if (or (and (string= state-of-merge "default-A") |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14582
diff
changeset
|
177 (not (string= reg-A reg-C))) |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
178 ;; was edited since first set by default |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
179 (and (string= state-of-merge "default-B") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
180 (not (string= reg-B reg-C))) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
181 ;; was edited since first set by default |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
182 (and (string= state-of-merge "combined") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
183 (not (string= |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
184 (ediff-make-combined-diff reg-A reg-B) reg-C))) |
14040 | 185 ;; was preferred--ignore |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
186 (string-match "prefer" state-of-merge)) |
11042 | 187 (setq do-not-copy t)) |
188 | |
189 ;; 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
|
190 (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
|
191 (not do-not-copy)) |
11042 | 192 (ediff-set-state-of-merge |
193 n (format "%S" ediff-default-variant))) | |
194 )) | |
195 | |
196 ;; 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
|
197 ;; check it once again |
11042 | 198 (setq state-of-merge (ediff-get-state-of-merge n)) |
199 | |
200 (or do-not-copy | |
201 (if (string= state-of-merge "combined") | |
202 ;; use n+1 because ediff-combine-diffs works via user numbering | |
203 ;; of diffs, which is 1+ to what ediff uses internally | |
204 (ediff-combine-diffs (1+ n) 'batch) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
205 (ediff-copy-diff |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
206 n (if (string-match "-A" state-of-merge) 'A 'B) 'C 'batch))) |
11042 | 207 (setq n (1+ n))) |
208 (message "Merging buffers A & B into C ... Done") | |
209 )) | |
210 | |
211 | |
212 (defun ediff-re-merge () | |
213 "Remerge unmodified diff regions using a new default. Start with the current region." | |
214 (interactive) | |
215 (let* ((default-variant-alist | |
216 (list '("default-A") '("default-B") '("combined"))) | |
217 (actual-alist | |
218 (delete (list (symbol-name ediff-default-variant)) | |
219 default-variant-alist))) | |
220 (setq ediff-default-variant | |
221 (intern | |
222 (completing-read | |
223 (format "Current merge default is `%S'. New default: " | |
224 ediff-default-variant) | |
225 actual-alist nil 'must-match))) | |
226 (ediff-do-merge ediff-current-difference 'remerge) | |
227 (ediff-recenter) | |
228 )) | |
229 | |
230 (defun ediff-shrink-window-C (arg) | |
231 "Shrink window C to just one line. | |
232 With a prefix argument, returns window C to its normal size. | |
233 Used only for merging jobs." | |
234 (interactive "P") | |
235 (if (not ediff-merge-job) | |
236 (error "ediff-shrink-window-C can be used only for merging jobs")) | |
237 (cond ((eq arg '-) (setq arg -1)) | |
238 ((not (numberp arg)) (setq arg nil))) | |
239 (cond ((null arg) | |
240 (let ((ediff-merge-window-share | |
241 (if (< (window-height ediff-window-C) 3) | |
242 ediff-merge-window-share 0))) | |
243 (setq ediff-window-config-saved "") ; force redisplay | |
244 (ediff-recenter 'no-rehighlight))) | |
245 ((and (< arg 0) (> (window-height ediff-window-C) 2)) | |
246 (setq ediff-merge-window-share (* ediff-merge-window-share 0.9)) | |
247 (setq ediff-window-config-saved "") ; force redisplay | |
248 (ediff-recenter 'no-rehighlight)) | |
249 ((and (> arg 0) (> (window-height ediff-window-A) 2)) | |
250 (setq ediff-merge-window-share (* ediff-merge-window-share 1.1)) | |
251 (setq ediff-window-config-saved "") ; force redisplay | |
252 (ediff-recenter 'no-rehighlight)))) | |
253 | |
254 | |
255 ;; N here is the user's region number. It is 1+ what Ediff uses internally. | |
256 (defun ediff-combine-diffs (n &optional batch-invocation) | |
257 "Combine Nth diff regions of buffers A and B and place the combination in C. | |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
258 N is a prefix argument. If nil, combine the current difference regions. |
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
259 Combining is done according to the specifications in variable |
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
260 `ediff-combination-pattern'." |
11042 | 261 (interactive "P") |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
262 (setq n (if (numberp n) (1- n) ediff-current-difference)) |
11042 | 263 |
264 (let (regA regB reg-combined) | |
265 (setq regA (ediff-get-region-contents n 'A ediff-control-buffer) | |
266 regB (ediff-get-region-contents n 'B ediff-control-buffer)) | |
267 | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
268 (setq reg-combined (ediff-make-combined-diff regA regB)) |
11042 | 269 |
270 (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
|
271 (or batch-invocation (ediff-jump-to-difference (1+ n)))) |
11042 | 272 |
273 | |
274 ;; Checks if the region in buff C looks like a combination of the regions | |
275 ;; in buffers A and B. Returns a list (reg-a-beg reg-a-end reg-b-beg reg-b-end) | |
276 ;; These refer to where the copies of region A and B start and end in buffer C | |
277 (defun ediff-looks-like-combined-merge (region-num) | |
278 (if ediff-merge-job | |
279 (let ((combined (string-match (regexp-quote "(A+B)") | |
280 (or (ediff-get-state-of-diff region-num 'C) | |
281 ""))) | |
282 (reg-beg (ediff-get-diff-posn 'C 'beg region-num)) | |
283 (reg-end (ediff-get-diff-posn 'C 'end region-num)) | |
284 (pat1 (nth 0 ediff-combination-pattern)) | |
285 (pat2 (nth 1 ediff-combination-pattern)) | |
286 (pat3 (nth 2 ediff-combination-pattern)) | |
287 reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end) | |
288 | |
289 (if combined | |
19047 | 290 (ediff-with-current-buffer ediff-buffer-C |
11042 | 291 (goto-char reg-beg) |
292 (search-forward pat1 reg-end 'noerror) | |
293 (setq reg-a-beg (match-beginning 0)) | |
294 (setq reg-a-end (match-end 0)) | |
295 (search-forward pat2 reg-end 'noerror) | |
296 (setq reg-b-beg (match-beginning 0)) | |
297 (setq reg-b-end (match-end 0)) | |
298 (search-forward pat3 reg-end 'noerror) | |
299 (setq reg-c-beg (match-beginning 0)) | |
300 (setq reg-c-end (match-end 0)))) | |
301 | |
302 (if (and reg-a-beg reg-a-end reg-b-beg reg-b-end) | |
303 (list reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end)) | |
304 ))) | |
305 | |
306 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
307 ;;; Local Variables: |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
308 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) |
19047 | 309 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1) |
310 ;;; 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
|
311 ;;; End: |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
312 |
11042 | 313 ;; ediff-merg.el ends here |