Mercurial > emacs
annotate lisp/emerge.el @ 2711:2c2052ec537d
The GNU coding standards specify that CFLAGS should be left for
users to set.
* Makefile.in (CFLAGS): Let configure determine the default value
for this. Don't
have it default to DEFS.
(${SUBDIR}): Pass CFLAGS down to submakes, not DEFS.
(lib-src/Makefile, src/Makefile): Edit the default value for
CFLAGS into these files, not DEFS.
* configure.in (CFLAGS): Choose a default value for this - "-g"
normally, or "-g -O" if we're using GCC. Edit it into the
top-level Makefile.
* configure.in: When scanning the machine and system description
#include files, write their names to conftest.c properly.
* configure.in: In configuration name case for Apallos running
Domainios, set opsys, not opsysfile.
* configure.in: Use the autoconf AC_CONFIG_HEADER macro to produce
src/config.h, instead of AC_OUTPUT; the latter overwrites
src/config.h even when it hasn't changed, puts a makefile-style
comment at the top even though it's C code, and produces a
config.status script which doesn't do the job right.
* configure.in: Add AC_LN_S test, so we can tell whether or not we
can use a symbolic link to get the X Menu library into src.
* Makefile.in (LN_S): New variable.
(src/Makefile): Edit the value of LN_S into this makefile.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sun, 09 May 1993 22:52:15 +0000 |
parents | 9364da723c1e |
children | 6574a888b539 |
rev | line source |
---|---|
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
1 ;;; emerge.el --- merge diffs under Emacs control |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
2 |
896 | 3 ;;; The author has placed this file in the public domain. |
583 | 4 |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
5 ;; Author: Dale R. Worley <drw@math.mit.edu> |
2496
9364da723c1e
(emerge-with-ancestor): Applied Donald Erway's fix patch, which
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
6 ;; Version: 4.1 |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
7 ;; Keywords: unix, tools |
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
8 |
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
9 ;;; Commentary: |
583 | 10 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
11 ;; This package assists you in reconciling differences between pair of files. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
12 |
583 | 13 ; - Starting |
14 ; | |
15 ; To start Emerge, you must run one of four commands: | |
16 ; | |
17 ; emerge-files | |
18 ; emerge-files-with-ancestor | |
19 ; emerge-buffers | |
20 ; emerge-buffers-with-ancestor | |
21 ; | |
22 ; The "files" versions prompt you for two file names (the "A" and "B" | |
23 ; files), the "buffers" versions prompt you for two buffer names (the | |
24 ; "A" and "B" buffers). Emerge then runs a "diff" of the two entities | |
25 ; (emerge-buffers writes the buffers into temporary files for input to | |
26 ; diff) and digests the output to form a list of the differences between | |
27 ; the two files. Then three buffers are set up: two containing the | |
28 ; entities (emerge-files does a find-file (C-x C-f) on the files to get | |
29 ; them into buffers), and one, the "merge buffer", which contains the | |
30 ; working copy of the merged file that you are constructing. The three | |
31 ; buffers are put up in a nice three-window display, showing the A and B | |
32 ; buffers in the upper half and the merge buffer in the lower half. | |
33 ; | |
34 ; The versions of the command that say "with-ancestor" ask for a third | |
35 ; name, that of an entity which is a common ancestor from which the | |
36 ; versions being merged were derived. These commands use "diff3" to | |
37 ; compare all three versions. If one version of a difference agrees | |
38 ; with the ancestor, then it is presumed that the other version is the | |
39 ; "correct" version, and is said to be "preferred". | |
40 ; | |
41 ; (Note that if you use emerge-files, Emerge attempts to make sure that | |
42 ; file on disk and the file in the buffer are the same. If the file on | |
43 ; disk has been changed, Emerge offers to revert the buffer. If the | |
44 ; buffer has been modified, Emerge offers to save the buffer. If the | |
45 ; user declines the offer, or if the file on disk and the buffer have | |
46 ; both been modified, Emerge aborts with an error message. Emerge is | |
47 ; careful to widen the buffers containing the files if they have been | |
48 ; narrowed. If you use emerge-buffers, the buffers are not widened -- | |
49 ; only the visible portion is used.) | |
50 ; | |
51 ; During the merge, the A and B buffers are read-only, so you don't | |
52 ; damage them. (This is because the A and B versions of the differences | |
53 ; are extracted from these buffers.) When you quit the merge, the | |
54 ; read-only/read-write status and modified flag on the A and B buffers | |
55 ; are restored. In addition, auto-saving of the A and B buffers is | |
56 ; suppressed during the merge. This is because Emerge modifies the A | |
57 ; and B buffers to point out the text of the differences, and it would | |
58 ; be useless to save these changes. (Just before suppressing | |
59 ; auto-saving, Emerge forces an auto-save.) | |
60 ; | |
61 ; If you give a prefix argument to emerge-files or | |
62 ; emerge-files-with-ancestor, it prompts you for another file name, | |
63 ; which is the file into which the merged file is to be written when you | |
64 ; exit Emerge. The output file name defaults to the A file name. If | |
65 ; you successfully quit Emerge, the merge buffer will be written to the | |
66 ; output file, and the buffers for the A, B, and ancestor buffers will | |
67 ; be deleted (if they exist and are not modified). If you abort Emerge, | |
68 ; the merge buffer will not be written and the buffers will not be | |
69 ; deleted. | |
70 ; | |
71 ; You can have any number of merges going at once -- just don't use any | |
72 ; one buffer as input to more than one merge at once, since that will | |
73 ; cause the read-only/modified/auto-save status save-and-restore to | |
74 ; screw up. | |
75 ; | |
76 ; Beware that when Emerge starts up, it does a diff or diff3 of the | |
77 ; files, which can take many minutes for long files with many | |
78 ; differences. Emacs can't do anything else until diff finishes. | |
79 ; | |
80 ; If diff or diff3 produces error messages, Emerge will beep and display | |
81 ; the error messages instead of the merge buffer. There will be a | |
82 ; message in the echo area giving the name of the merge buffer. Note | |
83 ; that this is really just an informational message -- you still have | |
84 ; switch to the merge buffer and abort the merge to restore the | |
85 ; conditions before you ran Emerge. (Emerge considers any output line | |
86 ; that does not match the regexp emerge-diff/diff3-ok-lines to be an | |
87 ; error message.) | |
88 ; | |
89 ; After the merge has been set up, Emerge runs the hooks in | |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
90 ; emerge-startup-hook. |
583 | 91 ; |
92 ; - Merging | |
93 ; | |
94 ; Once you have started the merge, you manipulate the merge buffer with | |
95 ; special commands issued in the merge buffer. You may also edit the | |
96 ; buffer with ordinary Emacs commands. Emerge keeps track of each | |
97 ; difference between the A and B buffers and the corresponding section | |
98 ; of the merge buffer. Initially, all differences show the A version, | |
99 ; except those for which B is preferred (because A agrees with the | |
100 ; ancestor), which show the B version. Emerge always has its attention | |
101 ; focused on one particular difference, which is marked off in the three | |
102 ; buffers by "vvvvvvvvvvvvvvvvvvvv" above and "^^^^^^^^^^^^^^^^^^^^" | |
103 ; below. The number of the difference is shown in the mode line. | |
104 ; | |
105 ; A merge buffer can be in two modes: "fast" mode and "edit" mode. In | |
106 ; fast mode, emerge commands are single characters, and ordinary Emacs | |
107 ; commands are disabled. This makes Emerge operations fast, but | |
108 ; prevents you from doing more than selecing the A or the B version of | |
109 ; differences. In edit mode, all emerge commands must be prefixed with | |
110 ; C-c, and all (non-conflicting) Emacs commands are available. This | |
111 ; allows editing the merge buffer, but slows down Emerge operations. | |
112 ; Edit and fast modes are indicated by "F" and "E" in the minor modes in | |
113 ; the mode line. | |
114 ; | |
115 ; The Emerge commands are: | |
116 ; | |
117 ; p go to the previous difference | |
118 ; n go to the next difference | |
119 ; a select the A version of this difference | |
120 ; b select the B version of this difference | |
121 ; j go to a particular difference (prefix argument | |
122 ; specifies which difference) (0j suppresses display of | |
123 ; the flags) | |
124 ; q quit - finish the merge* | |
125 ; f go into fast mode | |
126 ; e go into edit mode | |
127 ; s a set/clear auto-advance mode* | |
128 ; s s set/clear skip-prefers mode* | |
129 ; l recenter (C-l) all three windows* | |
130 ; - and 0 through 9 | |
131 ; prefix numeric arguments | |
132 ; d a select the A version as the default from here down in | |
133 ; the merge buffer* | |
134 ; d b select the B version as the default from here down in | |
135 ; the merge buffer* | |
136 ; c a copy the A version of the difference into the kill | |
137 ; ring | |
138 ; c b copy the B version of the difference into the kill | |
139 ; ring | |
140 ; i a insert the A version of the difference at the point | |
141 ; i b insert the B version of the difference at the point | |
142 ; m put the point and mark around the difference region | |
143 ; ^ scroll-down (like M-v) the three windows* | |
144 ; v scroll-up (like C-v) the three windows* | |
145 ; < scroll-left (like C-x <) the three windows* | |
146 ; > scroll-right (like C-x >) the three windows* | |
147 ; | reset horizontal scroll on the three windows* | |
148 ; x 1 shrink the merge window to one line (use C-u l to restore it | |
149 ; to full size) | |
150 ; x a find the difference containing a location in the A buffer* | |
151 ; x b find the difference containing a location in the B buffer* | |
152 ; x c combine the two versions of this difference* | |
153 ; x C combine the two versions of this difference, using a | |
154 ; register's value as the template* | |
155 ; x d find the difference containing a location in the merge buffer* | |
156 ; x f show the files/buffers Emerge is operating on in Help window | |
157 ; (use C-u l to restore windows) | |
158 ; x j join this difference with the following one | |
159 ; (C-u x j joins this difference with the previous one) | |
160 ; x l show line numbers of points in A, B, and merge buffers | |
161 ; x m change major mode of merge buffer* | |
162 ; x s split this difference into two differences | |
163 ; (first position the point in all three buffers to the places | |
164 ; to split the difference) | |
165 ; x t trim identical lines off top and bottom of difference | |
166 ; (such lines occur when the A and B versions are | |
167 ; identical but differ from the ancestor version) | |
168 ; x x set the template for the x c command* | |
169 ; | |
170 ; * - more details on these commands are given below | |
171 ; | |
172 ; emerge-version is a variable giving the version number of Emerge. It | |
173 ; is also a function which displays emerge-version (when called | |
174 ; interactively) or returns it (when called from a program). | |
175 ; | |
176 ; - Differences and their states | |
177 ; | |
178 ; A difference can have one of seven states: | |
179 ; | |
180 ; A: the difference is showing the A version. | |
181 ; | |
182 ; B: the difference is showing the B version. | |
183 ; | |
184 ; default-A and default-B: the difference is showing the A or B state, | |
185 ; but has never been selected by the user. All differences start in the | |
186 ; default-A state (and thus the merge buffer is a copy of the A buffer), | |
187 ; except those for which one buffer or another is preferred. When the | |
188 ; user selects the difference, it changes to the A or B state. | |
189 ; | |
190 ; prefer-A and prefer-B: the difference is showing the A or B state. In | |
191 ; addition, the other buffer (that is, for prefer-A, the B buffer; for | |
192 ; prefer-B, the A buffer) agrees with the ancestor buffer. Thus, | |
193 ; presumably, the displayed version is the correct one. The "a" and "b" | |
194 ; commands override these states, and turn them into the A and B states. | |
195 ; | |
196 ; combined: the difference is showing a combination of the A and B | |
197 ; states that was constructed by the "x c" or "x C" commands. Since | |
198 ; this state is neither the A or B states, the "a" and "b" commands | |
199 ; won't alter the difference unless they are given a prefix argument. | |
200 ; | |
201 ; The state of the currently selected difference is shown in the mode | |
202 ; line of the merge window: | |
203 ; | |
204 ; state display | |
205 ; | |
206 ; A A | |
207 ; B B | |
208 ; prefer-A A* | |
209 ; prefer-B B* | |
210 ; combined comb | |
211 ; | |
212 ; - Select default commands (d a and d b) | |
213 ; | |
214 ; The d a and d b commands change all default-A's to default-B's (or | |
215 ; vice-versa) from the selected difference on down to the end of the | |
216 ; file to default-A or default-B, respectively. (Since a difference | |
217 ; that has been selected can not have state default-A or default-B, it | |
218 ; will never be affected by d a or d b. This leads to the unexpected | |
219 ; result that d a or d b never affects the difference selected at the | |
220 ; moment, but prevents differences that you have already looked at from | |
221 ; changing unexpectedly.) | |
222 ; | |
223 ; If you work your way down from the top of the file, using d a and d b | |
224 ; at judicious points, you can effectivly make the A version the default | |
225 ; for some sections of the merge buffer and the B version the default | |
226 ; for others. | |
227 ; | |
228 ; - Exiting (q) | |
229 ; | |
230 ; The quit command finishes the merge session by restoring the state of | |
231 ; the A and B buffers and removing the markers around the currently | |
232 ; selected difference. It also disables the Emerge commands in the | |
233 ; merge buffer, since executing them later could damage the contents of | |
234 ; the various buffers. | |
235 ; | |
236 ; The action of "q" depends on how Emerge was started and whether "q" | |
237 ; was given a prefix argument. If there was no prefix argument, it is | |
238 ; considered a "successful" finish. If there was a prefix argument, it | |
239 ; is considered an "unsuccessful" finish. In either case, you are asked | |
240 ; to cofirm the exit, and the confirmation message tells which sort of | |
241 ; exit you are confirming. | |
242 ; | |
243 ; If Emerge was started by some other process, success/failure is | |
244 ; reported to the caller. | |
245 ; | |
246 ; If Emerge was started with emerge-files or emerge-files-with-ancestor, | |
247 ; if a prefix argument was given to that command, then you specified a | |
248 ; file into which the merge is to be written. A successful exit writes | |
249 ; the merge into the output file and then kills the A, B, and ancestor | |
250 ; buffers (so they aren't lying around to confuse you, since they | |
251 ; probably all have similar names). | |
252 ; | |
253 ; - Auto-advance mode (s a) | |
254 ; | |
255 ; If auto-advance mode is set, the "a" and "b" commands perform an "n" | |
256 ; (select next difference) afterward. When auto-advance mode is set, | |
257 ; it is indicated by "A" in the minor modes in the mode line. | |
258 ; "s a" with a positive argument sets auto-advance, with a non-positive | |
259 ; argument clears it, and with no argument toggles it. | |
260 ; | |
261 ; - Skip-prefers mode (s s) | |
262 ; | |
263 ; If skip-prefers mode is set, the "n" and "p" commands skip over | |
264 ; differences with states prefer-A and prefer-B. Thus you will only see | |
265 ; differences for which one version isn't presumed "correct". When | |
266 ; skip-prefers mode is set, it is indicated by "S" in the minor modes in | |
267 ; the mode line. "s s" with a positive argument sets auto-advance, with | |
268 ; a non-positive argument clears it, and with no argument toggles it. | |
269 ; | |
270 ; - Recenter (l) | |
271 ; | |
272 ; The Emerge "l" command causes the selected difference to be brought | |
273 ; into view in the three windows, or at least, whichever of the three | |
274 ; merge buffers are visible at the moment. If a prefix argument is | |
275 ; given, then the original three-window display is set up before the | |
276 ; difference texts are shown. | |
277 ; | |
278 ; - Scrolling the text (^, v, <, >, and |) | |
279 ; | |
280 ; Emerge has several commands which scroll all three windows by the same | |
281 ; amount, thus allowing you to easily compare the versions of the text. | |
282 ; The commands are "^" (scroll-up), "v" (scroll-down), "<" | |
283 ; (scroll-left), ">" (scroll-right), and "|" (reset horizontal | |
284 ; scrolling). (Remember that Emacs names scrolling commands by the | |
285 ; motion of the text with respect to the window, so C-v is called | |
286 ; "scroll-up".) | |
287 ; | |
288 ; If these commands (except "|") are given an argument, that is the | |
289 ; number of lines or characters by which the windows are scrolled. | |
290 ; Otherwise, the amount of motion is computed based on the dimensions of | |
291 ; the merge buffer window -- the height of the merge buffer window | |
778 | 292 ; (minus next-frame-context-lines), or half the width of the merge |
583 | 293 ; buffer window. (The A and B version windows are assumed to be as high |
294 ; as the merge window, but half as wide.) If the argument is just `C-u | |
295 ; -', then the scrolling is half the default amount. | |
296 ; | |
297 ; - Finding the difference at or near a location (x d, x a, and x b) | |
298 ; | |
299 ; The "x d" command selects the difference containing the current point | |
300 ; in the merge buffer. If there is no difference containing the point, | |
301 ; an error is given. An argument can be given to the command to change | |
302 ; this behavior: if the argument is positive (e.g., C-u), the next | |
303 ; following difference is selected; if the argument is negative (e.g., | |
304 ; C-u -), the previous difference is selected. | |
305 ; | |
306 ; The "x a" and "x b" commands select the difference containing the | |
307 ; current point in the A and B buffers, respectively. Otherwise, they | |
308 ; act like the "x d" command. Note that although the point used in the | |
309 ; commands is not the merge buffer point, the commands can only be | |
310 ; issued in the merge buffer, because it is the only buffer with the | |
311 ; Emerge keymap. | |
312 ; | |
313 ; - Combining the two versions (x c, x C, and x x) | |
314 ; | |
315 ; Sometimes one wants to combine the two versions of a difference. For | |
316 ; instance, when merging two versions of a program, one wants to make | |
317 ; something like this: | |
318 ; | |
319 ; #ifdef NEW | |
320 ; ...new version of code... | |
321 ; #else /* NEW */ | |
322 ; ...old version of code... | |
323 ; #endif /* NEW */ | |
324 ; | |
325 ; The "x c" command will make such a combined version. (Note that any | |
326 ; combined version is not the same as either the A or B versions, and so | |
327 ; the "a" and "b" commands will refuse to alter it unless they are given | |
328 ; a prefix argument.) The combination is made under control of a | |
329 ; template, which is a character string with the following | |
330 ; interpolations: | |
331 ; | |
332 ; %a the A version of the difference | |
333 ; %b the B version of the difference | |
334 ; %% the character '%' | |
335 ; | |
336 ; Thus, the template used above is | |
337 ; | |
338 ; #ifdef NEW\n%b#else /* NEW */\n%a#endif /* NEW */\n | |
339 ; | |
340 ; (using \n here to represent newlines). The template is stored in the | |
341 ; variable emerge-combine-versions-template, and its initial value is | |
342 ; the one given above. The template can be set (from the current | |
343 ; region) by the "x x" command. (Be careful to get the newlines in the | |
344 ; template in the right places!) ("x x" was chosen by analogy with "C-x | |
345 ; x".) ("x x" is only available in the merge buffer, of course. | |
346 ; Elsewhere, M-x emerge-set-combine-versions-template can be used.) If | |
347 ; "x x" is given a prefix argument, emerge-combine-versions-template is | |
348 ; localized in the merge buffer before its value is set, so the "x x" | |
349 ; command's effect (and the effect of any later "x x" command in the | |
350 ; merge buffer) is only on the merge buffer. | |
351 ; | |
352 ; The "x C" command is like "x c", but it prompts for a character | |
353 ; which is the register whose value is to be used as the template. | |
354 ; This allows one to use multiple templates conveniently. | |
355 ; | |
356 ; - Changing the major mode of the edit buffer (x m) | |
357 ; | |
358 ; The "x m" command prompts for the name of a major-mode-setting command | |
359 ; and executes it. Ordinarily, major-mode-setting commands change the | |
360 ; mode line and local keymap, so the "x m" command then resets the | |
361 ; Emerge mode line and the fast or edit mode local keymap, as | |
362 ; appropriate. | |
363 ; | |
364 ; If you have already changed the major mode of the merge buffer and | |
365 ; lost the Emerge keymap, you can use M-x emerge-set-merge-mode to | |
366 ; execute this command. | |
367 ; | |
368 ; Beware that "x m" accepts any command name, not just | |
369 ; major-mode-setting commands. | |
370 ; | |
371 ; - Writing the merge buffer manually | |
372 ; | |
373 ; Emerge places a wrapper (emerge-query-and-call) on the key bindings of | |
374 ; save-buffer (usually "C-x C-s") and write-file (usually "C-x C-w"), in | |
375 ; order to protect the user from writing out the merge before it is | |
376 ; finished. Emerge-query-and-call asks the user if he is sure he wants | |
377 ; to write out the incomplete merge. If he answers yes, the buffer is | |
378 ; written out. The flags are suppressed while the write is being done. | |
379 ; As a result of this, the displayed portions of the buffers are | |
380 ; recentered (equivalent to "l"). | |
381 ; | |
382 ; - Running Emerge standalone | |
383 ; | |
384 ; If you invoke emacs with the following arguments, you can execute | |
385 ; Emerge as a standalone program: | |
386 ; | |
387 ; emacs -l emerge -f emerge-files-command file-a file-b file-out | |
388 ; | |
389 ; emacs -l emerge -f emerge-files-with-ancestor-command | |
390 ; file-a file-b file-ancestor file-out | |
391 ; | |
392 ; When the user gives the "q" (quit) command, Emerge will write out the | |
393 ; merge buffer in file-out and terminate Emacs. If a prefix argument is | |
394 ; given, Emacs will terminate with an unsuccessful return code (1), if | |
395 ; not, it will terminate with a successful return code (0). | |
396 ; | |
397 ; - Invoking Emerge remotely | |
398 ; | |
399 ; If you use the Emacs client/server code that supports remote | |
400 ; execution, then you can invoke Emerge remotely by executing one of the | |
401 ; Lisp calls: | |
402 ; | |
403 ; (emerge-files-remote "file A" "file B" "output file") | |
404 ; | |
405 ; (emerge-files-with-ancestor-remote "file A" "file B" | |
406 ; "ancestor file" "output file") | |
407 ; | |
408 ; Returning a successful/unsuccessful return code is not yet supported | |
409 ; by the Emacs client/server code. | |
410 ; | |
411 ; Beware that in systems of networked workstations, even though all user | |
412 ; directories are shared between all the workstations, the /tmp | |
413 ; directory on each workstation is not shared, so writing files into | |
414 ; /tmp and then remotely invoking Emerge is not likely to work. | |
415 ; | |
416 ; - Effect of merge flags on indenting code | |
417 ; | |
418 ; The presence of the flags confuses the indentation code of C and | |
419 ; Emacs-Lisp modes. Starting the flag strings | |
420 ; (emerge-{before,after}-flag) with '#' (for C) or ';' (for Lisp) | |
421 ; prevents the indentation code from noticing the flags. Remember to | |
422 ; change the flag strings before loading Emerge, or to execute | |
423 ; emerge-new-flags after changing them. But never change the flag | |
424 ; strings while a merge is being performed. | |
425 ; | |
426 ; - Autoloading | |
427 ; | |
428 ; The following autoloads will make all top-level Emerge files | |
429 ; autoloading. Make sure that "emerge" is in a directory on load-path. | |
430 ; | |
431 ; (autoload 'emerge-files "emerge" | |
432 ; "Run Emerge on two files." | |
433 ; t) | |
434 ; (autoload 'emerge-files-with-ancestor "emerge" | |
435 ; "Run Emerge on two files, giving another file as the ancestor." | |
436 ; t) | |
437 ; (autoload 'emerge-buffers "emerge" | |
438 ; "Run Emerge on two buffers." | |
439 ; t) | |
440 ; (autoload 'emerge-buffers-with-ancestor "emerge" | |
441 ; "Run Emerge on two buffers, giving another buffer as the ancestor." | |
442 ; t) | |
443 ; (autoload 'emerge-files-command "emerge") | |
444 ; (autoload 'emerge-files-with-ancestor-command "emerge") | |
445 ; (autoload 'emerge-files-remote "emerge") | |
446 ; (autoload 'emerge-files-with-ancestor-remote "emerge") | |
447 ; | |
448 ; ================================================================ | |
449 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
450 ;;; Change Log: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
451 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
452 ; - Changes from version 3 to version 4 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
453 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
454 ; More configuration variables are marked as user options. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
455 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
456 ; Code is included for an improved version of make-auto-save-file-name |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
457 ; which eliminates many problems with the default version. See the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
458 ; documentation of emerge-make-auto-save-file-name to see how to |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
459 ; activate it. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
460 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
461 ; Emerge now works with Gnu diff3, which can produce the groups of lines |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
462 ; from the various files in the order 1, 2, 3 or 1, 3, 2. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
463 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
464 ; Added x f command to show what files or buffers are being operated on. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
465 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
466 ; The merge buffer now starts read-only, which being in fast mode it |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
467 ; should be. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
468 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
469 ; When merging buffers, Emerge writes their contents into temporary |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
470 ; files in the directory $TMPDIR (if it is defined), or /tmp by default. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
471 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
472 ; Added x j command to join two differences. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
473 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
474 ; Added x s command to split a difference into two differences. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
475 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
476 ; Added emerge-version variable and function to report the version of Emerge |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
477 ; being run. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
478 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
479 ; Added x t command to trim unchanged lines off top and bottom of |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
480 ; difference region. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
481 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
482 ; Added x d, x a, and x b commands to locate the differences at or near |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
483 ; a given location in one of the buffers. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
484 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
485 ; Emerge no longer tries to copy the minor modes from the A buffer to |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
486 ; the merge buffer, only the major mode. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
487 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
488 ; The programs executed to find the differences between versions of the file |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
489 ; are no longer controlled by emerge-diff/diff3-command, but rather by: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
490 ; emerge-diff-program |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
491 ; Variable: *Name of the program which compares two files. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
492 ; emerge-diff3-program |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
493 ; Variable: *Name of the program which compares an ancestor file |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
494 ; (first argument) and two variant files (second and third arguments). |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
495 ; emerge-diff-options |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
496 ; Variable: *Options to be passed to emerge-diff/diff3-program. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
497 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
498 ; The names of the files are expanded (see expand-file-name) before being |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
499 ; passed to emerge-diff/diff3-program, so diff need not invoked under a shell |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
500 ; that understands '~', for instance. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
501 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
502 ; If the diff/diff3 program reports errors, the user is notified and the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
503 ; errors are displayed. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
504 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
505 ; The command "0j" can be used to suppress the flags from showing in the buffers. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
506 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
507 ; A discussion of the effect of the merge flags on indentation of code |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
508 ; has been added to the documentation. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
509 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
510 ; If kill-fix.el is loaded, Emerge control variables new have their |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
511 ; 'preserved' property set, so setting the major mode in the merge |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
512 ; buffer doesn't destroy Emerge's state. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
513 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
514 ; Added x c, x C, and x x commands to allow the A and B versions to be |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
515 ; combined into #ifdef - #endif forms. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
516 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
517 ; Replaced calls of "ding" to calls of "error" where appropriate. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
518 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
519 ; Added x m command to allow major mode of merge buffer to be changed. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
520 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
521 ; Added x 1 command to shrink the merge window to one line. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
522 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
523 ; Added emerge-startup-hook to allow customization. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
524 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
525 ; Fixed a bug that is activated when a remote merge request is made when |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
526 ; the minibuffer window is selected. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
527 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
528 ; - Changes from version 2 to version 3 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
529 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
530 ; The directory into which temporary files are written is now controlled |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
531 ; by a user option (emerge-temp-file-prefix). |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
532 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
533 ; The A and B versions of the difference can be loaded into the kill |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
534 ; ring with the "c a" and "c b" commands. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
535 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
536 ; The A and B versions of the difference can be inserted into the merge |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
537 ; buffer with the "i a" and "i b" commands. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
538 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
539 ; The difference region of the merge buffer can be surrounded by the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
540 ; point and mark with the "m" command. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
541 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
542 ; The three windows can be scrolled together with the "^", "v", "<", |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
543 ; ">", and "|" commands. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
544 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
545 ; The "s s" and "s a" commands report the state of the option in the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
546 ; echo area. Similarly, the "f" and "e" commands report what they do in |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
547 ; the echo area. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
548 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
549 ; The "q" command has been revamped, and its behavior is now controlled |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
550 ; by the manner in which Emerge is started. In particular, if you wish |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
551 ; to write the merge buffer into a file upon exiting, invoke |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
552 ; emerge-files[-with-ancestor] with a prefix argument, and it will |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
553 ; prompt you for the file name. Then exiting will write the merge |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
554 ; buffer to the file, unless "q" is given a prefix argument. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
555 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
556 ; The "i a" and "i b" commands now work in fast mode. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
557 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
558 ; The modifications that Emerge makes to save-buffer and write-file are |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
559 ; described. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
560 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
561 ; Emerge now handles merging narrowed buffers correctly. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
562 ; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
563 ; Emerge now isn't fooled when the buffer visiting a file is not the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
564 ; same as the file on disk. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2029
diff
changeset
|
565 |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
566 ;;; Code: |
583 | 567 |
568 ;;; Macros | |
569 | |
570 (defmacro emerge-eval-in-buffer (buffer &rest forms) | |
571 "Macro to switch to BUFFER, evaluate FORMS, returns to original buffer. | |
1429 | 572 Differs from `save-excursion' in that it doesn't save the point and mark." |
583 | 573 (` (let ((StartBuffer (current-buffer))) |
574 (unwind-protect | |
575 (progn | |
576 (set-buffer (, buffer)) | |
577 (,@ forms)) | |
578 (set-buffer StartBuffer))))) | |
579 | |
580 (defmacro emerge-defvar-local (var value doc) | |
1429 | 581 "Defines SYMBOL as an advertised variable. |
582 Performs a defvar, then executes `make-variable-buffer-local' on | |
583 the variable. Also sets the 'preserved' property, so that | |
584 `kill-all-local-variables' (called by major-mode setting commands) | |
585 won't destroy Emerge control variables." | |
583 | 586 (` (progn |
587 (defvar (, var) (, value) (, doc)) | |
588 (make-variable-buffer-local '(, var)) | |
589 (put '(, var) 'preserved t)))) | |
590 | |
591 ;; Add entries to minor-mode-alist so that emerge modes show correctly | |
592 (setq emerge-minor-modes-list '((emerge-mode " Emerge") | |
593 (emerge-fast-mode " F") | |
594 (emerge-edit-mode " E") | |
595 (emerge-auto-advance " A") | |
596 (emerge-skip-prefers " S"))) | |
597 (if (not (assq 'emerge-mode minor-mode-alist)) | |
598 (setq minor-mode-alist (append emerge-minor-modes-list | |
599 minor-mode-alist))) | |
600 | |
601 ;; We need to define this function so describe-mode can describe Emerge mode. | |
602 (defun emerge-mode () | |
1429 | 603 "Emerge mode is used by the Emerge file-merging package. |
604 It is entered only through one of the functions: | |
605 `emerge-files' | |
606 `emerge-files-with-ancestor' | |
607 `emerge-buffers' | |
608 `emerge-buffers-with-ancestor' | |
609 `emerge-files-command' | |
610 `emerge-files-with-ancestor-command' | |
611 `emerge-files-remote' | |
612 `emerge-files-with-ancestor-remote' | |
583 | 613 |
614 Commands: | |
615 \\{emerge-basic-keymap} | |
616 Commands must be prefixed by \\<emerge-fast-keymap>\\[emerge-basic-keymap] in 'edit' mode, but can be invoked directly | |
617 in 'fast' mode.") | |
618 | |
619 (defvar emerge-version "4" | |
620 "The version of Emerge.") | |
621 | |
622 (defun emerge-version () | |
1429 | 623 "Return string describing the version of Emerge. |
624 When called interactively, displays the version." | |
583 | 625 (interactive) |
626 (if (interactive-p) | |
627 (message "Emerge version %s" (emerge-version)) | |
628 emerge-version)) | |
629 | |
630 ;;; Emerge configuration variables | |
631 | |
632 ;; Commands that produce difference files | |
633 ;; All that can be configured is the name of the programs to execute | |
634 ;; (emerge-diff-program and emerge-diff3-program) and the options | |
635 ;; to be provided (emerge-diff-options). The order in which the file names | |
636 ;; are given is fixed. | |
637 ;; The file names are always expanded (see expand-file-name) before being | |
638 ;; passed to diff, thus they need not be invoked under a shell that | |
639 ;; understands '~'. | |
640 ;; The code which processes the diff/diff3 output depends on all the | |
641 ;; finicky details of their output, including the somewhat strange | |
642 ;; way they number lines of a file. | |
643 (defvar emerge-diff-program "diff" | |
644 "*Name of the program which compares two files.") | |
645 (defvar emerge-diff3-program "diff3" | |
646 "*Name of the program which compares an ancestor file (first argument) | |
647 and two variant files (second and third arguments).") | |
648 (defvar emerge-diff-options "" | |
649 "*Options to be passed to emerge-diff/diff3-program.") | |
650 (defvar emerge-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)")) | |
651 (concat "^" x "\\([acd]\\)" x "$")) | |
652 "*Pattern to match lines produced by diff that describe differences (as | |
653 opposed to lines from the source files).") | |
654 (defvar emerge-diff-ok-lines | |
655 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\)" | |
656 "*Regexp that matches normal output lines from emerge-diff-program . | |
657 Lines that do not match are assumed to be error output.") | |
658 (defvar emerge-diff3-ok-lines | |
659 "^\\([1-3]:\\|====\\| \\)" | |
660 "*Regexp that matches normal output lines from emerge-diff3-program . | |
661 Lines that do not match are assumed to be error output.") | |
662 | |
663 ;; The flags used to mark differences in the buffers. | |
664 | |
665 ;; These function definitions need to be up here, because they are used | |
666 ;; during loading. | |
667 (defun emerge-new-flags () | |
1429 | 668 "Function to be called after `emerge-{before,after}-flag'. |
669 This is called after these functions are changed to compute values that | |
670 depend on the flags." | |
583 | 671 (setq emerge-before-flag-length (length emerge-before-flag)) |
672 (setq emerge-before-flag-lines | |
673 (count-matches-string emerge-before-flag "\n")) | |
674 (setq emerge-before-flag-match (regexp-quote emerge-before-flag)) | |
675 (setq emerge-after-flag-length (length emerge-after-flag)) | |
676 (setq emerge-after-flag-lines | |
677 (count-matches-string emerge-after-flag "\n")) | |
678 (setq emerge-after-flag-match (regexp-quote emerge-after-flag))) | |
679 (defun count-matches-string (string regexp) | |
680 "Return the number of matches in STRING for REGEXP." | |
681 (let ((i 0) | |
682 (count 0)) | |
683 (while (string-match regexp string i) | |
684 (setq count (1+ count)) | |
685 (setq i (match-end 0))) | |
686 count)) | |
687 | |
688 (defvar emerge-before-flag "vvvvvvvvvvvvvvvvvvvv\n" | |
689 "*Flag placed above the highlighted block of code. Must end with newline. | |
690 Must be set before Emerge is loaded, or emerge-new-flags must be run | |
691 after setting.") | |
692 (defvar emerge-after-flag "^^^^^^^^^^^^^^^^^^^^\n" | |
693 "*Flag placed below the highlighted block of code. Must end with newline. | |
694 Must be set before Emerge is loaded, or emerge-new-flags must be run | |
695 after setting.") | |
696 | |
697 ;; Calculate dependent variables | |
698 (emerge-new-flags) | |
699 | |
700 (defvar emerge-min-visible-lines 3 | |
701 "*Number of lines that we want to show above and below the flags when we are | |
702 displaying a difference.") | |
703 | |
704 (defvar emerge-temp-file-prefix | |
705 (let ((env (getenv "TMPDIR")) | |
706 d) | |
707 (setq d (if (and env (> (length env) 0)) | |
708 env | |
709 "/tmp")) | |
710 (if (= (aref d (1- (length d))) ?/) | |
711 (setq d (substring d 0 -1))) | |
712 (concat d "/emerge")) | |
713 "*Prefix to put on Emerge temporary file names. | |
714 Do not start with '~/' or '~user-name/'.") | |
715 | |
716 (defvar emerge-temp-file-mode 384 ; u=rw only | |
717 "*Mode for Emerge temporary files.") | |
718 | |
719 (defvar emerge-combine-versions-template | |
720 "#ifdef NEW\n%b#else /* NEW */\n%a#endif /* NEW */\n" | |
721 "*Template for emerge-combine-versions to combine the two versions. | |
722 The template is inserted as a string, with the following interpolations: | |
723 %a the A version of the difference | |
724 %b the B version of the difference | |
725 %% the character '%' | |
726 Don't forget to end the template with a newline. | |
727 Note that this variable can be made local to a particular merge buffer by | |
728 giving a prefix argument to emerge-set-combine-versions-template .") | |
729 | |
730 ;; Build keymaps | |
731 | |
732 (defvar emerge-basic-keymap nil | |
733 "Keymap of Emerge commands. | |
734 Directly available in 'fast' mode; | |
735 must be prefixed by \\<emerge-fast-keymap>\\[emerge-basic-keymap] in 'edit' mode.") | |
736 | |
737 (defvar emerge-fast-keymap nil | |
738 "Local keymap used in Emerge 'fast' mode. | |
739 Makes Emerge commands directly available.") | |
740 | |
741 (defvar emerge-command-prefix "\C-c" | |
742 "*Command prefix for Emerge commands in 'edit' mode. | |
743 Must be set before Emerge is loaded.") | |
744 | |
745 ;; This function sets up the fixed keymaps. It is executed when the first | |
746 ;; Emerge is done to allow the user maximum time to set up the global keymap. | |
747 (defun emerge-setup-fixed-keymaps () | |
748 ;; Set up the basic keymap | |
749 (setq emerge-basic-keymap (make-keymap)) | |
750 (suppress-keymap emerge-basic-keymap) ; this sets 0..9 to digit-argument and | |
751 ; - to negative-argument | |
752 (define-key emerge-basic-keymap "p" 'emerge-previous-difference) | |
753 (define-key emerge-basic-keymap "n" 'emerge-next-difference) | |
754 (define-key emerge-basic-keymap "a" 'emerge-select-A) | |
755 (define-key emerge-basic-keymap "b" 'emerge-select-B) | |
756 (define-key emerge-basic-keymap "j" 'emerge-jump-to-difference) | |
757 (define-key emerge-basic-keymap "q" 'emerge-quit) | |
758 (define-key emerge-basic-keymap "f" 'emerge-fast-mode) | |
759 (define-key emerge-basic-keymap "e" 'emerge-edit-mode) | |
760 (define-key emerge-basic-keymap "s" nil) | |
761 (define-key emerge-basic-keymap "sa" 'emerge-auto-advance) | |
762 (define-key emerge-basic-keymap "ss" 'emerge-skip-prefers) | |
763 (define-key emerge-basic-keymap "l" 'emerge-recenter) | |
764 (define-key emerge-basic-keymap "d" nil) | |
765 (define-key emerge-basic-keymap "da" 'emerge-default-A) | |
766 (define-key emerge-basic-keymap "db" 'emerge-default-B) | |
767 (define-key emerge-basic-keymap "c" nil) | |
768 (define-key emerge-basic-keymap "ca" 'emerge-copy-as-kill-A) | |
769 (define-key emerge-basic-keymap "cb" 'emerge-copy-as-kill-B) | |
770 (define-key emerge-basic-keymap "i" nil) | |
771 (define-key emerge-basic-keymap "ia" 'emerge-insert-A) | |
772 (define-key emerge-basic-keymap "ib" 'emerge-insert-B) | |
773 (define-key emerge-basic-keymap "m" 'emerge-mark-difference) | |
774 (define-key emerge-basic-keymap "v" 'emerge-scroll-up) | |
775 (define-key emerge-basic-keymap "^" 'emerge-scroll-down) | |
776 (define-key emerge-basic-keymap "<" 'emerge-scroll-left) | |
777 (define-key emerge-basic-keymap ">" 'emerge-scroll-right) | |
778 (define-key emerge-basic-keymap "|" 'emerge-scroll-reset) | |
779 (define-key emerge-basic-keymap "x" nil) | |
780 (define-key emerge-basic-keymap "x1" 'emerge-one-line-window) | |
781 (define-key emerge-basic-keymap "xa" 'emerge-find-difference-A) | |
782 (define-key emerge-basic-keymap "xb" 'emerge-find-difference-B) | |
783 (define-key emerge-basic-keymap "xc" 'emerge-combine-versions) | |
784 (define-key emerge-basic-keymap "xC" 'emerge-combine-versions-register) | |
785 (define-key emerge-basic-keymap "xd" 'emerge-find-difference) | |
786 (define-key emerge-basic-keymap "xf" 'emerge-file-names) | |
787 (define-key emerge-basic-keymap "xj" 'emerge-join-differences) | |
788 (define-key emerge-basic-keymap "xl" 'emerge-line-numbers) | |
789 (define-key emerge-basic-keymap "xm" 'emerge-set-merge-mode) | |
790 (define-key emerge-basic-keymap "xs" 'emerge-split-difference) | |
791 (define-key emerge-basic-keymap "xt" 'emerge-trim-difference) | |
792 (define-key emerge-basic-keymap "xx" 'emerge-set-combine-versions-template) | |
793 ;; Allow emerge-basic-keymap to be referenced indirectly | |
794 (fset 'emerge-basic-keymap emerge-basic-keymap) | |
795 ;; Set up the fast mode keymap | |
796 (setq emerge-fast-keymap (copy-keymap emerge-basic-keymap)) | |
797 ;; Allow prefixed commands to work in fast mode | |
798 (define-key emerge-fast-keymap emerge-command-prefix 'emerge-basic-keymap) | |
799 ;; Allow emerge-fast-keymap to be referenced indirectly | |
800 (fset 'emerge-fast-keymap emerge-fast-keymap) | |
801 ;; Suppress write-file and save-buffer | |
802 (emerge-shadow-key-definition 'write-file 'emerge-query-write-file | |
803 (current-global-map) emerge-fast-keymap) | |
804 (emerge-shadow-key-definition 'save-buffer 'emerge-query-save-buffer | |
805 (current-global-map) emerge-fast-keymap)) | |
806 | |
807 ;; Variables which control each merge. They are local to the merge buffer. | |
808 | |
809 ;; Mode variables | |
810 (emerge-defvar-local emerge-mode nil | |
811 "Indicator for emerge-mode.") | |
812 (emerge-defvar-local emerge-fast-mode nil | |
813 "Indicator for emerge-mode fast submode.") | |
814 (emerge-defvar-local emerge-edit-mode nil | |
815 "Indicator for emerge-mode edit submode.") | |
816 (emerge-defvar-local emerge-A-buffer nil | |
817 "The buffer in which the A variant is stored.") | |
818 (emerge-defvar-local emerge-B-buffer nil | |
819 "The buffer in which the B variant is stored.") | |
820 (emerge-defvar-local emerge-merge-buffer nil | |
821 "The buffer in which the merged file is manipulated.") | |
822 (emerge-defvar-local emerge-ancestor-buffer nil | |
823 "The buffer in which the ancestor variant is stored, | |
824 or nil if there is none.") | |
825 | |
826 (defconst emerge-saved-variables | |
827 '((buffer-modified-p set-buffer-modified-p) | |
828 buffer-read-only | |
829 buffer-auto-save-file-name) | |
830 "Variables and properties of a buffer which are saved, modified and restored | |
831 during a merge.") | |
832 (defconst emerge-merging-values '(nil t nil) | |
833 "Values to be assigned to emerge-saved-variables during a merge.") | |
834 | |
835 (emerge-defvar-local emerge-A-buffer-values nil | |
836 "Remembers emerge-saved-variables for emerge-A-buffer.") | |
837 (emerge-defvar-local emerge-B-buffer-values nil | |
838 "Remembers emerge-saved-variables for emerge-B-buffer.") | |
839 | |
840 (emerge-defvar-local emerge-difference-list nil | |
841 "Vector of differences between the variants, and markers in the buffers to | |
842 show where they are. Each difference is represented by a vector of seven | |
843 elements. The first two are markers to the beginning and end of the difference | |
844 section in the A buffer, the second two are markers for the B buffer, the third | |
845 two are markers for the merge buffer, and the last element is the \"state\" of | |
846 that difference in the merge buffer. | |
847 A section of a buffer is described by two markers, one to the beginning of | |
848 the first line of the section, and one to the beginning of the first line | |
849 after the section. (If the section is empty, both markers point to the same | |
850 point.) If the section is part of the selected difference, then the markers | |
851 are moved into the flags, so the user can edit the section without disturbing | |
852 the markers. | |
853 The \"states\" are: | |
854 A the merge buffer currently contains the A variant | |
855 B the merge buffer currently contains the B variant | |
856 default-A the merge buffer contains the A variant by default, | |
857 but this difference hasn't been selected yet, so | |
858 change-default commands can alter it | |
859 default-B the merge buffer contains the B variant by default, | |
860 but this difference hasn't been selected yet, so | |
861 change-default commands can alter it | |
862 prefer-A in a three-file merge, the A variant is the prefered | |
863 choice | |
864 prefer-B in a three-file merge, the B variant is the prefered | |
865 choice") | |
866 (emerge-defvar-local emerge-current-difference -1 | |
867 "The difference that is currently selected.") | |
868 (emerge-defvar-local emerge-number-of-differences nil | |
869 "Number of differences found.") | |
870 (emerge-defvar-local emerge-edit-keymap nil | |
871 "The local keymap for the merge buffer, with the emerge commands defined in | |
872 it. Used to save the local keymap during fast mode, when the local keymap is | |
873 replaced by emerge-fast-keymap.") | |
874 (emerge-defvar-local emerge-old-keymap nil | |
875 "The original local keymap for the merge buffer.") | |
876 (emerge-defvar-local emerge-auto-advance nil | |
877 "*If non-nil, emerge-select-A and emerge-select-B automatically advance to | |
878 the next difference.") | |
879 (emerge-defvar-local emerge-skip-prefers nil | |
880 "*If non-nil, differences for which there is a preference are automatically | |
881 skipped.") | |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
882 (emerge-defvar-local emerge-startup-hook nil |
583 | 883 "*Hooks to run in the merge buffer after the merge has been set up.") |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
884 (emerge-defvar-local emerge-quit-hook nil |
583 | 885 "Hooks to run in the merge buffer after the merge has been finished. |
886 emerge-prefix-argument will be bound to the prefix argument of the emerge-quit | |
887 command. | |
888 This is not a user option, since Emerge uses it for its own processing.") | |
889 (emerge-defvar-local emerge-output-description nil | |
1429 | 890 "Describes output destination merge, for the use of `emerge-file-names'.") |
583 | 891 |
892 ;;; Setup functions for two-file mode. | |
893 | |
894 (defun emerge-files-internal (file-A file-B &optional startup-hooks quit-hooks | |
895 output-file) | |
896 (let ((buffer-A (find-file-noselect file-A)) | |
897 (buffer-B (find-file-noselect file-B))) | |
898 ;; Make sure the entire files are seen, and they reflect what is on disk | |
899 (emerge-eval-in-buffer buffer-A | |
900 (widen) | |
901 (emerge-verify-file-buffer)) | |
902 (emerge-eval-in-buffer buffer-B | |
903 (widen) | |
904 (emerge-verify-file-buffer)) | |
905 (emerge-setup buffer-A file-A buffer-B file-B startup-hooks quit-hooks | |
906 output-file))) | |
907 | |
908 ;; Start up Emerge on two files | |
909 (defun emerge-setup (buffer-A file-A buffer-B file-B startup-hooks quit-hooks | |
910 output-file) | |
911 (setq file-A (expand-file-name file-A)) | |
912 (setq file-B (expand-file-name file-B)) | |
913 (setq output-file (and output-file (expand-file-name output-file))) | |
914 (let* ((merge-buffer-name (emerge-unique-buffer-name "*merge" "*")) | |
915 ;; create the merge buffer from buffer A, so it inherits buffer A's | |
916 ;; default directory, etc. | |
917 (merge-buffer (emerge-eval-in-buffer | |
918 buffer-A | |
919 (get-buffer-create merge-buffer-name)))) | |
920 (emerge-eval-in-buffer | |
921 merge-buffer | |
922 (emerge-copy-modes buffer-A) | |
923 (setq buffer-read-only nil) | |
924 (auto-save-mode 1) | |
925 (setq emerge-mode t) | |
926 (setq emerge-A-buffer buffer-A) | |
927 (setq emerge-B-buffer buffer-B) | |
928 (setq emerge-ancestor-buffer nil) | |
929 (setq emerge-merge-buffer merge-buffer) | |
930 (setq emerge-output-description | |
931 (if output-file | |
932 (concat "Output to file: " output-file) | |
933 (concat "Output to buffer: " (buffer-name merge-buffer)))) | |
934 (insert-buffer emerge-A-buffer) | |
935 (emerge-set-keys) | |
936 (setq emerge-difference-list (emerge-make-diff-list file-A file-B)) | |
937 (setq emerge-number-of-differences (length emerge-difference-list)) | |
938 (setq emerge-current-difference -1) | |
939 (setq emerge-quit-hooks quit-hooks) | |
940 (emerge-remember-buffer-characteristics)) | |
941 (emerge-setup-windows buffer-A buffer-B merge-buffer t) | |
942 (emerge-eval-in-buffer merge-buffer | |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
943 (run-hooks 'startup-hooks 'emerge-startup-hook) |
583 | 944 (setq buffer-read-only t)))) |
945 | |
946 ;; Generate the Emerge difference list between two files | |
947 (defun emerge-make-diff-list (file-A file-B) | |
948 (setq emerge-diff-buffer (get-buffer-create "*emerge-diff*")) | |
949 (emerge-eval-in-buffer | |
950 emerge-diff-buffer | |
951 (erase-buffer) | |
952 (shell-command | |
953 (format "%s %s %s %s" | |
954 emerge-diff-program emerge-diff-options file-A file-B) | |
955 t)) | |
956 (emerge-prepare-error-list emerge-diff-ok-lines) | |
957 (emerge-convert-diffs-to-markers | |
958 emerge-A-buffer emerge-B-buffer emerge-merge-buffer | |
959 (emerge-extract-diffs emerge-diff-buffer))) | |
960 | |
961 (defun emerge-extract-diffs (diff-buffer) | |
962 (let (list) | |
963 (emerge-eval-in-buffer | |
964 diff-buffer | |
965 (goto-char (point-min)) | |
966 (while (re-search-forward emerge-match-diff-line nil t) | |
967 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1) | |
968 (match-end 1)))) | |
969 (a-end (let ((b (match-beginning 3)) | |
970 (e (match-end 3))) | |
971 (if b | |
972 (string-to-int (buffer-substring b e)) | |
973 a-begin))) | |
974 (diff-type (buffer-substring (match-beginning 4) (match-end 4))) | |
975 (b-begin (string-to-int (buffer-substring (match-beginning 5) | |
976 (match-end 5)))) | |
977 (b-end (let ((b (match-beginning 7)) | |
978 (e (match-end 7))) | |
979 (if b | |
980 (string-to-int (buffer-substring b e)) | |
981 b-begin)))) | |
982 ;; fix the beginning and end numbers, because diff is somewhat | |
983 ;; strange about how it numbers lines | |
984 (if (string-equal diff-type "a") | |
985 (progn | |
986 (setq b-end (1+ b-end)) | |
987 (setq a-begin (1+ a-begin)) | |
988 (setq a-end a-begin)) | |
989 (if (string-equal diff-type "d") | |
990 (progn | |
991 (setq a-end (1+ a-end)) | |
992 (setq b-begin (1+ b-begin)) | |
993 (setq b-end b-begin)) | |
994 ;; (string-equal diff-type "c") | |
995 (progn | |
996 (setq a-end (1+ a-end)) | |
997 (setq b-end (1+ b-end))))) | |
998 (setq list (cons (vector a-begin a-end | |
999 b-begin b-end | |
1000 'default-A) | |
1001 list))))) | |
1002 (nreverse list))) | |
1003 | |
1004 ;; Set up buffer of diff/diff3 error messages. | |
1005 (defun emerge-prepare-error-list (ok-regexp) | |
1006 (setq emerge-diff-error-buffer (get-buffer-create "*emerge-diff-errors*")) | |
1007 (emerge-eval-in-buffer | |
1008 emerge-diff-error-buffer | |
1009 (erase-buffer) | |
1010 (insert-buffer emerge-diff-buffer) | |
1011 (delete-matching-lines ok-regexp))) | |
1012 | |
1013 ;;; Top-level and setup functions for three-file mode. | |
1014 | |
1015 (defun emerge-files-with-ancestor-internal (file-A file-B file-ancestor | |
1016 &optional startup-hooks quit-hooks | |
1017 output-file) | |
1018 (let ((buffer-A (find-file-noselect file-A)) | |
1019 (buffer-B (find-file-noselect file-B)) | |
1020 (buffer-ancestor (find-file-noselect file-ancestor))) | |
1021 ;; Make sure the entire files are seen, and they reflect what is on disk | |
1022 (emerge-eval-in-buffer buffer-A | |
1023 (widen) | |
1024 (emerge-verify-file-buffer)) | |
1025 (emerge-eval-in-buffer buffer-B | |
1026 (widen) | |
1027 (emerge-verify-file-buffer)) | |
1028 (emerge-eval-in-buffer buffer-ancestor | |
1029 (widen) | |
1030 (emerge-verify-file-buffer)) | |
1031 (emerge-setup-with-ancestor buffer-A file-A buffer-B file-B | |
1032 buffer-ancestor file-ancestor | |
1033 startup-hooks quit-hooks output-file))) | |
1034 | |
1035 ;; Start up Emerge on two files with an ancestor | |
1036 (defun emerge-setup-with-ancestor (buffer-A file-A buffer-B file-B | |
1037 buffer-ancestor file-ancestor | |
1038 &optional startup-hooks quit-hooks | |
1039 output-file) | |
1040 (setq file-A (expand-file-name file-A)) | |
1041 (setq file-B (expand-file-name file-B)) | |
1042 (setq file-ancestor (expand-file-name file-ancestor)) | |
1043 (setq output-file (and output-file (expand-file-name output-file))) | |
1044 (let* ((merge-buffer-name (emerge-unique-buffer-name "*merge" "*")) | |
1045 ;; create the merge buffer from buffer A, so it inherits buffer A's | |
1046 ;; default directory, etc. | |
1047 (merge-buffer (emerge-eval-in-buffer | |
1048 buffer-A | |
1049 (get-buffer-create merge-buffer-name)))) | |
1050 (emerge-eval-in-buffer | |
1051 merge-buffer | |
1052 (emerge-copy-modes buffer-A) | |
1053 (setq buffer-read-only nil) | |
1054 (auto-save-mode 1) | |
1055 (setq emerge-mode t) | |
1056 (setq emerge-A-buffer buffer-A) | |
1057 (setq emerge-B-buffer buffer-B) | |
1058 (setq emerge-ancestor-buffer buffer-ancestor) | |
1059 (setq emerge-merge-buffer merge-buffer) | |
1060 (setq emerge-output-description | |
1061 (if output-file | |
1062 (concat "Output to file: " output-file) | |
1063 (concat "Output to buffer: " (buffer-name merge-buffer)))) | |
1064 (insert-buffer emerge-A-buffer) | |
1065 (emerge-set-keys) | |
1066 (setq emerge-difference-list | |
1067 (emerge-make-diff3-list file-A file-B file-ancestor)) | |
1068 (setq emerge-number-of-differences (length emerge-difference-list)) | |
1069 (setq emerge-current-difference -1) | |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
1070 (setq emerge-quit-hook quit-hooks) |
583 | 1071 (emerge-remember-buffer-characteristics) |
1072 (emerge-select-prefer-Bs)) | |
1073 (emerge-setup-windows buffer-A buffer-B merge-buffer t) | |
1074 (emerge-eval-in-buffer merge-buffer | |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
1075 (run-hooks 'startup-hooks 'emerge-startup-hook) |
583 | 1076 (setq buffer-read-only t)))) |
1077 | |
1078 ;; Generate the Emerge difference list between two files with an ancestor | |
1079 (defun emerge-make-diff3-list (file-A file-B file-ancestor) | |
1080 (setq emerge-diff-buffer (get-buffer-create "*emerge-diff*")) | |
1081 (emerge-eval-in-buffer | |
1082 emerge-diff-buffer | |
1083 (erase-buffer) | |
1084 (shell-command | |
1085 (format "%s %s %s %s %s" | |
1086 emerge-diff3-program emerge-diff-options | |
1087 file-ancestor file-A file-B) | |
1088 t)) | |
1089 (emerge-prepare-error-list emerge-diff3-ok-lines) | |
1090 (emerge-convert-diffs-to-markers | |
1091 emerge-A-buffer emerge-B-buffer emerge-merge-buffer | |
1092 (emerge-extract-diffs3 emerge-diff-buffer))) | |
1093 | |
1094 (defun emerge-extract-diffs3 (diff-buffer) | |
1095 (let (list) | |
1096 (emerge-eval-in-buffer | |
1097 diff-buffer | |
1098 (while (re-search-forward "^====\\(.?\\)$" nil t) | |
1099 ;; leave point after matched line | |
1100 (beginning-of-line 2) | |
1101 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1)))) | |
1102 ;; if the A and B files are the same, ignore the difference | |
1103 (if (not (string-equal agreement "1")) | |
1104 (setq list | |
1105 (cons | |
2496
9364da723c1e
(emerge-with-ancestor): Applied Donald Erway's fix patch, which
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
1106 (let (group-2 group-3 pos) |
9364da723c1e
(emerge-with-ancestor): Applied Donald Erway's fix patch, which
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
1107 (setq pos (point)) |
9364da723c1e
(emerge-with-ancestor): Applied Donald Erway's fix patch, which
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
1108 (setq group-2 (emerge-get-diff3-group "2")) |
9364da723c1e
(emerge-with-ancestor): Applied Donald Erway's fix patch, which
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
1109 (goto-char pos) |
9364da723c1e
(emerge-with-ancestor): Applied Donald Erway's fix patch, which
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
1110 (setq group-3 (emerge-get-diff3-group "3")) |
583 | 1111 (vector (car group-2) (car (cdr group-2)) |
1112 (car group-3) (car (cdr group-3)) | |
1113 (cond ((string-equal agreement "2") 'prefer-A) | |
1114 ((string-equal agreement "3") 'prefer-B) | |
1115 (t 'default-A)))) | |
1116 list)))))) | |
1117 (nreverse list))) | |
1118 | |
1119 (defun emerge-get-diff3-group (file) | |
1120 ;; This save-excursion allows emerge-get-diff3-group to be called for the | |
1121 ;; various groups of lines (1, 2, 3) in any order, and for the lines to | |
1122 ;; appear in any order. The reason this is necessary is that Gnu diff3 | |
1123 ;; can produce the groups in the order 1, 2, 3 or 1, 3, 2. | |
1124 (save-excursion | |
1125 (re-search-forward | |
1126 (concat "^" file ":\\([0-9]+\\)\\(,\\([0-9]+\\)\\)?\\([ac]\\)$")) | |
1127 (beginning-of-line 2) | |
1128 ;; treatment depends on whether it is an "a" group or a "c" group | |
1129 (if (string-equal (buffer-substring (match-beginning 4) (match-end 4)) "c") | |
1130 ;; it is a "c" group | |
1131 (if (match-beginning 2) | |
1132 ;; it has two numbers | |
1133 (list (string-to-int | |
1134 (buffer-substring (match-beginning 1) (match-end 1))) | |
1135 (1+ (string-to-int | |
1136 (buffer-substring (match-beginning 3) (match-end 3))))) | |
1137 ;; it has one number | |
1138 (let ((x (string-to-int | |
1139 (buffer-substring (match-beginning 1) (match-end 1))))) | |
1140 (list x (1+ x)))) | |
1141 ;; it is an "a" group | |
1142 (let ((x (1+ (string-to-int | |
1143 (buffer-substring (match-beginning 1) (match-end 1)))))) | |
1144 (list x x))))) | |
1145 | |
1146 ;;; Functions to start Emerge on files | |
1147 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1148 ;;;###autoload |
583 | 1149 (defun emerge-files (arg file-A file-B file-out &optional startup-hooks |
1150 quit-hooks) | |
1151 "Run Emerge on two files." | |
1152 (interactive | |
1153 (let (f) | |
1154 (list current-prefix-arg | |
1155 (setq f (read-file-name "File A to merge: " nil nil 'confirm)) | |
1156 (read-file-name "File B to merge: " nil nil 'confirm) | |
1157 (and current-prefix-arg | |
1158 (read-file-name | |
1159 (format "Output file: (default %s) " f) | |
1160 nil f nil))))) | |
1161 (emerge-files-internal | |
1162 file-A file-B startup-hooks | |
1163 (if arg | |
1164 (cons (` (lambda () (emerge-files-exit (, file-out)))) | |
1165 quit-hooks) | |
1166 quit-hooks) | |
1167 file-out)) | |
1168 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1169 ;;;###autoload |
583 | 1170 (defun emerge-files-with-ancestor (arg file-A file-B file-ancestor file-out |
1171 &optional startup-hooks quit-hooks) | |
1172 "Run Emerge on two files, giving another file as the ancestor." | |
1173 (interactive | |
1174 (let (f) | |
1175 (list current-prefix-arg | |
1176 (setq f (read-file-name "File A to merge: " nil nil 'confirm)) | |
1177 (read-file-name "File B to merge: " nil nil 'confirm) | |
1178 (read-file-name "Ancestor file: " nil nil 'confirm) | |
1179 (and current-prefix-arg | |
1180 (read-file-name | |
1181 (format "Output file: (default %s) " f) | |
1182 nil f nil))))) | |
1183 (emerge-files-with-ancestor-internal | |
1184 file-A file-B file-ancestor startup-hooks | |
1185 (if arg | |
1186 (cons (` (lambda () (emerge-files-exit (, file-out)))) | |
1187 quit-hooks) | |
1188 quit-hooks) | |
1189 file-out)) | |
1190 | |
1191 ;; Write the merge buffer out in place of the file the A buffer is visiting. | |
1192 (defun emerge-files-exit (file-out) | |
1193 ;; if merge was successful was given, save to disk | |
1194 (if (not emerge-prefix-argument) | |
1195 (emerge-write-and-delete file-out))) | |
1196 | |
1197 ;;; Functions to start Emerge on buffers | |
1198 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1199 ;;;###autoload |
583 | 1200 (defun emerge-buffers (buffer-A buffer-B &optional startup-hooks quit-hooks) |
1201 "Run Emerge on two buffers." | |
1202 (interactive "bBuffer A to merge: \nbBuffer B to merge: ") | |
1203 (let ((emerge-file-A (emerge-make-temp-file "A")) | |
1204 (emerge-file-B (emerge-make-temp-file "B"))) | |
1205 (emerge-eval-in-buffer | |
1206 buffer-A | |
1207 (write-region (point-min) (point-max) emerge-file-A nil 'no-message)) | |
1208 (emerge-eval-in-buffer | |
1209 buffer-B | |
1210 (write-region (point-min) (point-max) emerge-file-B nil 'no-message)) | |
1211 (emerge-setup (get-buffer buffer-A) emerge-file-A | |
1212 (get-buffer buffer-B) emerge-file-B | |
1213 (cons (function (lambda () | |
1214 (delete-file emerge-file-A) | |
1215 (delete-file emerge-file-B))) | |
1216 startup-hooks) | |
1217 quit-hooks | |
1218 nil))) | |
1219 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1220 ;;;###autoload |
583 | 1221 (defun emerge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor |
1222 &optional startup-hooks | |
1223 quit-hooks) | |
1224 "Run Emerge on two buffers, giving another buffer as the ancestor." | |
1225 (interactive | |
1226 "bBuffer A to merge: \nbBuffer B to merge: \nbAncestor buffer: ") | |
1227 (let ((emerge-file-A (emerge-make-temp-file "A")) | |
1228 (emerge-file-B (emerge-make-temp-file "B")) | |
1229 (emerge-file-ancestor (emerge-make-temp-file "anc"))) | |
1230 (emerge-eval-in-buffer | |
1231 buffer-A | |
1232 (write-region (point-min) (point-max) emerge-file-A nil 'no-message)) | |
1233 (emerge-eval-in-buffer | |
1234 buffer-B | |
1235 (write-region (point-min) (point-max) emerge-file-B nil 'no-message)) | |
1236 (emerge-eval-in-buffer | |
1237 buffer-ancestor | |
1238 (write-region (point-min) (point-max) emerge-file-ancestor nil | |
1239 'no-message)) | |
1240 (emerge-setup-with-ancestor (get-buffer buffer-A) emerge-file-A | |
1241 (get-buffer buffer-B) emerge-file-B | |
1242 (get-buffer buffer-ancestor) | |
1243 emerge-file-ancestor | |
1244 (cons (function (lambda () | |
1245 (delete-file emerge-file-A) | |
1246 (delete-file emerge-file-B) | |
1247 (delete-file | |
1248 emerge-file-ancestor))) | |
1249 startup-hooks) | |
1250 quit-hooks | |
1251 nil))) | |
1252 | |
1253 ;;; Functions to start Emerge from the command line | |
1254 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1255 ;;;###autoload |
583 | 1256 (defun emerge-files-command () |
1257 (let ((file-a (nth 0 command-line-args-left)) | |
1258 (file-b (nth 1 command-line-args-left)) | |
1259 (file-out (nth 2 command-line-args-left))) | |
1260 (setq command-line-args-left (nthcdr 3 command-line-args-left)) | |
1261 (emerge-files-internal | |
1262 file-a file-b nil | |
1263 (list (` (lambda () (emerge-command-exit (, file-out)))))))) | |
1264 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1265 ;;;###autoload |
583 | 1266 (defun emerge-files-with-ancestor-command () |
1267 (let (file-a file-b file-anc file-out) | |
1268 ;; check for a -a flag, for filemerge compatibility | |
1269 (if (string= (car command-line-args-left) "-a") | |
1270 ;; arguments are "-a ancestor file-a file-b file-out" | |
1271 (progn | |
1272 (setq file-a (nth 2 command-line-args-left)) | |
1273 (setq file-b (nth 3 command-line-args-left)) | |
1274 (setq file-anc (nth 1 command-line-args-left)) | |
1275 (setq file-out (nth 4 command-line-args-left)) | |
1276 (setq command-line-args-left (nthcdr 5 command-line-args-left))) | |
1277 ;; arguments are "file-a file-b ancestor file-out" | |
1278 (setq file-a (nth 0 command-line-args-left)) | |
1279 (setq file-b (nth 1 command-line-args-left)) | |
1280 (setq file-anc (nth 2 command-line-args-left)) | |
1281 (setq file-out (nth 3 command-line-args-left)) | |
1282 (setq command-line-args-left (nthcdr 4 command-line-args-left))) | |
1283 (emerge-files-with-ancestor-internal | |
1284 file-a file-b file-anc nil | |
1285 (list (` (lambda () (emerge-command-exit (, file-out)))))))) | |
1286 | |
1287 (defun emerge-command-exit (file-out) | |
1288 (emerge-write-and-delete file-out) | |
1289 (kill-emacs (if emerge-prefix-argument 1 0))) | |
1290 | |
1291 ;;; Functions to start Emerge via remote request | |
1292 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1293 ;;;###autoload |
583 | 1294 (defun emerge-files-remote (file-a file-b file-out) |
1295 (setq emerge-file-out file-out) | |
1296 (emerge-files-internal | |
1297 file-a file-b nil | |
1298 (list (` (lambda () (emerge-remote-exit (, file-out) '(, exit-func))))) | |
1299 file-out) | |
1300 (throw 'client-wait nil)) | |
1301 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
1302 ;;;###autoload |
583 | 1303 (defun emerge-files-with-ancestor-remote (file-a file-b file-anc file-out) |
1304 (setq emerge-file-out file-out) | |
1305 (emerge-files-with-ancestor-internal | |
1306 file-a file-b file-anc nil | |
1307 (list (` (lambda () (emerge-remote-exit (, file-out) '(, exit-func))))) | |
1308 file-out) | |
1309 (throw 'client-wait nil)) | |
1310 | |
1311 (defun emerge-remote-exit (file-out exit-func) | |
1312 (emerge-write-and-delete file-out) | |
1313 (kill-buffer emerge-merge-buffer) | |
1314 (funcall exit-func (if emerge-prefix-argument 1 0))) | |
1315 | |
1316 ;;; Common setup routines | |
1317 | |
1318 ;; Set up the window configuration. If POS is given, set the points to | |
1319 ;; the beginnings of the buffers. | |
1320 (defun emerge-setup-windows (buffer-A buffer-B merge-buffer &optional pos) | |
1321 ;; Make sure we are not in the minibuffer window when we try to delete | |
1322 ;; all other windows. | |
1323 (if (eq (selected-window) (minibuffer-window)) | |
1324 (other-window 1)) | |
1325 (delete-other-windows) | |
1326 (switch-to-buffer merge-buffer) | |
1327 (emerge-refresh-mode-line) | |
1328 (split-window-vertically) | |
1329 (split-window-horizontally) | |
1330 (switch-to-buffer buffer-A) | |
1331 (if pos | |
1332 (goto-char (point-min))) | |
1333 (other-window 1) | |
1334 (switch-to-buffer buffer-B) | |
1335 (if pos | |
1336 (goto-char (point-min))) | |
1337 (other-window 1) | |
1338 (if pos | |
1339 (goto-char (point-min))) | |
1340 ;; If diff/diff3 reports errors, display them rather than the merge buffer. | |
1341 (if (/= 0 (emerge-eval-in-buffer emerge-diff-error-buffer (buffer-size))) | |
1342 (progn | |
1343 (ding) | |
1344 (message "Errors found in diff/diff3 output. Merge buffer is %s." | |
1345 (buffer-name emerge-merge-buffer)) | |
1346 (switch-to-buffer emerge-diff-error-buffer)))) | |
1347 | |
1348 ;; Set up the keymap in the merge buffer | |
1349 (defun emerge-set-keys () | |
1350 ;; Set up fixed keymaps if necessary | |
1351 (if (not emerge-basic-keymap) | |
1352 (emerge-setup-fixed-keymaps)) | |
1353 ;; Save the old local map | |
1354 (setq emerge-old-keymap (current-local-map)) | |
1355 ;; Construct the edit keymap | |
1356 (setq emerge-edit-keymap (if emerge-old-keymap | |
1357 (copy-keymap emerge-old-keymap) | |
1358 (make-sparse-keymap))) | |
1359 ;; Install the Emerge commands | |
1360 (emerge-force-define-key emerge-edit-keymap emerge-command-prefix | |
1361 'emerge-basic-keymap) | |
1362 ;; Suppress write-file and save-buffer | |
1363 (emerge-recursively-substitute-key-definition 'write-file | |
1364 'emerge-query-write-file | |
1365 emerge-edit-keymap) | |
1366 (emerge-recursively-substitute-key-definition 'save-buffer | |
1367 'emerge-query-save-buffer | |
1368 emerge-edit-keymap) | |
1369 (emerge-shadow-key-definition 'write-file 'emerge-query-write-file | |
1370 (current-global-map) emerge-edit-keymap) | |
1371 (emerge-shadow-key-definition 'save-buffer 'emerge-query-save-buffer | |
1372 (current-global-map) emerge-edit-keymap) | |
1373 (use-local-map emerge-fast-keymap) | |
1374 (setq emerge-edit-mode nil) | |
1375 (setq emerge-fast-mode t)) | |
1376 | |
1377 (defun emerge-remember-buffer-characteristics () | |
1429 | 1378 "Remembers certain properties of the buffers being merged. |
1379 Must be called in the merge buffer. Remembers read-only, modified, | |
1380 auto-save, and saves them in buffer local variables. Sets the buffers | |
1381 read-only and turns off `auto-save-mode'. | |
583 | 1382 These characteristics are restored by emerge-restore-buffer-characteristics." |
1383 ;; force auto-save, because we will turn off auto-saving in buffers for the | |
1384 ;; duration | |
1385 (do-auto-save) | |
1386 ;; remember and alter buffer characteristics | |
1387 (setq emerge-A-buffer-values | |
1388 (emerge-eval-in-buffer | |
1389 emerge-A-buffer | |
1390 (prog1 | |
1391 (emerge-save-variables emerge-saved-variables) | |
1392 (emerge-restore-variables emerge-saved-variables | |
1393 emerge-merging-values)))) | |
1394 (setq emerge-B-buffer-values | |
1395 (emerge-eval-in-buffer | |
1396 emerge-B-buffer | |
1397 (prog1 | |
1398 (emerge-save-variables emerge-saved-variables) | |
1399 (emerge-restore-variables emerge-saved-variables | |
1400 emerge-merging-values))))) | |
1401 | |
1402 (defun emerge-restore-buffer-characteristics () | |
1403 "Restores the characteristics remembered by | |
1404 emerge-remember-buffer-characteristics." | |
1405 (let ((A-values emerge-A-buffer-values) | |
1406 (B-values emerge-B-buffer-values)) | |
1407 (emerge-eval-in-buffer emerge-A-buffer | |
1408 (emerge-restore-variables emerge-saved-variables | |
1409 A-values)) | |
1410 (emerge-eval-in-buffer emerge-B-buffer | |
1411 (emerge-restore-variables emerge-saved-variables | |
1412 B-values)))) | |
1413 | |
1414 (defun emerge-convert-diffs-to-markers (A-buffer | |
1415 B-buffer | |
1416 merge-buffer | |
1417 lineno-list) | |
1418 (let* (marker-list | |
1419 (A-point-min (emerge-eval-in-buffer A-buffer (point-min))) | |
1420 (offset (1- A-point-min)) | |
1421 (A-hidden-lines (emerge-eval-in-buffer | |
1422 A-buffer | |
1423 (save-restriction | |
1424 (widen) | |
1425 (count-lines 1 A-point-min)))) | |
1426 (B-point-min (emerge-eval-in-buffer B-buffer (point-min))) | |
1427 (B-hidden-lines (emerge-eval-in-buffer | |
1428 B-buffer | |
1429 (save-restriction | |
1430 (widen) | |
1431 (count-lines 1 B-point-min))))) | |
1432 (while lineno-list | |
1433 (let* ((list-element (car lineno-list)) | |
1434 a-begin-marker | |
1435 a-end-marker | |
1436 b-begin-marker | |
1437 b-end-marker | |
1438 (a-begin (aref list-element 0)) | |
1439 (a-end (aref list-element 1)) | |
1440 (b-begin (aref list-element 2)) | |
1441 (b-end (aref list-element 3)) | |
1442 (state (aref list-element 4))) | |
1443 ;; place markers at the appropriate places in the buffers | |
1444 (emerge-eval-in-buffer | |
1445 A-buffer | |
1446 (goto-line (+ a-begin A-hidden-lines)) | |
1447 (setq a-begin-marker (point-marker)) | |
1448 (goto-line (+ a-end A-hidden-lines)) | |
1449 (setq a-end-marker (point-marker))) | |
1450 (emerge-eval-in-buffer | |
1451 B-buffer | |
1452 (goto-line (+ b-begin B-hidden-lines)) | |
1453 (setq b-begin-marker (point-marker)) | |
1454 (goto-line (+ b-end B-hidden-lines)) | |
1455 (setq b-end-marker (point-marker))) | |
1456 (setq merge-begin-marker (set-marker | |
1457 (make-marker) | |
1458 (- (marker-position a-begin-marker) | |
1459 offset) | |
1460 merge-buffer)) | |
1461 (setq merge-end-marker (set-marker | |
1462 (make-marker) | |
1463 (- (marker-position a-end-marker) | |
1464 offset) | |
1465 merge-buffer)) | |
1466 ;; record all the markers for this difference | |
1467 (setq marker-list (cons (vector a-begin-marker a-end-marker | |
1468 b-begin-marker b-end-marker | |
1469 merge-begin-marker merge-end-marker | |
1470 state) | |
1471 marker-list))) | |
1472 (setq lineno-list (cdr lineno-list))) | |
1473 ;; convert the list of difference information into a vector for | |
1474 ;; fast access | |
1475 (setq emerge-difference-list (apply 'vector (nreverse marker-list))))) | |
1476 | |
1477 ;; If we have an ancestor, select all B variants that we prefer | |
1478 (defun emerge-select-prefer-Bs () | |
1479 (let ((n 0)) | |
1480 (while (< n emerge-number-of-differences) | |
1481 (if (eq (aref (aref emerge-difference-list n) 6) 'prefer-B) | |
1482 (progn | |
1483 (emerge-unselect-and-select-difference n t) | |
1484 (emerge-select-B) | |
1485 (aset (aref emerge-difference-list n) 6 'prefer-B))) | |
1486 (setq n (1+ n)))) | |
1487 (emerge-unselect-and-select-difference -1)) | |
1488 | |
1489 ;;; Common exit routines | |
1490 | |
1491 (defun emerge-write-and-delete (file-out) | |
1492 ;; clear screen format | |
1493 (delete-other-windows) | |
1494 ;; delete A, B, and ancestor buffers, if they haven't been changed | |
1495 (if (not (buffer-modified-p emerge-A-buffer)) | |
1496 (kill-buffer emerge-A-buffer)) | |
1497 (if (not (buffer-modified-p emerge-B-buffer)) | |
1498 (kill-buffer emerge-B-buffer)) | |
1499 (if (and emerge-ancestor-buffer | |
1500 (not (buffer-modified-p emerge-ancestor-buffer))) | |
1501 (kill-buffer emerge-ancestor-buffer)) | |
1502 ;; Write merge buffer to file | |
1503 (write-file file-out)) | |
1504 | |
1505 ;;; Commands | |
1506 | |
1507 (defun emerge-recenter (&optional arg) | |
1429 | 1508 "Bring the highlighted region of all three merge buffers into view. |
1509 This brings the buffers into view if they are in windows. | |
1510 If an ARGUMENT is given, the default three-window display is reestablished." | |
583 | 1511 (interactive "P") |
1512 ;; If there is an argument, rebuild the window structure | |
1513 (if arg | |
1514 (emerge-setup-windows emerge-A-buffer emerge-B-buffer | |
1515 emerge-merge-buffer)) | |
1516 ;; Redisplay whatever buffers are showing, if there is a selected difference | |
1517 (if (and (>= emerge-current-difference 0) | |
1518 (< emerge-current-difference emerge-number-of-differences)) | |
1519 (let* ((merge-buffer emerge-merge-buffer) | |
1520 (buffer-A emerge-A-buffer) | |
1521 (buffer-B emerge-B-buffer) | |
1522 (window-A (get-buffer-window buffer-A)) | |
1523 (window-B (get-buffer-window buffer-B)) | |
1524 (merge-window (get-buffer-window merge-buffer)) | |
1525 (diff-vector | |
1526 (aref emerge-difference-list emerge-current-difference))) | |
1527 (if window-A (progn | |
1528 (select-window window-A) | |
1529 (emerge-position-region | |
1530 (- (aref diff-vector 0) | |
1531 (1- emerge-before-flag-length)) | |
1532 (+ (aref diff-vector 1) | |
1533 (1- emerge-after-flag-length)) | |
1534 (1+ (aref diff-vector 0))))) | |
1535 (if window-B (progn | |
1536 (select-window window-B) | |
1537 (emerge-position-region | |
1538 (- (aref diff-vector 2) | |
1539 (1- emerge-before-flag-length)) | |
1540 (+ (aref diff-vector 3) | |
1541 (1- emerge-after-flag-length)) | |
1542 (1+ (aref diff-vector 2))))) | |
1543 (if merge-window (progn | |
1544 (select-window merge-window) | |
1545 (emerge-position-region | |
1546 (- (aref diff-vector 4) | |
1547 (1- emerge-before-flag-length)) | |
1548 (+ (aref diff-vector 5) | |
1549 (1- emerge-after-flag-length)) | |
1550 (1+ (aref diff-vector 4)))))))) | |
1551 | |
1552 ;;; Window scrolling operations | |
1553 ;; These operations are designed to scroll all three windows the same amount, | |
1554 ;; so as to keep the text in them aligned. | |
1555 | |
1556 ;; Perform some operation on all three windows (if they are showing). | |
1557 ;; Catches all errors on the operation in the A and B windows, but not | |
1558 ;; in the merge window. Usually, errors come from scrolling off the | |
1559 ;; beginning or end of the buffer, and this gives a nice error message: | |
1560 ;; End of buffer is reported in the merge buffer, but if the scroll was | |
1561 ;; possible in the A or B windows, it is performed there before the error | |
1562 ;; is reported. | |
1563 (defun emerge-operate-on-windows (operation arg) | |
1564 (let* ((merge-buffer emerge-merge-buffer) | |
1565 (buffer-A emerge-A-buffer) | |
1566 (buffer-B emerge-B-buffer) | |
1567 (window-A (get-buffer-window buffer-A)) | |
1568 (window-B (get-buffer-window buffer-B)) | |
1569 (merge-window (get-buffer-window merge-buffer))) | |
1570 (if window-A (progn | |
1571 (select-window window-A) | |
1572 (condition-case nil | |
1573 (funcall operation arg) | |
1574 (error)))) | |
1575 (if window-B (progn | |
1576 (select-window window-B) | |
1577 (condition-case nil | |
1578 (funcall operation arg) | |
1579 (error)))) | |
1580 (if merge-window (progn | |
1581 (select-window merge-window) | |
1582 (funcall operation arg))))) | |
1583 | |
1584 (defun emerge-scroll-up (&optional arg) | |
1585 "Scroll up all three merge buffers, if they are in windows. | |
1586 If an ARGUMENT is given, that is how many lines are scrolled, else nearly | |
1587 the size of the merge window. `C-u -' alone as argument scrolls half the | |
1588 size of the merge window." | |
1589 (interactive "P") | |
1590 (emerge-operate-on-windows | |
1591 'scroll-up | |
1592 ;; calculate argument to scroll-up | |
1593 ;; if there is an explicit argument | |
1594 (if (and arg (not (equal arg '-))) | |
1595 ;; use it | |
1596 (prefix-numeric-value arg) | |
1597 ;; if not, see if we can determine a default amount (the window height) | |
1598 (let ((merge-window (get-buffer-window emerge-merge-buffer))) | |
1599 (if (null merge-window) | |
1600 ;; no window, use nil | |
1601 nil | |
1602 (let ((default-amount | |
1603 (- (window-height merge-window) 1 next-screen-context-lines))) | |
1604 ;; the window was found | |
1605 (if arg | |
1606 ;; C-u as argument means half of default amount | |
1607 (/ default-amount 2) | |
1608 ;; no argument means default amount | |
1609 default-amount))))))) | |
1610 | |
1611 (defun emerge-scroll-down (&optional arg) | |
1612 "Scroll down all three merge buffers, if they are in windows. | |
1613 If an ARGUMENT is given, that is how many lines are scrolled, else nearly | |
1614 the size of the merge window. `C-u -' alone as argument scrolls half the | |
1615 size of the merge window." | |
1616 (interactive "P") | |
1617 (emerge-operate-on-windows | |
1618 'scroll-down | |
1619 ;; calculate argument to scroll-down | |
1620 ;; if there is an explicit argument | |
1621 (if (and arg (not (equal arg '-))) | |
1622 ;; use it | |
1623 (prefix-numeric-value arg) | |
1624 ;; if not, see if we can determine a default amount (the window height) | |
1625 (let ((merge-window (get-buffer-window emerge-merge-buffer))) | |
1626 (if (null merge-window) | |
1627 ;; no window, use nil | |
1628 nil | |
1629 (let ((default-amount | |
1630 (- (window-height merge-window) 1 next-screen-context-lines))) | |
1631 ;; the window was found | |
1632 (if arg | |
1633 ;; C-u as argument means half of default amount | |
1634 (/ default-amount 2) | |
1635 ;; no argument means default amount | |
1636 default-amount))))))) | |
1637 | |
1638 (defun emerge-scroll-left (&optional arg) | |
1639 "Scroll left all three merge buffers, if they are in windows. | |
1640 If an ARGUMENT is given, that is how many columns are scrolled, else nearly | |
1429 | 1641 the width of the A and B windows. C-u - alone as argument scrolls half the |
583 | 1642 width of the A and B windows." |
1643 (interactive "P") | |
1644 (emerge-operate-on-windows | |
1645 'scroll-left | |
1646 ;; calculate argument to scroll-left | |
1647 ;; if there is an explicit argument | |
1648 (if (and arg (not (equal arg '-))) | |
1649 ;; use it | |
1650 (prefix-numeric-value arg) | |
1651 ;; if not, see if we can determine a default amount | |
1652 ;; (half the window width) | |
1653 (let ((merge-window (get-buffer-window emerge-merge-buffer))) | |
1654 (if (null merge-window) | |
1655 ;; no window, use nil | |
1656 nil | |
1657 (let ((default-amount | |
1658 (- (/ (window-width merge-window) 2) 3))) | |
1659 ;; the window was found | |
1660 (if arg | |
1661 ;; C-u as argument means half of default amount | |
1662 (/ default-amount 2) | |
1663 ;; no argument means default amount | |
1664 default-amount))))))) | |
1665 | |
1666 (defun emerge-scroll-right (&optional arg) | |
1667 "Scroll right all three merge buffers, if they are in windows. | |
1668 If an ARGUMENT is given, that is how many columns are scrolled, else nearly | |
1429 | 1669 the width of the A and B windows. C-u - alone as argument scrolls half the |
583 | 1670 width of the A and B windows." |
1671 (interactive "P") | |
1672 (emerge-operate-on-windows | |
1673 'scroll-right | |
1674 ;; calculate argument to scroll-right | |
1675 ;; if there is an explicit argument | |
1676 (if (and arg (not (equal arg '-))) | |
1677 ;; use it | |
1678 (prefix-numeric-value arg) | |
1679 ;; if not, see if we can determine a default amount | |
1680 ;; (half the window width) | |
1681 (let ((merge-window (get-buffer-window emerge-merge-buffer))) | |
1682 (if (null merge-window) | |
1683 ;; no window, use nil | |
1684 nil | |
1685 (let ((default-amount | |
1686 (- (/ (window-width merge-window) 2) 3))) | |
1687 ;; the window was found | |
1688 (if arg | |
1689 ;; C-u as argument means half of default amount | |
1690 (/ default-amount 2) | |
1691 ;; no argument means default amount | |
1692 default-amount))))))) | |
1693 | |
1694 (defun emerge-scroll-reset () | |
1429 | 1695 "Reset horizontal scrolling. |
1696 This resets the horizontal scrolling of all three merge buffers | |
1697 to the left margin, if they are in windows." | |
583 | 1698 (interactive) |
1699 (emerge-operate-on-windows | |
1700 (function (lambda (x) (set-window-hscroll (selected-window) 0))) | |
1701 nil)) | |
1702 | |
1703 ;; Attempt to show the region nicely. | |
1704 ;; If there are min-lines lines above and below the region, then don't do | |
1705 ;; anything. | |
1706 ;; If not, recenter the region to make it so. | |
1707 ;; If that isn't possible, remove context lines balancedly from top and botton | |
1708 ;; so the entire region shows. | |
1709 ;; If that isn't possible, show the top of the region. | |
1710 ;; BEG must be at the beginning of a line. | |
1711 (defun emerge-position-region (beg end pos) | |
1712 ;; First test whether the entire region is visible with | |
1713 ;; emerge-min-visible-lines above and below it | |
1714 (if (not (and (<= (progn | |
1715 (move-to-window-line emerge-min-visible-lines) | |
1716 (point)) | |
1717 beg) | |
1718 (<= end (progn | |
1719 (move-to-window-line | |
1720 (- (1+ emerge-min-visible-lines))) | |
1721 (point))))) | |
1722 ;; We failed that test, see if it fits at all | |
1723 ;; Meanwhile positioning it correctly in case it doesn't fit | |
1724 (progn | |
1725 (set-window-start (selected-window) beg) | |
1726 (setq fits (pos-visible-in-window-p end)) | |
1727 (if fits | |
1728 ;; Determine the number of lines that the region occupies | |
1729 (let ((lines 0)) | |
1730 (while (> end (progn | |
1731 (move-to-window-line lines) | |
1732 (point))) | |
1733 (setq lines (1+ lines))) | |
1734 ;; And position the beginning on the right line | |
1735 (goto-char beg) | |
1736 (recenter (/ (1+ (- (1- (window-height (selected-window))) | |
1737 lines)) | |
1738 2)))))) | |
1739 (goto-char pos)) | |
1740 | |
1741 (defun emerge-next-difference () | |
1742 "Advance to the next difference." | |
1743 (interactive) | |
1744 (if (< emerge-current-difference emerge-number-of-differences) | |
1745 (let ((n (1+ emerge-current-difference))) | |
1746 (while (and emerge-skip-prefers | |
1747 (< n emerge-number-of-differences) | |
1748 (memq (aref (aref emerge-difference-list n) 6) | |
1749 '(prefer-A prefer-B))) | |
1750 (setq n (1+ n))) | |
1751 (let ((buffer-read-only nil)) | |
1752 (emerge-unselect-and-select-difference n))) | |
1753 (error "At end"))) | |
1754 | |
1755 (defun emerge-previous-difference () | |
1756 "Go to the previous difference." | |
1757 (interactive) | |
1758 (if (> emerge-current-difference -1) | |
1759 (let ((n (1- emerge-current-difference))) | |
1760 (while (and emerge-skip-prefers | |
1761 (> n -1) | |
1762 (memq (aref (aref emerge-difference-list n) 6) | |
1763 '(prefer-A prefer-B))) | |
1764 (setq n (1- n))) | |
1765 (let ((buffer-read-only nil)) | |
1766 (emerge-unselect-and-select-difference n))) | |
1767 (error "At beginning"))) | |
1768 | |
1769 (defun emerge-jump-to-difference (difference-number) | |
1770 "Go to the N-th difference." | |
1771 (interactive "p") | |
1772 (let ((buffer-read-only nil)) | |
1773 (setq difference-number (1- difference-number)) | |
1774 (if (and (>= difference-number -1) | |
1775 (< difference-number (1+ emerge-number-of-differences))) | |
1776 (emerge-unselect-and-select-difference difference-number) | |
1777 (error "Bad difference number")))) | |
1778 | |
1779 (defun emerge-quit (arg) | |
1429 | 1780 "Finish an Emerge session. |
1781 Prefix argument means to abort rather than successfully finish. | |
1782 The difference depends on how the merge was started, | |
583 | 1783 but usually means to not write over one of the original files, or to signal |
1784 to some process which invoked Emerge a failure code. | |
1785 | |
1786 Unselects the selected difference, if any, restores the read-only and modified | |
1787 flags of the merged file buffers, restores the local keymap of the merge | |
1788 buffer, and sets off various emerge flags. Using Emerge commands in this | |
1789 buffer after this will cause serious problems." | |
1790 (interactive "P") | |
1791 (if (prog1 | |
1792 (y-or-n-p | |
1793 (if (not arg) | |
1794 "Do you really want to successfully finish this merge? " | |
1795 "Do you really want to abort this merge? ")) | |
1796 (message "")) | |
1797 (emerge-really-quit arg))) | |
1798 | |
1799 ;; Perform the quit operations. | |
1800 (defun emerge-really-quit (arg) | |
1801 (setq buffer-read-only nil) | |
1802 (emerge-unselect-and-select-difference -1) | |
1803 (emerge-restore-buffer-characteristics) | |
1804 ;; null out the difference markers so they don't slow down future editing | |
1805 ;; operations | |
1806 (mapcar (function (lambda (d) | |
1807 (set-marker (aref d 0) nil) | |
1808 (set-marker (aref d 1) nil) | |
1809 (set-marker (aref d 2) nil) | |
1810 (set-marker (aref d 3) nil) | |
1811 (set-marker (aref d 4) nil) | |
1812 (set-marker (aref d 5) nil))) | |
1813 emerge-difference-list) | |
1814 ;; allow them to be garbage collected | |
1815 (setq emerge-difference-list nil) | |
1816 ;; restore the local map | |
1817 (use-local-map emerge-old-keymap) | |
1818 ;; turn off all the emerge modes | |
1819 (setq emerge-mode nil) | |
1820 (setq emerge-fast-mode nil) | |
1821 (setq emerge-edit-mode nil) | |
1822 (setq emerge-auto-advance nil) | |
1823 (setq emerge-skip-prefers nil) | |
1824 ;; restore mode line | |
1825 (kill-local-variable 'mode-line-buffer-identification) | |
1826 (let ((emerge-prefix-argument arg)) | |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
778
diff
changeset
|
1827 (run-hooks 'emerge-quit-hook))) |
583 | 1828 |
1829 (defun emerge-select-A (&optional force) | |
1429 | 1830 "Select the A variant of this difference. |
1831 Refuses to function if this difference has been edited, i.e., if it | |
1832 is neither the A nor the B variant. | |
583 | 1833 An ARGUMENT forces the variant to be selected even if the difference has |
1834 been edited." | |
1835 (interactive "P") | |
1836 (let ((operate | |
1837 (function (lambda () | |
1838 (emerge-select-A-edit merge-begin merge-end A-begin A-end) | |
1839 (if emerge-auto-advance | |
1840 (emerge-next-difference))))) | |
1841 (operate-no-change | |
1842 (function (lambda () | |
1843 (if emerge-auto-advance | |
1844 (emerge-next-difference)))))) | |
1845 (emerge-select-version force operate-no-change operate operate))) | |
1846 | |
1847 ;; Actually select the A variant | |
1848 (defun emerge-select-A-edit (merge-begin merge-end A-begin A-end) | |
1849 (emerge-eval-in-buffer | |
1850 emerge-merge-buffer | |
1851 (delete-region merge-begin merge-end) | |
1852 (goto-char merge-begin) | |
1853 (insert-buffer-substring emerge-A-buffer A-begin A-end) | |
1854 (goto-char merge-begin) | |
1855 (aset diff-vector 6 'A) | |
1856 (emerge-refresh-mode-line))) | |
1857 | |
1858 (defun emerge-select-B (&optional force) | |
1429 | 1859 "Select the B variant of this difference. |
1860 Refuses to function if this difference has been edited, i.e., if it | |
1861 is neither the A nor the B variant. An ARGUMENT forces the variant to be selected even if the difference has | |
583 | 1862 been edited." |
1863 (interactive "P") | |
1864 (let ((operate | |
1865 (function (lambda () | |
1866 (emerge-select-B-edit merge-begin merge-end B-begin B-end) | |
1867 (if emerge-auto-advance | |
1868 (emerge-next-difference))))) | |
1869 (operate-no-change | |
1870 (function (lambda () | |
1871 (if emerge-auto-advance | |
1872 (emerge-next-difference)))))) | |
1873 (emerge-select-version force operate operate-no-change operate))) | |
1874 | |
1875 ;; Actually select the B variant | |
1876 (defun emerge-select-B-edit (merge-begin merge-end B-begin B-end) | |
1877 (emerge-eval-in-buffer | |
1878 emerge-merge-buffer | |
1879 (delete-region merge-begin merge-end) | |
1880 (goto-char merge-begin) | |
1881 (insert-buffer-substring emerge-B-buffer B-begin B-end) | |
1882 (goto-char merge-begin) | |
1883 (aset diff-vector 6 'B) | |
1884 (emerge-refresh-mode-line))) | |
1885 | |
1886 (defun emerge-default-A () | |
1429 | 1887 "Selects the A variant. |
1888 This selects the A variant for all differences from here down in the buffer | |
583 | 1889 which are still defaulted, i.e., which the user has not selected and for |
1890 which there is no preference." | |
1891 (interactive) | |
1892 (let ((buffer-read-only nil)) | |
1893 (let ((selected-difference emerge-current-difference) | |
1894 (n (max emerge-current-difference 0))) | |
1895 (while (< n emerge-number-of-differences) | |
1896 (let ((diff-vector (aref emerge-difference-list n))) | |
1897 (if (eq (aref diff-vector 6) 'default-B) | |
1898 (progn | |
1899 (emerge-unselect-and-select-difference n t) | |
1900 (emerge-select-A) | |
1901 (aset diff-vector 6 'default-A)))) | |
1902 (setq n (1+ n)) | |
1903 (if (= (* (/ n 10) 10) n) | |
1904 (message "Setting default to A...%d" n))) | |
1905 (emerge-unselect-and-select-difference selected-difference))) | |
1906 (message "Default A set")) | |
1907 | |
1908 (defun emerge-default-B () | |
1429 | 1909 "Selects the B variant. |
1910 This selects the B variant for all differences from here down in the buffer | |
583 | 1911 which are still defaulted, i.e., which the user has not selected and for |
1912 which there is no preference." | |
1913 (interactive) | |
1914 (let ((buffer-read-only nil)) | |
1915 (let ((selected-difference emerge-current-difference) | |
1916 (n (max emerge-current-difference 0))) | |
1917 (while (< n emerge-number-of-differences) | |
1918 (let ((diff-vector (aref emerge-difference-list n))) | |
1919 (if (eq (aref diff-vector 6) 'default-A) | |
1920 (progn | |
1921 (emerge-unselect-and-select-difference n t) | |
1922 (emerge-select-B) | |
1923 (aset diff-vector 6 'default-B)))) | |
1924 (setq n (1+ n)) | |
1925 (if (= (* (/ n 10) 10) n) | |
1926 (message "Setting default to B...%d" n))) | |
1927 (emerge-unselect-and-select-difference selected-difference))) | |
1928 (message "Default B set")) | |
1929 | |
1930 (defun emerge-fast-mode () | |
1429 | 1931 "Set fast mode. |
1932 In this mode ordinary Emacs commands are disabled, and Emerge commands | |
1933 are need not be prefixed with \\<emerge-fast-keymap>\\[emerge-basic-keymap]." | |
583 | 1934 (interactive) |
1935 (setq buffer-read-only t) | |
1936 (use-local-map emerge-fast-keymap) | |
1937 (setq emerge-mode t) | |
1938 (setq emerge-fast-mode t) | |
1939 (setq emerge-edit-mode nil) | |
1940 (message "Fast mode set") | |
1941 ;; force mode line redisplay | |
1942 (set-buffer-modified-p (buffer-modified-p))) | |
1943 | |
1944 (defun emerge-edit-mode () | |
1429 | 1945 "Set edit mode. |
1946 In this mode ordinary Emacs commands are available, and Emerge commands | |
1947 must be prefixed with \\<emerge-fast-keymap>\\[emerge-basic-keymap]." | |
583 | 1948 (interactive) |
1949 (setq buffer-read-only nil) | |
1950 (use-local-map emerge-edit-keymap) | |
1951 (setq emerge-mode t) | |
1952 (setq emerge-fast-mode nil) | |
1953 (setq emerge-edit-mode t) | |
1954 (message "Edit mode set") | |
1955 ;; force mode line redisplay | |
1956 (set-buffer-modified-p (buffer-modified-p))) | |
1957 | |
1958 (defun emerge-auto-advance (arg) | |
1429 | 1959 "Toggle auto-advance mode. |
1960 This mode causes `emerge-select-A' and `emerge-select-B' to automatically | |
1961 advance to the next difference. (See `emerge-auto-advance'.) | |
1962 If a positive ARGUMENT is given, it turns on `auto-advance-mode'. | |
1963 If a negative ARGUMENT is given, it turns off `auto-advance-mode'." | |
583 | 1964 (interactive "P") |
1965 (setq emerge-auto-advance (if (null arg) | |
1966 (not emerge-auto-advance) | |
1967 (> (prefix-numeric-value arg) 0))) | |
1968 (message (if emerge-skip-prefers | |
1969 "Auto-advance set" | |
1970 "Auto-advance cleared")) | |
1971 ;; force mode line redisplay | |
1972 (set-buffer-modified-p (buffer-modified-p))) | |
1973 | |
1974 (defun emerge-skip-prefers (arg) | |
1429 | 1975 "Toggle skip-prefers mode. |
1976 This mode causes `emerge-next-difference' and `emerge-previous-difference' | |
1977 to automatically skip over differences for which there is a preference. | |
1978 (See `emerge-skip-prefers'.) If a positive ARG is given, it turns on | |
1979 `skip-prefers' mode. | |
1980 If a negative ARG is given, it turns off `skip-prefers' mode." | |
583 | 1981 (interactive "P") |
1982 (setq emerge-skip-prefers (if (null arg) | |
1983 (not emerge-skip-prefers) | |
1984 (> (prefix-numeric-value arg) 0))) | |
1985 (message (if emerge-skip-prefers | |
1986 "Skip-prefers set" | |
1987 "Skip-prefers cleared")) | |
1988 ;; force mode line redisplay | |
1989 (set-buffer-modified-p (buffer-modified-p))) | |
1990 | |
1991 (defun emerge-copy-as-kill-A () | |
1992 "Put the A variant of this difference in the kill ring." | |
1993 (interactive) | |
1994 (emerge-validate-difference) | |
1995 (let* ((diff-vector | |
1996 (aref emerge-difference-list emerge-current-difference)) | |
1997 (A-begin (1+ (aref diff-vector 0))) | |
1998 (A-end (1- (aref diff-vector 1))) | |
1999 ;; so further kills don't append | |
2000 this-command) | |
2001 (save-excursion | |
2002 (set-buffer emerge-A-buffer) | |
2003 (copy-region-as-kill A-begin A-end)))) | |
2004 | |
2005 (defun emerge-copy-as-kill-B () | |
2006 "Put the B variant of this difference in the kill ring." | |
2007 (interactive) | |
2008 (emerge-validate-difference) | |
2009 (let* ((diff-vector | |
2010 (aref emerge-difference-list emerge-current-difference)) | |
2011 (B-begin (1+ (aref diff-vector 2))) | |
2012 (B-end (1- (aref diff-vector 3))) | |
2013 ;; so further kills don't append | |
2014 this-command) | |
2015 (save-excursion | |
2016 (set-buffer emerge-B-buffer) | |
2017 (copy-region-as-kill B-begin B-end)))) | |
2018 | |
2019 (defun emerge-insert-A (arg) | |
2020 "Insert the A variant of this difference at the point. | |
2021 Leaves point after text, mark before. | |
2022 With prefix argument, puts point before, mark after." | |
2023 (interactive "P") | |
2024 (emerge-validate-difference) | |
2025 (let* ((diff-vector | |
2026 (aref emerge-difference-list emerge-current-difference)) | |
2027 (A-begin (1+ (aref diff-vector 0))) | |
2028 (A-end (1- (aref diff-vector 1))) | |
2029 (opoint (point)) | |
2030 (buffer-read-only nil)) | |
2031 (insert-buffer-substring emerge-A-buffer A-begin A-end) | |
2032 (if (not arg) | |
2033 (set-mark opoint) | |
2034 (set-mark (point)) | |
2035 (goto-char opoint)))) | |
2036 | |
2037 (defun emerge-insert-B (arg) | |
2038 "Insert the B variant of this difference at the point. | |
2039 Leaves point after text, mark before. | |
2040 With prefix argument, puts point before, mark after." | |
2041 (interactive "P") | |
2042 (emerge-validate-difference) | |
2043 (let* ((diff-vector | |
2044 (aref emerge-difference-list emerge-current-difference)) | |
2045 (B-begin (1+ (aref diff-vector 2))) | |
2046 (B-end (1- (aref diff-vector 3))) | |
2047 (opoint (point)) | |
2048 (buffer-read-only nil)) | |
2049 (insert-buffer-substring emerge-B-buffer B-begin B-end) | |
2050 (if (not arg) | |
2051 (set-mark opoint) | |
2052 (set-mark (point)) | |
2053 (goto-char opoint)))) | |
2054 | |
2055 (defun emerge-mark-difference (arg) | |
2056 "Leaves the point before this difference and the mark after it. | |
2057 With prefix argument, puts mark before, point after." | |
2058 (interactive "P") | |
2059 (emerge-validate-difference) | |
2060 (let* ((diff-vector | |
2061 (aref emerge-difference-list emerge-current-difference)) | |
2062 (merge-begin (1+ (aref diff-vector 4))) | |
2063 (merge-end (1- (aref diff-vector 5)))) | |
2064 (if (not arg) | |
2065 (progn | |
2066 (goto-char merge-begin) | |
2067 (set-mark merge-end)) | |
2068 (goto-char merge-end) | |
2069 (set-mark merge-begin)))) | |
2070 | |
2071 (defun emerge-file-names () | |
2072 "Show the names of the buffers or files being operated on by Emerge. | |
1429 | 2073 Use C-u l to reset the windows afterward." |
583 | 2074 (interactive) |
2075 (delete-other-windows) | |
1610
fc2b0405bd87
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1429
diff
changeset
|
2076 (let ((temp-buffer-show-function |
583 | 2077 (function (lambda (buf) |
2078 (split-window-vertically) | |
2079 (switch-to-buffer buf) | |
2080 (other-window 1))))) | |
2081 (with-output-to-temp-buffer "*Help*" | |
2082 (emerge-eval-in-buffer emerge-A-buffer | |
2083 (if buffer-file-name | |
2084 (progn | |
2085 (princ "File A is: ") | |
2086 (princ buffer-file-name)) | |
2087 (progn | |
2088 (princ "Buffer A is: ") | |
2089 (princ (buffer-name)))) | |
2090 (princ "\n")) | |
2091 (emerge-eval-in-buffer emerge-B-buffer | |
2092 (if buffer-file-name | |
2093 (progn | |
2094 (princ "File B is: ") | |
2095 (princ buffer-file-name)) | |
2096 (progn | |
2097 (princ "Buffer B is: ") | |
2098 (princ (buffer-name)))) | |
2099 (princ "\n")) | |
2100 (if emerge-ancestor-buffer | |
2101 (emerge-eval-in-buffer emerge-ancestor-buffer | |
2102 (if buffer-file-name | |
2103 (progn | |
2104 (princ "Ancestor file is: ") | |
2105 (princ buffer-file-name)) | |
2106 (progn | |
2107 (princ "Ancestor buffer is: ") | |
2108 (princ (buffer-name)))) | |
2109 (princ "\n"))) | |
2110 (princ emerge-output-description)))) | |
2111 | |
2112 (defun emerge-join-differences (arg) | |
1429 | 2113 "Join the selected difference with the following one. |
2114 With a prefix argument, join with the preceeding one." | |
583 | 2115 (interactive "P") |
2116 (let ((n emerge-current-difference)) | |
2117 ;; adjust n to be first difference to join | |
2118 (if arg | |
2119 (setq n (1- n))) | |
2120 ;; n and n+1 are the differences to join | |
2121 ;; check that they are both differences | |
2122 (if (or (< n 0) (>= n (1- emerge-number-of-differences))) | |
2123 (error "Incorrect differences to join")) | |
2124 ;; remove the flags | |
2125 (emerge-unselect-difference emerge-current-difference) | |
2126 ;; decrement total number of differences | |
2127 (setq emerge-number-of-differences (1- emerge-number-of-differences)) | |
2128 ;; build new differences vector | |
2129 (let ((i 0) | |
2130 (new-differences (make-vector emerge-number-of-differences nil))) | |
2131 (while (< i emerge-number-of-differences) | |
2132 (aset new-differences i | |
2133 (cond | |
2134 ((< i n) (aref emerge-difference-list i)) | |
2135 ((> i n) (aref emerge-difference-list (1+ i))) | |
2136 (t (let ((prev (aref emerge-difference-list i)) | |
2137 (next (aref emerge-difference-list (1+ i)))) | |
2138 (vector (aref prev 0) | |
2139 (aref next 1) | |
2140 (aref prev 2) | |
2141 (aref next 3) | |
2142 (aref prev 4) | |
2143 (aref next 5) | |
2144 (let ((ps (aref prev 6)) | |
2145 (ns (aref next 6))) | |
2146 (cond | |
2147 ((eq ps ns) | |
2148 ps) | |
2149 ((and (or (eq ps 'B) (eq ps 'prefer-B)) | |
2150 (or (eq ns 'B) (eq ns 'prefer-B))) | |
2151 'B) | |
2152 (t 'A)))))))) | |
2153 (setq i (1+ i))) | |
2154 (setq emerge-difference-list new-differences)) | |
2155 ;; set the current difference correctly | |
2156 (setq emerge-current-difference n) | |
2157 ;; fix the mode line | |
2158 (emerge-refresh-mode-line) | |
2159 ;; reinsert the flags | |
2160 (emerge-select-difference emerge-current-difference) | |
2161 (emerge-recenter))) | |
2162 | |
2163 (defun emerge-split-difference () | |
2164 "Split the current difference where the points are in the three windows." | |
2165 (interactive) | |
2166 (let ((n emerge-current-difference)) | |
2167 ;; check that this is a valid difference | |
2168 (emerge-validate-difference) | |
2169 ;; get the point values and old difference | |
2170 (let ((A-point (emerge-eval-in-buffer emerge-A-buffer | |
2171 (point-marker))) | |
2172 (B-point (emerge-eval-in-buffer emerge-B-buffer | |
2173 (point-marker))) | |
2174 (merge-point (point-marker)) | |
2175 (old-diff (aref emerge-difference-list n))) | |
2176 ;; check location of the points, give error if they aren't in the | |
2177 ;; differences | |
2178 (if (or (< A-point (aref old-diff 0)) | |
2179 (> A-point (aref old-diff 1))) | |
2180 (error "Point outside of difference in A buffer")) | |
2181 (if (or (< B-point (aref old-diff 2)) | |
2182 (> B-point (aref old-diff 3))) | |
2183 (error "Point outside of difference in B buffer")) | |
2184 (if (or (< merge-point (aref old-diff 4)) | |
2185 (> merge-point (aref old-diff 5))) | |
2186 (error "Point outside of difference in merge buffer")) | |
2187 ;; remove the flags | |
2188 (emerge-unselect-difference emerge-current-difference) | |
2189 ;; increment total number of differences | |
2190 (setq emerge-number-of-differences (1+ emerge-number-of-differences)) | |
2191 ;; build new differences vector | |
2192 (let ((i 0) | |
2193 (new-differences (make-vector emerge-number-of-differences nil))) | |
2194 (while (< i emerge-number-of-differences) | |
2195 (aset new-differences i | |
2196 (cond | |
2197 ((< i n) | |
2198 (aref emerge-difference-list i)) | |
2199 ((> i (1+ n)) | |
2200 (aref emerge-difference-list (1- i))) | |
2201 ((= i n) | |
2202 (vector (aref old-diff 0) | |
2203 A-point | |
2204 (aref old-diff 2) | |
2205 B-point | |
2206 (aref old-diff 4) | |
2207 merge-point | |
2208 (aref old-diff 6))) | |
2209 (t | |
2210 (vector (copy-marker A-point) | |
2211 (aref old-diff 1) | |
2212 (copy-marker B-point) | |
2213 (aref old-diff 3) | |
2214 (copy-marker merge-point) | |
2215 (aref old-diff 5) | |
2216 (aref old-diff 6))))) | |
2217 (setq i (1+ i))) | |
2218 (setq emerge-difference-list new-differences)) | |
2219 ;; set the current difference correctly | |
2220 (setq emerge-current-difference n) | |
2221 ;; fix the mode line | |
2222 (emerge-refresh-mode-line) | |
2223 ;; reinsert the flags | |
2224 (emerge-select-difference emerge-current-difference) | |
2225 (emerge-recenter)))) | |
2226 | |
2227 (defun emerge-trim-difference () | |
1429 | 2228 "Trim lines off top and bottom of difference that are the same. |
2229 If lines are the same in both the A and the B versions, strip them off. | |
2230 (This can happen when the A and B versions have common lines that the | |
2231 ancestor version does not share.)" | |
583 | 2232 (interactive) |
2233 ;; make sure we are in a real difference | |
2234 (emerge-validate-difference) | |
2235 ;; remove the flags | |
2236 (emerge-unselect-difference emerge-current-difference) | |
2237 (let* ((diff (aref emerge-difference-list emerge-current-difference)) | |
2238 (top-a (marker-position (aref diff 0))) | |
2239 (bottom-a (marker-position (aref diff 1))) | |
2240 (top-b (marker-position (aref diff 2))) | |
2241 (bottom-b (marker-position (aref diff 3))) | |
2242 (top-m (marker-position (aref diff 4))) | |
2243 (bottom-m (marker-position (aref diff 5))) | |
2244 size success sa sb sm) | |
2245 ;; move down the tops of the difference regions as much as possible | |
2246 ;; Try advancing comparing 1000 chars at a time. | |
2247 ;; When that fails, go 500 chars at a time, and so on. | |
2248 (setq size 1000) | |
2249 (while (> size 0) | |
2250 (setq success t) | |
2251 (while success | |
2252 (setq size (min size (- bottom-a top-a) (- bottom-b top-b) | |
2253 (- bottom-m top-m))) | |
2254 (setq sa (emerge-eval-in-buffer emerge-A-buffer | |
2255 (buffer-substring top-a | |
2256 (+ size top-a)))) | |
2257 (setq sb (emerge-eval-in-buffer emerge-B-buffer | |
2258 (buffer-substring top-b | |
2259 (+ size top-b)))) | |
2260 (setq sm (buffer-substring top-m (+ size top-m))) | |
2261 (setq success (and (> size 0) (equal sa sb) (equal sb sm))) | |
2262 (if success | |
2263 (setq top-a (+ top-a size) | |
2264 top-b (+ top-b size) | |
2265 top-m (+ top-m size)))) | |
2266 (setq size (/ size 2))) | |
2267 ;; move up the bottoms of the difference regions as much as possible | |
2268 ;; Try advancing comparing 1000 chars at a time. | |
2269 ;; When that fails, go 500 chars at a time, and so on. | |
2270 (setq size 1000) | |
2271 (while (> size 0) | |
2272 (setq success t) | |
2273 (while success | |
2274 (setq size (min size (- bottom-a top-a) (- bottom-b top-b) | |
2275 (- bottom-m top-m))) | |
2276 (setq sa (emerge-eval-in-buffer emerge-A-buffer | |
2277 (buffer-substring (- bottom-a size) | |
2278 bottom-a))) | |
2279 (setq sb (emerge-eval-in-buffer emerge-B-buffer | |
2280 (buffer-substring (- bottom-b size) | |
2281 bottom-b))) | |
2282 (setq sm (buffer-substring (- bottom-m size) bottom-m)) | |
2283 (setq success (and (> size 0) (equal sa sb) (equal sb sm))) | |
2284 (if success | |
2285 (setq bottom-a (- bottom-a size) | |
2286 bottom-b (- bottom-b size) | |
2287 bottom-m (- bottom-m size)))) | |
2288 (setq size (/ size 2))) | |
2289 ;; {top,bottom}-{a,b,m} are now set at the new beginnings and ends | |
2290 ;; of the difference regions. Move them to the beginning of lines, as | |
2291 ;; appropriate. | |
2292 (emerge-eval-in-buffer emerge-A-buffer | |
2293 (goto-char top-a) | |
2294 (beginning-of-line) | |
2295 (aset diff 0 (point-marker)) | |
2296 (goto-char bottom-a) | |
2297 (beginning-of-line 2) | |
2298 (aset diff 1 (point-marker))) | |
2299 (emerge-eval-in-buffer emerge-B-buffer | |
2300 (goto-char top-b) | |
2301 (beginning-of-line) | |
2302 (aset diff 2 (point-marker)) | |
2303 (goto-char bottom-b) | |
2304 (beginning-of-line 2) | |
2305 (aset diff 3 (point-marker))) | |
2306 (goto-char top-m) | |
2307 (beginning-of-line) | |
2308 (aset diff 4 (point-marker)) | |
2309 (goto-char bottom-m) | |
2310 (beginning-of-line 2) | |
2311 (aset diff 5 (point-marker)) | |
2312 ;; put the flags back in, recenter the display | |
2313 (emerge-select-difference emerge-current-difference) | |
2314 (emerge-recenter))) | |
2315 | |
2316 (defun emerge-find-difference (arg) | |
2317 "Find the difference containing the current position of the point. | |
2318 If there is no containing difference and the prefix argument is positive, | |
2319 it finds the nearest following difference. A negative prefix argument finds | |
2320 the nearest previous difference." | |
2321 (interactive "P") | |
2322 ;; search for the point in the merge buffer, using the markers | |
2323 ;; for the beginning and end of the differences in the merge buffer | |
2324 (emerge-find-difference1 arg (point) 4 5)) | |
2325 | |
2326 (defun emerge-find-difference-A (arg) | |
1429 | 2327 "Find the difference containing the position of the point in the A buffer. |
2328 This command must be executed in the merge buffer. | |
583 | 2329 If there is no containing difference and the prefix argument is positive, |
2330 it finds the nearest following difference. A negative prefix argument finds | |
2331 the nearest previous difference." | |
2332 (interactive "P") | |
2333 ;; search for the point in the A buffer, using the markers | |
2334 ;; for the beginning and end of the differences in the A buffer | |
2335 (emerge-find-difference1 arg | |
2336 (emerge-eval-in-buffer emerge-A-buffer (point)) | |
2337 0 1)) | |
2338 | |
2339 (defun emerge-find-difference-B (arg) | |
1429 | 2340 "Find the difference containing the position of the point in the B buffer. |
2341 This command must be executed in the merge buffer. | |
583 | 2342 If there is no containing difference and the prefix argument is positive, |
2343 it finds the nearest following difference. A negative prefix argument finds | |
2344 the nearest previous difference." | |
2345 (interactive "P") | |
2346 ;; search for the point in the B buffer, using the markers | |
2347 ;; for the beginning and end of the differences in the B buffer | |
2348 (emerge-find-difference1 arg | |
2349 (emerge-eval-in-buffer emerge-B-buffer (point)) | |
2350 2 3)) | |
2351 | |
2352 (defun emerge-find-difference1 (arg location begin end) | |
2353 (let* ((index | |
2354 ;; find first difference containing or after the current position | |
2355 (catch 'search | |
2356 (let ((n 0)) | |
2357 (while (< n emerge-number-of-differences) | |
2358 (let ((diff-vector (aref emerge-difference-list n))) | |
2359 (if (<= location (marker-position (aref diff-vector end))) | |
2360 (throw 'search n))) | |
2361 (setq n (1+ n)))) | |
2362 emerge-number-of-differences)) | |
2363 (contains | |
2364 ;; whether the found difference contains the current position | |
2365 (and (< index emerge-number-of-differences) | |
2366 (<= (marker-position (aref (aref emerge-difference-list index) | |
2367 begin)) | |
2368 location))) | |
2369 (arg-value | |
2370 ;; numeric value of prefix argument | |
2371 (prefix-numeric-value arg))) | |
2372 (emerge-unselect-and-select-difference | |
2373 (cond | |
2374 ;; if the point is in a difference, select it | |
2375 (contains index) | |
2376 ;; if the arg is nil and the point is not in a difference, error | |
2377 ((null arg) (error "No difference contains point")) | |
2378 ;; if the arg is positive, select the following difference | |
2379 ((> arg-value 0) | |
2380 (if (< index emerge-number-of-differences) | |
2381 index | |
2382 (error "No difference contains or follows point"))) | |
2383 ;; if the arg is negative, select the preceeding difference | |
2384 (t | |
2385 (if (> index 0) | |
2386 (1- index) | |
2387 (error "No difference contains or preceeds point"))))))) | |
2388 | |
2389 (defun emerge-line-numbers () | |
1429 | 2390 "Display the current line numbers. |
2391 This function displays the line numbers of the points in the A, B, and | |
583 | 2392 merge buffers." |
2393 (interactive) | |
2394 (let* ((valid-diff | |
2395 (and (>= emerge-current-difference 0) | |
2396 (< emerge-current-difference emerge-number-of-differences))) | |
2397 (diff (and valid-diff | |
2398 (aref emerge-difference-list emerge-current-difference))) | |
2399 (merge-line (emerge-line-number-in-buf 4 5)) | |
2400 (A-line (emerge-eval-in-buffer emerge-A-buffer | |
2401 (emerge-line-number-in-buf 0 1))) | |
2402 (B-line (emerge-eval-in-buffer emerge-B-buffer | |
2403 (emerge-line-number-in-buf 2 3)))) | |
2404 (message "At lines: merge = %d, A = %d, B = %d" | |
2405 merge-line A-line B-line))) | |
2406 | |
2407 (defun emerge-line-number-in-buf (begin-marker end-marker) | |
2408 (let (temp) | |
2409 (setq temp (save-excursion | |
2410 (beginning-of-line) | |
2411 (1+ (count-lines 1 (point))))) | |
2412 (if valid-diff | |
2413 (progn | |
2414 (if (> (point) (aref diff begin-marker)) | |
2415 (setq temp (- temp emerge-before-flag-lines))) | |
2416 (if (> (point) (aref diff end-marker)) | |
2417 (setq temp (- temp emerge-after-flag-lines))))) | |
2418 temp)) | |
2419 | |
2420 (defun emerge-set-combine-versions-template (start end &optional localize) | |
1429 | 2421 "Copy region into `emerge-combine-versions-template'. |
2422 This controls how `emerge-combine-versions' will combine the two versions. | |
2423 With prefix argument, `emerge-combine-versions' is made local to this | |
583 | 2424 merge buffer. Localization is permanent for any particular merge buffer." |
2425 (interactive "r\nP") | |
2426 (if localize | |
2427 (make-local-variable 'emerge-combine-versions-template)) | |
2428 (setq emerge-combine-versions-template (buffer-substring start end)) | |
2429 (message | |
2430 (if (assq 'emerge-combine-versions-template (buffer-local-variables)) | |
2431 "emerge-set-combine-versions-template set locally." | |
2432 "emerge-set-combine-versions-template set."))) | |
2433 | |
2434 (defun emerge-combine-versions (&optional force) | |
1429 | 2435 "Combine versions using the template in `emerge-combine-versions-template'. |
583 | 2436 Refuses to function if this difference has been edited, i.e., if it is |
2437 neither the A nor the B variant. | |
1429 | 2438 An argument forces the variant to be selected even if the difference has |
583 | 2439 been edited." |
2440 (interactive "P") | |
2441 (emerge-combine-versions-internal emerge-combine-versions-template force)) | |
2442 | |
2443 (defun emerge-combine-versions-register (char &optional force) | |
2444 "Combine the two versions using the template in register REG. | |
1429 | 2445 See documentation of the variable `emerge-combine-versions-template' |
583 | 2446 for how the template is interpreted. |
2447 Refuses to function if this difference has been edited, i.e., if it is | |
2448 neither the A nor the B variant. | |
1429 | 2449 An argument forces the variant to be selected even if the difference has |
583 | 2450 been edited." |
2451 (interactive "cRegister containing template: \nP") | |
2452 (let ((template (get-register char))) | |
2453 (if (not (stringp template)) | |
2454 (error "Register does not contain text")) | |
2455 (emerge-combine-versions-internal template force))) | |
2456 | |
2457 (defun emerge-combine-versions-internal (template force) | |
2458 (let ((operate | |
2459 (function (lambda () | |
2460 (emerge-combine-versions-edit merge-begin merge-end | |
2461 A-begin A-end B-begin B-end) | |
2462 (if emerge-auto-advance | |
2463 (emerge-next-difference)))))) | |
2464 (emerge-select-version force operate operate operate))) | |
2465 | |
2466 (defun emerge-combine-versions-edit (merge-begin merge-end | |
2467 A-begin A-end B-begin B-end) | |
2468 (emerge-eval-in-buffer | |
2469 emerge-merge-buffer | |
2470 (delete-region merge-begin merge-end) | |
2471 (goto-char merge-begin) | |
2472 (let ((i 0)) | |
2473 (while (< i (length template)) | |
2474 (let ((c (aref template i))) | |
2475 (if (= c ?%) | |
2476 (progn | |
2477 (setq i (1+ i)) | |
2478 (setq c | |
2479 (condition-case nil | |
2480 (aref template i) | |
2481 (error ?%))) | |
2482 (cond ((= c ?a) | |
2483 (insert-buffer-substring emerge-A-buffer A-begin A-end)) | |
2484 ((= c ?b) | |
2485 (insert-buffer-substring emerge-B-buffer B-begin B-end)) | |
2486 ((= c ?%) | |
1610
fc2b0405bd87
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1429
diff
changeset
|
2487 (insert ?%)) |
fc2b0405bd87
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1429
diff
changeset
|
2488 (t |
fc2b0405bd87
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1429
diff
changeset
|
2489 (insert c)))) |
583 | 2490 (insert c))) |
2491 (setq i (1+ i)))) | |
2492 (goto-char merge-begin) | |
2493 (aset diff-vector 6 'combined) | |
2494 (emerge-refresh-mode-line))) | |
2495 | |
2496 (defun emerge-set-merge-mode (mode) | |
1429 | 2497 "Set the major mode in a merge buffer. |
2498 Overrides any change that the mode might make to the mode line or local | |
2499 keymap. Leaves merge in fast mode." | |
583 | 2500 (interactive |
2501 (list (intern (completing-read "New major mode for merge buffer: " | |
2502 obarray 'commandp t nil)))) | |
2503 (funcall mode) | |
2504 (emerge-refresh-mode-line) | |
2505 (if emerge-fast-mode | |
2506 (emerge-fast-mode) | |
2507 (emerge-edit-mode))) | |
2508 | |
2509 (defun emerge-one-line-window () | |
2510 (interactive) | |
2511 (let ((window-min-height 1)) | |
2512 (shrink-window (- (window-height) 2)))) | |
2513 | |
2514 ;;; Support routines | |
2515 | |
2516 ;; Select a difference by placing the visual flags around the appropriate | |
2517 ;; group of lines in the A, B, and merge buffers | |
2518 (defun emerge-select-difference (n) | |
2519 (let ((diff-vector (aref emerge-difference-list n))) | |
2520 (emerge-place-flags-in-buffer emerge-A-buffer | |
2521 (aref diff-vector 0) (aref diff-vector 1)) | |
2522 (emerge-place-flags-in-buffer emerge-B-buffer | |
2523 (aref diff-vector 2) (aref diff-vector 3)) | |
2524 (emerge-place-flags-in-buffer emerge-merge-buffer | |
2525 (aref diff-vector 4) (aref diff-vector 5)))) | |
2526 | |
2527 (defun emerge-place-flags-in-buffer (buffer before after) | |
2528 (if (eq buffer emerge-merge-buffer) | |
2529 (emerge-place-flags-in-buffer1 buffer before after) | |
2530 (emerge-eval-in-buffer | |
2531 buffer | |
2532 (emerge-place-flags-in-buffer1 buffer before after)))) | |
2533 | |
2534 (defun emerge-place-flags-in-buffer1 (buffer before after) | |
2535 (let ((buffer-read-only nil)) | |
2536 ;; insert the flags | |
2537 (goto-char before) | |
2538 (insert-before-markers emerge-before-flag) | |
2539 (goto-char after) | |
2540 (insert emerge-after-flag) | |
2541 ;; put the markers into the flags, so alterations above or below won't move | |
2542 ;; them | |
2543 ;; before marker is one char before the end of the before flag | |
2544 ;; after marker is one char after the beginning of the after flag | |
2545 (set-marker before (1- before)) | |
2546 (set-marker after (1+ after)))) | |
2547 | |
2548 ;; Unselect a difference by removing the visual flags in the buffers. | |
2549 (defun emerge-unselect-difference (n) | |
2550 (let ((diff-vector (aref emerge-difference-list n))) | |
2551 (emerge-remove-flags-in-buffer emerge-A-buffer | |
2552 (aref diff-vector 0) (aref diff-vector 1)) | |
2553 (emerge-remove-flags-in-buffer emerge-B-buffer | |
2554 (aref diff-vector 2) (aref diff-vector 3)) | |
2555 (emerge-remove-flags-in-buffer emerge-merge-buffer | |
2556 (aref diff-vector 4) (aref diff-vector 5)))) | |
2557 | |
2558 (defun emerge-remove-flags-in-buffer (buffer before after) | |
2559 (emerge-eval-in-buffer | |
2560 buffer | |
2561 (let ((buffer-read-only nil)) | |
2562 ;; put the markers at the beginning of the flags | |
2563 (set-marker before (- before (1- emerge-before-flag-length))) | |
2564 (set-marker after (1- after)) | |
2565 ;; remove the flags | |
2566 (goto-char before) | |
2567 (if (looking-at emerge-before-flag-match) | |
2568 (delete-char emerge-before-flag-length) | |
2569 ;; the flag isn't there | |
2570 (ding) | |
2571 (message "Trouble removing flag.")) | |
2572 (goto-char after) | |
2573 (if (looking-at emerge-after-flag-match) | |
2574 (delete-char emerge-after-flag-length) | |
2575 ;; the flag isn't there | |
2576 (ding) | |
2577 (message "Trouble removing flag."))))) | |
2578 | |
2579 ;; Select a difference, removing an flags that exist now. | |
2580 (defun emerge-unselect-and-select-difference (n &optional suppress-display) | |
2581 (if (and (>= emerge-current-difference 0) | |
2582 (< emerge-current-difference emerge-number-of-differences)) | |
2583 (emerge-unselect-difference emerge-current-difference)) | |
2584 (if (and (>= n 0) (< n emerge-number-of-differences)) | |
2585 (progn | |
2586 (emerge-select-difference n) | |
2587 (let* ((diff-vector (aref emerge-difference-list n)) | |
2588 (selection-type (aref diff-vector 6))) | |
2589 (if (eq selection-type 'default-A) | |
2590 (aset diff-vector 6 'A) | |
2591 (if (eq selection-type 'default-B) | |
2592 (aset diff-vector 6 'B)))))) | |
2593 (setq emerge-current-difference n) | |
2594 (if (not suppress-display) | |
2595 (progn | |
2596 (emerge-recenter) | |
2597 (emerge-refresh-mode-line)))) | |
2598 | |
2599 ;; Perform tests to see whether user should be allowed to select a version | |
2600 ;; of this difference: | |
2601 ;; a valid difference has been selected; and | |
2602 ;; the difference text in the merge buffer is: | |
2603 ;; the A version (execute a-version), or | |
2604 ;; the B version (execute b-version), or | |
2605 ;; empty (execute neither-version), or | |
2606 ;; argument FORCE is true (execute neither-version) | |
2607 ;; Otherwise, signal an error. | |
2608 (defun emerge-select-version (force a-version b-version neither-version) | |
2609 (emerge-validate-difference) | |
2610 (let ((buffer-read-only nil)) | |
2611 (let* ((diff-vector | |
2612 (aref emerge-difference-list emerge-current-difference)) | |
2613 (A-begin (1+ (aref diff-vector 0))) | |
2614 (A-end (1- (aref diff-vector 1))) | |
2615 (B-begin (1+ (aref diff-vector 2))) | |
2616 (B-end (1- (aref diff-vector 3))) | |
2617 (merge-begin (1+ (aref diff-vector 4))) | |
2618 (merge-end (1- (aref diff-vector 5)))) | |
2619 (if (emerge-compare-buffers emerge-A-buffer A-begin A-end | |
2620 emerge-merge-buffer merge-begin | |
2621 merge-end) | |
2622 (funcall a-version) | |
2623 (if (emerge-compare-buffers emerge-B-buffer B-begin B-end | |
2624 emerge-merge-buffer merge-begin | |
2625 merge-end) | |
2626 (funcall b-version) | |
2627 (if (or force (= merge-begin merge-end)) | |
2628 (funcall neither-version) | |
2629 (error "This difference region has been edited."))))))) | |
2630 | |
2631 ;; Revise the mode line to display which difference we have selected | |
2632 | |
2633 (defun emerge-refresh-mode-line () | |
2634 (setq mode-line-buffer-identification | |
2635 (list (format "Emerge: %%b diff %d of %d%s" | |
2636 (1+ emerge-current-difference) | |
2637 emerge-number-of-differences | |
2638 (if (and (>= emerge-current-difference 0) | |
2639 (< emerge-current-difference | |
2640 emerge-number-of-differences)) | |
2641 (cdr (assq (aref (aref emerge-difference-list | |
2642 emerge-current-difference) | |
2643 6) | |
2644 '((A . " - A") | |
2645 (B . " - B") | |
2646 (prefer-A . " - A*") | |
2647 (prefer-B . " - B*") | |
2648 (combined . " - comb")))) | |
2649 "")))) | |
2650 ;; Force mode-line redisplay | |
2651 (set-buffer-modified-p (buffer-modified-p))) | |
2652 | |
2653 ;; compare two regions in two buffers for containing the same text | |
2654 (defun emerge-compare-buffers (buffer-x x-begin x-end buffer-y y-begin y-end) | |
2655 ;; first check that the two regions are the same length | |
2656 (if (not (and (= (- x-end x-begin) (- y-end y-begin)))) | |
2657 nil | |
2658 (catch 'exit | |
2659 (while (< x-begin x-end) | |
2660 ;; bite off and compare no more than 1000 characters at a time | |
2661 (let* ((compare-length (min (- x-end x-begin) 1000)) | |
2662 (x-string (emerge-eval-in-buffer | |
2663 buffer-x | |
2664 (buffer-substring x-begin | |
2665 (+ x-begin compare-length)))) | |
2666 (y-string (emerge-eval-in-buffer | |
2667 buffer-y | |
2668 (buffer-substring y-begin | |
2669 (+ y-begin compare-length))))) | |
2670 (if (not (string-equal x-string y-string)) | |
2671 (throw 'exit nil) | |
2672 (setq x-begin (+ x-begin compare-length)) | |
2673 (setq y-begin (+ y-begin compare-length))))) | |
2674 t))) | |
2675 | |
2676 ;; Construct a unique buffer name. | |
2677 ;; The first one tried is prefixsuffix, then prefix<2>suffix, | |
2678 ;; prefix<3>suffix, etc. | |
2679 (defun emerge-unique-buffer-name (prefix suffix) | |
2680 (if (null (get-buffer (concat prefix suffix))) | |
2681 (concat prefix suffix) | |
2682 (let ((n 2)) | |
2683 (while (get-buffer (format "%s<%d>%s" prefix n suffix)) | |
2684 (setq n (1+ n))) | |
2685 (format "%s<%d>%s" prefix n suffix)))) | |
2686 | |
2687 ;; Verify that we have a difference selected. | |
2688 (defun emerge-validate-difference () | |
2689 (if (not (and (>= emerge-current-difference 0) | |
2690 (< emerge-current-difference emerge-number-of-differences))) | |
2691 (error "No difference selected"))) | |
2692 | |
2693 ;;; Functions for saving and restoring a batch of variables | |
2694 | |
2695 ;; These functions save (get the values of) and restore (set the values of) | |
2696 ;; a list of variables. The argument is a list of symbols (the names of | |
2697 ;; the variables). A list element can also be a list of two functions, | |
2698 ;; the first of which (when called with no arguments) gets the value, and | |
2699 ;; the second (when called with a value as an argment) sets the value. | |
2700 ;; A "function" is anything that funcall can handle as an argument. | |
2701 | |
2702 (defun emerge-save-variables (vars) | |
2703 (mapcar (function (lambda (v) (if (symbolp v) | |
2704 (symbol-value v) | |
2705 (funcall (car v))))) | |
2706 vars)) | |
2707 | |
2708 (defun emerge-restore-variables (vars values) | |
2709 (while vars | |
2710 (let ((var (car vars)) | |
2711 (value (car values))) | |
2712 (if (symbolp var) | |
2713 (set var value) | |
2714 (funcall (car (cdr var)) value))) | |
2715 (setq vars (cdr vars)) | |
2716 (setq values (cdr values)))) | |
2717 | |
2718 ;; Make a temporary file that only we have access to. | |
2719 ;; PREFIX is appended to emerge-temp-file-prefix to make the filename prefix. | |
2720 (defun emerge-make-temp-file (prefix) | |
2721 (let ((f (make-temp-name (concat emerge-temp-file-prefix prefix)))) | |
2722 ;; create the file | |
2723 (write-region (point-min) (point-min) f nil 'no-message) | |
2724 (set-file-modes f emerge-temp-file-mode) | |
2725 f)) | |
2726 | |
2727 ;;; Functions that query the user before he can write out the current buffer. | |
2728 | |
2729 (defun emerge-query-write-file () | |
2730 "Query the user if he really wants to write out the incomplete merge. | |
1429 | 2731 If he says yes, call `write-file' to do so. See `emerge-query-and-call' |
583 | 2732 for details of the querying process." |
2733 (interactive) | |
2734 (emerge-query-and-call 'write-file)) | |
2735 | |
2736 (defun emerge-query-save-buffer () | |
2737 "Query the user if he really wants to write out the incomplete merge. | |
1429 | 2738 If he says yes, call `save-buffer' to do so. See `emerge-query-and-call' |
583 | 2739 for details of the querying process." |
2740 (interactive) | |
2741 (emerge-query-and-call 'save-buffer)) | |
2742 | |
2743 (defun emerge-query-and-call (command) | |
2744 "Query the user if he really wants to write out the incomplete merge. | |
2745 If he says yes, call COMMAND interactively. During the call, the flags | |
2746 around the current difference are removed." | |
2747 (if (yes-or-no-p "Do you really write to write out this unfinished merge? ") | |
2748 ;; He really wants to do it -- unselect the difference for the duration | |
2749 (progn | |
2750 (if (and (>= emerge-current-difference 0) | |
2751 (< emerge-current-difference emerge-number-of-differences)) | |
2752 (emerge-unselect-difference emerge-current-difference)) | |
2753 ;; call-interactively takes the value of current-prefix-arg as the | |
2754 ;; prefix argument value to be passed to the command. Thus, we have | |
2755 ;; to do nothing special to make sure the prefix argument is | |
2756 ;; transmitted to the command. | |
2757 (call-interactively command) | |
2758 (if (and (>= emerge-current-difference 0) | |
2759 (< emerge-current-difference emerge-number-of-differences)) | |
2760 (progn | |
2761 (emerge-select-difference emerge-current-difference) | |
2762 (emerge-recenter)))) | |
2763 ;; He's being smart and not doing it | |
2764 (message "Not written"))) | |
2765 | |
2766 ;; Make sure the current buffer (for a file) has the same contents as the | |
2767 ;; file on disk, and attempt to remedy the situation if not. | |
2768 ;; Signal an error if we can't make them the same, or the user doesn't want | |
2769 ;; to do what is necessary to make them the same. | |
2770 (defun emerge-verify-file-buffer () | |
2771 ;; First check if the file has been modified since the buffer visited it. | |
2772 (if (verify-visited-file-modtime (current-buffer)) | |
2773 (if (buffer-modified-p) | |
2774 ;; If buffer is not obsolete and is modified, offer to save | |
2775 (if (yes-or-no-p (format "Save file %s? " buffer-file-name)) | |
2776 (save-buffer) | |
2777 (error "Buffer out of sync for file %s" buffer-file-name)) | |
2778 ;; If buffer is not obsolete and is not modified, do nothing | |
2779 nil) | |
2780 (if (buffer-modified-p) | |
2781 ;; If buffer is obsolete and is modified, give error | |
2782 (error "Buffer out of sync for file %s" buffer-file-name) | |
2783 ;; If buffer is obsolete and is not modified, offer to revert | |
2784 (if (yes-or-no-p (format "Revert file %s? " buffer-file-name)) | |
2785 (revert-buffer t t) | |
2786 (error "Buffer out of sync for file %s" buffer-file-name))))) | |
2787 | |
2788 ;; Utilities that might have value outside of Emerge. | |
2789 | |
2790 ;; Set up the mode in the current buffer to duplicate the mode in another | |
2791 ;; buffer. | |
2792 (defun emerge-copy-modes (buffer) | |
2793 ;; Set the major mode | |
2794 (funcall (emerge-eval-in-buffer buffer major-mode))) | |
2795 | |
2796 ;; Define a key, even if a prefix of it is defined | |
2797 (defun emerge-force-define-key (keymap key definition) | |
1429 | 2798 "Like `define-key', but isn't stopped if a prefix of KEY is a defined |
583 | 2799 command." |
2800 ;; Find out if a prefix of key is defined | |
2801 (let ((v (lookup-key keymap key))) | |
2802 ;; If so, undefine it | |
2803 (if (integerp v) | |
2804 (define-key keymap (substring key 0 v) nil))) | |
2805 ;; Now define the key | |
2806 (define-key keymap key definition)) | |
2807 | |
2808 ;;; Improvements to describe-mode, so that it describes minor modes as well | |
2809 ;;; as the major mode | |
2810 (defun describe-mode (&optional minor) | |
2811 "Display documentation of current major mode. | |
2812 If optional MINOR is non-nil (or prefix argument is given if interactive), | |
2813 display documentation of acive minor modes as well. | |
2814 For this to work correctly for a minor mode, the mode's indicator variable | |
1429 | 2815 (listed in `minor-mode-alist') must also be a function whose documentation |
583 | 2816 describes the minor mode." |
2817 (interactive) | |
2818 (with-output-to-temp-buffer "*Help*" | |
2819 (princ mode-name) | |
2820 (princ " Mode:\n") | |
2821 (princ (documentation major-mode)) | |
2822 (let ((minor-modes minor-mode-alist) | |
2823 (locals (buffer-local-variables))) | |
2824 (while minor-modes | |
2825 (let* ((minor-mode (car (car minor-modes))) | |
2826 (indicator (car (cdr (car minor-modes)))) | |
2827 (local-binding (assq minor-mode locals))) | |
2828 ;; Document a minor mode if it is listed in minor-mode-alist, | |
2829 ;; bound locally in this buffer, non-nil, and has a function | |
2830 ;; definition. | |
2831 (if (and local-binding | |
2832 (cdr local-binding) | |
2833 (fboundp minor-mode)) | |
2834 (progn | |
2835 (princ (format "\n\n\n%s minor mode (indicator%s):\n" | |
2836 minor-mode indicator)) | |
2837 (princ (documentation minor-mode))))) | |
2838 (setq minor-modes (cdr minor-modes)))) | |
2839 (print-help-return-message))) | |
2840 | |
2841 ;; Adjust things so that keyboard macro definitions are documented correctly. | |
2842 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro)) | |
2843 | |
2844 ;; Function to shadow a definition in a keymap with definitions in another. | |
2845 (defun emerge-shadow-key-definition (olddef newdef keymap shadowmap) | |
2846 "Shadow OLDDEF with NEWDEF for any keys in KEYMAP with entries in SHADOWMAP. | |
2847 In other words, SHADOWMAP will now shadow all definitions of OLDDEF in KEYMAP | |
2848 with NEWDEF. Does not affect keys that are already defined in SHADOWMAP, | |
2849 including those whose definition is OLDDEF." | |
2850 ;; loop through all keymaps accessible from keymap | |
2851 (let ((maps (accessible-keymaps keymap))) | |
2852 (while maps | |
2853 (let ((prefix (car (car maps))) | |
2854 (map (cdr (car maps)))) | |
2855 ;; examine a keymap | |
2856 (if (arrayp map) | |
2857 ;; array keymap | |
2858 (let ((len (length map)) | |
2859 (i 0)) | |
2860 (while (< i len) | |
2861 (if (eq (aref map i) olddef) | |
2862 ;; set the shadowing definition | |
2863 (let ((key (concat prefix (char-to-string i)))) | |
2864 (emerge-define-key-if-possible shadowmap key newdef))) | |
2865 (setq i (1+ i)))) | |
2866 ;; sparse keymap | |
2867 (while map | |
2868 (if (eq (cdr-safe (car-safe map)) olddef) | |
2869 ;; set the shadowing definition | |
2870 (let ((key | |
2871 (concat prefix (char-to-string (car (car map)))))) | |
2872 (emerge-define-key-if-possible shadowmap key newdef))) | |
2873 (setq map (cdr map))))) | |
2874 (setq maps (cdr maps))))) | |
2875 | |
2876 ;; Define a key if it (or a prefix) is not already defined in the map. | |
2877 (defun emerge-define-key-if-possible (keymap key definition) | |
2878 ;; look up the present definition of the key | |
2879 (let ((present (lookup-key keymap key))) | |
2880 (if (integerp present) | |
2881 ;; if it is "too long", look up the valid prefix | |
2882 (if (not (lookup-key keymap (substring key 0 present))) | |
2883 ;; if the prefix isn't defined, define it | |
2884 (define-key keymap key definition)) | |
2885 ;; if there is no present definition, define it | |
2886 (if (not present) | |
2887 (define-key keymap key definition))))) | |
2888 | |
2889 (defun emerge-recursively-substitute-key-definition (olddef newdef keymap) | |
1429 | 2890 "Like `substitute-key-definition', but examines and substitutes in all |
583 | 2891 keymaps accessible from KEYMAP. Make sure that subordinate keymaps aren't |
1429 | 2892 shared with other keymaps! (`copy-keymap' will suffice.)" |
583 | 2893 ;; Loop through all keymaps accessible from keymap |
2894 (let ((maps (accessible-keymaps keymap))) | |
2895 (while maps | |
2896 ;; Substitute in this keymap | |
2897 (substitute-key-definition olddef newdef (cdr (car maps))) | |
2898 (setq maps (cdr maps))))) | |
2899 | |
2900 ;; Show the name of the file in the buffer. | |
2901 (defun emerge-show-file-name () | |
2902 "Displays the name of the file loaded into the current buffer. | |
2903 If the name won't fit on one line, the minibuffer is expanded to hold it, | |
2904 and the command waits for a keystroke from the user. If the keystroke is | |
2905 SPC, it is ignored; if it is anything else, it is processed as a command." | |
2906 (interactive) | |
2907 (let ((name (buffer-file-name))) | |
2908 (or name | |
2909 (setq name "Buffer has no file name.")) | |
2910 (save-window-excursion | |
2911 (select-window (minibuffer-window)) | |
2912 (erase-buffer) | |
2913 (insert name) | |
2914 (if (not (pos-visible-in-window-p)) | |
2915 (let ((echo-keystrokes 0)) | |
2916 (while (and (not (pos-visible-in-window-p)) | |
778 | 2917 (> (1- (frame-height)) (window-height))) |
583 | 2918 (enlarge-window 1)) |
2029
c06b592ca52b
(emerge-show-file-name): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
2919 (let ((c (read-event))) |
c06b592ca52b
(emerge-show-file-name): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
2920 (if (not (eq c 32)) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1610
diff
changeset
|
2921 (setq unread-command-events (list c))))))))) |
583 | 2922 |
2923 ;; Improved auto-save file names. | |
2924 ;; This function fixes many problems with the standard auto-save file names: | |
2925 ;; Auto-save files for non-file buffers get put in the default directory | |
2926 ;; for the buffer, whether that makes sense or not. | |
2927 ;; Auto-save files for file buffers get put in the directory of the file, | |
2928 ;; regardless of whether we can write into it or not. | |
2929 ;; Auto-save files for non-file buffers don't use the process id, so if a | |
2930 ;; user runs more than on Emacs, they can make auto-save files that overwrite | |
2931 ;; each other. | |
2932 ;; To use this function, do: | |
2933 ;; (fset 'make-auto-save-file-name | |
2934 ;; (symbol-function 'emerge-make-auto-save-file-name)) | |
2935 (defun emerge-make-auto-save-file-name () | |
2936 "Return file name to use for auto-saves of current buffer. | |
2937 Does not consider auto-save-visited-file-name; that is checked | |
2938 before calling this function. | |
2939 You can redefine this for customization. | |
2940 See also auto-save-file-name-p." | |
2941 (if buffer-file-name | |
2942 ;; if buffer has a file, try the format <file directory>/#<file name># | |
2943 (let ((f (concat (file-name-directory buffer-file-name) | |
2944 "#" | |
2945 (file-name-nondirectory buffer-file-name) | |
2946 "#"))) | |
2947 (if (file-writable-p f) | |
2948 ;; the file is writable, so use it | |
2949 f | |
2950 ;; the file isn't writable, so use the format | |
2951 ;; ~/#&<file name>&<hash of directory># | |
2952 (concat (getenv "HOME") | |
2953 "/#&" | |
2954 (file-name-nondirectory buffer-file-name) | |
2955 "&" | |
2956 (hash-string-into-string | |
2957 (file-name-directory buffer-file-name)) | |
2958 "#"))) | |
2959 ;; if buffer has no file, use the format ~/#%<buffer name>%<process id># | |
2960 (expand-file-name (concat (getenv "HOME") | |
2961 "/#%" | |
2962 ;; quote / into \! and \ into \\ | |
2963 (unslashify-name (buffer-name)) | |
2964 "%" | |
2965 (make-temp-name "") | |
2966 "#")))) | |
2967 | |
2968 ;; Hash a string into five characters more-or-less suitable for use in a file | |
2969 ;; name. (Allowed characters are ! through ~, except /.) | |
2970 (defun hash-string-into-string (s) | |
2971 (let ((bins (vector 0 0 0 0 0)) | |
2972 (i 0)) | |
2973 (while (< i (length s)) | |
2974 (aset bins (% i 5) (% (+ (* (aref bins (% i 5)) 35) | |
2975 (aref s i)) | |
2976 65536)) | |
2977 (setq i (1+ i))) | |
2978 (mapconcat (function (lambda (b) | |
2979 (setq b (+ (% b 93) ?!)) | |
2980 (if (>= b ?/) | |
2981 (setq b (1+ b))) | |
2982 (char-to-string b))) | |
2983 bins ""))) | |
2984 | |
2985 ;; Quote any /s in a string by replacing them with \!. | |
2986 ;; Also, replace any \s by \\, to make it one-to-one. | |
2987 (defun unslashify-name (s) | |
2988 (let ((limit 0)) | |
2989 (while (string-match "[/\\]" s limit) | |
2990 (setq s (concat (substring s 0 (match-beginning 0)) | |
2991 (if (string= (substring s (match-beginning 0) | |
2992 (match-end 0)) | |
2993 "/") | |
2994 "\\!" | |
2995 "\\\\") | |
2996 (substring s (match-end 0)))) | |
2997 (setq limit (1+ (match-end 0))))) | |
2998 s) | |
2999 | |
3000 (provide 'emerge) | |
3001 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
583
diff
changeset
|
3002 ;;; emerge.el ends here |