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