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