annotate lisp/ediff-merg.el @ 12126:0b0b0c2e5254

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