Mercurial > emacs
annotate lisp/ediff-merg.el @ 15053:68d9a01cfb23
(simula-tab-always-indent, simula-indent-level)
(simula-substatement-offset, simula-continued-statement-offset)
(simula-label-offset, simula-if-indent, simula-inspect-indent)
(simula-electric-indent, simula-abbrev-keyword, simula-abbrev-stdproc):
Added default constants.
(simula-emacs-features): new constant to hold information
on which flavor if emacs is running (from cc-mode.el).
(simula-mode-menu): Menu definition for Lucid Emacs
(simula-mode-map): Bound new command simula-indent-exp to C-M-q
and added lots of commands to [menu-bar].
(simula-popup-menu): New function for Lucid menus.
(simula-keep-region-active): New function for Lucid menus.
(simula-indent-exp): New command that indents a whole expression.
(simula-indent-line): New strategies for finding the right amount to indent.
(simula-skip-comment-backward): Added optional parameter stop-at-end
to stop at the first END statement.
(simula-expand-stdproc): Added abbrev expansion to verbatim copy
of abbrev table, same for function simula-expand-keyword.
(simula-search-backward): Added Doc string, and lots of error checking.
(simula-search-forward): Added Doc string, and lots of error checking.
Added hilit19 config code.
(simula-version): New variable and function to report value.
(simula-submit-bug-report): New function to submit bug report.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 21 Apr 1996 01:39:51 +0000 |
parents | c768f6d7daaa |
children | 43a3308fcf61 |
rev | line source |
---|---|
11042 | 1 ;;; ediff-merg.el --- merging utilities |
14169 | 2 |
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
11042 | 4 |
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
14169 | 20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
11042 | 23 |
14169 | 24 ;;; Code: |
11042 | 25 |
26 (require 'ediff-init) | |
27 | |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
28 (defvar ediff-default-variant 'combined |
11042 | 29 "*The variant to be used as a default for buffer C in merging. |
30 Valid values are the symbols `default-A', `default-B', and `combined'.") | |
31 | |
32 (defvar ediff-combination-pattern | |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
33 '("<<<<<<<<<<<<<< variant A" ">>>>>>>>>>>>>> variant B" "======= end of combination") |
11042 | 34 "*Pattern to be used for combining difference regions in buffers A and B. |
35 The value is (STRING1 STRING2 STRING3). The combined text will look like this: | |
36 | |
37 STRING1 | |
38 diff region from variant A | |
39 STRING2 | |
40 diff region from variant B | |
41 STRING3 | |
42 ") | |
43 | |
44 (ediff-defvar-local ediff-show-clashes-only nil | |
45 "*If t, show only those diff regions where both buffers disagree with the ancestor. | |
46 This means that regions that have status prefer-A or prefer-B will be | |
47 skiped over. Nil means show all regions.") | |
48 | |
49 | |
50 (defsubst ediff-get-combined-region (n) | |
51 (concat (nth 0 ediff-combination-pattern) "\n" | |
52 (ediff-get-region-contents n 'A ediff-control-buffer) | |
53 (nth 1 ediff-combination-pattern) "\n" | |
54 (ediff-get-region-contents n 'B ediff-control-buffer) | |
55 (nth 2 ediff-combination-pattern) "\n")) | |
13216
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
56 |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
57 (defsubst ediff-make-combined-diff (regA regB) |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
58 (concat (nth 0 ediff-combination-pattern) "\n" |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
59 regA |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
60 (nth 1 ediff-combination-pattern) "\n" |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
61 regB |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
62 (nth 2 ediff-combination-pattern) "\n")) |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13129
diff
changeset
|
63 |
11042 | 64 (defsubst ediff-set-state-of-all-diffs-in-all-buffers (ctl-buf) |
65 (let ((n 0)) | |
66 (while (< n ediff-number-of-differences) | |
67 (ediff-set-state-of-diff-in-all-buffers n ctl-buf) | |
68 (setq n (1+ n))))) | |
69 | |
70 (defun ediff-set-state-of-diff-in-all-buffers (n ctl-buf) | |
71 (let ((regA (ediff-get-region-contents n 'A ctl-buf)) | |
72 (regB (ediff-get-region-contents n 'B ctl-buf)) | |
73 (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
|
74 (cond ((and (string= regA regB) (string= regA regC)) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
75 (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
|
76 (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
|
77 (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
|
78 ((string= regA regB) |
11042 | 79 (ediff-set-state-of-diff n 'A "=diff(B)") |
80 (ediff-set-state-of-diff n 'B "=diff(A)") | |
81 (ediff-set-state-of-diff n 'C nil)) | |
82 ((string= regA regC) | |
83 (ediff-set-state-of-diff n 'A "=diff(C)") | |
84 (ediff-set-state-of-diff n 'C "=diff(A)") | |
85 (ediff-set-state-of-diff n 'B nil)) | |
86 ((string= regB regC) | |
87 (ediff-set-state-of-diff n 'C "=diff(B)") | |
88 (ediff-set-state-of-diff n 'B "=diff(C)") | |
89 (ediff-set-state-of-diff n 'A nil)) | |
90 ((string= regC (ediff-get-combined-region n)) | |
91 (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 "=diff(A+B)")) | |
94 (t (ediff-set-state-of-diff n 'A nil) | |
95 (ediff-set-state-of-diff n 'B nil) | |
96 (ediff-set-state-of-diff n 'C nil))) | |
97 )) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
98 |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
99 (defun ediff-set-merge-mode () |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
100 ;; by Stig@hackvan.com |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
101 (normal-mode t) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
102 (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
|
103 |
11042 | 104 |
105 ;; Go over all diffs starting with DIFF-NUM and copy regions into buffer C | |
106 ;; according to the state of the difference. | |
107 ;; Since ediff-copy-diff refuses to copy identical diff regions, there is | |
108 ;; no need to optimize ediff-do-merge any further. | |
109 ;; | |
110 ;; If re-merging, change state of merge in all diffs starting with | |
111 ;; 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
|
112 ;; `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
|
113 ;; since last set by default. |
11042 | 114 (defun ediff-do-merge (diff-num &optional remerging) |
115 (if (< diff-num 0) (setq diff-num 0)) | |
116 (let ((n diff-num) | |
117 (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
|
118 do-not-copy state-of-merge) |
11042 | 119 (while (< n ediff-number-of-differences) |
120 (if (= (mod n 10) 0) | |
121 (message "%s buffers A & B into C ... region %d of %d" | |
122 (if remerging "Re-merging" "Merging") | |
123 n | |
124 ediff-number-of-differences)) | |
125 | |
126 (setq state-of-merge (ediff-get-state-of-merge n)) | |
127 | |
128 (if remerging | |
129 (let ((reg-A (ediff-get-region-contents n 'A ediff-control-buffer)) | |
130 (reg-B (ediff-get-region-contents n 'B ediff-control-buffer)) | |
131 (reg-C (ediff-get-region-contents n 'C ediff-control-buffer))) | |
132 | |
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 (if (or (and (string= state-of-merge "default-A") |
11042 | 135 (not (string= reg-A reg-C))) |
12167
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 "default-B") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
138 (not (string= reg-B reg-C))) |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
139 ;; was edited since first set by default |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
140 (and (string= state-of-merge "combined") |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
141 (not (string= |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
142 (ediff-make-combined-diff reg-A reg-B) reg-C))) |
14040 | 143 ;; was preferred--ignore |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
144 (string-match "prefer" state-of-merge)) |
11042 | 145 (setq do-not-copy t)) |
146 | |
147 ;; 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
|
148 (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
|
149 (not do-not-copy)) |
11042 | 150 (ediff-set-state-of-merge |
151 n (format "%S" ediff-default-variant))) | |
152 )) | |
153 | |
154 ;; 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
|
155 ;; check it once again |
11042 | 156 (setq state-of-merge (ediff-get-state-of-merge n)) |
157 | |
158 (or do-not-copy | |
159 (if (string= state-of-merge "combined") | |
160 ;; use n+1 because ediff-combine-diffs works via user numbering | |
161 ;; of diffs, which is 1+ to what ediff uses internally | |
162 (ediff-combine-diffs (1+ n) 'batch) | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
163 (ediff-copy-diff |
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
164 n (if (string-match "-A" state-of-merge) 'A 'B) 'C 'batch))) |
11042 | 165 (setq n (1+ n))) |
166 (message "Merging buffers A & B into C ... Done") | |
167 )) | |
168 | |
169 | |
170 (defun ediff-re-merge () | |
171 "Remerge unmodified diff regions using a new default. Start with the current region." | |
172 (interactive) | |
173 (let* ((default-variant-alist | |
174 (list '("default-A") '("default-B") '("combined"))) | |
175 (actual-alist | |
176 (delete (list (symbol-name ediff-default-variant)) | |
177 default-variant-alist))) | |
178 (setq ediff-default-variant | |
179 (intern | |
180 (completing-read | |
181 (format "Current merge default is `%S'. New default: " | |
182 ediff-default-variant) | |
183 actual-alist nil 'must-match))) | |
184 (ediff-do-merge ediff-current-difference 'remerge) | |
185 (ediff-recenter) | |
186 )) | |
187 | |
188 (defun ediff-shrink-window-C (arg) | |
189 "Shrink window C to just one line. | |
190 With a prefix argument, returns window C to its normal size. | |
191 Used only for merging jobs." | |
192 (interactive "P") | |
193 (if (not ediff-merge-job) | |
194 (error "ediff-shrink-window-C can be used only for merging jobs")) | |
195 (cond ((eq arg '-) (setq arg -1)) | |
196 ((not (numberp arg)) (setq arg nil))) | |
197 (cond ((null arg) | |
198 (let ((ediff-merge-window-share | |
199 (if (< (window-height ediff-window-C) 3) | |
200 ediff-merge-window-share 0))) | |
201 (setq ediff-window-config-saved "") ; force redisplay | |
202 (ediff-recenter 'no-rehighlight))) | |
203 ((and (< arg 0) (> (window-height ediff-window-C) 2)) | |
204 (setq ediff-merge-window-share (* ediff-merge-window-share 0.9)) | |
205 (setq ediff-window-config-saved "") ; force redisplay | |
206 (ediff-recenter 'no-rehighlight)) | |
207 ((and (> arg 0) (> (window-height ediff-window-A) 2)) | |
208 (setq ediff-merge-window-share (* ediff-merge-window-share 1.1)) | |
209 (setq ediff-window-config-saved "") ; force redisplay | |
210 (ediff-recenter 'no-rehighlight)))) | |
211 | |
212 | |
213 ;; N here is the user's region number. It is 1+ what Ediff uses internally. | |
214 (defun ediff-combine-diffs (n &optional batch-invocation) | |
215 "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
|
216 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
|
217 Combining is done according to the specifications in variable |
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
218 `ediff-combination-pattern'." |
11042 | 219 (interactive "P") |
14582
c768f6d7daaa
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
220 (setq n (if (numberp n) (1- n) ediff-current-difference)) |
11042 | 221 |
222 (let (regA regB reg-combined) | |
223 (setq regA (ediff-get-region-contents n 'A ediff-control-buffer) | |
224 regB (ediff-get-region-contents n 'B ediff-control-buffer)) | |
225 | |
12167
87f8b79217b3
Converted xemacs *screen* nomenclature to *frame*.
Karl Heuer <kwzh@gnu.org>
parents:
11234
diff
changeset
|
226 (setq reg-combined (ediff-make-combined-diff regA regB)) |
11042 | 227 |
228 (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
|
229 (or batch-invocation (ediff-jump-to-difference (1+ n)))) |
11042 | 230 |
231 | |
232 ;; Checks if the region in buff C looks like a combination of the regions | |
233 ;; in buffers A and B. Returns a list (reg-a-beg reg-a-end reg-b-beg reg-b-end) | |
234 ;; These refer to where the copies of region A and B start and end in buffer C | |
235 (defun ediff-looks-like-combined-merge (region-num) | |
236 (if ediff-merge-job | |
237 (let ((combined (string-match (regexp-quote "(A+B)") | |
238 (or (ediff-get-state-of-diff region-num 'C) | |
239 ""))) | |
240 (reg-beg (ediff-get-diff-posn 'C 'beg region-num)) | |
241 (reg-end (ediff-get-diff-posn 'C 'end region-num)) | |
242 (pat1 (nth 0 ediff-combination-pattern)) | |
243 (pat2 (nth 1 ediff-combination-pattern)) | |
244 (pat3 (nth 2 ediff-combination-pattern)) | |
245 reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end) | |
246 | |
247 (if combined | |
248 (ediff-eval-in-buffer ediff-buffer-C | |
249 (goto-char reg-beg) | |
250 (search-forward pat1 reg-end 'noerror) | |
251 (setq reg-a-beg (match-beginning 0)) | |
252 (setq reg-a-end (match-end 0)) | |
253 (search-forward pat2 reg-end 'noerror) | |
254 (setq reg-b-beg (match-beginning 0)) | |
255 (setq reg-b-end (match-end 0)) | |
256 (search-forward pat3 reg-end 'noerror) | |
257 (setq reg-c-beg (match-beginning 0)) | |
258 (setq reg-c-end (match-end 0)))) | |
259 | |
260 (if (and reg-a-beg reg-a-end reg-b-beg reg-b-end) | |
261 (list reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end)) | |
262 ))) | |
263 | |
264 | |
265 (provide 'ediff-merg) | |
266 | |
267 ;; ediff-merg.el ends here |