Mercurial > emacs
annotate lisp/ediff-merg.el @ 13230:ad1d4be6bb8d libc-951018 libc-951029 libc-951031 libc-951101 libc-951102 libc-951103 libc-951104 libc-951105 libc-951106 libc-951107 libc-951108 libc-951109 libc-951110 libc-951111 libc-951112 libc-951113 libc-951114 libc-951115 libc-951116 libc-951117 libc-951118 libc-951119 libc-951120 libc-951121 libc-951122 libc-951123 libc-951124 libc-951125 libc-951126 libc-951127 libc-951128 libc-951129 libc-951130
* config.guess: Recognize HP model 819 machines has having
a PA 1.1 processor.
author | Jeff Law <law@redhat.com> |
---|---|
date | Mon, 16 Oct 1995 15:40:29 +0000 |
parents | b9dc8cc658d5 |
children | 187735b53d52 |
rev | line source |
---|---|
11042 | 1 ;;; ediff-merg.el --- merging utilities |
11234 | 2 ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
11042 | 3 |
4 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 | |
23 (require 'ediff-init) | |
24 | |
25 (defvar ediff-default-variant 'default-A | |
26 "*The variant to be used as a default for buffer C in merging. | |
27 Valid values are the symbols `default-A', `default-B', and `combined'.") | |
28 | |
29 (defvar ediff-combination-pattern | |
30 '("#ifdef NEW /* variant A */" "#else /* variant B */" "#endif /* NEW */") | |
31 "*Pattern to be used for combining difference regions in buffers A and B. | |
32 The value is (STRING1 STRING2 STRING3). The combined text will look like this: | |
33 | |
34 STRING1 | |
35 diff region from variant A | |
36 STRING2 | |
37 diff region from variant B | |
38 STRING3 | |
39 ") | |
40 | |
41 (ediff-defvar-local ediff-show-clashes-only nil | |
42 "*If t, show only those diff regions where both buffers disagree with the ancestor. | |
43 This means that regions that have status prefer-A or prefer-B will be | |
44 skiped over. Nil means show all regions.") | |
45 | |
46 | |
47 (defsubst ediff-get-combined-region (n) | |
48 (concat (nth 0 ediff-combination-pattern) "\n" | |
49 (ediff-get-region-contents n 'A ediff-control-buffer) | |
50 (nth 1 ediff-combination-pattern) "\n" | |
51 (ediff-get-region-contents n 'B ediff-control-buffer) | |
52 (nth 2 ediff-combination-pattern) "\n")) | |
13216
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
53 |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
54 (defsubst ediff-make-combined-diff (regA regB) |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
55 (concat (nth 0 ediff-combination-pattern) "\n" |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
56 regA |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
57 (nth 1 ediff-combination-pattern) "\n" |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
58 regB |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
59 (nth 2 ediff-combination-pattern) "\n")) |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
60 |
11042 | 61 (defsubst ediff-set-state-of-all-diffs-in-all-buffers (ctl-buf) |
62 (let ((n 0)) | |
63 (while (< n ediff-number-of-differences) | |
64 (ediff-set-state-of-diff-in-all-buffers n ctl-buf) | |
65 (setq n (1+ n))))) | |
66 | |
67 (defun ediff-set-state-of-diff-in-all-buffers (n ctl-buf) | |
68 (let ((regA (ediff-get-region-contents n 'A ctl-buf)) | |
69 (regB (ediff-get-region-contents n 'B ctl-buf)) | |
70 (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
|
71 (cond ((and (string= regA regB) (string= regA regC)) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
72 (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
|
73 (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
|
74 (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
|
75 ((string= regA regB) |
11042 | 76 (ediff-set-state-of-diff n 'A "=diff(B)") |
77 (ediff-set-state-of-diff n 'B "=diff(A)") | |
78 (ediff-set-state-of-diff n 'C nil)) | |
79 ((string= regA regC) | |
80 (ediff-set-state-of-diff n 'A "=diff(C)") | |
81 (ediff-set-state-of-diff n 'C "=diff(A)") | |
82 (ediff-set-state-of-diff n 'B nil)) | |
83 ((string= regB regC) | |
84 (ediff-set-state-of-diff n 'C "=diff(B)") | |
85 (ediff-set-state-of-diff n 'B "=diff(C)") | |
86 (ediff-set-state-of-diff n 'A nil)) | |
87 ((string= regC (ediff-get-combined-region n)) | |
88 (ediff-set-state-of-diff n 'A nil) | |
89 (ediff-set-state-of-diff n 'B nil) | |
90 (ediff-set-state-of-diff n 'C "=diff(A+B)")) | |
91 (t (ediff-set-state-of-diff n 'A nil) | |
92 (ediff-set-state-of-diff n 'B nil) | |
93 (ediff-set-state-of-diff n 'C nil))) | |
94 )) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
95 |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
96 (defun ediff-set-merge-mode () |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
97 ;; by Stig@hackvan.com |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
98 (normal-mode t) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
99 (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
|
100 |
11042 | 101 |
102 ;; Go over all diffs starting with DIFF-NUM and copy regions into buffer C | |
103 ;; according to the state of the difference. | |
104 ;; Since ediff-copy-diff refuses to copy identical diff regions, there is | |
105 ;; no need to optimize ediff-do-merge any further. | |
106 ;; | |
107 ;; If re-merging, change state of merge in all diffs starting with | |
108 ;; 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
|
109 ;; `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
|
110 ;; since last set by default. |
11042 | 111 (defun ediff-do-merge (diff-num &optional remerging) |
112 (if (< diff-num 0) (setq diff-num 0)) | |
113 (let ((n diff-num) | |
114 (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
|
115 do-not-copy state-of-merge) |
11042 | 116 (while (< n ediff-number-of-differences) |
117 (if (= (mod n 10) 0) | |
118 (message "%s buffers A & B into C ... region %d of %d" | |
119 (if remerging "Re-merging" "Merging") | |
120 n | |
121 ediff-number-of-differences)) | |
122 | |
123 (setq state-of-merge (ediff-get-state-of-merge n)) | |
124 | |
125 (if remerging | |
126 (let ((reg-A (ediff-get-region-contents n 'A ediff-control-buffer)) | |
127 (reg-B (ediff-get-region-contents n 'B ediff-control-buffer)) | |
128 (reg-C (ediff-get-region-contents n 'C ediff-control-buffer))) | |
129 | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
130 ;;; was edited since first set by default |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
131 (if (or (and (string= state-of-merge "default-A") |
11042 | 132 (not (string= reg-A reg-C))) |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
133 ;; was edited since first set by default |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
134 (and (string= state-of-merge "default-B") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
135 (not (string= reg-B reg-C))) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
136 ;; was edited since first set by default |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
137 (and (string= state-of-merge "combined") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
138 (not (string= |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
139 (ediff-make-combined-diff reg-A reg-B) reg-C))) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
140 ;; was prefered--ignore |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
141 (string-match "prefer" state-of-merge)) |
11042 | 142 (setq do-not-copy t)) |
143 | |
144 ;; 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
|
145 (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
|
146 (not do-not-copy)) |
11042 | 147 (ediff-set-state-of-merge |
148 n (format "%S" ediff-default-variant))) | |
149 )) | |
150 | |
151 ;; 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
|
152 ;; check it once again |
11042 | 153 (setq state-of-merge (ediff-get-state-of-merge n)) |
154 | |
155 (or do-not-copy | |
156 (if (string= state-of-merge "combined") | |
157 ;; use n+1 because ediff-combine-diffs works via user numbering | |
158 ;; of diffs, which is 1+ to what ediff uses internally | |
159 (ediff-combine-diffs (1+ n) 'batch) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
160 (ediff-copy-diff |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
161 n (if (string-match "-A" state-of-merge) 'A 'B) 'C 'batch))) |
11042 | 162 (setq n (1+ n))) |
163 (message "Merging buffers A & B into C ... Done") | |
164 )) | |
165 | |
166 | |
167 (defun ediff-re-merge () | |
168 "Remerge unmodified diff regions using a new default. Start with the current region." | |
169 (interactive) | |
170 (let* ((default-variant-alist | |
171 (list '("default-A") '("default-B") '("combined"))) | |
172 (actual-alist | |
173 (delete (list (symbol-name ediff-default-variant)) | |
174 default-variant-alist))) | |
175 (setq ediff-default-variant | |
176 (intern | |
177 (completing-read | |
178 (format "Current merge default is `%S'. New default: " | |
179 ediff-default-variant) | |
180 actual-alist nil 'must-match))) | |
181 (ediff-do-merge ediff-current-difference 'remerge) | |
182 (ediff-recenter) | |
183 )) | |
184 | |
185 (defun ediff-shrink-window-C (arg) | |
186 "Shrink window C to just one line. | |
187 With a prefix argument, returns window C to its normal size. | |
188 Used only for merging jobs." | |
189 (interactive "P") | |
190 (if (not ediff-merge-job) | |
191 (error "ediff-shrink-window-C can be used only for merging jobs")) | |
192 (cond ((eq arg '-) (setq arg -1)) | |
193 ((not (numberp arg)) (setq arg nil))) | |
194 (cond ((null arg) | |
195 (let ((ediff-merge-window-share | |
196 (if (< (window-height ediff-window-C) 3) | |
197 ediff-merge-window-share 0))) | |
198 (setq ediff-window-config-saved "") ; force redisplay | |
199 (ediff-recenter 'no-rehighlight))) | |
200 ((and (< arg 0) (> (window-height ediff-window-C) 2)) | |
201 (setq ediff-merge-window-share (* ediff-merge-window-share 0.9)) | |
202 (setq ediff-window-config-saved "") ; force redisplay | |
203 (ediff-recenter 'no-rehighlight)) | |
204 ((and (> arg 0) (> (window-height ediff-window-A) 2)) | |
205 (setq ediff-merge-window-share (* ediff-merge-window-share 1.1)) | |
206 (setq ediff-window-config-saved "") ; force redisplay | |
207 (ediff-recenter 'no-rehighlight)))) | |
208 | |
209 | |
210 ;; N here is the user's region number. It is 1+ what Ediff uses internally. | |
211 (defun ediff-combine-diffs (n &optional batch-invocation) | |
212 "Combine Nth diff regions of buffers A and B and place the combination in C. | |
213 Combining is done using the list in variable `ediff-combination-pattern'." | |
214 (interactive "P") | |
215 (setq n (if n (1- n) ediff-current-difference)) | |
216 | |
217 (let (regA regB reg-combined) | |
218 (setq regA (ediff-get-region-contents n 'A ediff-control-buffer) | |
219 regB (ediff-get-region-contents n 'B ediff-control-buffer)) | |
220 | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
221 (setq reg-combined (ediff-make-combined-diff regA regB)) |
11042 | 222 |
223 (ediff-copy-diff n nil 'C batch-invocation reg-combined)) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
224 (or batch-invocation (ediff-recenter))) |
11042 | 225 |
226 | |
227 ;; Checks if the region in buff C looks like a combination of the regions | |
228 ;; in buffers A and B. Returns a list (reg-a-beg reg-a-end reg-b-beg reg-b-end) | |
229 ;; These refer to where the copies of region A and B start and end in buffer C | |
230 (defun ediff-looks-like-combined-merge (region-num) | |
231 (if ediff-merge-job | |
232 (let ((combined (string-match (regexp-quote "(A+B)") | |
233 (or (ediff-get-state-of-diff region-num 'C) | |
234 ""))) | |
235 (reg-beg (ediff-get-diff-posn 'C 'beg region-num)) | |
236 (reg-end (ediff-get-diff-posn 'C 'end region-num)) | |
237 (pat1 (nth 0 ediff-combination-pattern)) | |
238 (pat2 (nth 1 ediff-combination-pattern)) | |
239 (pat3 (nth 2 ediff-combination-pattern)) | |
240 reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end) | |
241 | |
242 (if combined | |
243 (ediff-eval-in-buffer ediff-buffer-C | |
244 (goto-char reg-beg) | |
245 (search-forward pat1 reg-end 'noerror) | |
246 (setq reg-a-beg (match-beginning 0)) | |
247 (setq reg-a-end (match-end 0)) | |
248 (search-forward pat2 reg-end 'noerror) | |
249 (setq reg-b-beg (match-beginning 0)) | |
250 (setq reg-b-end (match-end 0)) | |
251 (search-forward pat3 reg-end 'noerror) | |
252 (setq reg-c-beg (match-beginning 0)) | |
253 (setq reg-c-end (match-end 0)))) | |
254 | |
255 (if (and reg-a-beg reg-a-end reg-b-beg reg-b-end) | |
256 (list reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end)) | |
257 ))) | |
258 | |
259 | |
260 (provide 'ediff-merg) | |
261 | |
262 ;; ediff-merg.el ends here |