1 ;;; ediff.el --- a visual interface to diff & patch
2 ;;; Copyright (C) 1994 Free Software Foundation, Inc.
4 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
5 ;; Created: February 2, 1994
6 ;; Version of last Kifer changes: 1.64.2
7 ;; Keywords: comparing, merging, patching, version control.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;; Never read those diff outputs again!
30 ;; Apply patch selectively, like a pro!
32 ;; This package provides a convenient way of simultaneous browsing through
33 ;; the differences between a pair of files or buffers. The two files being
34 ;; compared (file-A and file-B) are shown in separate windows (side by
35 ;; side, one above the another, or in separate frames), and the differences
36 ;; are highlighted as you step through them. You can also copy difference
37 ;; regions from one buffer to another (and recover old differences if you
40 ;; In addition, Ediff can apply a patch to a file and then let you step
41 ;; though both files, the patched and the original one, simultaneously,
42 ;; difference-by-difference. You can even apply a patch right out of a
43 ;; mail buffer, i.e., patches received by mail don't even have to be saved.
44 ;; Since Ediff lets you copy differences between buffers, you can, in
45 ;; effect, apply patches selectively (i.e., you can copy a difference
46 ;; region from file.orig to file, thereby undoing any particular patch that
49 ;; This package builds upon the ideas borrowed from emerge.el. It is still
50 ;; using half a dozen of functions defined there. Several other Ediff's
51 ;; functions are adaptations from emerge.el. Ediff requires, at least,
52 ;; Version 5 of emerge.el. This version comes with standard distributions
53 ;; of Emacs and Lemacs. Make sure you don't have some stray old copy of
54 ;; Emerge on your load path.
56 ;; Ediff is complimentary to Emerge. While Emerge is primarily intended
57 ;; for merging of files, Ediff is by far superior for browsing through
58 ;; files compared via diff and for patching files with patch.
59 ;; Furthermore, Ediff is more convenient even for merging, when one of the
60 ;; files is a designated output. This situation arises while patching
61 ;; files or when comparing an old version of a file with a newer version
62 ;; (in such cases, it is often desirable to selectively revert some
63 ;; portions of the new file to its old state).
65 ;; Ediff also supports version control via vc.el (in the standard
66 ;; distribution of Emacs 19) and rcs.el. The latter is a package written by
67 ;; Sebastian Kremer <sk@thp.Uni-Koeln.DE>, which is available in
69 ;; ftp.cs.buffalo.edu:pub/Emacs/rcs.tar.Z
70 ;; ftp.uni-koeln.de:/pub/gnu/emacs/rcs.tar.Z
74 ;; Window configuration:
75 ;; ----------------------
77 ;; By default, Ediff sets things up in one frame, splitting it between a
78 ;; small control window and the two windows for file-A and file-B. The
79 ;; split between these latter windows can be horizontal or vertical, which
80 ;; can be changed interactively by hitting 's' while the cursor is in the
83 ;; In a multi-frame situation, Ediff would work as follows. When it starts,
84 ;; it will place the control window in the frame that was selected at the
85 ;; time of the invocation. If file-A or file-B is seen in one of the
86 ;; frames, Ediff will leave it there. If a file (A/B) is not visible in any
87 ;; frame, Ediff will arrange that it will share a frame with the control
88 ;; window. (If none of the files is visible, then both will share the
89 ;; control window frame.) The same algorithm works when you hit 'c'
90 ;; (ediff-recenter), 'p' (ediff-previous-difference), 'n', etc.
92 ;; Thus, you can compare files in one frame or in different frames.
93 ;; The former is done by default, while the latter can be achieved by
94 ;; arranging files A and B to be seen in different frames. Ediff
95 ;; respects these arrangements, automatically adapting itself to
96 ;; the multi-frame mode.
99 ;; To those who like to go where noone has gone before:
101 ;; Ediff lets the user run multiple sessions at once, i.e., you can invoke
102 ;; Ediff on different functions several times in a row, without exiting
103 ;; the previous Ediff sessions. Different sessions may even operate on the
104 ;; same pair of files. So, in principle, it is possible to do, say,
105 ;; pairwise comparison of three (or more) different files. Each session
106 ;; would have its own Ediff Control Panel and all the regarding a
107 ;; particular session is local to the associated control panel buffer.
108 ;; You can switch between sessions by suspending one session and then
109 ;; switching to another control panel. (Different control panel buffers
110 ;; are distinguished by a numerical suffix, e.g., Ediff Control Panel<3>.)
111 ;; Thus, if you would like to compare three files pairwise, you can do
112 ;; this by preparing three different frames, each with its own control
113 ;; window. (This would require a very wide screen, and I never claimed
114 ;; that such 3-way comparison is very easy to do.)
116 ;; If you need to conduct multiple Ediff sessions on the same file, one
117 ;; thing should be kept in mind: each time you invoke Ediff on a buffer that
118 ;; already participates in another Ediff session, that buffer should not
119 ;; have any ASCII Ediff flags in it. (Highlighting with faces is OK.) If
120 ;; flags are not removed, difference overlays won't be set correctly
121 ;; for the second invocation of Ediff. The simplest way to remove ASCII
122 ;; flags from an Ediff buffer is to hit `h' and thus switch to highlighting
123 ;; with faces (unhighlighting on a dumb terminal).
125 ;;; Remote and Compressed Files
126 ;; ---------------------------
128 ;; Ediff will work with remote files, compressed files, and, probably,
129 ;; with encrypted files. (I have only tested it with ange-ftp.el,
130 ;; jka-compr.el, and uncompress.el.) This means that you can compare files
131 ;; residing on another machine, or you can apply a patch to a file on
132 ;; another machine (even the patch itself can be a remote file!). This is
133 ;; provided that you access remote files via the usual find-file command
134 ;; using the syntax acceptable to ange-ftp (see Emacs Manual).
136 ;; The files to be compared or patched can be compressed or be both
137 ;; compressed and remote. To be able to handle compressed files, you
138 ;; should use uncompress.el or jka-compr.el. Ediff is designed so that it
139 ;; will interface to these packages. When patching compressed or remote
140 ;; files, Ediff doesn't rename the source file into source-file-name.orig
141 ;; (unlike what `patch' would usually do). Instead, the source file
142 ;; retains its name and the result of applying the patch is placed in a
143 ;; temporary file that has the suffix `.patched'. Generally, this applies
144 ;; to files that are handled using black magic, such as special file
145 ;; handlers (ange-ftp and some compression and encryption packages all
148 ;; Regular files are treated by `patch' in the usual manner, i.e., the
149 ;; original is renamed into source-name.orig and the result of the patch
150 ;; is placed into the file source-name.
156 ;; 1. Ediff is heavily dependent on the new features of Emacs 19.
157 ;; It won't run under Emacs 18 at all.
158 ;; 2. If running Lucid Emacs, Ediff requires at least version 19.9.
159 ;; 3. The function vc-ediff requires the version of vc.el that comes with
160 ;; Emacs 19.22 and later.
163 ;;; Installation and use:
164 ;; --------------------
166 ;; You can invoke Ediff interactively using the following functions:
168 ;; ediff-buffers - compare buffers
169 ;; ediff - alias for ediff-files)
170 ;; ediff-files - compare files
171 ;; ediff-patch-file - patch file then compare
172 ;; epatch - alias for ediff-patch-file
173 ;; ediff-patch-buffer - patch buffer then compare
174 ;; epatch-buffer - alias for ediff-patch-buffer
175 ;; vc-ediff - compare buffer & version
176 ;; using vc.el package
177 ;; (Emacs 19.22 and up).
178 ;; rcs-ediff - same using rcs.el; rcs.el
179 ;; is not part of the
180 ;; standard Emacs distribution.
183 ;; To use Ediff, put this in your .emacs file:
185 ;; (autoload 'ediff-buffers "ediff" "Visual interface to diff" t)
186 ;; (autoload 'ediff "ediff" "Visual interface to diff" t)
187 ;; (autoload 'ediff-files "ediff" "Visual interface to diff" t)
188 ;; (autoload 'epatch "ediff" "Visual interface to patch" t)
189 ;; (autoload 'ediff-patch-file "ediff" "Visual interface to patch" t)
190 ;; (autoload 'ediff-patch-buffer "ediff" "Visual interface to patch" t)
191 ;; (autoload 'epatch-buffer "ediff" "Visual interface to patch" t)
192 ;; (autoload 'vc-ediff "ediff"
193 ;; "Interface to diff & version control via vc.el" t)
194 ;; (autoload 'rcs-ediff "ediff"
195 ;; "Interface to diff & version control via rcs.el" t)
198 ;; If you want Ediff to be loaded from the very beginning, you should have
202 ;; in your .emacs file. This way it is also easier to figure out changes
203 ;; to the default Ediff setting, if such changes become necessary --- see
210 ;; When you byte-compile Ediff, you will get some warnings about functions
211 ;; being undefined. These can be safely ignored.
216 ;; If you are using advice.el (directly or indirectly, via one of the
217 ;; other packages), Ediff may not compile properly. In this case, you
220 ;; M-x ad-deactivate-all RET
222 ;; M-x byte-compile-file RET ediff.el RET
224 ;; M-x ad-activate-all RET
226 ;; This precaution will not be needed starting with GNU Emacs 19.23 and
227 ;; Lucid Emacs 19.10, due to fixing a bug in advice.el.
234 ;; If you don't like the default setting, you can change it through the
235 ;; various variables and hooks. In particular, the following hooks are
239 ;; ediff-before-setup-windows-hooks
240 ;; ediff-startup-hooks
241 ;; ediff-select-hooks
242 ;; ediff-unselect-hooks
243 ;; ediff-suspend-hooks
245 ;; ediff-prepare-buffer-hooks
247 ;; The hooks in ediff-load-hooks can be used to change defaults after Ediff
249 ;; The hooks in ediff-before-setup-windows-hooks, ediff-suspend-hooks, and
250 ;; ediff-quit-hooks can be used to save and then restore whatever window
251 ;; configuration you want. However, make sure you understand what you are
252 ;; doing. Many variables that drive Ediff are local to the different
253 ;; Ediff Control Panel buffers. Take a look at ediff-default-suspend-hook and
254 ;; ediff-default-quit-hook to see what's involved.
255 ;; The hooks in ediff-prepare-buffer-hooks are executed for each Ediff buffer
256 ;; (A and B) right after these buffers are arranged.
259 ;; Selective browsing: Control over stepping through difference regions
260 ;; -----------------------------------------------
262 ;; Sometimes it is convenient to be able to step through only some
263 ;; difference regions, those that satisfy certain conditions and to ignore
264 ;; all others. The commands `#f' and `#h' let the user specify regular
265 ;; expressions to control the way Ediff skips to the next or previous
266 ;; difference. Typing `#f' lets one specify a pair of regular expressions,
267 ;; regexp-A and regexp-B.
268 ;; Ediff will then start stepping only through those difference regions where
269 ;; the region in buffer A matches regexp-A and the region in buffer B
271 ;; Similarly, using `#h', one specifies expressions that match difference
272 ;; regions to be ignored while stepping through the differences. That is, if
273 ;; the buf A part matches regexp-A and the buf B part matches regexp B then
274 ;; the region will be ignored by ediff-next-difference and
275 ;; ediff-previous-difference commands.
277 ;; Hitting `#f' and `#h' toggles this feature on/off.
279 ;; Note that selective browsing affects only ediff-next-difference and
280 ;; ediff-previous-difference, i.e., the commands invoked by typing n/SPC
281 ;; and p/DEL. You can still jump directly (using `j' or `ga/gb') to any
282 ;; numbered difference. Also, it should be understood, that #f and #h do
283 ;; not change the position of the point in the buffers. The effect of these
284 ;; commands is seen only when the user types `n' or `p', i.e., when
285 ;; Ediff is told to jump to the next or previous difference.
287 ;; Users can supply their own functions that specify how Ediff should do
288 ;; selective browsing. To change the default Ediff function, add a function to
289 ;; ediff-load-hooks which will do the following assignments:
291 ;; (fset ediff-hide-regexp-matches 'your-hide-function)
292 ;; (fset ediff-focus-on-regexp-matches 'your-focus-function)
294 ;; Useful hints: To specify a regexp that matches everything, don't simply
295 ;; type RET in response to a prompt. Typing RET tells Ediff to accept the
296 ;; default value, which may not be what you want. Instead, one should enter
297 ;; something like `^' or `$' --- which would match every line.
299 ;; If the user doesn't remember if selective browsing is in effect and
300 ;; which regexps are being used, the status command, `i', will supply
301 ;; the requisite information.
304 ;; Highlighting difference regions
305 ;; -------------------------------
306 ;; The second group of Ediff variables that could be changed, if you so
309 ;; ediff-before-flag-eol
310 ;; ediff-after-flag-eol
311 ;; ediff-before-flag-mol
312 ;; ediff-after-flag-mol
314 ;; ediff-current-diff-face-A
315 ;; ediff-current-diff-face-B
316 ;; ediff-fine-diff-face-A
317 ;; ediff-fine-diff-face-B
318 ;; ediff-even-diff-face-A
319 ;; ediff-even-diff-face-B
320 ;; ediff-odd-diff-face-A
321 ;; ediff-odd-diff-face-B
323 ;; The first four are ASCII strings that mark the beginning and the end of
324 ;; the differences found in file-A and file-B. Ediff uses different flags
325 ;; to highlight regions that begin/end at the beginning of a line or in a
328 ;; The rest are the faces used to highlight text on X displays. On X
329 ;; displays, Ediff uses ediff-current-diff-face-A and
330 ;; ediff-current-diff-face-B to highlight the current difference regions.
331 ;; The faces ediff-fine-diff-face-A and ediff-fine-diff-face-B
332 ;; are used to show the fine differences between the current differences
333 ;; regions in buffer A and B.
334 ;; Other (non-current) difference regions are displayed in alternating
335 ;; faces: ediff-even/odd-diff-face-A/B. The odd and the even
336 ;; faces are actually identical on monochrome displays, because it is
337 ;; rather poor in what you can do on such a display. So, I chose to use
338 ;; italics to highlight other differences. Any ideas would be welcome.
339 ;; There are two ways to change the default setting for highlighting faces:
340 ;; either change the variables, as in
342 ;; (setq ediff-current-diff-face-A 'bold-italic)
346 ;; (setq ediff-current-diff-face-A
347 ;; (copy-face 'bold-italic 'ediff-current-diff-face-A))
349 ;; or by selectively modifying the defaults:
351 ;; (add-hook 'ediff-load-hooks
352 ;; (function (lambda ()
353 ;; (set-face-foreground ediff-current-diff-face-B "blue")
354 ;; (set-face-background ediff-current-diff-face-B "red")
355 ;; (make-face-italic ediff-current-diff-face-B))))
357 ;; You may also want to take a look at how the above faces are defined in
360 ;; Note: it is not recommended to use `internal-get-face' (or `get-face' in
361 ;; Lucid) when defining faces for Ediff, since this may cause
362 ;; problems when there are several frames with different font sizes.
363 ;; Instead, use copy-face or set/make-face-* as shown above.
365 ;; The last group of variables in this group,
368 ;; ediff-highlight-all-diffs
369 ;; ediff-want-default-menus
371 ;; indicate whether---on a window system---you want differences to be
372 ;; marked using ASCII strings (like on a dumb terminal) or using colors and
373 ;; highlighting. If ediff-want-faces is t, then highlighting with faces is
374 ;; used. Normally, Ediff highlights all differences, but the selected
375 ;; difference is highlighted more visibly. You can cycle through various
376 ;; modes of highlighting by hitting `h'. By default, Ediff starts in the
377 ;; mode where all difference regions are highlighted. If you prefer to
378 ;; start in the mode where unselected differences are not highlighted, you
379 ;; should set ediff-highlight-all-diffs to nil.
380 ;; You will still be able to turn on highlighting of all differences by
382 ;; The variable `ediff-want-default-menus', if true, will cause Ediff to
383 ;; set up a pair of menues in the menu bar, so you can invoke it from there.
384 ;; If you don't like the look of the default menus, set this variable to
385 ;; nil and design your own menus.
387 ;; If you plan on changing these variables, they must be set
388 ;; BEFORE ediff.el is loaded.
390 ;; Note: Ediff lets you switch between the two types of highlighting. That
391 ;; is you can switch, interactively, from highlighting using faces to
392 ;; highlighting using ASCII flags, and back. Of course, toggling has
393 ;; effect only on a window system. On a dumb terminal or in an xterm
394 ;; window, the only available option is highlighting with ASCII flags.
396 ;; Refining difference regions
397 ;; ---------------------------
398 ;; Ediff has variables that control the way fine differences are
399 ;; highlighted. This feature lets the user highlight the exact words that
400 ;; make the difference regions in buffer A and B different. This process
401 ;; ignores spaces, tabs, and newlines.
404 ;; ediff-auto-refine-limit
406 ;; By default, `ediff-auto-refine' is `'on', which means that fine differences
407 ;; within regions will be highlighted automatically. On a slow system, this
408 ;; feature may be undesirable. In any case, the user can always toggle
409 ;; auto-refining on/off/nix by hitting `@'. When auto-refining is off, fine
410 ;; differences will be shown only for regions for which these differences
411 ;; have been computed and saved before. If auto-refining is nixed, fine
412 ;; differences will not be shown at all. Hitting `*' will compute and
413 ;; display fine differences for the current difference region regardless of
414 ;; whether auto-refining is on, off, or nixed.
415 ;; If auto-refining is on, the variable `ediff-auto-refine-limit' limits
416 ;; the size of the regions to be auto-refined. This variable guards against
417 ;; possible slow-down that may be caused by an extraordinary large
418 ;; difference region. However, the user can always force refining by
421 ;; ediff-fine-diff-program
422 ;; ediff-fine-diff-options
423 ;; ediff-forward-word-function
425 ;; These variables let the user control how fine differences are computed.
426 ;; `ediff-fine-diff-program' is diff, by default. However, you can use
427 ;; any function as long as it produces output consistent with diff.
428 ;; `ediff-forward-word-function' is a lisp function that determines how the
429 ;; current difference region is split into words. (Fine diferences are
430 ;; computed by first splitting the current difference region into words and
431 ;; then passing this along to `ediff-fine-diff-program'. For the default
432 ;; wordify function, `ediff-forward-word', a word is a string consisting of
433 ;; letters, `-', or `_', or a string consisting of symbols that are neither
434 ;; space, nor a letter.)
436 ;; Patch and diff programs
437 ;; -----------------------
438 ;; The next group of variables determines the programs to be used for
439 ;; applying patches and for computing the main difference regions (not the
440 ;; fine difference regions):
442 ;; ediff-patch-program
443 ;; ediff-patch-options
444 ;; ediff-diff-program
445 ;; ediff-diff-options
447 ;; These specify the functions that produce differences and do patching.
448 ;; The *-options variables specify which options to pass to these programs.
449 ;; It is unlikely that you would want to change these. One possible
450 ;; exception is when you may want to generate differences with context
451 ;; lines in order to send a patch file through email. Then, you might want
452 ;; to set ediff-diff-options to '-c'. Sometimes, you may also want to tell
453 ;; diff to ignore spaces and such. Use the option '-w' for that. Diff
454 ;; has several other useful options (type 'man diff' to find out).
456 ;; The output from diff is found in *ediff-diff* buffer. However, this
457 ;; makes sense only if you also intend to use Ediff to browse through the
458 ;; diff'ed files before sending the patch. This is because diff.el is much
459 ;; faster in yielding the output of diff (Ediff is a big gun, if used
460 ;; for this simple purpose).
465 ;; When Ediff is running, the mode line of Ediff Control Panel buffer
466 ;; displays the current difference being displayed and the total number of
467 ;; difference regions in the two files.
469 ;; The mode line of the buffers being compared displays the type of the
470 ;; buffer (`A:' or `B:') and (usually) the file name. Ediff is trying to be
471 ;; intelligent in choosing mode line buffer identification. In particular,
472 ;; it works well with uniquify.el and mode-line.el packages (which improve
473 ;; on the default way in which Emacs displays buffer identification).
474 ;; If you don't like the way Ediff identifies its buffers, there is always
475 ;; ediff-prepare-buffer-hooks, which can be used to modify the mode line.
479 ;; The last set of variables that can be modified is
481 ;; ediff-split-window-function
482 ;; ediff-use-last-dir
483 ;; ediff-no-help-in-control-buffer
485 ;; ediff-split-window-function controls the way you want the window be
486 ;; split between file-A and file-B. It defaults to vertical split, but you
487 ;; can set it to 'split-window-horizontally, if you want. Ediff lets you
488 ;; toggle the way windows are split, so you can try different settings
489 ;; interactively. Note: if file-A and file-B are in different frames,
490 ;; windows are not split, regardless of the value
491 ;; ediff-split-window-function. Instead, other windows on these frames are
492 ;; deleted and Ediff starts displaying file-A and file-B using these two
493 ;; frames, one file per frame. You can then switch to one-frame mode
494 ;; simply by hiding the file-A/B buffer that is displayed on a frame other
495 ;; than the control-window frame.
497 ;; Note that if Ediff sees that the two buffers it compares are residing in
498 ;; separate frames, it assumes that the user wants them to be so displayed
499 ;; and stops splitting windows. Instead, it will arrange each buffer to
500 ;; occupy its own frame (possibly shared with Ediff's help window).
502 ;; The variable ediff-use-last-dir controls the way Ediff presents the
503 ;; default directory when it prompts the user for files to compare. If nil,
504 ;; Ediff will use the default directory of the current buffer when it
505 ;; prompts the user for file names. Otherwise, it will use the
506 ;; directories it had previously used for file-A and file-B.
508 ;; The ediff-no-help-in-control-buffer, if set to t, makes C-h behave like
509 ;; the DEL key, i.e., it will move you back to the previous difference
510 ;; rather than invoking help. This is useful when, in an xterm window or on
511 ;; a dumb terminal, the Backspace key is bound to C-h and is positioned
512 ;; more conveniently than the DEL key.
518 ;; All Ediff commands are displayed in a help window, unless you hit '?' to
519 ;; shrink it to just one line. You can redisplay the help window by hitting
522 ;; Many Ediff commands take numeric prefix arguments. For instance, if you
523 ;; hit a number, N, and then 'j' (ediff-jump-to-difference), Ediff will
524 ;; take you to Nth difference. Hitting a number, N, and then 'ab'
525 ;; (ediff-diff-to-diff) will copy Nth difference from buffer A to buffer B.
526 ;; Hitting 'ba' does copying in the other direction.
527 ;; Likewise, a number, N, followed by 'ra' will restore the Nth difference
528 ;; region in buffer A (if it was previously saved as a result of copying
531 ;; Without the prefix argument, all commands operate on the current
532 ;; difference region.
534 ;; The total number of differences and the current difference number are
535 ;; always displayed in the mode line of the control window.
540 ;; Ediff can display files in one frame, stacked side-by-side or one on top
541 ;; of another; or it can display the files in different frames. When you
542 ;; start Ediff, it assumes a 1-frame mode. You can toggle the side-by-side
543 ;; and one-on-top-of-another displays by simply hitting 's'.
545 ;; Ediff switches to the multi-frame mode when:
547 ;; 1. file-A and file-B are in different frames (you have to put them into
548 ;; different frames manually); or
549 ;; 2. Ediff Control Panel is visible in one frame and one other file (A
550 ;; or B) is visible in another frame. If, say, fileA is visible in a
551 ;; different frame than Ediff Control Panel, fileB doesn't have to be
552 ;; visible. If it is, Ediff will continue displaying fileB in the frame
553 ;; where it was visible before. If it isn't then Ediff will arrange for
554 ;; fileB to share a frame with Ediff Control Panel.
556 ;; If all three buffers are in separate frames, Ediff will switch to a
557 ;; 3-frame mode. If Ediff buffers are currently visible only in two
558 ;; frames, Ediff will work in a 2-frame mode. In this mode, one of the
559 ;; frames will be shared by Ediff Control Panel and file-A or file-B
560 ;; (whichever is appropriate).
566 ;; 1. The undo command doesn't restore deleted regions well. That is, if
567 ;; you delete all characters in a difference region and then invoke
568 ;; `undo', the reinserted text will most likely be reinserted outside of
569 ;; what Ediff thinks is the current difference region. (This problem
570 ;; doesn't seem to exist with Lucid Emacs.)
572 ;; If at any point you feel that difference regions are no longer correct,
573 ;; you can hit '!' to recompute the differences.
575 ;; 2. Emacs 19.xx, where xx < 23, has several bugs related to overlays and
576 ;; faces. Somethimes, these may cause highlighting of the refinements or
577 ;; of the unselected differences to disappear. Hitting `!' will bring them
578 ;; back. In version 19.23 and later, these problems no longer occur.
580 ;; 3. On a monochrome display, the repertoire of faces with which to
581 ;; highlight fine differences is limited. By default, Ediff is using
582 ;; underlining. However, if the region is already underlied by some other
583 ;; overlays, there is no simple way to temporarily remove that residual
584 ;; underlining. This problem occurs when a buffer is highlighted with
585 ;; hilit19.el or font-lock.el packages. If this residual highlighting gets
586 ;; in the way, you can do the following. Both font-lock.el and hilit19.el
587 ;; provide commands for unhighlighting buffers. You can either place these
588 ;; commands in `ediff-prepare-buffer-hooks' (which will unhighlight every
589 ;; buffer used by Ediff) or you can execute them interactively, at any time
590 ;; and on any buffer.
592 ;; 4. In Lucid Emacs (statically linked with Motif libraries), emerge.el
593 ;; and hence ediff.el won't start, unless you set (setq scrollbar-width 0).
594 ;; This is a Motif-related bug, I was told.
602 ;; Added ediff-read-file-name, which is a stub that takes care of Lemacs
603 ;; versions of Emerge. (Thanks to Alastair Burt <burt@dfki.uni-kl.de>.)
605 ;; Fixed a bug in ediff-setup-windows that caused control window to
606 ;; appear in a wrong place when split-window-keep-point is nil
607 ;; (Thanks to Kevin Broadey <KevinB@bartley.demon.co.uk>.)
609 ;; Added mechanism for using faces instead of before/after flags. This
610 ;; looks much better on an X display, especially on a color one.
611 ;; (Thanks to Boris Goldowsky <boris@cs.rochester.edu> for the code
612 ;; that led to ediff-highlight-diff.
613 ;; Also, thanks to Kevin Esler <esler@ch.hp.com> for suggestions
614 ;; regarding highlighting differences on X displays.)
616 ;; Added functions to apply patches.
617 ;; (Thanks to Kevin Broadey <KevinB@bartley.demon.co.uk> for this
622 ;; Added mechanism for toggling vertical/horizontal window split.
623 ;; (Inspired by a suggestion from Allan Gottlieb
624 ;; <gottlieb@allan.ultra.nyu.edu> -- thanks.)
626 ;; Added mechanism for toggling between highlighting using faces and
627 ;; highlighting using ASCII flags.
629 ;; Fixed a problem with undo. Now, Ediff has smartened up and doesn't
630 ;; keep undo info on ASCII flags inserted in buffer-A and buffer-B.
631 ;; So, if you edit the files while browsing through them, undo behaves
632 ;; as you would expect, i.e., faces/flags don't get in the way.
636 ;; Added horizontal scrolling. Added ediff-position-region to ensure
637 ;; that difference regions in buffer-A and buffer-B are aligned with
638 ;; each other. Disabled ediff-toggle-split when buffers are displayed
639 ;; in different frames.
643 ;; Added toggle-window help (Suggested by Boris Goldowsky
644 ;; <boris@cs.rochester.edu>.)
645 ;; Added functions to copy differences from one buffer to another and to
646 ;; recover old differences.
647 ;; Added prefix arguments to ediff-next-difference and
648 ;; ediff-previous-difference.
652 ;; Replaced text properties with overlays. Fixed ediff-setup-windows.
653 ;; Added ediff-save-buffer to local-write-file-hooks to prevent user
654 ;; from saving corrupted states. (Thanks to <boris@cs.rochester.edu>
655 ;; for suggestion.) Instead, Ediff now has a pair of functions for
656 ;; safe saving of buffers.
657 ;; Changed ediff-read-file-name to be more intuitive on ediff-files.
658 ;; Added ediff-prepare-buffer-hooks. (Thanks to Kevin Esler
659 ;; <esler@ch.hp.com> for the idea.)
663 ;; Cleanups in ediff-patch-file. Protected ediff-copy-diff against
664 ;; a bug that Emacs has in kill-region.
668 ;; Added support for Lemacs. (Thanks to Alastair Burt
669 ;; <burt@dfki.uni-kl.de> for coercing Ediff into working under Lemacs.)
670 ;; Added ediff-kill-buffer-carefully and other suggestions by Boris
671 ;; Goldowsky <boris@cs.rochester.edu>.
672 ;; Refined the protection against interference with highlighting caused
673 ;; by Hilit19. Added the variable ediff-third-party-highlighting.
674 ;; Added mechanisn for unhighlighting regions highlighted with Hilit19
675 ;; before hightlighting them with Ediff's overlays. (And for
676 ;; rehighlighting them with Hilit19, when the current difference moves on.)
680 ;; Added ediff-place-flags-in-buffer and ediff-remote-exit, which are
681 ;; modifications of Emerge's similar functions. The difference is that
682 ;; in Ediff they make ediff-before-flag and ediff-after-flag into
683 ;; read-only regions, so the user can't change them by mistake.
685 ;; Adopted a suggestion by Boris Goldowsky <boris@cs.rochester.edu>
686 ;; that led to a more elegant treatment of faces.
688 ;; Added protection against interference with Font-Lock highlighting
689 ;; similar to that of Hilit19's protection.
693 ;; Deleted spurious (auto-save-mode 1) in ediff-control-buffer, which
694 ;; was causing this buffer to be auto-saved for no good reason.
695 ;; Added read-only protection to ediff-before/after-flags in Lemacs.
696 ;; (Thanks to Alastair Burt <burt@dfki.uni-kl.de> for help in testing.)
700 ;; Further fixes in the Lemacs part. Changed highlighted region in
701 ;; ediff-highlight-diff so that an extra character will be highlighted
702 ;; only if a difference is empty (thereby allowing the user to see where an
703 ;; insertion or a deletion has taken place).
705 ;; Simplified interaction with other highlighting packages by giving
706 ;; Ediff overlays the highest priority. (Taking a cue from
707 ;; ediff-highlight-diff-lemacs written by Alastair Burt
708 ;; <burt@dfki.uni-kl.de>.) Zapped ediff-third-party-highlighting
709 ;; variable and hooks that were previously used to
710 ;; unhighlight/rehighlight buffers when hilit19/font-lock are on.
714 ;; Added a bit more sophistication to ediff-read-file-name. Now,
715 ;; ediff-files remembers both, the file-A and the file-B directories.
716 ;; They are offered as defaults when ediff-use-last-dir is set to t.
720 ;; Added ediff-before-change-guard to remove ASCII highlighting when
721 ;; the user attempts to change buffer-A/B. This is needed because
722 ;; otherwise the undo info may become screwed up in those buffers.
723 ;; Hitting 'h' (ediff-toggle-hilit) on a dumb terminal will toggle
724 ;; between ASCII highlighting and no highlighting.
728 ;; Fixed problems with multiple Ediff sessions running simultaneously.
732 ;; Added vc-ediff, the Ediff interface to vc.el. (Thanks to Eric
733 ;; Freudenthal <freudent@jan.ultra.nyu.edu> for contributing this
738 ;; Added rcs-ediff, an Ediff interface to RCS via rcs.el. (Thanks to
739 ;; Alastair Burt <burt@dfki.uni-kl.de>.)
740 ;; Some minor improvements.
742 ;; Tue March 15, 1994
744 ;; Fixed a buglet in defining ediff-current-diff-face-A/B.
745 ;; (Thanks to Job Ganzevoort <Job.Ganzevoort@cwi.nl>.)
747 ;; Tue March 22, 1994
749 ;; Fixed a bug with ediffing narrowed buffers, reported by Kevin
750 ;; Broadey <KevinB@bartley.demon.co.uk>.
751 ;; Made Ediff to work with files that have incomplete last line.
752 ;; Made Ediff execute diff and patch using Bourne Shell, which
753 ;; should eliminate problems with $prompt that some people had.
755 ;; Thu March 24, 1994
757 ;; Achieved quadratic speedup in the size of the file by replacing the
758 ;; slow goto-line by forward-line. Ediff is now *much* faster than
759 ;; Emerge on large files. Converted demarkation of difference regions
760 ;; from markers to overlays. This will later allow us to highlight all
761 ;; diffs, not just the current one.
763 ;; Wed March 30, 1994
765 ;; Under X, Ediff now highlights all differences in dim colors and the
766 ;; current difference in bright colors. Improved Lucid Emacs support.
768 ;; Thu March 31, 1994
770 ;; Changed toggle hilit to cycle through 3 states: highlighting all
771 ;; diffs, highlighting only the current diff, and highlighting using
773 ;; Added support for difference regions that are not full lines.
777 ;; Fixed bugs related to writing buffers A and B.
778 ;; Added commands 'ga', 'gb' to jump directly to the closest diff in
779 ;; buffer A and B, respectively.
781 ;; Fri April 11, 1994
783 ;; Added `ediff-recompute-diffs', a function that lets the user recompute
784 ;; difference regions after extensive editing done to buffers A and B
787 ;; Wed April 13, 1994
789 ;; Added the new feature: refining the current difference region.
790 ;; This would highlight the precise differences between the regions in
791 ;; buffer A and B. (A way to implement this was suggested by Boris
792 ;; Goldowsky <boris@cs.rochester.edu>.)
794 ;; Fixed Ediff to be immune to several different versions of rcs.el
795 ;; that are currently in distribution.
797 ;; Thu April 14, 1994
799 ;; Ediff now respects X resources for the faces it uses. It no longer
800 ;; barks when the colormap has no colors it is using; or when face
801 ;; fonts can't be italicized, etc.
803 ;; Fri April 15, 1994
805 ;; Changed `ediff-setup-windows' to minimize the need to delete and
806 ;; create windows. Now jumps faster from diff to diff.
808 ;; Sat April 16, 1994
810 ;; Added Ediff to the File menu on the menu bar (FSF's version).
812 ;; Mon April 18, 1994
814 ;; Fixed to work with OS/2's PM-Emacs.
816 ;; Thu April 21, 1994
818 ;; Lemacs' menus added (thanks to Alastair Burt for the help).
820 ;; Wed April 28, 1994
822 ;; Fixed ediff-leave-window-config (thanks to Norbert Kiesel
823 ;; <norbert@i3.informatik.rwth-aachen.de>), ediff-shell and
824 ;; ediff-protect-metachars (thanks to Richard Stanton
825 ;; <stanton@haas.berkeley.edu>). Made access to difference
826 ;; overlays structure-independent, making it less bug-prone.
827 ;; Patched ediff-read-file-name to work more intuitively with directory
828 ;; names (thanks to Kevin Broadey <KevinB@bartley.demon.co.uk>).
832 ;; Added `ediff-frame-has-menubar' to guard against the possibility that
833 ;; the current frame has no menu bar.
837 ;; Fixed buglet in vc-ediff (thanks to Ray Nickson <nickson@cs.uq.oz.au>).
841 ;; Modified ediff-read-file-name to not put long file names in the
842 ;; default prompt area, as suggested by KevinB@bartley.demon.co.uk.
843 ;; Applied patch supplied by burt@dfki.uni-kl.de, fixing a problem with
844 ;; ediff-diff-to-diff in Lemacs.
848 ;; Added ediff-forward-word-function (as suggested by Job Ganzevoort
849 ;; <Job.Ganzevoort@cwi.nl>). Modified ediff-default-quit-hook so it
850 ;; will clean things up in a more satisfactory way.
854 ;; Added `ediff-toggle-regexp-match', which allows the user to step
855 ;; through only those difference regions that match some regexp; or,
856 ;; vice versa, to skip over regions that match a regexp. (This feature
857 ;; was suggested by Andy Scott <ascott@pcocd2.intel.com>.)
858 ;; Added ediff-eval-in-buffer, which is a modified emerge-eval-in-buffer.
859 ;; The function ediff-status-info, bound to `i', now replaces and extends
860 ;; ediff-file-names and ediff-line-numbers, which were bound to `f'
861 ;; and `i', respectively.
865 ;; Made `ediff-frame-has-menubar' into a function; copied
866 ;; `emerge-defvar-local' and turned it into `ediff-defvar-local'
867 ;; This is supposed to make the same ediff.elc file work for both Emacs
868 ;; and Lucid Emacs, at least, if compiled under Lucid Emacs. (Thanks
869 ;; to Eric Eide <eeide@asylum.cs.utah.edu>.)
873 ;; Improved `ediff-read-file-name' and `ediff-buffers' so they are now
874 ;; providing more intuitive defaults. Modified `ediff-read-file-name'
875 ;; so it won't cause problems under OS/2.
879 ;; Modified ediff-find-file, ediff-files-internal, and made
880 ;; emerge-verify-file-buffer into ediff-verify-file-buffer so that
881 ;; Ediff will work correctly with remote and compressed
882 ;; files. (Suggested by Sandy Rutherford <sandy@ibm550.sissa.it>.)
886 ;; Fixed ediff-patch-files to work with remote and compressed files.
890 ;; Changed menu bar items per RMS's suggestion. Changed odd/even faces
891 ;; in Lemacs to italic. Changed ediff-*-face-* variables so that they
892 ;; will contain names of faces instead of the face internal
893 ;; representation. (Copy-face works better with face names than with
894 ;; face internal representation. With face internal representation, if
895 ;; a face vector mentions a font explicitly, copy-face may attempt to
896 ;; copy this font, which would cause an error if the font has a wrong
897 ;; size for one of the existing frames.) Improved the way
898 ;; mode-line-buffer-identification is set in ediff-setup so that Ediff
899 ;; will accommodate the way buffers are identified in mode-line.el and
903 ;;; Acknowledgements:
905 ;; Special thanks to Alastair Burt <burt@dfki.uni-kl.de>, Kevin Esler
906 ;; <esler@ch.hp.com>, Kevin Broadey <KevinB@bartley.demon.co.uk>,
907 ;; Harald Boegeholz <hwb@machnix.mathematik.uni-stuttgart.de>,
908 ;; Robert Estes <estes@ece.ucdavis.edu>, Eric Eide <eeide@asylum.cs.utah.edu>,
909 ;; Eric Freudenthal <freudent@jan.ultra.nyu.edu>, Job Ganzevoort
910 ;; <Job.Ganzevoort@cwi.nl>, Boris Goldowsky <boris@cs.rochester.edu>,
911 ;; Allan Gottlieb <gottlieb@allan.ultra.nyu.edu>, Xiaoli Huang
912 ;; <hxl@epic.com>, irvine@lks.csi.com, jaffe@chipmunk.cita.utoronto.ca,
913 ;; David Karr, <dkarr@nmo.gtegsc.com>, Norbert Kiesel
914 ;; <norbert@i3.informatik.rwth-aachen.de>, Heinz Knutzen
915 ;; <hk@informatik.uni-kiel.d400.de>, Martin Maechler
916 ;; <maechler@stat.math.ethz.ch>, Richard Mlynarik <mly@adoc.xerox.com>,
917 ;; Ray Nickson <nickson@cs.uq.oz.au>, Sandy Rutherford
918 ;; <sandy@ibm550.sissa.it>, Andy Scott <ascott@pcocd2.intel.com>,
919 ;; Richard Stallman <rms@gnu.ai.mit.edu>, Richard Stanton
920 ;; <stanton@haas.berkeley.edu>, Peter Stout <Peter_Stout@cs.cmu.edu>
921 ;; for contributing ideas, patches, and bug reports.
923 ;; Thanks also to many others who felt obliged to drop a thanks note.
929 (require 'emerge) ;; Ediff uses some functions defined in emerge.el
933 (defmacro ediff-if-lucid ()
934 (` (string-match "Lucid" emacs-version)))
936 (defmacro ediff-odd-p (arg)
937 (` (eq (logand (, arg) 1) 1)))
939 (defmacro ediff-buffer-live-p (buf)
940 (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf))))))
942 (defmacro ediff-get-buffer (arg)
943 (` (cond ((eq (, arg) 'A) ediff-A-buffer)
944 ((eq (, arg) 'B) ediff-B-buffer)
948 (defmacro ediff-char-to-buftype (arg)
949 (` (cond ((eq (, arg) ?a) 'A)
954 (defmacro ediff-get-difference (n)
955 (` (aref ediff-difference-vector (, n))))
957 (defmacro ediff-get-diff-overlay-from-vector (vec buf-type)
959 (cond ((eq (, buf-type) 'A) 0)
960 ((eq (, buf-type) 'B) 1)
964 (defmacro ediff-get-diff-overlay (n buf-type)
965 (` (ediff-get-diff-overlay-from-vector
966 (ediff-get-difference (, n))
969 (defmacro ediff-get-fine-diff-vector-from-vec (current-diff-vec)
970 (` (aref (, current-diff-vec) 2)))
972 (defmacro ediff-set-fine-diff-vector (n fine-vec)
973 (` (aset (ediff-get-difference (, n)) 2 (, fine-vec))))
975 (defmacro ediff-get-fine-diff-vector (n)
976 (` (ediff-get-fine-diff-vector-from-vec (ediff-get-difference (, n)))))
978 (defmacro ediff-defvar-local (var value doc)
979 "Defines SYMBOL as an advertised local variable.
980 Performs a defvar, then executes `make-variable-buffer-local' on
981 the variable. Also sets the `preserved' (Emacs) or `permanent-local' (Lucid)
982 property, so that `kill-all-local-variables' (called by major-mode setting
983 commands) won't destroy Ediff control variables.
985 This is a merge of `emerge-defvar-local' for Emacs and Lucid Emacs. It is
986 needed to make the same ediff.elc work under both Emacsen."
988 (defvar (, var) (, value) (, doc))
989 (make-variable-buffer-local '(, var))
991 (if (ediff-if-lucid) 'permanent-local 'preserved)
994 (defmacro ediff-eval-in-buffer (buffer &rest forms)
995 "Macro to switch to BUFFER, evaluate FORMS, returns to original buffer.
996 Differs from `save-excursion' in that it doesn't save the point and mark.
997 This is essentially `emerge-eval-in-buffer' with the test for live buffers."
998 (` (let ((StartBuffer (current-buffer)))
999 (if (ediff-buffer-live-p (, buffer))
1002 (set-buffer (, buffer))
1004 (set-buffer StartBuffer))
1006 (message "You seem to have killed an essential Ediff buffer---quit!"))
1012 (defun ediff-mode ()
1013 "Ediff mode is used by the Ediff file-difference package.
1014 It is entered only through one of the following commands:
1020 `ediff-patch-buffer'
1028 (kill-all-local-variables)
1029 (setq major-mode 'ediff-mode)
1030 (setq mode-name "Ediff"))
1035 (defvar ediff-before-setup-windows-hooks nil
1036 "*Hooks to run before Ediff sets its own window config.
1037 This can be used to save the previous window config, which can be restored
1038 on ediff-quit or ediff-suspend.")
1039 (defvar ediff-startup-hooks nil
1040 "*Hooks to run in the control buffer after Ediff has been set up.")
1041 (defvar ediff-select-hooks nil
1042 "*Hooks to run after a difference has been selected.")
1043 (defvar ediff-unselect-hooks nil
1044 "*Hooks to run after a difference has been unselected.")
1045 (defvar ediff-prepare-buffer-hooks nil
1046 "*Hooks called after buffers A and B are set up.")
1047 (defvar ediff-load-hooks nil
1048 "*Hook run after Ediff is loaded. Can be used to change defaults.")
1050 (defvar ediff-suspend-hooks (list 'ediff-default-suspend-hook)
1051 "*Hooks to run in the Ediff control buffer when Ediff is suspended.")
1052 (defvar ediff-quit-hooks (list 'ediff-default-quit-hook)
1053 "*Hooks to run in the Ediff control buffer after finishing Ediff.")
1055 (make-variable-buffer-local 'local-write-file-hooks)
1056 (make-variable-buffer-local 'before-change-function)
1060 (defconst ediff-help-message-long
1061 "p,DEL - prev diff v/V - scroll up/dn ab - diff A to B * - refine diff
1062 n,SPC - next diff </> - scroll lt/rt ba - diff B to A ! - recomp diffs
1063 j - jump to diff s - toggle split ra - restore A i - status info
1064 ga/gb - goto pt in A/B h - toggle hilit rb - restore B z - suspend Ediff
1065 c - recenter @ - toggle refine q - quit Ediff
1066 #f/#h - toggle focus/hide diff regions
1067 wa/wb - save buf A/B A/B - toggle read-only in buffers A/B ? - toggle help")
1069 (defconst ediff-help-message-short
1070 " ? - toggle help window")
1072 (defvar ediff-help-message ediff-help-message-long
1073 "*The actual help message.")
1076 (defvar ediff-diff-program "diff"
1077 "*Name of the program that compares two files.")
1078 (defvar ediff-diff-options ""
1079 "*Options to pass to `ediff-diff-program'.
1080 If diff\(1\) is used as `ediff-diff-program', then the most useful options are
1081 `-w', to ignore space, and `-i', to ignore case of letters.")
1084 (defvar ediff-forward-word-function 'ediff-forward-word
1085 "*Function to call to move to the next word.
1086 Used for splitting difference regions into individual words.")
1088 (defvar ediff-fine-diff-program "diff"
1089 "*Name of the program that compares the current diff regions for fine differences.
1091 This program should produce output in the format of diff. One could
1092 possibly use `spiff' here if appropriate options are set.")
1094 (defvar ediff-fine-diff-options ""
1095 "*Options to pass to `ediff-fine-diff-program'.
1096 If diff\(1\) is used as `ediff-diff-program', then the most useful options are
1097 `-w', to ignore space, and `-i', to ignore case of letters.")
1099 (defvar ediff-whitespace " \n\t\C-j"
1100 "*White space. Used to split strings into words.")
1102 (defvar ediff-word-1 "a-zA-Z---_`'.?!:"
1103 "*Characters constituting type 1 words.
1105 Ediff is using a very simple schema for splitting text into words, which is
1106 used to determine fine differences between regions. There are two types of
1107 words. One consists entirely out of characters in `ediff-word-1' and
1108 another out of characters matching `ediff-word-1'.")
1110 (defvar ediff-word-2 "^a-zA-Z---_`'.?!: \t\n\C-j"
1111 "*Characters matching this regexp constitute words of type 2.
1112 See `ediff-word-1' for more details.")
1114 ;; Selective browsing
1116 (defconst ediff-skip-diff-region-function 'ediff-show-all-diffs
1117 "Function that determines the next/previous diff region to show.")
1119 (defconst ediff-regexp-focus-A ""
1120 "Regexp that determines buf A regions to focus on when skipping to diff.")
1121 (defconst ediff-regexp-focus-B ""
1122 "Regexp that determines buf B regions to focus on when skipping to diff.")
1124 (defconst ediff-regexp-hide-A ""
1125 "Regexp that determines buf A regions to ignore when skipping to diff.")
1126 (defconst ediff-regexp-hide-B ""
1127 "Regexp that determines buf B regions to ignore when skipping to diff.")
1130 ;; Support for patches
1132 (defvar ediff-patch-program "patch"
1133 "*Name of the program that applies patches.")
1134 (defvar ediff-patch-options ""
1135 "*Options to pass to ediff-patch-program.")
1137 (defvar ediff-shell (cond ((eq system-type 'emx) "cmd") ;; OS/2
1139 "*The shell used to run diff and patch. If user's .profile or
1140 .cshrc files are set up correctly, any shell will do. However, some people
1141 set $prompt or other things incorrectly, which leads to undesirable output
1142 messages. These may cause Ediff to fail. In such a case, set ediff-shell
1143 to a shell that you are not using or, better, fix your shell's startup file.")
1145 (defvar ediff-diff-ok-lines-regexp
1146 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\|Warning:\\)"
1147 "*Regexp that matches normal output lines from `ediff-diff-program'.
1148 This is mostly lifted from Emerge, except that Ediff also considers the
1149 'Missing newline' message to be 'normal output.'
1150 Lines that do not match are assumed to be error messages.")
1152 (defvar ediff-fine-diff-ok-lines-regexp
1153 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\|Warning:\\)"
1154 "*Regexp that matches normal output lines from `ediff-fine-diff-program'.
1155 This is mostly lifted from Emerge, except that Ediff also considers the
1156 'Missing newline' message to be 'normal output.'
1157 Lines that do not match are assumed to be error messages.")
1159 (defvar ediff-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
1160 (concat "^" x "\\([acd]\\)" x "$"))
1161 "*Pattern to match lines produced by diff that describe differences.")
1163 (defvar ediff-patch-buf nil
1164 "The buffer of the patch file.")
1165 (defvar ediff-patch-diagnostics nil
1166 "The buffer where patch would display its diagnostics.")
1169 ;; Copying diffs betw buffers.
1171 (ediff-defvar-local ediff-killed-diffs-alist nil
1172 "A list of killed diffs.
1173 A diff is saved here if it is replaced by a diff
1174 from another buffer. This alist has the form:
1175 \((num (A . diff) (B . diff)) ...),
1176 where A or B parts may be missing.")
1180 (defvar ediff-before-flag-bol
1181 ;"vvvvvvvvvvvvvvvv---- ediff ----vvvvvvvvvvvvvvv\n"
1183 "*Flag placed above the highlighted block of differences.
1184 Must end with newline. Must be set before Ediff is loaded.")
1185 (defvar ediff-after-flag-bol
1186 ;"^^^^^^^^^^^^^^^^---- ediff ----^^^^^^^^^^^^^^^\n"
1188 "*Flag placed below the highlighted block of differences.
1189 Must end with newline. Must be set before Ediff is loaded.")
1191 (defvar ediff-before-flag-mol ">>--->>>"
1192 "*Like ediff-before-flag, used when a difference starts in mid-line.")
1193 (defvar ediff-after-flag-mol "<<<---<<"
1194 "*Like ediff-after-flag, used when a difference starts in mid-line.")
1196 (ediff-defvar-local ediff-before-flag-A nil
1197 "This is the actual ASCII before-flag in effect in buffer A.
1198 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
1199 on whether the selected difference region starts in the middle of a line
1200 or at the beginning of a line.")
1201 (ediff-defvar-local ediff-after-flag-A nil
1202 "This is the actual ASCII after-flag in effect in buffer A.
1203 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
1204 on whether the selected difference region starts in the middle of a line
1205 or at the beginning of a line.")
1206 (ediff-defvar-local ediff-before-flag-B nil
1207 "This is the actual ASCII before-flag in effect in buffer B.
1208 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
1209 on whether the selected difference region starts in the middle of a line
1210 or at the beginning of a line.")
1211 (ediff-defvar-local ediff-after-flag-B nil
1212 "This is the actual ASCII after-flag in effect in buffer B.
1213 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
1214 on whether the selected difference region starts in the middle of a line
1215 or at the beginning of a line.")
1218 (ediff-defvar-local ediff-want-faces t
1219 "If t, differences are highlighted using faces on a window system.
1220 If nil, they are highlighted using ASCII flags, ediff-before-flag
1221 and ediff-after-flag. On a non-window system, differences are always
1222 highlighted using ASCII flags.
1224 This variable can be set either in .emacs or toggled interactively, using
1225 ediff-toggle-hilit.")
1227 (ediff-defvar-local ediff-want-default-menus t
1228 "If t, Ediff will set up menus in the menu bar.
1229 This variable must be set before Ediff is loaded. If you don't like the
1230 look of the default menus, set this variable to nil and make your own
1233 (ediff-defvar-local ediff-auto-refine 'on
1234 "If `'on', Ediff auto-highlights fine diffs for the current diff region.
1235 If `off', auto-highlighting is not used. If `'nix', no fine diffs are shown
1236 at all, unless the user force-refines the region by hitting `*'.
1238 This variable can be set either in .emacs or toggled interactively, using
1239 ediff-toggle-hilit.")
1241 (ediff-defvar-local ediff-auto-refine-limit 700
1242 "Auto-refine only those regions that are smaller than this number of bytes.")
1244 (ediff-defvar-local ediff-highlight-all-diffs t
1245 "If nil, only the selected differences are highlighted.
1246 This variable can be set either in .emacs or toggled interactively, using
1247 ediff-toggle-hilit.")
1249 (ediff-defvar-local ediff-highlighting-style nil
1250 "A var local to each control panel buffer.
1251 Indicates highlighting style in effect for this buffer: `face', `ascii',
1252 nil -- temporarily unhighlighted, `off' -- turned off \(on a dumb
1257 ;; Variables that control each Ediff session. They are local to the
1261 (ediff-defvar-local ediff-A-buffer nil
1262 "The buffer in which the A variant is stored.")
1263 (ediff-defvar-local ediff-B-buffer nil
1264 "The buffer in which the B variant is stored.")
1265 (ediff-defvar-local ediff-control-buffer nil
1266 "The control buffer of ediff. ")
1268 ;(ediff-defvar-local ediff-control-buffer-suffix nil
1269 ; "The suffix of the control buffer name. ")
1271 (ediff-defvar-local ediff-control-window nil
1272 "The control window.")
1273 (ediff-defvar-local ediff-window-config-saved ""
1274 "Ediff's window configuration.
1275 Used to minimize the need to rearrange windows.")
1278 (ediff-defvar-local ediff-A-buffer-values nil
1279 "Keeps working values of ediff-saved-variables for ediff-A-buffer.")
1280 (ediff-defvar-local ediff-B-buffer-values nil
1281 "Keeps working values of ediff-saved-variables for ediff-B-buffer.")
1283 (ediff-defvar-local ediff-A-buffer-values-setup nil
1284 "Remembers ediff-saved-variables for ediff-A-buffer as they were at setup.")
1285 (ediff-defvar-local ediff-B-buffer-values-setup nil
1286 "Remembers ediff-saved-variables for ediff-B-buffer as they were at setup.")
1288 (ediff-defvar-local ediff-difference-vector nil
1289 "Vector of differences between the variants.
1290 Each difference is represented by a vector of two overlays. The first
1291 overlays the difference section in the A buffer and the second overlays the
1292 diff in the B buffer. If a difference section is empty, the corresponding
1293 overlay's endpoints coincide. ")
1295 (ediff-defvar-local ediff-current-difference -1
1296 "The difference that is currently selected.")
1297 (ediff-defvar-local ediff-number-of-differences nil
1298 "Number of differences found.")
1300 (ediff-defvar-local ediff-diff-buffer nil
1301 "Buffer containing the output of diff, which is used by Ediff to step
1303 (ediff-defvar-local ediff-tmp-buffer nil
1304 "Temporary buffer used for computing fine differences.")
1305 (ediff-defvar-local ediff-error-buffer nil
1306 "Buffer containing the output of diff when diff returns errors.")
1308 (ediff-defvar-local ediff-this-buffer-control-sessions nil
1309 "List of ediff control panels associated with each buffer A/B.")
1311 (defvar ediff-disturbed-overlays nil
1312 "List of difference overlays disturbed by working with the current diff.")
1314 (defvar ediff-shaded-overlay-priority 100
1315 "Priority of non-selected overlays.")
1318 (if (ediff-if-lucid)
1320 (fset 'ediff-overlayp (symbol-function 'extentp))
1321 (fset 'ediff-make-overlay (symbol-function 'make-extent))
1322 (fset 'ediff-delete-overlay (symbol-function 'delete-extent))
1323 (fset 'ediff-overlay-put (symbol-function 'set-extent-property))
1324 (fset 'ediff-move-overlay (symbol-function 'set-extent-endpoints))
1325 (fset 'ediff-overlay-start (symbol-function 'extent-start-position))
1326 (fset 'ediff-overlay-end (symbol-function 'extent-end-position))
1327 (fset 'ediff-overlay-get (symbol-function 'extent-property)))
1328 (fset 'ediff-overlayp (symbol-function 'overlayp))
1329 (fset 'ediff-make-overlay (symbol-function 'make-overlay))
1330 (fset 'ediff-delete-overlay (symbol-function 'delete-overlay))
1331 (fset 'ediff-overlay-put (symbol-function 'overlay-put))
1332 (fset 'ediff-move-overlay (symbol-function 'move-overlay))
1333 (fset 'ediff-overlay-start (symbol-function 'overlay-start))
1334 (fset 'ediff-overlay-end (symbol-function 'overlay-end))
1335 (fset 'ediff-overlay-get (symbol-function 'overlay-get)))
1338 (if (ediff-if-lucid)
1340 (fset 'ediff-select-frame (symbol-function 'select-screen))
1341 (fset 'ediff-window-frame (symbol-function 'window-screen))
1342 (fset 'ediff-display-color-p (symbol-function 'x-color-display-p))
1343 (fset 'ediff-valid-color-p (symbol-function 'x-valid-color-name-p))
1344 (fset 'ediff-get-face (symbol-function 'get-face)))
1345 (fset 'ediff-window-frame (symbol-function 'window-frame))
1346 (fset 'ediff-select-frame (symbol-function 'select-frame))
1347 (fset 'ediff-display-color-p (symbol-function 'x-display-color-p))
1349 ;; This is a temporary fix for OS/2 users
1350 ;; pm-win.el in PM-Emacs should be fixed.
1351 (if (eq window-system 'pm)
1352 (fset 'ediff-valid-color-p
1353 (function (lambda (color) (assoc color pm-color-alist))))
1354 (fset 'ediff-valid-color-p (symbol-function 'x-color-defined-p))
1357 (fset 'ediff-get-face (symbol-function 'internal-get-face)))
1358 ;; not a window system
1359 (fset 'ediff-window-frame (function (lambda (wind) (if wind 1 nil)) ))
1360 (fset 'ediff-select-frame (symbol-function 'identity))
1361 (fset 'ediff-make-current-diff-overlay (function (lambda (type) nil)))
1362 (fset 'ediff-unhighlight-diffs-totally (function (lambda () nil))))
1365 (if (not window-system)
1367 (defun ediff-set-face (ground face color)
1368 "Sets face foreground/background."
1369 (if (ediff-valid-color-p color)
1370 (if (eq ground 'foreground)
1371 (set-face-foreground face color)
1372 (set-face-background face color))
1374 '(ediff-current-diff-face-A ediff-current-diff-face-B))
1375 (copy-face 'highlight face))
1377 '(ediff-fine-diff-face-A ediff-fine-diff-face-B))
1378 (copy-face 'secondary-selection face)
1379 (set-face-underline-p face t))
1381 '(ediff-odd-diff-face-A ediff-odd-diff-face-B
1382 ediff-even-diff-face-A ediff-even-diff-face-B))
1383 (copy-face 'secondary-selection face)))))
1385 (defvar ediff-current-diff-face-A
1387 (make-face 'ediff-current-diff-face-A)
1388 (or (face-differs-from-default-p 'ediff-current-diff-face-A)
1389 (cond ((ediff-display-color-p)
1391 'foreground 'ediff-current-diff-face-A "firebrick")
1393 'background 'ediff-current-diff-face-A "pale green"))
1395 (if (ediff-if-lucid)
1396 (copy-face 'modeline 'ediff-current-diff-face-A)
1397 (copy-face 'highlight 'ediff-current-diff-face-A))
1399 'ediff-current-diff-face-A)
1400 ;;(ediff-get-face 'ediff-current-diff-face-A))
1401 "Face for highlighting the selected difference in buffer A.")
1403 (defvar ediff-current-diff-face-B
1405 (make-face 'ediff-current-diff-face-B)
1406 (or (face-differs-from-default-p 'ediff-current-diff-face-B)
1407 (cond ((ediff-display-color-p)
1409 'foreground 'ediff-current-diff-face-B "DarkOrchid")
1411 'background 'ediff-current-diff-face-B "Yellow"))
1413 (if (ediff-if-lucid)
1414 (copy-face 'modeline 'ediff-current-diff-face-B)
1415 (copy-face 'highlight 'ediff-current-diff-face-B))
1417 'ediff-current-diff-face-B)
1418 ;;(ediff-get-face 'ediff-current-diff-face-B))
1419 "Face for highlighting the selected difference in buffer B.")
1421 (defvar ediff-fine-diff-face-A
1423 (make-face 'ediff-fine-diff-face-A)
1424 (or (face-differs-from-default-p 'ediff-fine-diff-face-A)
1425 (cond ((ediff-display-color-p)
1426 (ediff-set-face 'foreground 'ediff-fine-diff-face-A
1428 (ediff-set-face 'background 'ediff-fine-diff-face-A
1430 (t (set-face-underline-p 'ediff-fine-diff-face-A t))))
1431 'ediff-fine-diff-face-A)
1432 ;;(ediff-get-face 'ediff-fine-diff-face-A))
1433 "Face for highlighting the refinement of the selected diff in buffer A.")
1435 (defvar ediff-fine-diff-face-B
1437 (make-face 'ediff-fine-diff-face-B)
1438 (or (face-differs-from-default-p 'ediff-fine-diff-face-B)
1439 (cond ((ediff-display-color-p)
1440 (ediff-set-face 'foreground 'ediff-fine-diff-face-B "Black")
1441 (ediff-set-face 'background 'ediff-fine-diff-face-B "cyan"))
1442 (t (set-face-underline-p 'ediff-fine-diff-face-B t))))
1443 'ediff-fine-diff-face-B)
1444 ;;(ediff-get-face 'ediff-fine-diff-face-B))
1445 "Face for highlighting the refinement of the selected diff in buffer B.")
1448 (defvar ediff-even-diff-face-A
1450 (make-face 'ediff-even-diff-face-A)
1451 (or (face-differs-from-default-p 'ediff-even-diff-face-A)
1452 (cond ((ediff-display-color-p)
1454 'foreground 'ediff-even-diff-face-A "black")
1456 'background 'ediff-even-diff-face-A "light grey"))
1458 (copy-face 'italic 'ediff-even-diff-face-A))))
1459 'ediff-even-diff-face-A)
1460 ;;(ediff-get-face 'ediff-even-diff-face-A))
1461 "Face used to highlight even-numbered differences in buffer A.")
1463 (defvar ediff-even-diff-face-B
1465 (make-face 'ediff-even-diff-face-B)
1466 (or (face-differs-from-default-p 'ediff-even-diff-face-B)
1467 (cond ((ediff-display-color-p)
1469 'foreground 'ediff-even-diff-face-B "White")
1471 'background 'ediff-even-diff-face-B "Gray"))
1473 (copy-face 'italic 'ediff-even-diff-face-B))))
1474 'ediff-even-diff-face-B)
1475 ;;(ediff-get-face 'ediff-even-diff-face-B))
1476 "Face used to highlight even-numbered differences in buffer B.")
1478 (defvar ediff-odd-diff-face-A
1480 (make-face 'ediff-odd-diff-face-A)
1481 (or (face-differs-from-default-p 'ediff-odd-diff-face-A)
1482 (cond ((ediff-display-color-p)
1484 'foreground 'ediff-odd-diff-face-A "White")
1486 'background 'ediff-odd-diff-face-A "Gray"))
1488 (copy-face 'italic 'ediff-odd-diff-face-A))))
1489 'ediff-odd-diff-face-A)
1490 ;;(ediff-get-face 'ediff-odd-diff-face-A))
1491 "Face used to highlight odd-numbered differences in buffer A.")
1493 (defvar ediff-odd-diff-face-B
1495 (make-face 'ediff-odd-diff-face-B)
1496 (or (face-differs-from-default-p 'ediff-odd-diff-face-B)
1497 (cond ((ediff-display-color-p)
1499 'foreground 'ediff-odd-diff-face-B "Black")
1501 'background 'ediff-odd-diff-face-B "light grey"))
1503 (copy-face 'italic 'ediff-odd-diff-face-B))))
1504 'ediff-odd-diff-face-B)
1505 ;;(ediff-get-face 'ediff-odd-diff-face-B))
1506 "Face used to highlight odd-numbered differences in buffer B.")
1508 ;; Create *-var faces. These are the actual faces used to highlight
1509 ;; odd-numbered difference regions.
1510 ;; They are used as follows: when highlighting is turned on,
1511 ;; ediff-odd/even-diff-face-A/B are copied
1512 ;; into ediff-odd/even-diff-face-A/B-var, and all odd/even overlays become
1513 ;; highlighted. When highlighting is turned off, then the face 'default is
1514 ;; copied into ediff-odd/even-diff-face-A/B-var, thereby unhighlighting all
1515 ;; difference regions.
1516 (make-face 'ediff-even-diff-face-A-var)
1517 (make-face 'ediff-even-diff-face-B-var)
1518 (make-face 'ediff-odd-diff-face-A-var)
1519 (make-face 'ediff-odd-diff-face-B-var)
1521 ;; initialize *-var faces
1522 (defun ediff-init-var-faces ()
1523 (copy-face (if (and ediff-want-faces ediff-highlight-all-diffs)
1524 ediff-even-diff-face-A 'default)
1525 'ediff-even-diff-face-A-var)
1526 (copy-face (if (and ediff-want-faces ediff-highlight-all-diffs)
1527 ediff-even-diff-face-B 'default)
1528 'ediff-even-diff-face-B-var)
1529 (copy-face (if (and ediff-want-faces ediff-highlight-all-diffs)
1530 ediff-odd-diff-face-A 'default)
1531 'ediff-odd-diff-face-A-var)
1532 (copy-face (if (and ediff-want-faces ediff-highlight-all-diffs)
1533 ediff-odd-diff-face-B 'default)
1534 'ediff-odd-diff-face-B-var))
1539 (ediff-defvar-local ediff-current-diff-overlay-A nil
1540 "Overlay in buffer A.")
1541 (ediff-defvar-local ediff-current-diff-overlay-B nil
1542 "Overlay in buffer B.")
1544 (defun ediff-make-current-diff-overlay (type)
1545 (let ((overlay (if (eq type 'A)
1546 'ediff-current-diff-overlay-A
1547 'ediff-current-diff-overlay-B))
1548 (buffer (ediff-get-buffer type))
1549 (face (if (eq type 'A)
1550 (face-name ediff-current-diff-face-A)
1551 (face-name ediff-current-diff-face-B))))
1552 (set overlay (ediff-make-overlay (point-max) (point-max) buffer))
1553 (ediff-overlay-put (eval overlay) 'face face)
1554 (ediff-overlay-put (eval overlay) 'ediff ediff-control-buffer)
1557 ;; Compute priority of ediff overlay.
1558 (defun ediff-highest-priority (start end buffer)
1559 (let ((pos (max 1 (1- start)))
1561 (if (ediff-if-lucid)
1562 (1+ ediff-shaded-overlay-priority)
1563 (ediff-eval-in-buffer
1565 (while (< pos (min (point-max) (1+ end)))
1566 (setq ovr-list (append (overlays-at pos) ovr-list))
1567 (setq pos (next-overlay-change pos)))
1573 (or (ediff-overlay-get ovr 'priority) 0)
1579 ) ; end of window-system-only code.
1585 (defvar ediff-split-window-function 'split-window-vertically
1586 "*The function to split the main window between buffer-A and buffer-B.
1587 You can set it to be split horizontally instead of the
1588 default vertical split by setting this variable to
1589 'split-window-horizontally. You can also have your own function for fancy
1590 splits. This variable has no effect when buffer-A and buffer-B are shown in
1591 different frames. In this case, Ediff will use those frames to display
1594 (defconst ediff-saved-variables
1596 buffer-auto-save-file-name)
1597 "Buffer-local variables saved and restored during an Ediff session.")
1599 (defconst ediff-working-values '(nil nil)
1600 "Values to be assigned to `ediff-saved-variables' during diff.")
1602 (defvar ediff-use-last-dir nil
1603 "*If t, Ediff uses previous directory as default when reading file name.")
1605 (defvar ediff-no-help-in-control-buffer nil
1606 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1607 Instead, C-h jumps to previous difference.")
1609 (defvar ediff-temp-file-prefix
1610 (let ((env (or (getenv "TMPDIR")
1614 (setq d (if (and env (> (length env) 0))
1617 (if (= (aref d (1- (length d))) ?/)
1618 (setq d (substring d 0 -1)))
1619 (concat d "/ediff"))
1620 "*Prefix to put on Ediff temporary file names.
1621 Do not start with `~/' or `~user-name/'.")
1623 (defvar ediff-temp-file-mode 384 ; u=rw only
1624 "*Mode for Ediff temporary files.")
1626 (ediff-defvar-local ediff-temp-file-A nil
1627 "Temporary file used for refining difference regions in buffer B.")
1628 (ediff-defvar-local ediff-temp-file-B nil
1629 "Temporary file used for refining difference regions in buffer B.")
1631 (defvar ediff-last-dir-A nil
1632 "Last directory used by an Ediff command for file-A.")
1633 (defvar ediff-last-dir-B nil
1634 "Last directory used by an Ediff command for file-B.")
1635 (defvar ediff-last-dir-patch nil
1636 "Last directory used by an Ediff command for file to patch.")
1640 (defvar ediff-mode-map nil
1641 "Local keymap used in Ediff mode.")
1643 (defun ediff-frame-has-menubar ()
1644 (if (ediff-if-lucid)
1646 (< 0 (cdr (assq 'menu-bar-lines (frame-parameters (selected-frame)))))
1649 ;;; This is split in three parts to avoid
1650 ;;; making a line in loaddefs.el that is too long for patch.
1651 ;;; Note that autoload.el currently looks for cookies
1652 ;;; only at top level in the file.
1653 ;;; So I moved these to top level. But the conditionals on
1654 ;;; purify-flag make these no-ops when you load ediff.
1655 ;;; They only do something in loaddefs.el.
1659 (defvar menu-bar-epatch-menu (make-sparse-keymap "Epatch"))
1660 (fset 'menu-bar-epatch-menu (symbol-value 'menu-bar-epatch-menu))
1661 (defvar menu-bar-ediff-menu (make-sparse-keymap "Ediff"))
1662 (fset 'menu-bar-ediff-menu (symbol-value 'menu-bar-ediff-menu))))
1668 (define-key menu-bar-ediff-menu [rcs-ediff]
1669 '("Compare with a version via RCS ..." . rcs-ediff))
1670 (define-key menu-bar-ediff-menu [vc-ediff]
1671 '("Compare with a version via VC ..." . vc-ediff))
1672 (define-key menu-bar-ediff-menu [ediff-buffers]
1673 '("Compare buffers ..." . ediff-buffers))
1674 (define-key menu-bar-ediff-menu [ediff-files]
1675 '("Compare files ..." . ediff-files))))
1680 (define-key menu-bar-epatch-menu [ediff-patch-buffer]
1681 '("To a Buffer ..." . ediff-patch-buffer))
1682 (define-key menu-bar-epatch-menu [ediff-patch-file]
1683 '("To a File ..." . ediff-patch-file))))
1685 (if (and window-system ediff-want-default-menus (ediff-frame-has-menubar)
1687 (progn ;; Lucid menu bars
1690 ["Compare files ..." ediff-files t]
1691 ["Compare buffers ..." ediff-buffers t]
1692 ["Compare with a version via VC ..." vc-ediff t]
1693 ["Compare with a version via RCS ..." rcs-ediff t]))
1696 ["To a file ..." ediff-patch-file t]
1697 ["To a buffer ..." ediff-patch-buffer t]))
1698 (add-menu '("File") "Compare files"
1701 (add-menu '("File") "Apply Patch"
1704 ;; Displays as a solid horizontal line
1705 (add-menu-item '("File") "---" nil nil "New Screen")))
1709 (defun ediff-setup-keymap ()
1710 "Set up the keymap used in the control buffer of Ediff."
1711 (setq ediff-mode-map (make-sparse-keymap))
1712 (suppress-keymap ediff-mode-map)
1714 (define-key ediff-mode-map "p" 'ediff-previous-difference)
1715 (define-key ediff-mode-map "\C-?" 'ediff-previous-difference)
1716 (define-key ediff-mode-map "\C-h" (if ediff-no-help-in-control-buffer
1717 'ediff-previous-difference nil))
1718 (define-key ediff-mode-map "n" 'ediff-next-difference)
1719 (define-key ediff-mode-map " " 'ediff-next-difference)
1720 (define-key ediff-mode-map "j" 'ediff-jump-to-difference)
1721 (define-key ediff-mode-map "g" nil)
1722 (define-key ediff-mode-map "ga" 'ediff-jump-to-difference-at-point)
1723 (define-key ediff-mode-map "gb" 'ediff-jump-to-difference-at-point)
1724 (define-key ediff-mode-map "q" 'ediff-quit)
1725 (define-key ediff-mode-map "z" 'ediff-suspend)
1726 (define-key ediff-mode-map "c" 'ediff-recenter)
1727 (define-key ediff-mode-map "s" 'ediff-toggle-split)
1728 (define-key ediff-mode-map "h" 'ediff-toggle-hilit)
1729 (define-key ediff-mode-map "@" 'ediff-toggle-autorefine)
1730 (define-key ediff-mode-map "v" 'ediff-scroll-up)
1731 (define-key ediff-mode-map "\C-v" 'ediff-scroll-up)
1732 (define-key ediff-mode-map "^" 'ediff-scroll-down)
1733 (define-key ediff-mode-map "\M-v" 'ediff-scroll-down)
1734 (define-key ediff-mode-map "V" 'ediff-scroll-down)
1735 (define-key ediff-mode-map "<" 'ediff-scroll-left)
1736 (define-key ediff-mode-map ">" 'ediff-scroll-right)
1737 (define-key ediff-mode-map "i" 'ediff-status-info)
1738 (define-key ediff-mode-map "?" 'ediff-toggle-help)
1739 (define-key ediff-mode-map "!" 'ediff-recompute-diffs)
1740 (define-key ediff-mode-map "*" 'ediff-make-fine-diffs)
1741 (define-key ediff-mode-map "a" nil)
1742 (define-key ediff-mode-map "ab" 'ediff-diff-to-diff)
1743 (define-key ediff-mode-map "b" nil)
1744 (define-key ediff-mode-map "ba" 'ediff-diff-to-diff)
1745 (define-key ediff-mode-map "r" nil)
1746 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
1747 (define-key ediff-mode-map "rb" 'ediff-restore-diff)
1748 (define-key ediff-mode-map "#" nil)
1749 (define-key ediff-mode-map "#h" 'ediff-toggle-regexp-match)
1750 (define-key ediff-mode-map "#f" 'ediff-toggle-regexp-match)
1751 (define-key ediff-mode-map "o" nil)
1752 (define-key ediff-mode-map "A" 'ediff-toggle-read-only)
1753 (define-key ediff-mode-map "B" 'ediff-toggle-read-only)
1754 (define-key ediff-mode-map "w" nil)
1755 (define-key ediff-mode-map "wa" 'ediff-save-buffer)
1756 (define-key ediff-mode-map "wb" 'ediff-save-buffer)
1757 (define-key ediff-mode-map "k" nil)
1758 (define-key ediff-mode-map "kkk" 'ediff-reload-keymap) ;; for debug
1759 ;; Allow ediff-mode-map to be referenced indirectly
1760 (fset 'ediff-mode-map ediff-mode-map))
1765 (defun ediff-find-file (file-var buffer &optional last-dir hooks-var)
1766 "Visit FILE and arrange its buffer to Ediff's liking.
1767 FILE is actually a variables symbol that must contain a true file name.
1768 BUFFER is a variable symbol, which will get the buffer object into which
1769 FILE is read. LAST-DIR is the directory variable symbol where FILE's
1770 directory name should be returned. HOOKS is a variable symbol that will be
1771 assigned the hook to be executed after `ediff-strartup' is finished.
1772 `ediff-find-file' arranges that the temp files it might create will be
1774 Arguments: (file buffer &optional last-dir hooks)"
1775 (let* ((file (eval file-var))
1776 (file-magic (find-file-name-handler file 'find-file-noselect)))
1777 (if (not (file-readable-p file))
1778 (error "File `%s' does not exist or is not readable" file))
1780 ;; Record the directory of the file
1782 (set last-dir (expand-file-name (file-name-directory file))))
1785 (set buffer (find-file-noselect file))
1787 (ediff-eval-in-buffer
1789 (widen) ;; Make sure the entire file is seen
1790 (cond (file-magic ;; file has handler, such as jka-compr-handler or
1791 ;; ange-ftp-hook-function--arrange for temp file
1792 (ediff-verify-file-buffer 'magic)
1793 (setq file (ediff-make-temp-file))
1794 (set hooks-var (cons (` (lambda () (delete-file (, file))))
1796 ;; file processed via auto-mode-alist, a la uncompress.el
1797 ((not (equal (expand-file-name file) (buffer-file-name)))
1798 (setq file (ediff-make-temp-file))
1799 (set hooks-var (cons (` (lambda () (delete-file (, file))))
1801 (t ;; plain file---just check that the file matches the buffer
1802 (ediff-verify-file-buffer))))
1803 (set file-var file)))
1805 (defun ediff-files-internal (file-A file-B &optional startup-hooks)
1806 (let (buffer-A buffer-B)
1807 (message "Reading file %s ... " file-A)(sit-for .5)
1808 (ediff-find-file 'file-A 'buffer-A 'ediff-last-dir-A 'startup-hooks)
1809 (message "Reading file %s ... " file-B)(sit-for .5)
1810 (ediff-find-file 'file-B 'buffer-B 'ediff-last-dir-B 'startup-hooks)
1811 (ediff-setup buffer-A file-A buffer-B file-B startup-hooks)))
1813 (defun ediff-get-patch-buffer (dir)
1814 "Obtain patch buffer. If patch is already in a buffer---use it.
1815 Else, read patch file into a new buffer."
1816 (if (y-or-n-p "Is the patch file already in a buffer? ")
1817 (setq ediff-patch-buf
1818 (get-buffer (read-buffer "Patch buffer name: " nil t))) ;must match
1819 (setq ediff-patch-buf
1820 (find-file-noselect (read-file-name "Patch file name: " dir))))
1821 (ediff-eval-in-buffer
1823 (toggle-read-only 1))
1824 (setq ediff-patch-diagnostics
1825 (get-buffer-create "*ediff patch diagnostics*"))
1826 (ediff-eval-in-buffer
1827 ediff-patch-diagnostics
1828 (insert-buffer ediff-patch-buf))
1831 ;; Start up Ediff on two files
1832 (defun ediff-setup (buffer-A file-A buffer-B file-B startup-hooks)
1833 (setq file-A (expand-file-name file-A))
1834 (setq file-B (expand-file-name file-B))
1835 (let* ((control-buffer-name
1836 (emerge-unique-buffer-name "Ediff Control Panel" ""))
1837 (control-buffer (ediff-eval-in-buffer
1839 (get-buffer-create control-buffer-name))))
1840 (ediff-eval-in-buffer
1842 (ediff-mode) ;; in control buffer only
1843 (setq buffer-read-only nil)
1844 (setq ediff-A-buffer buffer-A)
1845 (setq ediff-B-buffer buffer-B)
1846 (setq ediff-control-buffer control-buffer)
1847 ; (setq ediff-control-buffer-suffix
1848 ; (if (string-match "<[0-9]*>" control-buffer-name)
1849 ; (substring control-buffer-name
1850 ; (match-beginning 0) (match-end 0))
1852 (setq ediff-error-buffer (get-buffer-create (emerge-unique-buffer-name
1853 "*ediff-errors" "*")))
1854 (ediff-remember-buffer-characteristics t) ;; remember at setup
1857 (setq ediff-difference-vector (ediff-setup-diff-regions file-A file-B))
1858 (setq ediff-number-of-differences (length ediff-difference-vector))
1859 (setq ediff-current-difference -1)
1860 (ediff-make-current-diff-overlay 'A)
1861 (ediff-make-current-diff-overlay 'B)
1863 (ediff-init-var-faces))
1864 (run-hooks 'ediff-before-setup-windows-hooks)
1865 (ediff-setup-windows buffer-A buffer-B control-buffer t)
1867 ;; all these must be inside ediff-eval-in-buffer control-buffer,
1868 ;; since these vars are local to control-buffer
1869 ;; These won't run if there are errors in diff
1870 (ediff-eval-in-buffer
1872 (add-hook 'local-write-file-hooks 'ediff-block-write-file)
1873 (setq before-change-function 'ediff-before-change-guard)
1874 ;; add control-buffer to the list of sessions
1875 (or (memq control-buffer ediff-this-buffer-control-sessions)
1876 (setq ediff-this-buffer-control-sessions
1877 (cons control-buffer ediff-this-buffer-control-sessions)))
1878 (setq mode-line-buffer-identification
1880 (if (string-match "\\(^ \\|^[^ \t]*: \\)"
1881 (car mode-line-buffer-identification))
1882 (cons (substring (car mode-line-buffer-identification)
1884 (cdr mode-line-buffer-identification))
1885 mode-line-buffer-identification)))
1886 (run-hooks 'ediff-prepare-buffer-hooks))
1887 (ediff-eval-in-buffer
1889 (add-hook 'local-write-file-hooks 'ediff-block-write-file)
1890 (setq before-change-function 'ediff-before-change-guard)
1891 ;; add control-buffer to the list of sessions
1892 (or (memq control-buffer ediff-this-buffer-control-sessions)
1893 (setq ediff-this-buffer-control-sessions
1894 (cons control-buffer ediff-this-buffer-control-sessions)))
1895 (setq mode-line-buffer-identification
1897 (if (string-match "\\(^ \\|^[^ \t]*: \\)"
1898 (car mode-line-buffer-identification))
1899 (cons (substring (car mode-line-buffer-identification)
1901 (cdr mode-line-buffer-identification))
1902 mode-line-buffer-identification)))
1903 (run-hooks 'ediff-prepare-buffer-hooks))
1905 (ediff-eval-in-buffer control-buffer
1906 (run-hooks 'startup-hooks 'ediff-startup-hooks)
1907 (setq buffer-read-only t)))))
1909 ;; Generate the difference vector and overlays for the two files
1910 ;; With optional arg `refine', create refining difference regions
1911 (defun ediff-setup-diff-regions (file-A file-B
1912 &optional use-old refine-region
1913 diff-program diff-options
1914 diff-ok-lines-regexp)
1916 (setq diff-program (or diff-program ediff-diff-program)
1917 diff-options (or diff-options ediff-diff-options)
1918 diff-ok-lines-regexp
1919 (or diff-ok-lines-regexp ediff-diff-ok-lines-regexp))
1921 (or use-old (setq ediff-diff-buffer
1923 (emerge-unique-buffer-name "*ediff-diff" "*"))))
1924 (ediff-eval-in-buffer
1927 ;; shell-command tends to display old shell command buffers even when it
1928 ;; puts output in another buffer---probably an Emacs bug.
1929 (ediff-kill-buffer-carefully "*Shell Command Output*")
1930 (let ((shell-file-name ediff-shell))
1932 (message "Refining difference region %d ..." (1+ refine-region))
1933 (message "Computing differences ...")(sit-for .5))
1935 (format "%s %s %s %s"
1936 diff-program diff-options
1937 (ediff-protect-metachars file-A)
1938 (ediff-protect-metachars file-B))
1941 (ediff-prepare-error-list diff-ok-lines-regexp)
1943 (message "Refining difference region %d ... Done." (1+ refine-region))
1944 (message "Computing differences ... Done.")(sit-for .5))
1946 (ediff-convert-diffs-to-overlays-refine
1947 ediff-A-buffer ediff-B-buffer
1948 (ediff-extract-diffs ediff-diff-buffer)
1950 (ediff-convert-diffs-to-overlays
1951 ediff-A-buffer ediff-B-buffer
1952 (ediff-extract-diffs ediff-diff-buffer ediff-A-buffer ediff-B-buffer)))
1956 (defun ediff-prepare-error-list (ok-regexp)
1957 (let ((diff-buff ediff-diff-buffer))
1958 (ediff-eval-in-buffer
1961 (insert-buffer diff-buff)
1962 (delete-matching-lines ok-regexp))))
1964 ;;; Function to start Ediff by patching a file
1967 (defun ediff-patch-file (source-filename &optional startup-hooks)
1968 "Run Ediff by patching FILE-TP-PATCH."
1970 (list (ediff-read-file-name "File to patch"
1971 (if ediff-use-last-dir
1972 ediff-last-dir-patch
1976 (ediff-get-patch-buffer (file-name-directory source-filename))
1977 (let* ((backup-extension
1978 ;; if the user specified a -b option, extract the backup
1979 ;; extension from there; else use `.orig'
1980 (substring ediff-patch-options
1981 (if (string-match "-b[ \t]+" ediff-patch-options)
1983 (if (string-match "-b[ \t]+[^ \t]+" ediff-patch-options)
1985 (backup-extension (if (string= backup-extension "")
1986 "orig" backup-extension))
1987 (shell-file-name ediff-shell)
1988 ;; ediff-find-file may use a temp file to do the patch
1989 ;; so, we save source-filename and true-source-filename as a var
1990 ;; that initially is source-filename but may be changed to a temp
1991 ;; file for the purpose of patching.
1992 (true-source-filename source-filename)
1993 (target-filename source-filename)
1994 target-buf buf-to-patch file-name-magic-p)
1996 ;; Make a temp file, if source-filename has a magic file handler (or if
1997 ;; it is handled via auto-mode-alist and similar magic).
1998 ;; Check if there is a buffer visiting source-filename and if they are in
1999 ;; synch; arrange for the deletion of temp file.
2000 (ediff-find-file 'true-source-filename 'buf-to-patch
2001 'ediff-last-dir-patch 'startup-hooks)
2003 ;; Check if source file name has triggered black magic, such as file name
2004 ;; handlers or auto mode alist, and make a note of it.
2005 (setq file-name-magic-p (not (equal (expand-file-name true-source-filename)
2006 (expand-file-name source-filename))))
2008 (ediff-eval-in-buffer
2009 ediff-patch-diagnostics
2010 (message "Applying patch ... ")(sit-for .5)
2011 ;; always pass patch the -f option, so it won't ask any questions
2012 (shell-command-on-region
2013 (point-min) (point-max)
2014 (format "%s -f %s %s"
2015 ediff-patch-program ediff-patch-options
2016 (expand-file-name true-source-filename))
2018 (message "Applying patch ... Done.")(sit-for .5)
2019 (switch-to-buffer ediff-patch-diagnostics)
2020 (sit-for 0) ;; synchronize
2022 (or (file-exists-p (concat true-source-filename "." backup-extension))
2023 (error "Patch failed or didn't modify the original file."))
2025 ;; If black magic is involved, apply patch to a temp copy of the
2026 ;; file. Otherwise, apply patch to the orig copy.
2027 ;; If patch is applied to temp copy, we name the result
2028 ;; ***.patched. The orig file name isn't changed, and the temp copy of
2029 ;; the original is later deleted.
2030 ;; Without magic, the original file is renamed (usually into
2031 ;; old-name.orig) and the result of patching will have the
2032 ;; same name as the original.
2033 (if (not file-name-magic-p)
2034 (ediff-eval-in-buffer
2036 (set-visited-file-name (concat source-filename "." backup-extension))
2037 (set-buffer-modified-p nil))
2038 (setq target-filename (concat true-source-filename ".patched"))
2039 (rename-file true-source-filename target-filename t)
2041 ;; arrange that the temp copy of orig will be deleted
2042 (rename-file (concat true-source-filename "." backup-extension)
2043 true-source-filename t))
2045 ;; make orig buffer read-only
2046 (setq startup-hooks (cons 'ediff-toggle-read-only-A startup-hooks))
2047 ;; set up a buf for the patched file
2048 (setq target-buf (find-file-noselect target-filename))
2050 (ediff-buffers buf-to-patch target-buf startup-hooks)
2052 (bury-buffer ediff-patch-diagnostics)
2053 (message "Patch diagnostics available in buffer %s."
2054 (buffer-name ediff-patch-diagnostics))))
2056 (defalias 'epatch 'ediff-patch-file)
2057 (defalias 'epatch-buffer 'ediff-patch-buffer)
2059 ;;; Function to start Ediff on files
2062 (defun ediff-files (file-A file-B &optional startup-hooks)
2063 "Run Ediff on a pair files, FILE-A and FILE-B."
2066 (list (setq f (ediff-read-file-name "File A to compare"
2067 (if ediff-use-last-dir
2071 (ediff-read-file-name "File B to compare"
2072 (if ediff-use-last-dir
2073 ediff-last-dir-B nil)
2076 (ediff-files-internal file-A
2077 (if (file-directory-p file-B)
2079 (file-name-nondirectory file-A) file-B)
2084 (defalias 'ediff 'ediff-files)
2087 ;;; Function to start Ediff on buffers
2090 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks)
2091 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
2093 (list (read-buffer "Buffer A to compare: " (current-buffer) t)
2094 (read-buffer "Buffer B to compare: "
2096 ;; realign buffers so that two visible bufs will be
2098 (save-window-excursion (other-window 1))
2099 (other-buffer (current-buffer) t))
2101 (if (not (ediff-buffer-live-p buffer-A))
2102 (error "Buffer %S doesn't exist." buffer-A))
2103 (if (not (ediff-buffer-live-p buffer-B))
2104 (error "Buffer %S doesn't exist." buffer-B))
2106 (let (file-A file-B)
2107 (ediff-eval-in-buffer
2109 (setq file-A (ediff-make-temp-file)))
2110 (ediff-eval-in-buffer
2112 (setq file-B (ediff-make-temp-file)))
2113 (ediff-setup (get-buffer buffer-A) file-A
2114 (get-buffer buffer-B) file-B
2116 (delete-file (, file-A))
2117 (delete-file (, file-B))))
2122 (defun ediff-patch-buffer (buffer-name &optional startup-hooks)
2123 "Run Ediff by patching BUFFER-NAME."
2124 (interactive "bBuffer to patch: ")
2126 (let* ((file-buffer (get-buffer buffer-name))
2127 (file-name (if file-buffer (buffer-file-name file-buffer))))
2129 (error "Buffer %s doesn't exist or doesn't visit any file. Why patch?"
2132 (ediff-patch-file file-name startup-hooks)))
2135 ;;; Versions Control functions
2138 (defun vc-ediff (rev)
2139 ;; Note: this function will work only with Emacs 19.22 and higher.
2140 "Run ediff on version REV of the current buffer in another window.
2141 If the current buffer is named `F', the version is named `F.~REV~'.
2142 If `F.~REV~' already exists, it is used instead of being re-created."
2143 (interactive "sVersion to ediff with (default is the latest version): ")
2145 (if (locate-library "vc") ;; if vc.el is available
2148 (define-key vc-prefix-map "=" 'vc-ediff))
2149 (error "The VC package is apparently not installed.")))
2150 (let ((newvers (current-buffer))
2152 (vc-version-other-window rev)
2153 ;; current-buffer is supposed to contain the old version in another
2155 (ediff-buffers newvers (current-buffer))
2158 (defun rcs-ediff-view-revision (&optional rev)
2159 "View previous RCS revision of current file.
2160 With prefix argument, prompts for a revision name."
2161 (interactive (list (if current-prefix-arg
2162 (read-string "Revision: "))))
2163 (let* ((filename (buffer-file-name (current-buffer)))
2164 (switches (append '("-p")
2165 (if rev (list (concat "-r" rev)) nil)))
2166 (buff (concat (file-name-nondirectory filename) ".~" rev "~")))
2167 (message "Working...")
2168 (setq filename (expand-file-name filename))
2169 (with-output-to-temp-buffer
2171 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff)))
2172 (delete-windows-on output-buffer)
2174 (set-buffer output-buffer)
2175 (apply 'call-process "co" nil t nil
2176 ;; -q: quiet (no diagnostics)
2177 (append switches rcs-default-co-switches
2178 (list "-q" filename)))))
2182 (defun ediff-rcs-get-output-buffer (file name)
2183 ;; Get a buffer for RCS output for FILE, make it writable and clean it up.
2184 ;; Optional NAME is name to use instead of `*RCS-output*'.
2185 ;; This is a modified version from rcs.el v1.1. I use it here to make
2186 ;; Ediff immune to changes in rcs.el
2187 (let* ((default-major-mode 'fundamental-mode);; no frills!
2188 (buf (get-buffer-create name)))
2191 (setq buffer-read-only nil
2192 default-directory (file-name-directory (expand-file-name file)))
2197 (defun rcs-ediff (&optional rev)
2198 "Run Ediff on the current buffer, comparing it with previous RCS revision.
2199 With prefix argument, prompts for revision name."
2200 (interactive (list (if current-prefix-arg
2201 (read-string "Revision: "))))
2203 (if (locate-library "rcs")
2206 (global-set-key "\C-cD" 'rcs-ediff))
2207 (error "The RCS package is apparently not installed.")))
2208 (let ((newvers (current-buffer))
2209 (oldvers (rcs-ediff-view-revision rev)))
2210 (ediff-buffers newvers oldvers)
2216 ;; Select the lowest window on the frame.
2217 (defun ediff-select-lowest-window ()
2218 (let* ((lowest-window (selected-window))
2219 (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
2220 (last-window (previous-window))
2222 (while window-search
2223 (let* ((this-window (next-window))
2224 (next-bottom-edge (car (cdr (cdr (cdr
2225 (window-edges this-window)))))))
2226 (if (< bottom-edge next-bottom-edge)
2228 (setq bottom-edge next-bottom-edge)
2229 (setq lowest-window this-window)))
2231 (select-window this-window)
2232 (if (eq last-window this-window)
2234 (select-window lowest-window)
2235 (setq window-search nil)))))))
2237 ;;; Common setup routines
2239 ;; Set up the window configuration. If POS is given, set the points to
2240 ;; the beginnings of the buffers.
2241 (defun ediff-setup-windows (buffer-A buffer-B control-buffer &optional pos)
2242 ;; Make sure we are not in the minibuffer window when we try to delete
2243 ;; all other windows.
2244 (if (eq (selected-window) (minibuffer-window))
2246 (or (ediff-leave-window-config control-buffer)
2248 (delete-other-windows)
2249 (switch-to-buffer control-buffer)
2250 (ediff-refresh-mode-line)
2252 (ediff-arrange-buffer buffer-A buffer-B (current-buffer) pos)
2253 (ediff-arrange-buffer buffer-B buffer-A (current-buffer) pos)
2254 ;; ediff-arrange-buffer always leaves in ctl buffer
2255 ;; setup ctl wind if it is not set.
2256 (ediff-setup-control-window)
2258 ;; If diff reports errors, show them then quit.
2259 (if (/= 0 (ediff-eval-in-buffer ediff-error-buffer (buffer-size)))
2260 (let ((diff-output-buf ediff-diff-buffer))
2261 (switch-to-buffer ediff-error-buffer)
2262 (ediff-kill-buffer-carefully control-buffer)
2263 (error "Errors found in diff output. Diff output buffer is %s"
2264 diff-output-buf))))))
2267 ;; Arranges goal-buf on the screen.
2268 (defun ediff-arrange-buffer (goal-buf other-buf ctl-buf &optional pos)
2269 (let* ((ctl-wind (get-buffer-window ctl-buf t))
2270 (goal-wind (get-buffer-window goal-buf t))
2271 (other-wind (get-buffer-window other-buf t))
2272 (ctl-frame (ediff-window-frame ctl-wind))
2273 (goal-frame (if goal-wind (ediff-window-frame goal-wind)))
2274 (other-frame (if other-wind (ediff-window-frame other-wind)))
2275 (ctl-frame-shared (or (eq ctl-frame goal-frame)
2276 (eq ctl-frame other-frame))))
2278 (cond ((and goal-frame (not (eq goal-wind other-wind)))
2279 ;; goal buffer is visible and we are not comparing file
2280 ;; against itself (by mistake).
2281 ;; Note: goal-frame != ctl-frame, as we deleted other
2282 ;; windows on ctl-frame.
2283 (ediff-select-frame goal-frame)
2284 (select-window goal-wind)
2285 (delete-other-windows))
2287 ;; goal-buf invisible, ctl-frame has only ctl-buf
2288 ;; then put goal-buf on ctl-frame
2289 ((null ctl-frame-shared)
2290 (ediff-select-frame ctl-frame)
2291 (split-window-vertically)
2292 (ediff-select-lowest-window)
2293 (setq ctl-wind (selected-window))
2294 (switch-to-buffer ctl-buf)
2295 (ediff-setup-control-window)
2297 (switch-to-buffer goal-buf)) ; goal-buf set
2298 ;; goal-buf invisible, ctl-frame has ctl-buf and other-buf
2299 ;; So, put everything in one frame
2300 (other-frame ;; share with the other buf
2301 (ediff-select-frame ctl-frame)
2302 (select-window other-wind)
2303 (funcall ediff-split-window-function)
2305 (switch-to-buffer goal-buf))
2307 (error "Funny window combination (Ediff bug?)")))
2310 (goto-char (point-min)))
2312 (ediff-select-frame ctl-frame)
2313 (select-window ctl-wind)
2314 (switch-to-buffer ctl-buf)))
2316 ;; This function assumes that we are in the window where control buffer is
2318 (defun ediff-setup-control-window ()
2319 "Set up window for control buffer."
2321 (insert ediff-help-message)
2322 (shrink-window-if-larger-than-buffer)
2323 (setq ediff-control-window (selected-window))
2324 (setq ediff-window-config-saved
2326 ediff-control-window
2327 (get-buffer-window ediff-A-buffer t)
2328 (get-buffer-window ediff-B-buffer t)
2329 ediff-split-window-function))
2330 (goto-char (point-min))
2331 (skip-chars-forward ediff-whitespace))
2333 (defun ediff-leave-window-config (control-buf)
2334 (and (eq control-buf (current-buffer))
2335 (/= (buffer-size) 0)
2336 (ediff-eval-in-buffer
2338 (string= ediff-window-config-saved
2340 (get-buffer-window ediff-control-buffer t)
2341 (get-buffer-window ediff-A-buffer t)
2342 (get-buffer-window ediff-B-buffer t)
2343 ediff-split-window-function)))))
2346 ;; Set up the keymap in the control buffer
2347 (defun ediff-set-keys ()
2348 "Set up Ediff keymap, if necessary."
2349 (if (null ediff-mode-map)
2350 (ediff-setup-keymap))
2351 (use-local-map ediff-mode-map))
2353 ;; Reload Ediff keymap. For debugging only.
2354 (defun ediff-reload-keymap ()
2356 (setq ediff-mode-map nil)
2359 (defun ediff-before-change-guard (start end)
2360 "If buffer is highlighted with ASCII flags, remove highlighting.
2361 Arguments, START and END are not used, but are provided
2362 because this is required by `before-change-function'."
2363 (let (rehighlight-key)
2364 (save-window-excursion
2368 (ediff-eval-in-buffer
2370 (if (eq ediff-highlighting-style 'ascii)
2372 (ediff-unselect-and-select-difference
2373 ediff-current-difference
2374 'unselect-only 'no-recenter)
2375 (setq rehighlight-key
2376 (substitute-command-keys "\\[ediff-recenter]"))
2378 ediff-this-buffer-control-sessions)
2381 "ASCII flags removed. You can edit now. Hit %S to rehighlight."
2385 (defun ediff-recompute-diffs ()
2386 "Recompute difference regions in buffers A and B."
2388 (let ((point-A (ediff-eval-in-buffer ediff-A-buffer (point)))
2389 (point-B (ediff-eval-in-buffer ediff-B-buffer (point)))
2391 (ediff-unselect-and-select-difference -1)
2392 (ediff-eval-in-buffer
2394 (setq file-A (ediff-make-temp-file)))
2395 (ediff-eval-in-buffer
2397 (setq file-B (ediff-make-temp-file)))
2398 (ediff-clear-diff-vector ediff-difference-vector 'fine-diffs-also)
2399 (setq ediff-killed-diffs-alist nil) ; saved kills will no longer be valid
2401 (setq ediff-difference-vector
2402 (ediff-setup-diff-regions file-A file-B 'use-old))
2403 (setq ediff-number-of-differences (length ediff-difference-vector))
2404 (delete-file file-A)
2405 (delete-file file-B)
2406 (ediff-eval-in-buffer ediff-A-buffer (goto-char point-A))
2407 (ediff-jump-to-difference (ediff-diff-at-point 'A))
2410 "Ediff is at last posn in buff A. Stay (or goto last posn in B)? ")
2412 (ediff-eval-in-buffer ediff-B-buffer (goto-char point-B))
2413 (ediff-jump-to-difference (ediff-diff-at-point 'B)))
2417 (defun ediff-remember-buffer-characteristics (&optional arg)
2418 "Record certain properties of the buffers being compared.
2419 Must be called in the control buffer. Saves `read-only', `modified',
2420 and `auto-save' properties in buffer local variables. Turns off
2421 `auto-save-mode'. These properties are restored via a call to
2422 `ediff-restore-buffer-characteristics'."
2424 ;; remember and alter buffer characteristics
2425 (set (if arg 'ediff-A-buffer-values-setup 'ediff-A-buffer-values)
2426 (ediff-eval-in-buffer
2429 (emerge-save-variables ediff-saved-variables)
2430 (emerge-restore-variables ediff-saved-variables
2431 ediff-working-values))))
2432 (set (if arg 'ediff-B-buffer-values-setup 'ediff-B-buffer-values)
2433 (ediff-eval-in-buffer
2436 (emerge-save-variables ediff-saved-variables)
2437 (emerge-restore-variables ediff-saved-variables
2438 ediff-working-values)))))
2440 (defun ediff-restore-buffer-characteristics (&optional arg)
2441 "Restores properties saved by `ediff-remember-buffer-characteristics'."
2442 (let ((A-values (if arg ediff-A-buffer-values-setup ediff-A-buffer-values))
2443 (B-values (if arg ediff-B-buffer-values-setup ediff-B-buffer-values)))
2445 (ediff-eval-in-buffer ediff-A-buffer
2446 (emerge-restore-variables ediff-saved-variables
2448 (ediff-eval-in-buffer ediff-B-buffer
2449 (emerge-restore-variables ediff-saved-variables
2453 ;; If optional A-buffer and B-buffer are given, then construct a vector of
2454 ;; diff using point values. Otherwise, use line offsets.
2455 (defun ediff-extract-diffs (diff-buffer &optional A-buffer B-buffer)
2457 (a-prev 1) ;; this is needed to set the first diff line correctly
2460 (if (and A-buffer B-buffer)
2461 (progn ;; reset point in buffers A and B
2462 (ediff-eval-in-buffer
2464 (goto-char (point-min)))
2465 (ediff-eval-in-buffer
2467 (goto-char (point-min)))))
2469 (ediff-eval-in-buffer
2471 (goto-char (point-min))
2472 (while (re-search-forward ediff-match-diff-line nil t)
2473 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1)
2475 (a-end (let ((b (match-beginning 3))
2478 (string-to-int (buffer-substring b e))
2480 (diff-type (buffer-substring (match-beginning 4) (match-end 4)))
2481 (b-begin (string-to-int (buffer-substring (match-beginning 5)
2483 (b-end (let ((b (match-beginning 7))
2486 (string-to-int (buffer-substring b e))
2488 a-begin-pt a-end-pt b-begin-pt b-end-pt)
2489 ;; fix the beginning and end numbers, because diff is somewhat
2490 ;; strange about how it numbers lines
2491 (if (string-equal diff-type "a")
2492 (setq b-end (1+ b-end)
2493 a-begin (1+ a-begin)
2495 (if (string-equal diff-type "d")
2496 (setq a-end (1+ a-end)
2497 b-begin (1+ b-begin)
2499 ;; (string-equal diff-type "c")
2500 (setq a-end (1+ a-end)
2502 (if (and A-buffer B-buffer)
2503 (progn ;; computing main diff vector
2504 ;; convert to relative line numbers
2505 (ediff-eval-in-buffer
2507 (forward-line (- a-begin a-prev))
2508 (setq a-begin-pt (point))
2509 (forward-line (- a-end a-begin))
2510 (setq a-end-pt (point)
2512 (ediff-eval-in-buffer
2514 (forward-line (- b-begin b-prev))
2515 (setq b-begin-pt (point))
2516 (forward-line (- b-end b-begin))
2517 (setq b-end-pt (point)
2520 (nconc diff-list (list (vector a-begin-pt a-end-pt
2521 b-begin-pt b-end-pt)))))
2522 ;; computing refinement vector
2524 (nconc diff-list (list (vector (- a-begin a-prev)
2527 (- b-end b-begin))))
2531 ))) ;; end ediff-eval-in-buffer
2535 (defun ediff-convert-diffs-to-overlays (A-buffer B-buffer diff-list)
2536 (let* ((current-diff -1)
2537 (total-diffs (length diff-list))
2538 ; (control-buffer-suffix ediff-control-buffer-suffix)
2539 diff-overlay-list list-element
2540 a-begin a-end b-begin b-end
2541 a-overlay b-overlay)
2544 (setq current-diff (1+ current-diff)
2545 list-element (car diff-list)
2546 a-begin (aref list-element 0)
2547 a-end (aref list-element 1)
2548 b-begin (aref list-element 2)
2549 b-end (aref list-element 3))
2551 ;; Put overlays at the appropriate places in the buffers
2552 (setq a-overlay (ediff-make-overlay a-begin a-end A-buffer))
2553 ;; Priorities of overlays should be equal in all ediff control
2554 ;; panels buffers. Otherwise it won't work due to Emacs
2555 ;; bug---insert-in-front-hooks will be called
2556 ;; only on behalf of the buffer with higher priority.
2557 (ediff-overlay-put a-overlay 'priority ediff-shaded-overlay-priority)
2558 (ediff-overlay-put a-overlay 'ediff-diff-num current-diff)
2559 (ediff-overlay-put a-overlay
2560 'insert-in-front-hooks '(ediff-insert-in-front))
2561 ; (ediff-overlay-put a-overlay
2562 ; 'ediff-control-buffer control-buffer-suffix)
2563 (ediff-overlay-put a-overlay
2564 'face (if (ediff-odd-p current-diff) ;; odd diff
2565 'ediff-odd-diff-face-A-var
2566 'ediff-even-diff-face-A-var))
2568 (setq b-overlay (ediff-make-overlay b-begin b-end B-buffer))
2569 (ediff-overlay-put b-overlay 'priority ediff-shaded-overlay-priority)
2570 (ediff-overlay-put b-overlay 'ediff-diff-num current-diff)
2571 (ediff-overlay-put b-overlay
2572 'insert-in-front-hooks '(ediff-insert-in-front))
2573 ; (ediff-overlay-put b-overlay
2574 ; 'ediff-control-buffer control-buffer-suffix)
2575 (ediff-overlay-put b-overlay
2576 'face (if (ediff-odd-p current-diff) ;; odd diff
2577 'ediff-odd-diff-face-B-var
2578 'ediff-even-diff-face-B-var))
2580 (if (ediff-if-lucid) ;; chars inserted at end will be inside extent
2582 (ediff-overlay-put a-overlay
2584 (move-marker (make-marker) a-begin A-buffer))
2585 (ediff-overlay-put b-overlay
2587 (move-marker (make-marker) b-begin B-buffer))
2588 (ediff-overlay-put a-overlay 'end-open nil)
2589 (ediff-overlay-put b-overlay 'end-open nil)))
2591 ;; record all overlays for this difference
2592 (setq diff-overlay-list
2593 (nconc diff-overlay-list (list (vector a-overlay b-overlay nil)))
2594 diff-list (cdr diff-list))
2595 (message "Processing diff region %d of %d"
2596 current-diff total-diffs)
2598 ;; this is just to avoid confusing the user with diff num < total-diffs
2599 (message "Processing diff region %d of %d"
2600 (1+ current-diff) total-diffs)
2601 ;; convert the list of difference information into a vector for
2603 (apply 'vector diff-overlay-list)))
2609 (defun ediff-recenter (&optional no-rehighlight)
2610 "Bring the highlighted region of all buffers A and B into view.
2611 Reestablish the default three-window display."
2613 (setq ediff-disturbed-overlays nil) ;; clear after use
2614 (let (buffer-read-only)
2615 (if (and (ediff-buffer-live-p ediff-A-buffer)
2616 (ediff-buffer-live-p ediff-B-buffer))
2617 (ediff-setup-windows
2618 ediff-A-buffer ediff-B-buffer ediff-control-buffer)))
2619 ;; Redisplay whatever buffers are showing, if there is a selected difference
2620 (if (and (ediff-buffer-live-p ediff-A-buffer)
2621 (ediff-buffer-live-p ediff-B-buffer)
2622 (>= ediff-current-difference 0)
2623 (< ediff-current-difference ediff-number-of-differences))
2624 (let* ( ;; context must be saved before switching to windows A/B
2625 (buffer-A ediff-A-buffer)
2626 (buffer-B ediff-B-buffer)
2627 (wind (selected-window))
2628 (control-buf ediff-control-buffer)
2629 (before-flag-shift-A (if (eq ediff-highlighting-style 'ascii)
2630 (1- (length ediff-before-flag-A))
2632 (after-flag-shift-A (if (eq ediff-highlighting-style 'ascii)
2633 (1- (length ediff-after-flag-A))
2635 (before-flag-shift-B (if (eq ediff-highlighting-style 'ascii)
2636 (1- (length ediff-before-flag-B))
2638 (after-flag-shift-B (if (eq ediff-highlighting-style 'ascii)
2639 (1- (length ediff-after-flag-B))
2641 (window-A (get-buffer-window buffer-A t))
2642 (window-B (get-buffer-window buffer-B t)))
2645 (ediff-operate-on-flags 'insert))
2648 (select-window window-A)
2649 (ediff-position-region
2650 (- (ediff-get-diff-posn 'A 'beg nil control-buf)
2651 before-flag-shift-A)
2652 (+ (ediff-get-diff-posn 'A 'end nil control-buf)
2654 (ediff-get-diff-posn 'A 'beg nil control-buf))))
2656 (select-window window-B)
2657 (ediff-position-region
2658 (- (ediff-get-diff-posn 'B 'beg nil control-buf)
2659 before-flag-shift-B)
2660 (+ (ediff-get-diff-posn 'B 'end nil control-buf)
2662 (ediff-get-diff-posn 'B 'beg nil control-buf))))
2663 (select-window wind))))
2665 (defun ediff-toggle-split ()
2666 "Toggle vertical/horizontal window split.
2667 Does nothing if file-A and file-B are in different frames."
2669 (let* ((wind-A (get-buffer-window ediff-A-buffer t))
2670 (wind-B (get-buffer-window ediff-B-buffer t))
2671 (frame-A (if wind-A (ediff-window-frame wind-A)))
2672 (frame-B (if wind-B (ediff-window-frame wind-B))))
2673 (if (eq frame-A frame-B)
2674 (setq ediff-split-window-function
2675 (if (eq ediff-split-window-function 'split-window-vertically)
2676 'split-window-horizontally
2677 'split-window-vertically))
2678 (message "No splitting: Buffers A and B are in different frames."))
2679 (ediff-recenter 'no-rehighlight)))
2681 (defun ediff-toggle-hilit ()
2682 "Switch between highlighting using ASCII flags and highlighting using faces.
2683 On a dumb terminal, switches between ASCII highlighting and no highlighting."
2685 (if (not window-system)
2686 (if (eq ediff-highlighting-style 'ascii)
2688 (message "ASCII highlighting flags removed.")
2689 (ediff-unselect-and-select-difference ediff-current-difference
2691 (setq ediff-highlighting-style 'off))
2692 (ediff-unselect-and-select-difference ediff-current-difference
2694 (ediff-unselect-and-select-difference ediff-current-difference
2696 ;; cycle through highlighting
2697 (cond ((and ediff-want-faces ediff-highlight-all-diffs)
2698 (message "Unhighlighting unselected difference regions.")
2699 (setq ediff-highlight-all-diffs nil))
2701 (message "Highlighting with ASCII flags.")
2702 (setq ediff-want-faces nil))
2704 (message "Re-highlighting all difference regions.")
2705 (setq ediff-want-faces t
2706 ediff-highlight-all-diffs t)))
2708 (if (and ediff-want-faces ediff-highlight-all-diffs)
2709 (if (not (face-differs-from-default-p 'ediff-odd-diff-face-A-var))
2711 (copy-face ediff-odd-diff-face-A 'ediff-odd-diff-face-A-var)
2712 (copy-face ediff-odd-diff-face-B 'ediff-odd-diff-face-B-var)
2713 (copy-face ediff-even-diff-face-A 'ediff-even-diff-face-A-var)
2714 (copy-face ediff-even-diff-face-B 'ediff-even-diff-face-B-var)))
2715 (copy-face 'default 'ediff-odd-diff-face-A-var)
2716 (copy-face 'default 'ediff-odd-diff-face-B-var)
2717 (copy-face 'default 'ediff-even-diff-face-A-var)
2718 (copy-face 'default 'ediff-even-diff-face-B-var))
2720 (ediff-unselect-and-select-difference
2721 ediff-current-difference 'select-only))
2722 (ediff-operate-on-flags 'insert)
2725 (defun ediff-toggle-autorefine ()
2726 "Toggle auto-refine mode."
2729 (cond ((eq ediff-auto-refine 'nix)
2730 (setq ediff-auto-refine 'on)
2731 (ediff-make-fine-diffs ediff-current-difference 'noforce)
2732 (message "Auto-refining is ON."))
2733 ((eq ediff-auto-refine 'on)
2734 (message "Auto-refining is OFF.")
2735 (setq ediff-auto-refine 'off))
2737 (ediff-set-fine-diff-properties ediff-current-difference 'default)
2738 (message "Refinements are HIDDEN.")
2739 (setq ediff-auto-refine 'nix))
2742 (defun ediff-toggle-help ()
2743 "Toggle short/long help message."
2745 (let (buffer-read-only)
2747 (if (string= ediff-help-message ediff-help-message-long)
2748 (setq ediff-help-message ediff-help-message-short)
2749 (setq ediff-help-message ediff-help-message-long)))
2750 (setq ediff-window-config-saved "") ;; force redisplay
2751 (ediff-recenter 'no-rehighlight))
2754 (defun ediff-toggle-read-only-A ()
2755 "Used as a startup hook to set `.orig' patch file read-only."
2756 (let ((last-command-char ?A))
2757 (ediff-toggle-read-only)))
2759 (defun ediff-toggle-read-only ()
2760 "Toggles buffer-read-only for buffer buffers A and B."
2762 (ediff-eval-in-buffer
2763 (if (eq last-command-char ?A) ediff-A-buffer ediff-B-buffer)
2764 (setq buffer-read-only (null buffer-read-only))))
2766 ;;; Window scrolling operations
2767 ;; These operations are designed to scroll all three windows the same amount,
2768 ;; so as to keep the text in them aligned.
2770 ;; Perform some operation on the two file windows (if they are showing).
2771 ;; Catches all errors on the operation in the A and B windows.
2772 ;; Usually, errors come from scrolling off the
2773 ;; beginning or end of the buffer, and this gives nice nice error messages.
2774 (defun ediff-operate-on-windows (operation arg)
2775 (let* ((buffer-A ediff-A-buffer)
2776 (buffer-B ediff-B-buffer)
2777 (wind (selected-window))
2778 (window-A (get-buffer-window buffer-A t))
2779 (window-B (get-buffer-window buffer-B t)))
2781 (select-window window-A)
2783 (funcall operation arg)
2786 (select-window window-B)
2788 (funcall operation arg)
2790 (select-window wind)
2793 (defun ediff-scroll-up (&optional arg)
2794 "Scroll up buffers A and B, if they are in windows.
2795 With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
2796 the height of window-A."
2798 (ediff-operate-on-windows
2800 ;; calculate argument to scroll-up
2801 ;; if there is an explicit argument
2802 (if (and arg (not (equal arg '-)))
2804 (prefix-numeric-value arg)
2805 ;; if not, see if we can determine a default amount (the window height)
2806 (let* ((window-A (get-buffer-window ediff-A-buffer t))
2807 (window-B (get-buffer-window ediff-B-buffer t))
2809 (if (or (null window-A) (null window-B))
2810 (setq default-amount 0)
2811 (setq default-amount
2812 (- (min (window-height window-A) (window-height window-B))
2813 1 next-screen-context-lines)))
2814 ;; the window was found
2816 ;; C-u as argument means half of default amount
2817 (/ default-amount 2)
2818 ;; no argument means default amount
2821 (defun ediff-scroll-down (&optional arg)
2822 "Scroll down buffers A and B, if they are in windows.
2823 With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
2824 the height of window-A."
2826 (ediff-operate-on-windows
2828 ;; calculate argument to scroll-down
2829 ;; if there is an explicit argument
2830 (if (and arg (not (equal arg '-)))
2832 (prefix-numeric-value arg)
2833 ;; if not, see if we can determine a default amount (the window height)
2834 (let* ((window-A (get-buffer-window ediff-A-buffer t))
2835 (window-B (get-buffer-window ediff-B-buffer t))
2837 (if (or (null window-A) (null window-B))
2838 (setq default-amount 0)
2839 (setq default-amount
2840 (- (min (window-height window-A) (window-height window-B))
2841 1 next-screen-context-lines)))
2842 ;; the window was found
2844 ;; C-u as argument means half of default amount
2845 (/ default-amount 2)
2846 ;; no argument means default amount
2849 (defun ediff-scroll-left (&optional arg)
2850 "Scroll left buffer-A and buffer-B, if they are in windows.
2851 If an argument is given, that is how many columns are scrolled, else nearly
2852 the width of the A and B windows."
2854 (ediff-operate-on-windows
2856 ;; calculate argument to scroll-left
2857 ;; if there is an explicit argument
2858 (if (and arg (not (equal arg '-)))
2860 (prefix-numeric-value arg)
2861 ;; if not, see if we can determine a default amount
2862 ;; (half the window width)
2863 (if (null ediff-control-window)
2864 ;; no control window, use nil
2866 (let ((default-amount
2867 (- (/ (window-width ediff-control-window) 2) 3)))
2868 ;; the window was found
2870 ;; C-u as argument means half of default amount
2871 (/ default-amount 2)
2872 ;; no argument means default amount
2873 default-amount))))))
2875 (defun ediff-scroll-right (&optional arg)
2876 "Scroll right buffer-A and buffer-B, if they are in windows.
2877 If an argument is given, that is how many columns are scrolled, else nearly
2878 the width of the A and B windows."
2880 (ediff-operate-on-windows
2882 ;; calculate argument to scroll-right
2883 ;; if there is an explicit argument
2884 (if (and arg (not (equal arg '-)))
2886 (prefix-numeric-value arg)
2887 ;; if not, see if we can determine a default amount
2888 ;; (half the window width)
2889 (if (null ediff-control-window)
2890 ;; no control window, use nil
2892 (let ((default-amount
2893 (- (/ (window-width ediff-control-window) 2) 3)))
2894 ;; the window was found
2896 ;; C-u as argument means half of default amount
2897 (/ default-amount 2)
2898 ;; no argument means default amount
2899 default-amount))))))
2901 (defun ediff-position-region (beg end pos)
2902 "This is a variation on `emerge-position-region'.
2903 The difference is that it always tries to align difference regions in
2904 buffer-A and buffer-B, so that it will be easier to compare them."
2905 (set-window-start (selected-window) beg)
2906 (if (pos-visible-in-window-p end)
2907 ;; Determine the number of lines that the region occupies
2909 (while (> end (progn
2910 (move-to-window-line lines)
2912 (setq lines (1+ lines)))
2913 ;; And position the beginning on the right line
2915 (recenter (/ (1+ (max (- (1- (window-height (selected-window)))
2924 (defun ediff-next-difference (&optional arg)
2925 "Advance to the next difference.
2926 With a prefix argument, go back that many differences."
2928 (if (< ediff-current-difference ediff-number-of-differences)
2929 (let ((n (min ediff-number-of-differences
2930 (+ ediff-current-difference (if arg arg 1))))
2931 (buffer-read-only nil))
2932 (while (funcall ediff-skip-diff-region-function n)
2934 (ediff-unselect-and-select-difference n))
2935 (error "At end of the difference list.")))
2937 (defun ediff-previous-difference (&optional arg)
2938 "Go to the previous difference.
2939 With a prefix argument, go back that many differences."
2941 (if (> ediff-current-difference -1)
2942 (let ((n (max -1 (- ediff-current-difference (if arg arg 1))))
2943 (buffer-read-only nil))
2944 (while (funcall ediff-skip-diff-region-function n)
2946 (ediff-unselect-and-select-difference n))
2947 (error "At beginning of the difference list.")))
2949 (defun ediff-jump-to-difference (difference-number)
2950 "Go to the difference specified as a prefix argument."
2952 (let ((buffer-read-only nil))
2953 (setq difference-number (1- difference-number))
2954 (if (and (>= difference-number -1)
2955 (< difference-number (1+ ediff-number-of-differences)))
2956 (ediff-unselect-and-select-difference difference-number)
2957 (error "Bad difference number"))))
2959 (defun ediff-jump-to-difference-at-point ()
2960 "Go to the difference closest to the point in buffer A or B.
2961 If this command is invoked via `\\[ediff-jump-to-difference-at-point]'
2962 then the point in buffer B is used.
2963 Otherwise, buffer A's point is used."
2965 (let ((buffer-read-only nil)
2966 (buf-type (ediff-char-to-buftype last-command-char)))
2967 (ediff-jump-to-difference (ediff-diff-at-point buf-type))))
2970 ;; find region "most related to the current point position
2972 (defun ediff-diff-at-point (buf-type)
2973 (let ((buffer (ediff-get-buffer buf-type))
2974 (ctl-buffer ediff-control-buffer)
2975 (max-dif-num (1- ediff-number-of-differences))
2982 (ediff-eval-in-buffer
2984 (while (and (or (< (point) prev-beg) (> (point) beg))
2985 (< diff-no max-dif-num))
2986 (setq diff-no (1+ diff-no))
2989 (setq beg (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer)
2990 end (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
2993 (if (< (abs (- (point) prev-end))
2994 (abs (- (point) beg)))
2996 (1+ diff-no)) ;; jump-to-diff works with diff nums higher by 1
3001 (defun ediff-diff-to-diff (arg)
3002 "Copy buffer-A'th diff to buffer B.
3003 If numerical prefix argument, copy this diff specified in the arg.
3004 Otherwise, copy the difference given by `ediff-current-difference'."
3007 (ediff-jump-to-difference arg))
3008 (let* ((key1 (aref (this-command-keys) 0))
3009 (key2 (aref (this-command-keys) 1))
3010 (char1 (if (ediff-if-lucid) (event-key key1) key1))
3011 (char2 (if (ediff-if-lucid) (event-key key2) key2)))
3012 (ediff-copy-diff ediff-current-difference
3013 (ediff-char-to-buftype char1)
3014 (ediff-char-to-buftype char2))
3015 (ediff-recenter 'no-rehighlight)))
3018 (defun ediff-copy-diff (n from-buf-type to-buf-type)
3019 "Copy diff N from FROM-BUF-TYPE \(given as 'A or 'B\) to TO-BUF-TYPE."
3020 (let* ((to-buf (ediff-get-buffer to-buf-type))
3021 (from-buf (ediff-get-buffer from-buf-type))
3022 (ctrl-buf ediff-control-buffer)
3023 reg-to-copy reg-to-delete
3024 reg-to-delete-beg reg-to-delete-end)
3026 (ediff-operate-on-flags 'remove)
3027 (setq reg-to-delete-beg
3028 (ediff-get-diff-posn to-buf-type 'beg n ctrl-buf))
3029 (setq reg-to-delete-end
3030 (ediff-get-diff-posn to-buf-type 'end n ctrl-buf))
3031 (setq reg-to-copy (ediff-eval-in-buffer
3033 (buffer-substring (ediff-get-diff-posn
3034 from-buf-type 'beg n ctrl-buf)
3035 (ediff-get-diff-posn
3036 from-buf-type 'end n ctrl-buf))))
3037 (setq reg-to-delete (ediff-eval-in-buffer
3039 (buffer-substring reg-to-delete-beg
3040 reg-to-delete-end)))
3041 (setq ediff-disturbed-overlays nil) ;; clear before use
3043 (if (string= reg-to-delete reg-to-copy)
3047 "Diff regions %d are identical in buffers %S and %S. Nothing copied."
3048 (1+ n) from-buf-type to-buf-type))
3051 (if (ediff-test-save-region n to-buf-type)
3052 (condition-case conds
3053 (let (inhibit-read-only)
3054 (ediff-eval-in-buffer
3056 ;; to prevent flags from interfering if buffer is writable
3057 (setq inhibit-read-only (null buffer-read-only))
3058 (let ((before-change-function nil))
3059 (goto-char reg-to-delete-end)
3060 (insert-before-markers reg-to-copy)
3061 (if (ediff-if-lucid)
3063 (ediff-collect-extents-lucid reg-to-delete-beg)
3064 (if (> reg-to-delete-end reg-to-delete-beg)
3066 (kill-region reg-to-delete-beg
3068 (if (string= reg-to-copy "")
3069 (ediff-adjust-disturbed-extents-lucid
3070 reg-to-delete-beg)))))
3071 (if (> reg-to-delete-end reg-to-delete-beg)
3072 (kill-region reg-to-delete-beg reg-to-delete-end)
3073 (ediff-move-disturbed-overlays reg-to-delete-beg)))
3075 (ediff-save-diff-region n to-buf-type reg-to-delete))
3076 (error (message "%s %s"
3078 (mapconcat 'prin1-to-string (cdr conds) " "))
3081 (ediff-operate-on-flags 'insert)
3084 (defun ediff-save-diff-region (n buf-type reg)
3085 "Save Nth diff of buffer BUF-TYPE \(`A' or `B'\).
3086 That is to say, the Nth diff on the `ediff-killed-diffs-alist'. REG
3087 is the region to save. It is redundant here, but is passed anyway, for
3090 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
3091 (this-buf-n-th-diff-saved (assoc buf-type (cdr n-th-diff-saved))))
3093 (if this-buf-n-th-diff-saved
3094 ;; either nothing saved for n-th diff and buffer or we OK'ed
3096 (setcdr this-buf-n-th-diff-saved reg)
3097 (if n-th-diff-saved ;; n-th diff saved, but for another buffer
3098 (nconc n-th-diff-saved (list (cons buf-type reg)))
3099 (setq ediff-killed-diffs-alist ;; create record for n-th diff
3100 (cons (list n (cons buf-type reg))
3101 ediff-killed-diffs-alist))))
3102 (message "Saved diff region #%d for buffer %S. To recover hit 'r%s'."
3104 (downcase (symbol-name buf-type)))))
3106 (defun ediff-test-save-region (n buf-type)
3107 "Test if saving Nth difference region of buffer BUF-TYPE is possible."
3108 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
3109 (this-buf-n-th-diff-saved (assoc buf-type (cdr n-th-diff-saved))))
3111 (if this-buf-n-th-diff-saved
3114 "You've previously copied diff region %d to buffer %S. Confirm."
3120 (defun ediff-pop-diff (n buf-type)
3121 "Pop last killed Nth diff region from buffer BUF-TYPE."
3122 (let* ((n-th-record (assoc n ediff-killed-diffs-alist))
3123 (saved-rec (assoc buf-type (cdr n-th-record)))
3124 (buf (ediff-get-buffer buf-type))
3125 saved-diff reg-beg reg-end recovered)
3128 (setq saved-diff (cdr saved-rec))
3129 (if (> ediff-number-of-differences 0)
3130 (error "Nothing saved for diff %d in buffer %S." (1+ n) buf-type)
3131 (error "No differences found.")))
3133 (ediff-operate-on-flags 'remove)
3135 (setq reg-beg (ediff-get-diff-posn buf-type 'beg n ediff-control-buffer))
3136 (setq reg-end (ediff-get-diff-posn buf-type 'end n ediff-control-buffer))
3137 (setq ediff-disturbed-overlays nil) ;; clear before use
3139 (condition-case conds
3140 (ediff-eval-in-buffer
3142 (let ((inhibit-read-only (null buffer-read-only))
3143 (before-change-function nil))
3145 (insert-before-markers saved-diff)
3147 (if (ediff-if-lucid)
3149 (ediff-collect-extents-lucid reg-beg)
3150 (if (> reg-end reg-beg)
3152 (kill-region reg-beg reg-end)
3153 (if (string= saved-diff "")
3154 (ediff-adjust-disturbed-extents-lucid reg-beg)))))
3155 (if (> reg-end reg-beg)
3156 (kill-region reg-beg reg-end)
3157 (ediff-move-disturbed-overlays reg-beg)))
3161 (error (message "%s %s"
3163 (mapconcat 'prin1-to-string (cdr conds) " "))
3166 (ediff-operate-on-flags 'insert)
3169 (setq n-th-record (delq saved-rec n-th-record))
3170 (message "Restored diff region %d in buffer %S." (1+ n) buf-type)))
3173 (defun ediff-restore-diff (arg)
3174 "Restore ARGth diff from `ediff-killed-diffs-alist'.
3175 ARG is a prefix argument. If ARG is nil, restore current-difference."
3178 (ediff-jump-to-difference arg))
3179 (ediff-pop-diff ediff-current-difference
3180 (ediff-char-to-buftype last-command-char))
3181 (ediff-recenter 'no-rehighlight))
3183 (defun ediff-toggle-regexp-match ()
3184 "Focus on difference regions that match a regexp or hide those diffs."
3186 (let (regexp-A regexp-B)
3188 ((or (and (eq ediff-skip-diff-region-function 'ediff-focus-on-regexp-matches)
3189 (eq last-command-char ?f))
3190 (and (eq ediff-skip-diff-region-function 'ediff-hide-regexp-matches)
3191 (eq last-command-char ?h)))
3192 (message "Show all difference regions.")
3193 (setq ediff-skip-diff-region-function 'ediff-show-all-diffs))
3194 ((eq last-command-char ?h)
3195 (setq ediff-skip-diff-region-function 'ediff-hide-regexp-matches
3199 "Ignore A-regions matching this regexp (default \"%s\"): "
3200 (regexp-quote ediff-regexp-hide-A)))
3204 "Ignore B-regions matching this regexp (default \"%s\"): "
3205 (regexp-quote ediff-regexp-hide-B))))
3206 (message "Hide difference regions matching regexp.")
3207 (or (string= regexp-A "") (setq ediff-regexp-hide-A regexp-A))
3208 (or (string= regexp-B "") (setq ediff-regexp-hide-B regexp-B)))
3209 ((eq last-command-char ?f)
3210 (setq ediff-skip-diff-region-function 'ediff-focus-on-regexp-matches
3214 "Focus on A-regions matching this regexp (default \"%s\"): "
3215 (regexp-quote ediff-regexp-focus-A)))
3219 "Focus on B-regions matching this regexp (default \"%s\"): "
3220 (regexp-quote ediff-regexp-focus-B))))
3221 (message "Focus on difference regions matching regexp.")
3222 (or (string= regexp-A "") (setq ediff-regexp-focus-A regexp-A))
3223 (or (string= regexp-B "") (setq ediff-regexp-focus-B regexp-B))))))
3225 (defun ediff-show-all-diffs (n)
3226 "Don't skip difference regions."
3229 (defun ediff-focus-on-regexp-matches (n)
3230 "Focus on diffs that match regexp `ediff-regexp-focus-A/B'.
3231 Regions to be ignored according to this function are those where
3232 buf A region doesn't match `ediff-regexp-focus-A' and buf B region
3233 doesn't match `ediff-regexp-focus-B'.
3234 This function should return nil for regions not to be ignored and t for
3235 regions to be ignored."
3236 (if (and (>= n 0) (< n ediff-number-of-differences))
3237 (let* ((ctl-buf ediff-control-buffer)
3238 (reg-A-match (ediff-eval-in-buffer
3240 (goto-char (ediff-get-diff-posn 'A 'beg n ctl-buf))
3242 ediff-regexp-focus-A
3243 (ediff-get-diff-posn 'A 'end n ctl-buf)
3245 (reg-B-match (ediff-eval-in-buffer
3247 (goto-char (ediff-get-diff-posn 'B 'beg n ctl-buf))
3249 ediff-regexp-focus-B
3250 (ediff-get-diff-posn 'B 'end n ctl-buf)
3252 (not (and reg-A-match reg-B-match)))))
3254 (defun ediff-hide-regexp-matches (n)
3255 "Hide diffs that match regexp `ediff-regexp-hide-A/B'.
3256 Regions to be ignored are those where buf A region matches
3257 `ediff-regexp-hide-A' and buf B region matches `ediff-regexp-hide-B'.
3258 This function returns nil for regions not to be ignored and t for regions
3260 (if (and (>= n 0) (< n ediff-number-of-differences))
3261 (let* ((ctl-buf ediff-control-buffer)
3262 (reg-A-match (ediff-eval-in-buffer
3264 (goto-char (ediff-get-diff-posn 'A 'beg n ctl-buf))
3267 (ediff-get-diff-posn 'A 'end n ctl-buf)
3269 (reg-B-match (ediff-eval-in-buffer
3271 (goto-char (ediff-get-diff-posn 'B 'beg n ctl-buf))
3274 (ediff-get-diff-posn 'B 'end n ctl-buf)
3276 (and reg-A-match reg-B-match))))
3279 ;;; Quitting, suspending, etc.
3280 (defun ediff-quit ()
3281 "Finish an Ediff session and exit Ediff.
3282 Unselects the selected difference, if any, restores the read-only and modified
3283 flags of the compared file buffers, kills Ediff buffers for this session
3284 \(but not file-A and file-B\)."
3287 (y-or-n-p "Do you really want to exit Ediff? ")
3289 (ediff-really-quit)))
3292 ;; Perform the quit operations.
3293 (defun ediff-really-quit ()
3294 (setq ediff-help-message ediff-help-message-long)
3295 (ediff-restore-buffer-characteristics t) ;; restore as they were at setup
3296 (ediff-unhighlight-diffs-totally)
3297 (ediff-clear-diff-vector ediff-difference-vector 'fine-diffs-also)
3298 (if ediff-temp-file-A (delete-file ediff-temp-file-A))
3299 (if ediff-temp-file-B (delete-file ediff-temp-file-B))
3301 ;; restore buffer mode line id's in buffer-A/B
3302 (let ((control-buffer ediff-control-buffer))
3304 (ediff-eval-in-buffer
3306 (setq before-change-function nil)
3307 (setq ediff-this-buffer-control-sessions
3308 (delq control-buffer ediff-this-buffer-control-sessions))
3309 (if (null ediff-this-buffer-control-sessions)
3310 (setq local-write-file-hooks
3311 (delq 'ediff-block-write-file local-write-file-hooks)))
3312 (kill-local-variable 'mode-line-buffer-identification))
3316 (ediff-eval-in-buffer
3318 (setq ediff-this-buffer-control-sessions
3319 (delq control-buffer ediff-this-buffer-control-sessions))
3320 (if (null ediff-this-buffer-control-sessions)
3321 (setq local-write-file-hooks
3322 (delq 'ediff-block-write-file local-write-file-hooks)))
3323 (setq before-change-function nil)
3324 (kill-local-variable 'mode-line-buffer-identification))
3327 (run-hooks 'ediff-quit-hooks))
3329 (defun ediff-kill-buffer-carefully (buf)
3330 "Kill buffer BUF if it exists."
3331 (if (ediff-buffer-live-p buf)
3332 (kill-buffer (get-buffer buf))))
3334 ;; The default way of quitting Ediff.
3335 ;; Kills control buffers and leaves the
3336 ;; frame split between the two diff'ed files.
3337 (defun ediff-default-quit-hook ()
3338 (let ((buff-A ediff-A-buffer)
3339 (buff-B ediff-B-buffer))
3340 (ediff-kill-buffer-carefully ediff-diff-buffer)
3341 (ediff-kill-buffer-carefully ediff-tmp-buffer)
3342 (ediff-kill-buffer-carefully ediff-error-buffer)
3343 (ediff-kill-buffer-carefully ediff-control-buffer)
3344 (ediff-kill-buffer-carefully ediff-patch-diagnostics)
3345 (delete-other-windows)
3346 ;; display only if not visible
3349 (or (get-buffer-window buff-B t)
3350 (switch-to-buffer buff-B))
3353 (or (get-buffer-window buff-A t)
3355 (if (get-buffer-window buff-B)
3356 (split-window-vertically))
3357 (switch-to-buffer buff-A)))
3362 ;; The default way of suspending Ediff.
3363 ;; Buries Ediff buffers, kills all windows.
3364 (defun ediff-default-suspend-hook ()
3365 (let ((buf-A ediff-A-buffer)
3366 (buf-B ediff-B-buffer)
3367 (buf-patch ediff-patch-buf)
3368 (buf-patch-diag ediff-patch-diagnostics)
3369 (buf-err ediff-error-buffer)
3370 (buf-diff ediff-diff-buffer))
3371 (bury-buffer) ;; ediff-control-buffer
3372 (delete-other-windows)
3373 (bury-buffer buf-err)
3374 (bury-buffer buf-diff)
3375 (bury-buffer buf-patch)
3376 (bury-buffer buf-patch-diag)
3378 (bury-buffer buf-B)))
3381 (defun ediff-suspend ()
3383 To resume, switch to the appropriate `Ediff Control Panel'
3384 buffer and then type \\[ediff-recenter]. Ediff will automatically set
3385 up an appropriate window config."
3387 (let ((key (substitute-command-keys "\\[ediff-recenter]")))
3388 (run-hooks 'ediff-suspend-hooks)
3390 "To resume Ediff, switch to Ediff Control Panel and hit '%S'" key)))
3393 (defun ediff-status-info ()
3394 "Show the names of the buffers or files being operated on by Ediff.
3395 Hit \\[ediff-recenter] to reset the windows afterward."
3397 (with-output-to-temp-buffer " *ediff-info*"
3398 (ediff-eval-in-buffer ediff-A-buffer
3399 (if buffer-file-name
3401 (format "File A is: %s\n" buffer-file-name))
3403 (format "Buffer A is: %s\n" (buffer-name)))))
3404 (ediff-eval-in-buffer ediff-B-buffer
3405 (if buffer-file-name
3407 (format "File B is: %s\n" buffer-file-name))
3409 (format "Buffer B is: %s\n" (buffer-name)))))
3411 (let* ((A-line (ediff-eval-in-buffer ediff-A-buffer
3412 (count-lines (point-min) (point))))
3413 (B-line (ediff-eval-in-buffer ediff-B-buffer
3414 (count-lines (point-min) (point)))))
3415 (princ (format "\nPoint position in buffer A = %d\n" A-line))
3416 (princ (format "Point position in buffer B = %d\n" B-line)))
3418 (princ (format "\nCurrent difference number = %d\n"
3419 (1+ ediff-current-difference)))
3421 (cond ((eq ediff-skip-diff-region-function 'ediff-show-all-diffs)
3422 (princ "\nSelective browsing is not in effect.\n"))
3423 ((eq ediff-skip-diff-region-function 'ediff-hide-regexp-matches)
3425 "\nSelective browsing is in effect. Ignoring diff regions that:")
3427 (format "\n match `%s' in buffer A and `%s' in buffer B\n"
3428 ediff-regexp-hide-A ediff-regexp-hide-B)))
3429 ((eq ediff-skip-diff-region-function 'ediff-focus-on-regexp-matches)
3431 "\nSelective browsing is in effect. Focus on diff regions that:")
3433 (format "\n match `%s' in buffer A and `%s' in buffer B\n"
3434 ediff-regexp-focus-A ediff-regexp-focus-B))))
3436 (princ "\nBug fixes to: Michael Kifer <kifer@cs.sunysb.edu>\n")
3437 (princ "Gripes to: /dev/null <dev@null.gov>\n")
3442 ;;; Support routines
3444 ;; Select a difference by placing the ASCII flags around the appropriate
3445 ;; group of lines in the A, B buffers
3446 (defun ediff-select-difference (n)
3447 (if (and (ediff-buffer-live-p ediff-A-buffer)
3448 (ediff-buffer-live-p ediff-B-buffer)
3449 (>= n 0) (< n ediff-number-of-differences))
3451 (ediff-remember-buffer-characteristics)
3452 (if (and window-system ediff-want-faces)
3454 (ediff-highlight-diff n)
3455 (setq ediff-highlighting-style 'face))
3456 (setq ediff-highlighting-style 'ascii)
3457 (ediff-place-flags-in-buffer 'A ediff-A-buffer
3458 ediff-control-buffer n)
3459 (ediff-place-flags-in-buffer 'B ediff-B-buffer
3460 ediff-control-buffer n))
3463 (cond ((eq ediff-auto-refine 'on)
3465 (> ediff-auto-refine-limit
3466 (- (ediff-get-diff-posn 'A 'end n)
3467 (ediff-get-diff-posn 'A 'beg n)))
3468 (> ediff-auto-refine-limit
3469 (- (ediff-get-diff-posn 'B 'end n)
3470 (ediff-get-diff-posn 'B 'beg n))))
3471 (ediff-make-fine-diffs n 'noforce)
3472 (ediff-make-fine-diffs n 'skip)))
3474 ((eq ediff-auto-refine 'off) ; highlight iff fine diffs
3475 (ediff-make-fine-diffs n 'skip)))) ; already exist
3477 (ediff-restore-buffer-characteristics)
3478 (run-hooks 'ediff-select-hooks))))
3481 ;; Unselect a difference by removing the ASCII flags in the buffers.
3482 (defun ediff-unselect-difference (n)
3483 (if (and (>= n 0) (< n ediff-number-of-differences))
3485 (ediff-remember-buffer-characteristics)
3487 (cond ((and window-system ediff-want-faces)
3488 (ediff-unhighlight-diff))
3489 ((eq ediff-highlighting-style 'ascii)
3490 (ediff-remove-flags-from-buffer
3492 (ediff-get-diff-posn 'A 'beg n)
3493 (ediff-get-diff-posn 'A 'end n)
3494 ediff-before-flag-A ediff-after-flag-A)
3495 (ediff-remove-flags-from-buffer
3497 (ediff-get-diff-posn 'B 'beg n)
3498 (ediff-get-diff-posn 'B 'end n)
3499 ediff-before-flag-B ediff-after-flag-B)))
3501 (ediff-restore-buffer-characteristics)
3502 (setq ediff-highlighting-style nil)
3504 ;; unhighlight fine diffs
3506 (ediff-set-fine-diff-properties
3507 ediff-current-difference 'default))
3509 (run-hooks 'ediff-unselect-hooks))))
3512 ;; Unselects prev diff and selects a new one, if FLAG has value other than
3513 ;; 'select-only or 'unselect-only. If FLAG is 'select-only, the
3514 ;; next difference is selected, but the current selection is not
3515 ;; unselected. If FLAG is 'unselect-only then the current selection is
3516 ;; unselected, but the next one is not selected. If NO-RECENTER is non-nil,
3517 ;; don't recenter buffers after selecting/unselecting.
3519 ;; Don't use `ediff-select-difference' and `ediff-unselect-difference'
3520 ;; directly, since this will screw up the undo info in the presence of
3522 ;; Instead, use `ediff-unselect-and-select-difference' with appropriate
3525 (defun ediff-unselect-and-select-difference (n &optional flag no-recenter)
3526 (let (;; save buf modified info
3527 (control-buf ediff-control-buffer)
3528 (buf-A-modified (buffer-modified-p ediff-A-buffer))
3529 (buf-B-modified (buffer-modified-p ediff-B-buffer))
3530 ;; temporarily disable undo so highlighting won't confuse the user
3531 buf-A-undo buf-B-undo)
3533 (let ((ediff-current-difference n))
3535 (ediff-recenter 'no-rehighlight)))
3537 (if (and (ediff-buffer-live-p ediff-A-buffer)
3538 (ediff-buffer-live-p ediff-B-buffer))
3540 (ediff-eval-in-buffer
3542 (setq buf-A-undo buffer-undo-list))
3543 (ediff-eval-in-buffer
3545 (setq buf-B-undo buffer-undo-list))
3547 (buffer-disable-undo ediff-A-buffer)
3548 (buffer-disable-undo ediff-B-buffer)))
3550 (unwind-protect ;; we don't want to lose undo info due to error
3552 (or (eq flag 'select-only)
3553 (ediff-unselect-difference ediff-current-difference))
3555 ;; Auto-save buffers while Ediff flags are temporarily removed.
3556 (ediff-eval-in-buffer
3560 (ediff-eval-in-buffer
3565 (or (eq flag 'unselect-only)
3566 (ediff-select-difference n))
3567 (setq ediff-current-difference n)
3568 ) ;; end protected section
3570 (ediff-eval-in-buffer
3572 (ediff-refresh-mode-line)
3573 ;; restore undo and buffer-modified info
3574 (ediff-eval-in-buffer
3576 (set-buffer-modified-p buf-A-modified)
3577 (setq buffer-undo-list buf-A-undo)))
3579 (ediff-eval-in-buffer
3581 (ediff-eval-in-buffer
3583 (set-buffer-modified-p buf-B-modified)
3584 (setq buffer-undo-list buf-B-undo)))
3587 ;; Revise the mode line to display which difference we have selected
3589 (defun ediff-refresh-mode-line ()
3590 (setq mode-line-buffer-identification
3591 (cond ((< ediff-current-difference 0)
3592 (list (format "%%b: At start of %d diffs"
3593 ediff-number-of-differences)))
3594 ((>= ediff-current-difference ediff-number-of-differences)
3595 (list (format "%%b: At end of %d diffs"
3596 ediff-number-of-differences)))
3598 (list (format "%%b: diff %d of %d"
3599 (1+ ediff-current-difference)
3600 ediff-number-of-differences)))))
3601 ;; Force mode-line redisplay
3602 (force-mode-line-update))
3606 ;; Verify that we have a difference selected.
3607 (defun ediff-validate-difference ()
3608 (if (not (and (>= ediff-current-difference 0)
3609 (< ediff-current-difference ediff-number-of-differences)))
3610 (error "No difference selected")))
3612 (defun ediff-read-file-name (prompt default-dir default-file)
3613 ; This is a modified version of a similar function in `emerge.el'.
3614 ; PROMPT should not have trailing ': ', so that it can be modified
3615 ; according to context.
3616 ; If default-file is set, it should be used as the default value.
3617 ; If default-dir is non-nil, use it as the default directory.
3618 ; Otherwise, use the value of Emacs' variable `default-directory.'
3620 ;; hack default-dir if it is not set
3622 (file-name-as-directory
3623 (abbreviate-file-name
3624 (expand-file-name (or default-dir
3626 (file-name-directory default-file))
3627 default-directory)))))
3629 ;; strip the directory from default-file
3631 (setq default-file (file-name-nondirectory default-file)))
3634 (setq f (expand-file-name
3639 (concat " (default " default-file ")")
3648 ;; If user enters a directory name, expand the default file in that
3649 ;; directory. This allows the user to enter a directory name for the
3650 ;; B-file and diff against the default-file in that directory instead
3651 ;; of a DIRED listing!
3652 (if (and (file-directory-p f) default-file)
3653 (setq f (expand-file-name
3654 (file-name-nondirectory default-file) f)))
3657 ;; If `prefix' is given, then it is used as a prefix for the temp file
3658 ;; name. Otherwise, `.buffer-name' is used. If `file' is given, use this
3659 ;; file and don't create a new one.
3660 (defun ediff-make-temp-file (&optional prefix given-file)
3661 (let ((f (or given-file
3662 (make-temp-name (concat
3663 ediff-temp-file-prefix
3669 (write-region (point-min) (point-max) f nil 'no-message)
3670 (set-file-modes f ediff-temp-file-mode)
3673 ;; Quote metacharacters (using \) when executing diff in Unix, but not in
3675 (defun ediff-protect-metachars (str)
3676 (or (eq system-type 'emx)
3678 (while (string-match emerge-metachars str limit)
3679 (setq str (concat (substring str 0 (match-beginning 0))
3681 (substring str (match-beginning 0))))
3682 (setq limit (1+ (match-end 0))))))
3685 ;; Make sure the current buffer (for a file) has the same contents as the
3686 ;; file on disk, and attempt to remedy the situation if not.
3687 ;; Signal an error if we can't make them the same, or the user doesn't want
3688 ;; to do what is necessary to make them the same.
3689 ;; If file has file handlers (indicated by the optional arg), then we
3690 ;; offer to instead of saving. This is one difference with Emerge.
3691 ;; Another is that we always offer to revert obsolete files, whether they
3692 ;; are modified or not.
3693 (defun ediff-verify-file-buffer (&optional file-magic)
3694 ;; First check if the file has been modified since the buffer visited it.
3695 (if (verify-visited-file-modtime (current-buffer))
3696 (if (buffer-modified-p)
3697 ;; If buffer is not obsolete and is modified, offer to save
3699 (format "Buffer out of sync with visited file. %s file %s? "
3700 (if file-magic "Revert" "Save")
3702 (if (not file-magic)
3704 ;; for some reason, file-name-handlers append instead of
3705 ;; replacing, so we have to erase first.
3707 (revert-buffer t t))
3708 (error "Buffer out of sync for file %s" buffer-file-name))
3709 ;; If buffer is not obsolete and is not modified, do nothing
3711 ;; If buffer is obsolete, offer to revert
3713 (format "Buffer out of sync with visited file. Revert file %s? "
3718 (revert-buffer t t))
3719 (error "Buffer out of sync for file %s" buffer-file-name))))
3722 (defun ediff-block-write-file ()
3723 "Prevent writing files A and B directly."
3724 (if (ediff-check-for-ascii-flags)
3725 (error "Type 'wa' and 'wb' in Ediff Control Panel to save buffs A/B.")))
3727 (defun ediff-check-for-ascii-flags ()
3730 (mapcar (function (lambda (buf)
3731 (if (ediff-buffer-live-p buf)
3732 (ediff-eval-in-buffer
3734 (eq ediff-highlighting-style 'ascii)))))
3735 ediff-this-buffer-control-sessions))))
3737 (defun ediff-insert-in-front (overl beg end)
3738 "Capture overlays that had insertions in the front.
3739 Called when overlay OVERL gets insertion in front."
3740 (if (ediff-overlay-get overl 'ediff-diff-num)
3741 (setq ediff-disturbed-overlays
3742 (cons overl ediff-disturbed-overlays)))
3745 (defun ediff-collect-extents-lucid (pos)
3746 "Collects all extents at POS having property `ediff-diff-num'.
3747 Lucid Emacs causes headache by detaching empty extents, so I have to save
3748 them before they disappear."
3750 (while (setq elt (extent-at pos nil 'ediff-diff-num elt))
3751 (setq lis (cons elt lis)))
3752 (setq ediff-disturbed-overlays lis)))
3754 (defun ediff-move-disturbed-overlays (posn)
3755 (mapcar (function (lambda (overl)
3756 (ediff-move-overlay overl
3758 (ediff-overlay-end overl))
3760 ediff-disturbed-overlays)
3761 (setq ediff-disturbed-overlays nil))
3763 (defun ediff-adjust-disturbed-extents-lucid (posn &optional posn-type)
3764 ;; POSN-TYPE tells if POSN should become a new start of the extents
3765 ;; (if 'new-start) or a new end (if 'new-end). If POSN-TYPE is nil, then
3766 ;; POSN is both the new start and the new end.
3767 (mapcar (function (lambda (overl)
3768 (cond ((and (null posn-type)
3769 (equal (ediff-overlay-start overl)
3770 (ediff-overlay-end overl)))
3771 (ediff-move-overlay overl posn posn))
3776 (if (eq posn-type 'new-start)
3778 (ediff-overlay-start overl))
3779 (if (eq posn-type 'new-end)
3781 (ediff-overlay-end overl)))))))
3782 ediff-disturbed-overlays)
3783 (setq ediff-disturbed-overlays nil))
3785 (defun ediff-save-buffer ()
3786 "Safe way of saving buffers A and B."
3788 (let ((hooks local-write-file-hooks))
3789 (ediff-unselect-and-select-difference ediff-current-difference
3792 (ediff-eval-in-buffer
3793 (if (eq last-command-char ?a) ediff-A-buffer ediff-B-buffer)
3794 ;; temporarily remove writing block
3795 (setq hooks (delq 'ediff-block-write-file hooks))
3796 (let ((local-write-file-hooks hooks))
3798 (ediff-unselect-and-select-difference ediff-current-difference
3804 ;; Essentially `emerge-remove-flags-in-buffer', modified to allow deletion
3805 ;; of read-only flags.
3806 (defun ediff-remove-flags-from-buffer (buffer before-posn after-posn
3807 before-flag after-flag)
3808 (ediff-eval-in-buffer
3810 (let ((buffer-read-only nil)
3811 (before-change-function nil)
3812 (inhibit-read-only t)
3813 (before-flag-length (length before-flag))
3814 (after-flag-length (length after-flag))
3816 (goto-char after-posn)
3817 (setq after-posn (point-marker)) ;; after-posn is now a marker
3818 ;; remove the flags, if they're there
3819 (goto-char (- before-posn before-flag-length))
3820 (if (ediff-if-lucid)
3821 (ediff-collect-extents-lucid (+ (point) before-flag-length)))
3822 (if (looking-at (regexp-quote before-flag))
3823 (delete-region (point) (+ (point) before-flag-length))
3824 ;; the flag isn't there
3826 (message "Trouble removing ASCII flag"))
3827 (if (ediff-if-lucid)
3828 (ediff-adjust-disturbed-extents-lucid (point)))
3830 (if (ediff-if-lucid)
3831 (ediff-collect-extents-lucid (point)))
3832 (goto-char after-posn)
3833 (if (looking-at (regexp-quote after-flag))
3834 (delete-region (point) (+ (point) after-flag-length))
3835 ;; the flag isn't there
3837 (message "Trouble removing ASCII flag"))
3838 (if (ediff-if-lucid)
3839 (ediff-adjust-disturbed-extents-lucid (point)))
3840 (setq after-posn nil) ;; after has become a marker--garbage-collect
3844 ;; This is a modified `emerge-place-flags-in-buffer'.
3845 (defun ediff-place-flags-in-buffer (buf-type buffer ctl-buffer difference)
3846 (ediff-eval-in-buffer
3848 (ediff-place-flags-in-buffer1 buf-type ctl-buffer difference)))
3850 ;; Modified `emerge-place-flags-in-buffer1'.
3851 (defun ediff-place-flags-in-buffer1 (buf-type ctl-buffer difference)
3852 (let ((buffer-read-only nil)
3853 (inhibit-read-only t)
3854 (before-change-function nil)
3855 (before-flag-name (if (eq buf-type 'A)
3856 'ediff-before-flag-A
3857 'ediff-before-flag-B))
3858 (after-flag-name (if (eq buf-type 'A)
3860 'ediff-after-flag-B))
3863 ;; insert the flag before the difference
3864 (let ((before (ediff-get-diff-posn buf-type 'beg difference ctl-buffer)))
3866 (setq beg-of-line (bolp))
3868 (setq flag (ediff-eval-in-buffer
3871 (set before-flag-name ediff-before-flag-bol)
3872 (set before-flag-name ediff-before-flag-mol))))
3874 ;; insert the flag itself
3875 (if (ediff-if-lucid)
3876 (ediff-collect-extents-lucid (point)))
3877 (insert-before-markers flag)
3878 (if (ediff-if-lucid)
3879 ;; Lucid's extent end-points behave strangely; they won't
3880 ;; respect insert-before-markers
3881 (ediff-adjust-disturbed-extents-lucid (point) 'new-start))
3883 ;; insert the flag after the difference
3884 (let* ((after (ediff-get-diff-posn buf-type 'end difference ctl-buffer)))
3886 (setq beg-of-line (bolp))
3888 (setq flag (ediff-eval-in-buffer
3891 (set after-flag-name ediff-after-flag-bol)
3892 (set after-flag-name ediff-after-flag-mol))))
3894 ;; insert the flag itself
3895 (if (ediff-if-lucid)
3896 (ediff-collect-extents-lucid (point)))
3898 (if (ediff-if-lucid)
3899 (ediff-adjust-disturbed-extents-lucid after 'new-end))
3903 (defun ediff-get-diff-posn (buf-type pos &optional n control-buf)
3904 "Returns positions of difference sectors in the BUF-TYPE buffer.
3905 BUF-TYPE should be a symbol--either `A' or `B'.
3906 POS is either `beg' or `end'--it specifies whether you want the position at the
3907 beginning of a difference or at the end.
3909 The optional argument N says which difference \(default:
3910 `ediff-current-difference'\). The optional argument CONTROL-BUF says
3911 which control buffer is in effect in case it is not the current
3915 (setq control-buf (current-buffer)))
3917 (ediff-eval-in-buffer
3919 (or n (setq n ediff-current-difference))
3920 (if (or (< n 0) (>= n ediff-number-of-differences))
3921 (if (> ediff-number-of-differences 0)
3922 (error "There is no diff %d. Valid diffs are 1 to %d."
3923 (1+ n) ediff-number-of-differences)
3924 (error "No differences found.")))
3925 (setq diff-overlay (ediff-get-diff-overlay n buf-type)))
3927 (if (ediff-overlay-get diff-overlay 'detached)
3928 (ediff-move-overlay diff-overlay
3929 (ediff-overlay-get diff-overlay 'ediff-marker)
3930 (ediff-overlay-get diff-overlay 'ediff-marker)))
3932 (ediff-overlay-start diff-overlay)
3933 (ediff-overlay-end diff-overlay))
3938 ;; These would highlight differences under X
3939 (defun ediff-highlight-diff (n)
3940 "Put face on diff N. Invoked for X displays only."
3941 (let* ((last-A (ediff-eval-in-buffer ediff-A-buffer (point-max)))
3942 (last-B (ediff-eval-in-buffer ediff-B-buffer (point-max)))
3943 (begin-A (ediff-get-diff-posn 'A 'beg n))
3944 (end-A (ediff-get-diff-posn 'A 'end n))
3945 (xtraA (if (equal begin-A end-A) 1 0))
3946 (end-A-hilit (min last-A (+ end-A xtraA)))
3948 (begin-B (ediff-get-diff-posn 'B 'beg n))
3949 (end-B (ediff-get-diff-posn 'B 'end n))
3950 (xtraB (if (equal begin-B end-B) 1 0))
3951 (end-B-hilit (min last-B (+ end-B xtraB))))
3953 (if (ediff-if-lucid)
3956 ediff-current-diff-overlay-A begin-A end-A-hilit)
3958 ediff-current-diff-overlay-B begin-B end-B-hilit))
3959 ;; Emacs 19.22 has a bug, which requires that ediff-move-overlay will
3960 ;; have the buffer as a parameter. Believed fixed in 19.23.
3961 (ediff-move-overlay ediff-current-diff-overlay-A
3962 begin-A end-A-hilit ediff-A-buffer)
3963 (ediff-move-overlay ediff-current-diff-overlay-B
3964 begin-B end-B-hilit ediff-B-buffer))
3965 ;; giving priority of 0 and then changing it may look funny, but
3966 ;; this is intended to overcome an Emacs bug.
3967 (ediff-overlay-put ediff-current-diff-overlay-A 'priority 0)
3968 (ediff-overlay-put ediff-current-diff-overlay-B 'priority 0)
3969 (ediff-overlay-put ediff-current-diff-overlay-A 'priority
3970 (ediff-highest-priority begin-A end-A-hilit ediff-A-buffer))
3971 (ediff-overlay-put ediff-current-diff-overlay-B 'priority
3972 (ediff-highest-priority begin-B end-B-hilit ediff-B-buffer))
3974 (or (face-differs-from-default-p 'ediff-odd-diff-face-A-var)
3975 (not ediff-highlight-all-diffs)
3977 (copy-face ediff-odd-diff-face-A 'ediff-odd-diff-face-A-var)
3978 (copy-face ediff-odd-diff-face-B 'ediff-odd-diff-face-B-var)
3979 (copy-face ediff-even-diff-face-A 'ediff-even-diff-face-A-var)
3980 (copy-face ediff-even-diff-face-B 'ediff-even-diff-face-B-var)))
3982 ;; unhighlight the background overlay for the diff n so they won't
3983 ;; interfere with the current diff overlay
3984 (ediff-overlay-put (ediff-get-diff-overlay n 'A) 'face nil)
3985 (ediff-overlay-put (ediff-get-diff-overlay n 'B) 'face nil)
3987 (sit-for 0) ;; needs to synch for some reason
3991 (defun ediff-unhighlight-diff ()
3992 "Remove overlays from buffers A and B."
3994 (ediff-move-overlay ediff-current-diff-overlay-A 1 1)
3995 (ediff-move-overlay ediff-current-diff-overlay-B 1 1)
3997 ;; rehighlight the overlay in the background of the
3998 ;; current difference region
3999 (ediff-overlay-put (ediff-get-diff-overlay ediff-current-difference 'A)
4000 'face (if (ediff-odd-p ediff-current-difference)
4001 'ediff-odd-diff-face-A-var
4002 'ediff-even-diff-face-A-var))
4003 (ediff-overlay-put (ediff-get-diff-overlay ediff-current-difference 'B)
4004 'face (if (ediff-odd-p ediff-current-difference)
4005 'ediff-odd-diff-face-B-var
4006 'ediff-even-diff-face-B-var))
4010 ;; delete highlighting overlays, restore faces to their original form
4011 (defun ediff-unhighlight-diffs-totally ()
4012 (setq buffer-read-only nil)
4013 (ediff-unselect-and-select-difference -1)
4015 (if (and window-system ediff-want-faces)
4016 (let ((inhibit-quit t))
4017 (if (face-differs-from-default-p 'ediff-odd-diff-face-A-var)
4019 (copy-face 'default 'ediff-odd-diff-face-A-var)
4020 (copy-face 'default 'ediff-odd-diff-face-B-var)
4021 (copy-face 'default 'ediff-even-diff-face-A-var)
4022 (copy-face 'default 'ediff-even-diff-face-B-var)))
4023 (if (ediff-overlayp ediff-current-diff-overlay-A)
4024 (ediff-delete-overlay ediff-current-diff-overlay-A))
4025 (setq ediff-current-diff-overlay-A nil)
4026 (if (ediff-overlayp ediff-current-diff-overlay-B)
4027 (ediff-delete-overlay ediff-current-diff-overlay-B))
4028 (setq ediff-current-diff-overlay-B nil)))
4031 (defun ediff-clear-diff-vector (vec &optional fin-diffs-also)
4032 ;; null out the difference overlays so they won't slow down future
4033 ;; editing operations
4036 (ediff-delete-overlay (ediff-get-diff-overlay-from-vector elt 'A))
4037 (ediff-delete-overlay (ediff-get-diff-overlay-from-vector elt 'B))
4039 (ediff-clear-diff-vector
4040 (ediff-get-fine-diff-vector-from-vec elt)))
4043 ;; allow them to be garbage collected
4046 (defun ediff-operate-on-flags (action)
4047 "Re/unhighlights buffers A and B with all flags from all Ediff sessions.
4048 This is usually needed only when a
4049 buffer is involved in multiple Ediff sessions."
4050 (let* ((A-sessions (ediff-eval-in-buffer
4052 ediff-this-buffer-control-sessions))
4053 (B-sessions (ediff-eval-in-buffer
4055 ediff-this-buffer-control-sessions))
4056 (sessions (ediff-union A-sessions B-sessions))
4057 (flag (if (eq action 'remove) 'unselect-only 'select-only)))
4059 (mapcar (function (lambda (buf)
4060 (ediff-eval-in-buffer
4062 (or (if (eq action 'insert)
4063 (memq ediff-highlighting-style '(ascii off))
4064 (not (eq ediff-highlighting-style 'ascii)))
4065 (ediff-unselect-and-select-difference
4066 ediff-current-difference
4073 ;;; Refinement of current diff
4074 ;; Split region along word boundaries. Each word will be on its own line.
4075 ;; Output to buffer out-buffer.
4076 (defun ediff-forward-word ()
4077 "Move point one word forward. Used for splitting diff regions into words.
4078 This is the default for `ediff-forward-word-function'."
4079 (or (> (skip-chars-forward ediff-word-1) 0)
4080 (> (skip-chars-forward ediff-word-2) 0)))
4082 (defun ediff-wordify (beg end in-buffer out-buffer)
4083 (let (sv-point string)
4085 (set-buffer in-buffer)
4086 (setq string (buffer-substring beg end))
4088 (set-buffer out-buffer)
4091 (goto-char (point-min))
4092 (skip-chars-forward ediff-whitespace)
4093 (delete-region (point-min) (point))
4096 (funcall ediff-forward-word-function)
4097 (setq sv-point (point))
4098 (skip-chars-forward ediff-whitespace)
4099 (delete-region sv-point (point))
4102 ;; `n' is the diff region to work on.
4103 ;; if `flag' is 'noforce then make fine-diffs only if this region's fine
4104 ;; diffs have not been computed before.
4105 ;; if `flag' is 'skip then don't compute fine diffs for this region.
4106 (defun ediff-make-fine-diffs (&optional n flag)
4108 (if (not window-system)
4109 (error "Non-window system."))
4110 (or n (setq n ediff-current-difference))
4112 (if (< ediff-number-of-differences 1)
4113 (error "No differences found."))
4115 (let ((file-A ediff-temp-file-A)
4116 (file-B ediff-temp-file-B))
4118 (cond ((and (eq flag 'noforce) (ediff-get-fine-diff-vector n))
4121 (or (ediff-get-fine-diff-vector n)
4122 (eq ediff-auto-refine 'off)
4123 (message "Region %d is larger than auto-refine limit. Hit %S to force-refine."
4125 (substitute-command-keys "\\[ediff-make-fine-diffs]")
4128 ;; delete old fine diffs
4129 (ediff-clear-diff-vector (ediff-get-fine-diff-vector n))
4130 ;; recompute fine diffs
4131 (setq ediff-tmp-buffer (get-buffer-create "*ediff-tmp*"))
4134 (ediff-get-diff-posn 'A 'beg n)
4135 (ediff-get-diff-posn 'A 'end n)
4138 (ediff-eval-in-buffer
4140 (setq file-A (ediff-make-temp-file ".fine-diffs-A" file-A)))
4143 (ediff-get-diff-posn 'B 'beg n)
4144 (ediff-get-diff-posn 'B 'end n)
4147 (ediff-eval-in-buffer
4149 (setq file-B (ediff-make-temp-file ".fine-diffs-B" file-B)))
4151 ;; save temp file names.
4152 (setq ediff-temp-file-A file-A
4153 ediff-temp-file-B file-B)
4155 ;; set the new vector of fine diffs, if none exists
4156 (ediff-set-fine-diff-vector
4158 (ediff-setup-diff-regions file-A file-B 'use-old-diff-buf n
4159 ediff-fine-diff-program
4160 ediff-fine-diff-options
4161 ediff-fine-diff-ok-lines-regexp))
4162 (if (eq (length (ediff-get-fine-diff-vector n)) 0)
4163 (message "No differences found in region %d, except for white space and line breaks."
4166 (ediff-set-fine-diff-properties n)
4170 (defun ediff-set-fine-diff-properties (n &optional default)
4171 (let ((fine-diff-vector (ediff-get-fine-diff-vector n))
4172 (face-A (if default 'default (face-name ediff-fine-diff-face-A)))
4173 (face-B (if default 'default (face-name ediff-fine-diff-face-B)))
4174 (priority-A (if default
4176 (1+ (ediff-overlay-get ediff-current-diff-overlay-A
4178 (priority-B (if default
4180 (1+ (ediff-overlay-get ediff-current-diff-overlay-B
4183 (function (lambda (vec)
4185 (ediff-get-diff-overlay-from-vector vec 'A)
4188 (ediff-get-diff-overlay-from-vector vec 'A)
4189 'priority priority-A)
4192 (ediff-get-diff-overlay-from-vector vec 'B)
4195 (ediff-get-diff-overlay-from-vector vec 'B)
4196 'priority priority-B)
4201 (defun ediff-convert-diffs-to-overlays-refine (A-buffer B-buffer
4202 diff-list refine-region)
4203 (let* ((current-diff -1)
4204 (reg-A-start (ediff-get-diff-posn 'A 'beg refine-region))
4205 (reg-B-start (ediff-get-diff-posn 'B 'beg refine-region))
4206 diff-overlay-list list-element
4207 a-begin a-end b-begin b-end
4208 a-overlay b-overlay)
4210 (ediff-eval-in-buffer A-buffer (goto-char reg-A-start))
4211 (ediff-eval-in-buffer B-buffer (goto-char reg-B-start))
4214 (setq current-diff (1+ current-diff)
4215 list-element (car diff-list)
4216 a-begin (aref list-element 0)
4217 a-end (aref list-element 1)
4218 b-begin (aref list-element 2)
4219 b-end (aref list-element 3))
4221 ;; place overlays at the appropriate places in the buffers
4222 (setq a-overlay (ediff-make-overlay
4223 (ediff-goto-word (1+ a-begin) A-buffer)
4224 (ediff-goto-word a-end A-buffer 'end)
4227 (setq b-overlay (ediff-make-overlay
4228 (ediff-goto-word (1+ b-begin) B-buffer)
4229 (ediff-goto-word b-end B-buffer 'end)
4232 ;; record all overlays for this difference
4233 (setq diff-overlay-list (nconc diff-overlay-list
4234 (list (vector a-overlay b-overlay)))
4235 diff-list (cdr diff-list))
4237 ;; convert the list of difference information into a vector for
4239 (apply 'vector diff-overlay-list)))
4241 ;; goto word #n starting at current position in buffer `buf'
4242 ;; For ediff, a word is either a string of a-z,A-Z, incl `-' and `_';
4243 ;; or a string of other non-blanks. A blank is a \n\t\C-j
4244 ;; If `flag' is non-nil, goto the end of the n-th word.
4245 (defun ediff-goto-word (n buf &optional flag)
4246 (ediff-eval-in-buffer
4248 (skip-chars-forward ediff-whitespace)
4250 (funcall ediff-forward-word-function)
4251 (skip-chars-forward ediff-whitespace)
4254 (if (and flag (> n 0))
4255 (funcall ediff-forward-word-function))
4264 (defun ediff-union (list1 list2)
4265 "Combine LIST1 and LIST2 using a set-union operation.
4266 The result list contains all items that appear in either LIST1 or LIST2.
4267 This is a non-destructive function; it makes a copy of the data if necessary
4268 to avoid corrupting the original LIST1 and LIST2.
4269 This is a slightly simplified version from `cl-seq.el'. Added here to
4270 avoid loading cl-*."
4271 (cond ((null list1) list2) ((null list2) list1)
4272 ((equal list1 list2) list1)
4274 (or (>= (length list1) (length list2))
4275 (setq list1 (prog1 list2 (setq list2 list1))))
4277 (or (memq (car list2) list1)
4278 (setq list1 (cons (car list2) list1)))
4279 (setq list2 (cdr list2)))
4282 ;(defun ediff-debug ()
4284 ; (with-output-to-temp-buffer "*ediff-debug*"
4286 ; (format "Ctl buffer: %S\n\nediff-difference-vector:\n"
4287 ; ediff-control-buffer))
4289 ; (lambda (overl-vec)
4290 ; (princ (format "Diff %d: %S %S %S\n\t %S %S %S\n"
4291 ; (1+ (ediff-overlay-get (aref overl-vec 0)
4293 ; (ediff-overlay-get (aref overl-vec 0)
4294 ; 'ediff-control-buffer)
4295 ; (ediff-overlay-get (aref overl-vec 0)
4296 ; 'insert-in-front-hooks)
4297 ; (aref overl-vec 0)
4298 ; (ediff-overlay-get (aref overl-vec 1)
4299 ; 'ediff-control-buffer)
4300 ; (ediff-overlay-get (aref overl-vec 0)
4301 ; 'insert-in-front-hooks)
4302 ; (aref overl-vec 1)
4304 ; ediff-difference-vector)
4305 ; (princ "\nediff-disturbed-overlays:\n")
4308 ; (princ (format "%S %S\n"
4309 ; (ediff-overlay-get overl 'ediff-control-buffer)
4312 ; ediff-disturbed-overlays)))
4315 (run-hooks 'ediff-load-hooks)
4320 ;;; ediff.el ends here