annotate lisp/ediff/ediff-merg.el @ 171:929b76928fce r20-3b12

Import from CVS: tag r20-3b12
author cvs
date Mon, 13 Aug 2007 09:47:52 +0200
parents 34a5b81f86ba
children 2d532a89d707
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; ediff-merg.el --- merging utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
26 (provide 'ediff-merg)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
27
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
28 (defgroup ediff-merge nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
29 "Merging utilities"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
30 :prefix "ediff-"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
31 :group 'ediff)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
32
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
33
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
34 ;; compiler pacifier
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
35 (defvar ediff-window-A)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
36 (defvar ediff-window-B)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
37 (defvar ediff-window-C)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
38 (defvar ediff-merge-window-share)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
39 (defvar ediff-window-config-saved)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
40
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
41 (eval-when-compile
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
42 (let ((load-path (cons (expand-file-name ".") load-path)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
43 (or (featurep 'ediff-init)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
44 (load "ediff-init.el" nil nil 'nosuffix))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
45 (or (featurep 'ediff-util)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
46 (load "ediff-util.el" nil nil 'nosuffix))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
47 ))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
48 ;; end pacifier
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
49
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (require 'ediff-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
53 (defcustom ediff-default-variant 'combined
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 "*The variant to be used as a default for buffer C in merging.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
55 Valid values are the symbols `default-A', `default-B', and `combined'."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
56 :type '(radio (const default-A) (const default-B) (const combined))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
57 :group 'ediff-merge)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
59 (defcustom ediff-combination-pattern
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 '("<<<<<<<<<<<<<< variant A" ">>>>>>>>>>>>>> variant B" "======= end of combination")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "*Pattern to be used for combining difference regions in buffers A and B.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 The value is (STRING1 STRING2 STRING3). The combined text will look like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 STRING1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 diff region from variant A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 STRING2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 diff region from variant B
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 STRING3
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
69 "
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
70 :type '(list string string string)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 82
diff changeset
71 :group 'ediff-merge)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (ediff-defvar-local ediff-show-clashes-only nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "*If t, show only those diff regions where both buffers disagree with the ancestor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 This means that regions that have status prefer-A or prefer-B will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 skiped over. Nil means show all regions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defsubst ediff-get-combined-region (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (concat (nth 0 ediff-combination-pattern) "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (ediff-get-region-contents n 'A ediff-control-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (nth 1 ediff-combination-pattern) "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (ediff-get-region-contents n 'B ediff-control-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (nth 2 ediff-combination-pattern) "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defsubst ediff-make-combined-diff (regA regB)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (concat (nth 0 ediff-combination-pattern) "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 regA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (nth 1 ediff-combination-pattern) "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 regB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (nth 2 ediff-combination-pattern) "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defsubst ediff-set-state-of-all-diffs-in-all-buffers (ctl-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (let ((n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (while (< n ediff-number-of-differences)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (ediff-set-state-of-diff-in-all-buffers n ctl-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq n (1+ n)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defun ediff-set-state-of-diff-in-all-buffers (n ctl-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (let ((regA (ediff-get-region-contents n 'A ctl-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (regB (ediff-get-region-contents n 'B ctl-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (regC (ediff-get-region-contents n 'C ctl-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (cond ((and (string= regA regB) (string= regA regC))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (ediff-set-state-of-diff n 'A "=diff(B)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (ediff-set-state-of-diff n 'B "=diff(C)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (ediff-set-state-of-diff n 'C "=diff(A)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ((string= regA regB)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (ediff-set-state-of-diff n 'A "=diff(B)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (ediff-set-state-of-diff n 'B "=diff(A)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (ediff-set-state-of-diff n 'C nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ((string= regA regC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (ediff-set-state-of-diff n 'A "=diff(C)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (ediff-set-state-of-diff n 'C "=diff(A)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (ediff-set-state-of-diff n 'B nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ((string= regB regC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (ediff-set-state-of-diff n 'C "=diff(B)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (ediff-set-state-of-diff n 'B "=diff(C)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (ediff-set-state-of-diff n 'A nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ((string= regC (ediff-get-combined-region n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (ediff-set-state-of-diff n 'A nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (ediff-set-state-of-diff n 'B nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (ediff-set-state-of-diff n 'C "=diff(A+B)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (t (ediff-set-state-of-diff n 'A nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (ediff-set-state-of-diff n 'B nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (ediff-set-state-of-diff n 'C nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defun ediff-set-merge-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; by Stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (normal-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (remove-hook 'local-write-file-hooks 'ediff-set-merge-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; Go over all diffs starting with DIFF-NUM and copy regions into buffer C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; according to the state of the difference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; Since ediff-copy-diff refuses to copy identical diff regions, there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; no need to optimize ediff-do-merge any further.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; If re-merging, change state of merge in all diffs starting with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; DIFF-NUM, except those where the state is prefer-* or where it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; `default-*' or `combined' but the buf C region appears to be modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; since last set by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defun ediff-do-merge (diff-num &optional remerging)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (< diff-num 0) (setq diff-num 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (let ((n diff-num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;;(default-state-of-merge (format "%S" ediff-default-variant))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 do-not-copy state-of-merge)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (while (< n ediff-number-of-differences)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq do-not-copy nil) ; reset after each cycle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (= (mod n 10) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (message "%s buffers A & B into C ... region %d of %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (if remerging "Re-merging" "Merging")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ediff-number-of-differences))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (setq state-of-merge (ediff-get-state-of-merge n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if remerging
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (let ((reg-A (ediff-get-region-contents n 'A ediff-control-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (reg-B (ediff-get-region-contents n 'B ediff-control-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (reg-C (ediff-get-region-contents n 'C ediff-control-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; if region was edited since it was first set by default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (if (or (and (string= state-of-merge "default-A")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (not (string= reg-A reg-C)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; was edited since first set by default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (and (string= state-of-merge "default-B")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (not (string= reg-B reg-C)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; was edited since first set by default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (and (string= state-of-merge "combined")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (not (string=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (ediff-make-combined-diff reg-A reg-B) reg-C)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; was preferred--ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (string-match "prefer" state-of-merge))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (setq do-not-copy t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; change state of merge for this diff, if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (if (and (string-match "\\(default\\|combined\\)" state-of-merge)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (not do-not-copy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (ediff-set-state-of-merge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 n (format "%S" ediff-default-variant)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; state-of-merge may have changed via ediff-set-state-of-merge, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; check it once again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq state-of-merge (ediff-get-state-of-merge n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (or do-not-copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (if (string= state-of-merge "combined")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; use n+1 because ediff-combine-diffs works via user numbering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; of diffs, which is 1+ to what ediff uses internally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (ediff-combine-diffs (1+ n) 'batch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (ediff-copy-diff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 n (if (string-match "-A" state-of-merge) 'A 'B) 'C 'batch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq n (1+ n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (message "Merging buffers A & B into C ... Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun ediff-re-merge ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 "Remerge unmodified diff regions using a new default. Start with the current region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (let* ((default-variant-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (list '("default-A") '("default-B") '("combined")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (actual-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (delete (list (symbol-name ediff-default-variant))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 default-variant-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setq ediff-default-variant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (intern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (format "Current merge default is `%S'. New default: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ediff-default-variant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 actual-alist nil 'must-match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (ediff-do-merge ediff-current-difference 'remerge)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (ediff-recenter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (defun ediff-shrink-window-C (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "Shrink window C to just one line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 With a prefix argument, returns window C to its normal size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 Used only for merging jobs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if (not ediff-merge-job)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (error "ediff-shrink-window-C can be used only for merging jobs"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (cond ((eq arg '-) (setq arg -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ((not (numberp arg)) (setq arg nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (cond ((null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (let ((ediff-merge-window-share
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (< (window-height ediff-window-C) 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ediff-merge-window-share 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq ediff-window-config-saved "") ; force redisplay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (ediff-recenter 'no-rehighlight)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ((and (< arg 0) (> (window-height ediff-window-C) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (setq ediff-merge-window-share (* ediff-merge-window-share 0.9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq ediff-window-config-saved "") ; force redisplay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (ediff-recenter 'no-rehighlight))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ((and (> arg 0) (> (window-height ediff-window-A) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq ediff-merge-window-share (* ediff-merge-window-share 1.1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq ediff-window-config-saved "") ; force redisplay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (ediff-recenter 'no-rehighlight))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; N here is the user's region number. It is 1+ what Ediff uses internally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun ediff-combine-diffs (n &optional batch-invocation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Combine Nth diff regions of buffers A and B and place the combination in C.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 N is a prefix argument. If nil, combine the current difference regions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 Combining is done according to the specifications in variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 `ediff-combination-pattern'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq n (if (numberp n) (1- n) ediff-current-difference))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (let (regA regB reg-combined)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (setq regA (ediff-get-region-contents n 'A ediff-control-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 regB (ediff-get-region-contents n 'B ediff-control-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (setq reg-combined (ediff-make-combined-diff regA regB))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (ediff-copy-diff n nil 'C batch-invocation reg-combined))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (or batch-invocation (ediff-jump-to-difference (1+ n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; Checks if the region in buff C looks like a combination of the regions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; in buffers A and B. Returns a list (reg-a-beg reg-a-end reg-b-beg reg-b-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; These refer to where the copies of region A and B start and end in buffer C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (defun ediff-looks-like-combined-merge (region-num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if ediff-merge-job
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (let ((combined (string-match (regexp-quote "(A+B)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (or (ediff-get-state-of-diff region-num 'C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (reg-beg (ediff-get-diff-posn 'C 'beg region-num))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (reg-end (ediff-get-diff-posn 'C 'end region-num))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (pat1 (nth 0 ediff-combination-pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (pat2 (nth 1 ediff-combination-pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (pat3 (nth 2 ediff-combination-pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if combined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (ediff-eval-in-buffer ediff-buffer-C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (goto-char reg-beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (search-forward pat1 reg-end 'noerror)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (setq reg-a-beg (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (setq reg-a-end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (search-forward pat2 reg-end 'noerror)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (setq reg-b-beg (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (setq reg-b-end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (search-forward pat3 reg-end 'noerror)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq reg-c-beg (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (setq reg-c-end (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (if (and reg-a-beg reg-a-end reg-b-beg reg-b-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (list reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
295 ;;; Local Variables:
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
296 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
297 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
298 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
299 ;;; End:
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
300
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;; ediff-merg.el ends here