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