7267
|
1 ;;; ediff.el --- a visual interface to diff & patch
|
|
2 ;;; Copyright (C) 1994 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
|
|
5 ;; Created: February 2, 1994
|
|
6 ;; Version: 1.31
|
|
7 ;; Keywords: comparing, merging, patching, version control.
|
|
8
|
|
9 ;; This file is part of GNU Emacs.
|
|
10
|
|
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)
|
|
14 ;; any later version.
|
|
15
|
|
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.
|
|
20
|
|
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.
|
|
24
|
|
25
|
|
26 ;;; Commentary:
|
|
27 ;; ----------
|
|
28
|
7391
|
29 ;; Never read those diff outputs again!
|
|
30 ;; Apply patch selectively, like a pro!
|
7267
|
31
|
|
32 ;; This package provides a convenient way of simultaneous brousing 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
|
|
38 ;; change your mind).
|
|
39
|
|
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, simultateously,
|
|
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
|
|
47 ;; you don't like).
|
|
48
|
|
49 ;; This package is based on emerge.el. It uses a few utilities and
|
|
50 ;; variables defined there and several other Ediff's functions are
|
|
51 ;; adaptations from emerge.el.
|
|
52
|
|
53 ;; Ediff is complimentary to Emerge. While Emerge is better at heavy-duty
|
|
54 ;; tasks that involve merging of files, Ediff is by far superior
|
7391
|
55 ;; for browsing through files compared via diff and for patching files
|
|
56 ;; with patch. Furthermore, I feel that Ediff is more convenient for
|
7267
|
57 ;; merging tasks where one of the files is a designated output. This
|
|
58 ;; situation arises while patching files or when comparing an old version
|
|
59 ;; of a file with a newer version (in such cases, it is often desirable to
|
|
60 ;; selectively revert some portions of the new file to its old state).
|
|
61
|
|
62 ;; This version of Ediff is much faster than the previous ones and than
|
|
63 ;; Emerge (in Emacs 19.23, Emerge will become much faster as well).
|
|
64 ;; The difference in startup time is dramatic for large files with many
|
|
65 ;; differences.
|
|
66
|
|
67 ;; Window configuration:
|
|
68 ;; ----------------------
|
|
69
|
|
70 ;; By default, Ediff sets things up in one frame, splitting it between a
|
|
71 ;; small control window and the two windows for file-A and file-B. The
|
|
72 ;; split between these latter windows can be horizontal or vertical, which
|
|
73 ;; can be changed interactively by hitting 's' while the cursor is in the
|
|
74 ;; control window.
|
|
75 ;;
|
|
76 ;; In a multi-frame situation, Ediff would work as follows. When it starts,
|
|
77 ;; it will place the control window in the frame that was selected at the
|
|
78 ;; time of the invocation. If file-A or file-B is seen in one of the
|
|
79 ;; frames, Ediff will leave it there. If a file (A/B) is not visible in any
|
|
80 ;; frame, Ediff will arrange that it will share a frame with the control
|
|
81 ;; window. (If none of the files is visible, then both will share the
|
|
82 ;; control window frame.) The same algorithm works when you hit 'c'
|
|
83 ;; (ediff-recenter), 'p' (ediff-previous-difference), 'n', etc.
|
|
84 ;;
|
|
85 ;; Thus, you can compare files in one frame or in different frames.
|
|
86 ;; The former is done by default, while the latter can be achieved by
|
|
87 ;; arranging files A and B to be seen in different frames. Ediff
|
|
88 ;; respects these arrangements, automatically adapting itself to
|
|
89 ;; the multi-frame mode.
|
|
90
|
|
91
|
|
92 ;; A note to heavy-duty users:
|
|
93
|
|
94 ;; Ediff lets the user run multiple sessions at once, i.e., you can invoke
|
|
95 ;; Ediff on different functions several times in a row, without exiting
|
|
96 ;; the previous Ediff sessions. Different sessions may even operate on the
|
|
97 ;; same pair of files. So, in principle, it is possible to do, say,
|
|
98 ;; pairwise comparison of three (or more) different files. Each session
|
|
99 ;; would have its own *ediff-control* buffer and all the regarding a
|
|
100 ;; particular session is local to the associated *ediff-control* buffer.
|
|
101 ;; You can switch between sessions by suspending one session and then
|
|
102 ;; switching to another *ediff-control* buffer. (Different such buffers
|
|
103 ;; are distinguished by a numerical suffix, e.g., *ediff-control*<3>.)
|
|
104 ;; This, if you would like to compare three files pairwise, you can do
|
|
105 ;; this by preparing three different frames, each with its own control
|
|
106 ;; window. (This would require a very wide screen, and I never claimed
|
|
107 ;; that such 3-way comparison is very easy to do.)
|
|
108 ;;
|
|
109 ;; If you need to conduct multiple Ediff sessions on the same file, one
|
|
110 ;; thing should be kept in mind: each time you invoke Ediff on a buffer that
|
|
111 ;; already participates in another Ediff session, that buffer should not
|
|
112 ;; have any ASCII Ediff flags in it. (Highlighting with faces is OK.) If
|
|
113 ;; flags are not removed, difference overlays won't be set correctly
|
|
114 ;; for the second invocation of Ediff. The simplest way to remove ASCII
|
|
115 ;; flags from an Ediff buffer is to switch to that buffer and try to insert
|
|
116 ;; or delete something. If ASCII flags have been inserted by an Ediff
|
|
117 ;; session, Ediff will ignore this first editing operation, but it will
|
|
118 ;; remove all flags and notify you that this buffer can now be edited.
|
|
119 ;;
|
|
120 ;; To rehighlight Ediff buffers, hit 'c' in ediff-control buffer.
|
|
121
|
|
122
|
|
123 ;;; Remarks:
|
|
124 ;; -------
|
|
125
|
|
126 ;; 1. Ediff is unlikely to run under Emacs 18 without some further work.
|
|
127 ;; 2. If running Lucid Emacs, Ediff requires at least version 19.9.
|
7391
|
128 ;; 3. I didn't test Ediff on Emacs versions older than 19.19.
|
7267
|
129 ;; 4. The function vc-ediff requires the vc.el version that comes with
|
|
130 ;; Emacs 19.22.
|
|
131
|
|
132
|
|
133 ;;; Installation and use:
|
|
134 ;; --------------------
|
|
135
|
|
136 ;; You can invoke Ediff interactively using the following functions:
|
|
137 ;;
|
|
138 ;; ediff-buffers - compare buffers
|
|
139 ;; ediff (alias for ediff-files)
|
|
140 ;; ediff-files - compare files
|
|
141 ;; ediff-patch-file - patch file then compare
|
|
142 ;; epatch (alias for ediff-patch-file)
|
|
143 ;; ediff-patch-buffer - patch buffer then compare
|
|
144 ;; vc-ediff - compare buffer & version
|
|
145 ;; using vc.el package
|
|
146 ;; (Emacs 19.22 and up).
|
|
147 ;; rcs-ediff - same using rcs.el; rcs.el
|
|
148 ;; is not part of the
|
|
149 ;; standard Emacs distribution.
|
|
150 ;;
|
|
151 ;; There is also the function ediff-files-remote, which can be invoked only
|
|
152 ;; from within another Emacs Lisp function, i.e., non-interactively.
|
|
153 ;;
|
|
154 ;; To use Ediff, put this in your .emacs file:
|
|
155 ;;
|
7391
|
156 ;; (autoload 'ediff-buffers "ediff" "Visual interface to diff" t)
|
|
157 ;; (autoload 'ediff "ediff" "Visual interface to diff" t)
|
|
158 ;; (autoload 'ediff-files "ediff" "Visual interface to diff" t)
|
|
159 ;; (autoload 'ediff-files-remote "ediff" "Visual interface to diff")
|
|
160 ;; (autoload 'epatch "ediff" "Visual interface to patch" t)
|
|
161 ;; (autoload 'ediff-patch-file "ediff" "Visual interface to patch" t)
|
|
162 ;; (autoload 'ediff-patch-buffer "ediff" "Visual interface to patch" t)
|
7267
|
163 ;; (autoload 'vc-ediff "ediff"
|
|
164 ;; "Interface to diff & version control via vc.el" t)
|
|
165 ;; (autoload 'rcs-ediff "ediff"
|
|
166 ;; "Interface to diff & version control via rcs.el" t)
|
|
167 ;;
|
|
168 ;;
|
|
169 ;; If you want Ediff to be loaded from the very beginning, you should have
|
|
170 ;;
|
|
171 ;; (require 'ediff)
|
|
172 ;;
|
|
173 ;; in your .emacs file. This way it is also easier to figure out changes
|
|
174 ;; to the default Ediff setting, if such changes become necessary --- see
|
|
175 ;; Customization.
|
|
176 ;;
|
|
177
|
|
178 ;;; Compilation
|
|
179 ;; -----------
|
|
180 ;;
|
|
181 ;; When you byte-compile Ediff, you will get some warnings about functions
|
|
182 ;; being undefined. These can be safely ignored.
|
|
183
|
|
184 ;;; Customization:
|
|
185 ;; -------------
|
|
186
|
|
187 ;; If you don't like the default setting, you can change it through the
|
|
188 ;; various variables and hooks. In particular, the following hooks are
|
|
189 ;; available:
|
|
190
|
|
191 ;; ediff-load-hooks
|
|
192 ;; ediff-before-setup-windows-hooks
|
|
193 ;; ediff-startup-hooks
|
|
194 ;; ediff-select-hooks
|
|
195 ;; ediff-unselect-hooks
|
|
196 ;; ediff-suspend-hooks
|
|
197 ;; ediff-quit-hooks
|
|
198 ;; ediff-prepare-buffer-hooks
|
|
199
|
|
200 ;; The hooks in ediff-load-hooks can be used to change defaults after Ediff
|
|
201 ;; is loaded.
|
|
202 ;; The hooks in ediff-before-setup-windows-hooks, ediff-suspend-hooks, and
|
|
203 ;; ediff-quit-hooks can be used to save and then restore whatever window
|
|
204 ;; configuration you want. However, make sure you understand what you are
|
|
205 ;; doing. Many variables that drive Ediff are local to the different
|
|
206 ;; *ediff-control* buffers. Take a look at ediff-default-suspend-hook and
|
|
207 ;; ediff-default-quit-hook to see what's involved.
|
|
208 ;; The hooks in ediff-prepare-buffer-hooks are executed for each Ediff buffer
|
|
209 ;; (A and B) right after these buffers are arranged.
|
|
210 ;;
|
|
211 ;; The second group of Ediff variables that could be changed, if you so
|
|
212 ;; wish, is:
|
|
213 ;;
|
|
214 ;; ediff-before-flag-eol
|
|
215 ;; ediff-after-flag-eol
|
|
216 ;; ediff-before-flag-mol
|
|
217 ;; ediff-after-flag-mol
|
|
218 ;;
|
|
219 ;; ediff-current-diff-face-A
|
|
220 ;; ediff-current-diff-face-B
|
|
221 ;; ediff-even-diff-face-A
|
|
222 ;; ediff-even-diff-face-B
|
|
223 ;; ediff-odd-diff-face-A
|
|
224 ;; ediff-odd-diff-face-B
|
|
225 ;
|
|
226 ;; The first four are ASCII strings that mark the beginning and the end of
|
|
227 ;; the differences found in file-A and file-B. Ediff uses different flags
|
|
228 ;; to highlight regions that begin/end at the beginning of a line or in a
|
|
229 ;; middle of a line.
|
|
230
|
|
231 ;; The rest are the faces used to highlight text on X displays. On X
|
|
232 ;; displays, Ediff uses ediff-current-diff-face-A and
|
|
233 ;; ediff-current-diff-face-B to highlight the current difference regions.
|
|
234 ;; Other (non-current) difference regions are displayed in alternating
|
7391
|
235 ;; faces: ediff-even/odd-diff-face-A/B. The odd and the even
|
7267
|
236 ;; faces are actually identical on monochrome displays, because it is
|
7391
|
237 ;; rather poor in what you can do on such a display. So, I chose to use
|
|
238 ;; italics to highlight other differences. Any ideas would be welcome.
|
|
239 ;;
|
7267
|
240 ;; There are two ways to change the default setting for highlighting faces:
|
|
241 ;; either change the variables, as in
|
|
242 ;;
|
|
243 ;; (setq ediff-current-diff-face-A (internal-get-face 'bold-italic))
|
|
244 ;;
|
|
245 ;; (`internal-get-face' should be `get-face' if you are using Lucid Emacs)
|
|
246 ;; or by selectively modifying the defaults:
|
|
247 ;;
|
|
248 ;; (add-hook 'ediff-load-hooks
|
|
249 ;; (function (lambda ()
|
|
250 ;; (set-face-foreground ediff-current-diff-face-B "blue")
|
|
251 ;; (set-face-background ediff-current-diff-face-B "red")
|
|
252 ;; (make-face-italic ediff-current-diff-face-B))))
|
|
253 ;;
|
|
254 ;; You may also want to take a look at how the above faces are defined in
|
|
255 ;; Ediff.
|
|
256 ;;
|
|
257 ;; The last pair of variables in this group,
|
|
258 ;;
|
|
259 ;; ediff-want-faces
|
|
260 ;; ediff-highlight-selected-only
|
|
261 ;;
|
|
262 ;; indicate whether---on a window system---you want differences to be
|
|
263 ;; marked using ASCII strings (like on a dumb terminal) or using colors and
|
|
264 ;; highlighting. If ediff-want-faces is t, then highlighting with faces is
|
|
265 ;; used. Normally, Ediff highlights all differences, but the selected
|
|
266 ;; difference is highlighted more visibly. If you prefer that unselected
|
|
267 ;; differences won't be highlighted, you can set
|
|
268 ;; ediff-highlight-selected-only to t.
|
|
269 ;;
|
|
270 ;; If you plan on changing these variables, they must be set
|
|
271 ;; BEFORE ediff.el is loaded.
|
|
272 ;;
|
|
273 ;; Note: Ediff lets you switch between the two types of highlighting. That
|
|
274 ;; is you can switch, interactively, from highlighting using faces to
|
|
275 ;; highlighting using ASCII flags, and back. Of course, toggling has
|
|
276 ;; effect only on a window system. On a dumb terminal or in an xterm
|
|
277 ;; window, the only available option is highlighting with ASCII flags.
|
|
278 ;;
|
|
279 ;; The third group of variables controls miscellaneous functions:
|
|
280 ;;
|
|
281 ;; ediff-patch-program
|
|
282 ;; ediff-patch-options
|
|
283 ;; ediff-diff-program
|
|
284 ;; ediff-diff-options
|
|
285 ;;
|
|
286 ;; These specify the functions that produce differences and do patching.
|
|
287 ;; The *-options variables specify which options to pass to these programs.
|
|
288 ;; It is unlikely that you would want to change these. One possible
|
|
289 ;; exception is when you may want to generate differences with context
|
|
290 ;; lines in order to send a patch file through email. Then, you might want
|
|
291 ;; to set ediff-diff-options to '-c'. Sometimes, you may also want to tell
|
7391
|
292 ;; diff to ignore spaces and such. Use the option '-w' for that. Diff
|
7267
|
293 ;; has several other useful options (type 'man diff' to find out).
|
|
294 ;;
|
7391
|
295 ;; The output from diff is found in *ediff-diff* buffer. However, this
|
7267
|
296 ;; makes sense only if you also intend to use Ediff to browse through the
|
|
297 ;; diff'ed files before sending the patch. This is because diff.el is much
|
7391
|
298 ;; faster in yielding the output of diff ;; (Ediff is a big gun, if used
|
7267
|
299 ;; for this simple purpose).
|
|
300 ;;
|
|
301 ;; The last set of variables that can be modified is
|
|
302 ;;
|
|
303 ;; ediff-split-window-function
|
|
304 ;; ediff-use-last-dir
|
|
305 ;; ediff-nix-help-in-control-buffer
|
|
306 ;;
|
|
307 ;; ediff-split-window-function controls the way you want the window be
|
|
308 ;; split between file-A and file-B. It defaults to vertical split, but you
|
|
309 ;; can set it to 'split-window-horizontally, if you want. Ediff lets you
|
|
310 ;; toggle the way windows are split, so you can try different settings
|
|
311 ;; interactively. Note: if file-A and file-B are in different frames,
|
|
312 ;; windows are not split, regardless of the value
|
|
313 ;; ediff-split-window-function. Instead, other windows on these frames are
|
|
314 ;; deleted and Ediff starts displaying file-A and file-B using these two
|
|
315 ;; frames, one file per frame. You can then switch to one-frame mode
|
|
316 ;; simply by hiding the file-A/B buffer that is displayed on a frame other
|
|
317 ;; than the control-window frame.
|
|
318 ;;
|
|
319 ;; Note that if Ediff sees that the two buffers it compares are residing in
|
|
320 ;; separate frames, it assumes that the user wants them to be so displayed
|
|
321 ;; and stops splitting windows. Instead, it will arrange each buffer to
|
|
322 ;; occupy its own frame (possibly shared with Ediff's help window).
|
|
323 ;;
|
|
324 ;; The variable ediff-use-last-dir controls the way Ediff presents the
|
|
325 ;; default directory when it prompts the user for files to compare. If nil,
|
|
326 ;; Ediff will use the default directory of the current buffer when it
|
|
327 ;; prompts the user for file names. Otherwise, it will use the
|
|
328 ;; directories it had previously used for file-A and file-B.
|
|
329 ;;
|
|
330 ;; The ediff-nix-help-in-control-buffer, if set to t, makes C-h behave like
|
|
331 ;; the DEL key, i.e., it will move you back to the previous difference
|
|
332 ;; rather than invoking help. This is useful when, in an xterm window or on
|
|
333 ;; a dumb terminal, the Backspace key is bound to C-h and is positioned
|
|
334 ;; more conveniently than the DEL key.
|
|
335
|
|
336
|
|
337 ;;; Commands
|
|
338 ;; --------
|
|
339
|
|
340 ;; All Ediff commands are displayed in a help window, unless you hit '?' to
|
|
341 ;; shrink it to just one line. You can redisplay the help window by hitting
|
|
342 ;; '?' again.
|
|
343 ;;
|
|
344 ;; Many Ediff commands take numeric prefix arguments. For instance, if you
|
|
345 ;; hit a number, n, and then 'j' (ediff-jump-to-difference), Ediff will
|
|
346 ;; take you to n-th difference. Hitting a number, n, and then 'ab'
|
|
347 ;; (ediff-diff-to-diff) will copy n-th difference from buffer A to buffer B.
|
|
348 ;; Hitting 'ba' does copying in the other direction.
|
|
349 ;; Likewise, a number, n, followed by 'ra' will restore the n-th difference
|
|
350 ;; region in buffer A (if it was previously saved as a result of copying
|
|
351 ;; from B to A).
|
|
352 ;;
|
|
353 ;; Without the prefix argument, all commands operate on the current
|
|
354 ;; difference region.
|
|
355 ;;
|
|
356 ;; The total number of differences and the current difference number are
|
|
357 ;; always displayed in the mode line of the control window.
|
|
358
|
|
359 ;;; Display Modes
|
|
360 ;; -------------
|
|
361
|
|
362 ;; Ediff can display files in one frame, stacked side-by-side or one on top
|
|
363 ;; of another; or it can display the files in different frames. When you
|
|
364 ;; start Ediff, it assumes a 1-frame mode. You can toggle the side-by-side
|
|
365 ;; and one-on-top-of-another displays by simply hitting 's'.
|
|
366 ;;
|
|
367 ;; Ediff switches to the multi-frame mode when:
|
|
368 ;;
|
|
369 ;; 1. file-A and file-B are in different frames (you have to put them into
|
|
370 ;; different frames manually); or
|
|
371 ;; 2. *ediff-control* buffer is visible in one frame and one other file (A
|
|
372 ;; or B) is visible in another frame. If, say, fileA is visible in a
|
|
373 ;; different frame than *ediff-control*, fileB doesn't have to be
|
|
374 ;; visible. If it is, Ediff will continue displaying fileB in the frame
|
|
375 ;; where it was visible before. If it isn't then Ediff will arrange for
|
|
376 ;; fileB to share a frame with *ediff-control*.
|
|
377 ;;
|
|
378 ;; If all three buffers are in separate frames, Ediff will switch to a
|
|
379 ;; 3-frame mode. If Ediff buffers are currently visible only in two
|
|
380 ;; frames, Ediff will work in a 2-frame mode. In this mode, one of the
|
|
381 ;; frames will be shared by *ediff-control* and file-A or file-B
|
|
382 ;; (whichever is appropriate).
|
|
383
|
|
384
|
|
385 ;;; Bugs:
|
|
386 ;; ----
|
|
387
|
|
388 ;; 1. The undo command doesn't restore deleted regions well. That is, if
|
|
389 ;; you delete all characters in a difference region and then invoke
|
|
390 ;; `undo', the reinserted text will most likely be reinserted outside of
|
7391
|
391 ;; what Ediff thinks is the current difference region.
|
7267
|
392
|
|
393 ;; 2. You may get an error if your colormap doesn't have the colors requested
|
|
394 ;; by Ediff (on a color display). If this happens, you should create your
|
|
395 ;; own faces using available colors. See `ediff-current-diff-face-A',
|
|
396 ;; ediff-current-diff-face-B, ediff-even-diff-face-A, ediff-even-diff-face-B,
|
|
397 ;; ediff-odd-diff-face-A, and ediff-odd-diff-face-B to get an idea on how
|
|
398 ;; to do this.
|
|
399
|
|
400
|
|
401 ;;; Change Log:
|
|
402 ;; ----------
|
|
403
|
|
404 ;; Thu Feb 3, 1994
|
|
405
|
|
406 ;; Added ediff-read-file-name, which is a stub that takes care of Lemacs
|
|
407 ;; versions of Emerge. (Thanks to Alastair Burt <burt@dfki.uni-kl.de>.)
|
|
408 ;;
|
|
409 ;; Fixed a bug in ediff-setup-windows that caused control window to
|
|
410 ;; appear in a wrong place when split-window-keep-point is nil
|
|
411 ;; (Thanks to Kevin Broadey <KevinB@bartley.demon.co.uk>.)
|
|
412 ;;
|
|
413 ;; Added mechanism for using faces instead of before/after flags. This
|
|
414 ;; looks much better on an X display, especially on a color one.
|
|
415 ;; (Thanks to Boris Goldowsky <boris@cs.rochester.edu> for the code
|
|
416 ;; that led to ediff-highlight-diff.
|
|
417 ;; Also, thanks to Kevin Esler <esler@ch.hp.com> for suggestions
|
|
418 ;; regarding highlighting differences on X displays.)
|
|
419 ;;
|
|
420 ;; Added functions to apply patches.
|
|
421 ;; (Thanks to Kevin Broadey <KevinB@bartley.demon.co.uk> for this
|
|
422 ;; suggestion.)
|
|
423
|
|
424 ;; Fri Feb 4, 1994
|
|
425
|
|
426 ;; Added mechanism for toggling vertical/horizontal window split.
|
|
427 ;; (Inspired by a suggestion from Allan Gottlieb
|
|
428 ;; <gottlieb@allan.ultra.nyu.edu> -- thanks.)
|
|
429 ;;
|
|
430 ;; Added mechanism for toggling between highlighting using faces and
|
|
431 ;; highlighting using ASCII flags.
|
|
432 ;;
|
|
433 ;; Fixed a problem with undo. Now, Ediff has smartened up and doesn't
|
|
434 ;; keep undo info on ASCII flags inserted in buffer-A and buffer-B.
|
|
435 ;; So, if you edit the files while browsing through them, undo behaves
|
|
436 ;; as you would expect, i.e., faces/flags don't get in the way.
|
|
437
|
|
438 ;; Sun Feb 6, 1994
|
|
439
|
|
440 ;; Added horizontal scrolling. Added ediff-position-region to ensure
|
|
441 ;; that difference regions in buffer-A and buffer-B are aligned with
|
|
442 ;; each other. Disabled ediff-toggle-split when buffers are displayed
|
|
443 ;; in different frames.
|
|
444
|
|
445 ;; Mon Feb 7, 1994
|
|
446
|
|
447 ;; Added toggle-window help (Suggested by Boris Goldowsky
|
|
448 ;; <boris@cs.rochester.edu>.)
|
|
449 ;; Added functions to copy differences from one buffer to another and to
|
|
450 ;; recover old differences.
|
|
451 ;; Added prefix arguments to ediff-next-difference and
|
|
452 ;; ediff-previous-difference.
|
|
453
|
|
454 ;; Tue Feb 8, 1994
|
|
455
|
|
456 ;; Replaced text properties with overlays. Fixed ediff-setup-windows.
|
|
457 ;; Added ediff-save-buffer to local-write-file-hooks to prevent user
|
|
458 ;; from saving corrupted states. (Thanks to <boris@cs.rochester.edu>
|
|
459 ;; for suggestion.) Instead, Ediff now has a pair of functions for
|
|
460 ;; safe saving of buffers.
|
|
461 ;; Changed ediff-read-file-name to be more intuitive on ediff-files.
|
|
462 ;; Added ediff-prepare-buffer-hooks. (Thanks to Kevin Esler
|
|
463 ;; <esler@ch.hp.com> for the idea.)
|
|
464
|
|
465 ;; Wed Feb 9, 1994
|
|
466
|
|
467 ;; Cleanups in ediff-patch-file. Protected ediff-copy-diff against
|
|
468 ;; a bug that Emacs has in kill-region.
|
|
469
|
|
470 ;; Thu Feb 10, 1994
|
|
471
|
|
472 ;; Added support for Lemacs. (Thanks to Alastair Burt
|
|
473 ;; <burt@dfki.uni-kl.de> for coercing Ediff into working under Lemacs.)
|
|
474 ;; Added ediff-kill-buffer-carefully and other suggestions by Boris
|
|
475 ;; Goldowsky <boris@cs.rochester.edu>.
|
|
476 ;; Refined the protection against interference with highlighting caused
|
|
477 ;; by Hilit19. Added the variable ediff-third-party-highlighting.
|
|
478 ;; Added mechanisn for unhighlighting regions highlighted with Hilit19
|
|
479 ;; before hightlighting them with Ediff's overlays. (And for
|
|
480 ;; rehighlighting them with Hilit19, when the current difference moves on.)
|
|
481
|
|
482 ;; Sun Feb 13, 1994
|
|
483
|
|
484 ;; Added ediff-place-flags-in-buffer and ediff-remote-exit, which are
|
|
485 ;; modifications of Emerge's similar functions. The difference is that
|
|
486 ;; in Ediff they make ediff-before-flag and ediff-after-flag into
|
|
487 ;; read-only regions, so the user can't change them by mistake.
|
|
488 ;;
|
|
489 ;; Adopted a suggestion by Boris Goldowsky <boris@cs.rochester.edu>
|
|
490 ;; that led to a more elegant treatment of faces.
|
|
491 ;;
|
|
492 ;; Added protection against interference with Font-Lock highlighting
|
|
493 ;; similar to that of Hilit19's protection.
|
|
494
|
|
495 ;; Tue Feb 15, 1994
|
|
496
|
|
497 ;; Deleted spurious (auto-save-mode 1) in ediff-control-buffer, which
|
|
498 ;; was causing this buffer to be auto-saved for no good reason.
|
|
499 ;; Added read-only protection to ediff-before/after-flags in Lemacs.
|
|
500 ;; (Thanks to Alastair Burt <burt@dfki.uni-kl.de> for help in testing.)
|
|
501
|
|
502 ;; Wed Feb 16, 1994
|
|
503
|
|
504 ;; Further fixes in the Lemacs part. Changed highlighted region in
|
|
505 ;; ediff-highlight-diff so that an extra character will be highlighted
|
|
506 ;; only if a difference is empty (thereby allowing the user to see where an
|
|
507 ;; insertion or a deletion has taken place).
|
|
508 ;;
|
|
509 ;; Simplified interaction with other highlighting packages by giving
|
|
510 ;; Ediff overlays the highest priority. (Taking a cue from
|
|
511 ;; ediff-highlight-diff-lemacs written by Alastair Burt
|
|
512 ;; <burt@dfki.uni-kl.de>.) Zapped ediff-third-party-highlighting
|
|
513 ;; variable and hooks that were previously used to
|
|
514 ;; unhighlight/rehighlight buffers when hilit19/font-lock are on.
|
|
515
|
|
516 ;; Fri Feb 18, 1994
|
|
517
|
|
518 ;; Added a bit more sophistication to ediff-read-file-name. Now,
|
|
519 ;; ediff-files remembers both, the file-A and the file-B directories.
|
|
520 ;; They are offered as defaults when ediff-use-last-dir is set to t.
|
|
521
|
|
522 ;; Fri Feb 22, 1994
|
|
523
|
|
524 ;; Added ediff-before-change-guard to remove ASCII highlighting when
|
|
525 ;; the user attempts to change buffer-A/B. This is needed because
|
|
526 ;; otherwise the undo info may become screwed up in those buffers.
|
|
527 ;; Hitting 'h' (ediff-toggle-hilit) on a dumb terminal will toggle
|
|
528 ;; between ASCII highlighting and no highlighting.
|
|
529
|
|
530 ;; Fri Feb 24, 1994
|
|
531
|
|
532 ;; Fixed problems with multiple Ediff sessions running simultaneously.
|
|
533
|
|
534 ;; Tue Mar 1, 1994
|
|
535
|
|
536 ;; Added vc-ediff, the Ediff interface to vc.el. (Thanks to Eric
|
|
537 ;; Freudenthal <freudent@jan.ultra.nyu.edu> for contributing this
|
|
538 ;; function.)
|
|
539
|
|
540 ;; Sun Mar 6, 1994
|
|
541
|
|
542 ;; Added rcs-ediff, an Ediff interface to RCS via rcs.el. (Thanks to
|
|
543 ;; Alastair Burt <burt@dfki.uni-kl.de>.)
|
|
544 ;; Some minor improvements.
|
|
545
|
|
546 ;; Tue March 15, 1994
|
|
547
|
|
548 ;; Fixed a buglet in defining ediff-current-diff-face-A/B.
|
|
549 ;; (Thanks to Job Ganzevoort <Job.Ganzevoort@cwi.nl>.)
|
|
550
|
|
551 ;; Tue March 22, 1994
|
|
552
|
|
553 ;; Fixed a bug with ediffing narrowed buffers, reported by Kevin
|
|
554 ;; Broadey <KevinB@bartley.demon.co.uk>.
|
|
555 ;; Made Ediff to work with files that have incomplete last line.
|
7391
|
556 ;; Made Ediff execute diff and patch using Bourne Shell, which
|
7267
|
557 ;; should eliminate problems with $prompt that some people had.
|
|
558
|
|
559 ;; Thu March 24, 1994
|
|
560
|
|
561 ;; Achieved quadratic speedup in the size of the file by replacing the
|
|
562 ;; slow goto-line by forward-line. Ediff is now *much* faster than
|
|
563 ;; Emerge on large files. Converted demarkation of difference regions
|
|
564 ;; from markers to overlays. This will later allow us to highlight all
|
|
565 ;; diffs, not just the current one.
|
|
566
|
|
567 ;; Wed March 30, 1994
|
|
568
|
|
569 ;; Under X, Ediff now highlights all differences in dim colors and the
|
|
570 ;; current difference in bright colors. Improved Lucid Emacs support.
|
|
571
|
|
572 ;; Thu March 31, 1994
|
|
573
|
|
574 ;; Changed toggle hilit to cycle through 3 states: highlighting all
|
|
575 ;; diffs, highlighting only the current diff, and highlighting using
|
|
576 ;; ASCII flags.
|
|
577 ;; Added support for difference regions that are not full lines.
|
|
578
|
|
579 ;; Fri April 1, 1994
|
|
580
|
|
581 ;; Fixed bugs related to writing buffers A and B.
|
|
582 ;; Added commands 'ga', 'gb' to jump directly to the closest diff in
|
|
583 ;; buffer A and B, respectively.
|
|
584
|
|
585
|
|
586 ;;; Code:
|
|
587
|
|
588 (require 'emerge) ;; Ediff is based on emerge
|
|
589
|
|
590
|
|
591 ;;; Macros
|
|
592 (defmacro ediff-if-lucid ()
|
|
593 (` (string-match "Lucid" emacs-version)))
|
|
594 (defmacro ediff-odd-p (arg)
|
|
595 (` (eq (logand (, arg) 1) 1)))
|
|
596 (defmacro ediff-buffer-live-p (buf)
|
|
597 (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf))))))
|
|
598
|
|
599
|
|
600 (defun ediff-mode ()
|
|
601 "Ediff mode is used by the Ediff file-difference package.
|
|
602 It is entered only through one of the following commands:
|
|
603 ``ediff''
|
|
604 ``ediff-files''
|
|
605 ``ediff-buffers''
|
|
606 ``epatch''
|
|
607 ``ediff-patch-file''
|
|
608 ``ediff-patch-buffer''
|
|
609 ``vc-ediff''
|
|
610 ``rcs-ediff''
|
|
611 or through a non-interactive Emacs Lisp function
|
|
612 ``ediff-files-remote''
|
|
613
|
|
614 Commands:
|
|
615 \\{ediff-mode-map}"
|
|
616 (interactive)
|
|
617 (kill-all-local-variables)
|
|
618 (setq major-mode 'ediff-mode)
|
|
619 (setq mode-name "Ediff"))
|
|
620
|
|
621 (defvar ediff-version "1.31"
|
|
622 "The current version of Ediff.")
|
|
623
|
|
624 (defun ediff-version ()
|
|
625 "Return string describing the version of Ediff.
|
|
626 When called interactively, displays the version."
|
|
627 (interactive)
|
|
628 (if (interactive-p)
|
|
629 (message "Ediff version %s" (ediff-version))
|
|
630 ediff-version))
|
|
631
|
|
632
|
|
633 ;; Hook variables
|
|
634
|
|
635 (defvar ediff-before-setup-windows-hooks nil
|
|
636 "* Hooks to run before Ediff sets its own window config. This can be used
|
|
637 to save the previous window config, which can be restored on ediff-quit or
|
|
638 ediff-suspend.")
|
|
639 (defvar ediff-startup-hooks nil
|
|
640 "*Hooks to run in the control buffer after Ediff has been set up.")
|
|
641 (defvar ediff-select-hooks nil
|
|
642 "*Hooks to run after a difference has been selected.")
|
|
643 (defvar ediff-unselect-hooks nil
|
|
644 "*Hooks to run after a difference has been unselected.")
|
|
645 (defvar ediff-prepare-buffer-hooks nil
|
|
646 "*Hooks called after buffers A and B are set up.")
|
|
647 (defvar ediff-load-hooks nil
|
|
648 "* Hook run after Ediff is loaded. Can be used to change defaults.")
|
|
649
|
|
650 (defvar ediff-suspend-hooks 'ediff-default-suspend-hook
|
|
651 "* Hooks to run in the Ediff control buffer each time Ediff is
|
|
652 suspended.")
|
|
653 (defvar ediff-quit-hooks 'ediff-default-quit-hook
|
|
654 "* Hooks to run in the Ediff control buffer after the ediff has been
|
|
655 finished.")
|
|
656
|
|
657 (make-variable-buffer-local 'local-write-file-hooks)
|
|
658 (make-variable-buffer-local 'before-change-function)
|
|
659
|
|
660 ;; Help messages
|
|
661
|
|
662 (defconst ediff-help-message-long
|
|
663 "p,DEL - prev diff c - recenter ab - diff A to B l - line numbers
|
|
664 n,SPC - next diff v/V - scroll up/dn ba - diff B to A f - file names
|
|
665 j - jump to diff </> - scroll lt/rt ra - restore A z - suspend Ediff
|
|
666 ga - goto pt in A s - toggle split rb - restore B q - quit Ediff
|
|
667 gb - goto pt in B h - toggle hilit
|
|
668 wa/wb - save buf A/B A/B - toggle read-only buf A/B ? - toggle help")
|
|
669
|
|
670 (defconst ediff-help-message-short
|
|
671 " ? - toggle help window")
|
|
672
|
|
673 (defvar ediff-help-message ediff-help-message-long
|
|
674 "* The actual help message.")
|
|
675
|
|
676
|
|
677 (defvar ediff-diff-program "diff"
|
|
678 "* Name of the program that compares two files.")
|
|
679 (defvar ediff-diff-options ""
|
|
680 "* Options to pass to ``ediff-diff-program''.")
|
|
681
|
|
682
|
|
683 ;; Support for patches
|
|
684
|
|
685 (defvar ediff-patch-program "patch"
|
|
686 "* Name of the program that applies patches.")
|
|
687 (defvar ediff-patch-options ""
|
|
688 "* Options to pass to ediff-patch-program.")
|
|
689
|
|
690 (defvar ediff-shell "sh"
|
7391
|
691 "* The shell used to run diff and patch. If user's .profile or
|
7267
|
692 .cshrc files are set up correctly, any shell will do. However, some people
|
|
693 set $prompt or other things incorrectly, which leads to undesirable output
|
|
694 messages. These may cause Ediff to fail. In such a case, set ediff-shell
|
|
695 to a shell that you are not using or, better, fix your shell's startup file.")
|
|
696
|
|
697 (defvar ediff-diff-ok-lines-regexp
|
|
698 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\|Warning:\\)"
|
|
699 "*Regexp that matches normal output lines from ``ediff-diff-program''.
|
|
700 This is mostly lifted from Emerge, except that Ediff also considers the
|
|
701 'Missing newline' message to be 'normal output.'
|
|
702 Lines that do not match are assumed to be error messages.")
|
|
703
|
|
704 (defvar ediff-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
|
|
705 (concat "^" x "\\([acd]\\)" x "$"))
|
|
706 "*Pattern to match lines produced by diff that describe differences.")
|
|
707
|
|
708 (defvar ediff-patch-buf nil
|
|
709 "The buffer of the patch file.")
|
|
710 (defvar ediff-patch-diagnostics nil
|
7391
|
711 "The buffer where patch would display its diagnostics.")
|
7267
|
712
|
|
713
|
|
714 ;; Copying diffs betw buffers.
|
|
715
|
|
716 (emerge-defvar-local ediff-killed-diffs-alist nil
|
|
717 "A list of killed diffs. A diff is saved here if it is replaced by a diff
|
|
718 from another buffer. This alist has the form:
|
|
719 ((num (A . diff) (B . diff)) ...), where A or B parts may be missing.")
|
|
720
|
|
721
|
|
722 ;; Highlighting
|
|
723 (defvar ediff-before-flag-bol
|
|
724 ;"vvvvvvvvvvvvvvvv---- ediff ----vvvvvvvvvvvvvvv\n"
|
|
725 ">>--->>>\n"
|
|
726 "*Flag placed above the highlighted block of differences. Must end with
|
|
727 newline. Must be set before Ediff is loaded. If set to nil, the flags from
|
|
728 emerge.el are used.")
|
|
729 (defvar ediff-after-flag-bol
|
|
730 ;"^^^^^^^^^^^^^^^^---- ediff ----^^^^^^^^^^^^^^^\n"
|
|
731 "<<<---<<\n"
|
|
732 "*Flag placed below the highlighted block of differences. Must end with
|
|
733 newline. Must be set before Ediff is loaded. If set to nil, the flags from
|
|
734 emerge.el are used.")
|
|
735
|
|
736 (defvar ediff-before-flag-mol ">>--->>>"
|
|
737 "*This is like ediff-before-flag, except it is used when a difference
|
|
738 region starts in the middle of a line.")
|
|
739 (defvar ediff-after-flag-mol "<<<---<<"
|
|
740 "*This is like ediff-after-flag, except it is used when a difference
|
|
741 region starts in the middle of a line.")
|
|
742
|
|
743 (emerge-defvar-local ediff-before-flag-A nil
|
|
744 "This is the actual ASCII before-flag in effect in buffer A.
|
|
745 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
|
|
746 on whether the selected difference region starts in the middle of a line
|
|
747 or at the beginning of a line.")
|
|
748 (emerge-defvar-local ediff-after-flag-A nil
|
|
749 "This is the actual ASCII after-flag in effect in buffer A.
|
|
750 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
|
|
751 on whether the selected difference region starts in the middle of a line
|
|
752 or at the beginning of a line.")
|
|
753 (emerge-defvar-local ediff-before-flag-B nil
|
|
754 "This is the actual ASCII before-flag in effect in buffer B.
|
|
755 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
|
|
756 on whether the selected difference region starts in the middle of a line
|
|
757 or at the beginning of a line.")
|
|
758 (emerge-defvar-local ediff-after-flag-B nil
|
|
759 "This is the actual ASCII after-flag in effect in buffer B.
|
|
760 It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
|
|
761 on whether the selected difference region starts in the middle of a line
|
|
762 or at the beginning of a line.")
|
|
763
|
|
764
|
|
765 (emerge-defvar-local ediff-want-faces t
|
|
766 "If t, differences will be highlighted using faces on a window
|
|
767 system. If nil, they will be highlighted using ASCII flags, ediff-before-flag
|
|
768 and ediff-after-flag. On a non-window system, differences are always
|
|
769 highlighted using ASCII flags.
|
|
770
|
|
771 This is not a user option. Can be set either in .emacs or toggled
|
|
772 interactively, using ediff-toggle-hilit.")
|
|
773
|
|
774 (emerge-defvar-local ediff-highlight-selected-only nil
|
|
775 "If t, only the selected differences are highlighted.
|
|
776
|
|
777 This is not a user option. Can be set either in .emacs or toggled
|
|
778 interactively, using ediff-toggle-hilit.")
|
|
779
|
|
780 (emerge-defvar-local ediff-highlighting-style nil
|
|
781 "A var local to each ediff-control buffer. Indicates highlighting style
|
|
782 in effect for this buffer: 'face, 'ascii, nil -- temporarily unhighlighted,
|
|
783 'off -- turned off \(on a dumb terminal only\).")
|
|
784
|
|
785
|
|
786
|
|
787 ;; Variables that control each Ediff session. They are local to the
|
|
788 ;; control buffer.
|
|
789
|
|
790 ;; Mode variables
|
|
791 (emerge-defvar-local ediff-A-buffer nil
|
|
792 "The buffer in which the A variant is stored.")
|
|
793 (emerge-defvar-local ediff-B-buffer nil
|
|
794 "The buffer in which the B variant is stored.")
|
|
795 (emerge-defvar-local ediff-control-buffer nil
|
|
796 "The control buffer of ediff. ")
|
|
797
|
|
798 (emerge-defvar-local ediff-control-buffer-suffix nil
|
|
799 "The suffix of the control buffer name. ")
|
|
800
|
|
801 (defvar ediff-control-window nil
|
|
802 "The control window.")
|
|
803
|
|
804
|
|
805 (emerge-defvar-local ediff-A-buffer-values nil
|
|
806 "Keeps working values of ediff-saved-variables for ediff-A-buffer.")
|
|
807 (emerge-defvar-local ediff-B-buffer-values nil
|
|
808 "Keeps working values of ediff-saved-variables for ediff-B-buffer.")
|
|
809
|
|
810 (emerge-defvar-local ediff-A-buffer-values-setup nil
|
|
811 "Remembers ediff-saved-variables for ediff-A-buffer as they were at setup.")
|
|
812 (emerge-defvar-local ediff-B-buffer-values-setup nil
|
|
813 "Remembers ediff-saved-variables for ediff-B-buffer as they were at setup.")
|
|
814
|
|
815 (emerge-defvar-local ediff-difference-vector nil
|
|
816 "Vector of differences between the variants. Each difference is
|
|
817 represented by a vector of two overlays. The first overlays the difference
|
|
818 section in the A buffer and the second overlays the diff in the B buffer.
|
|
819 If a difference section is empty, the corresponding overlay's endpoints
|
|
820 councide. ")
|
|
821
|
|
822 (emerge-defvar-local ediff-current-difference -1
|
|
823 "The difference that is currently selected.")
|
|
824 (emerge-defvar-local ediff-number-of-differences nil
|
|
825 "Number of differences found.")
|
|
826
|
|
827 (emerge-defvar-local ediff-diff-buffer nil
|
7391
|
828 "Buffer containing the output of diff, used by Ediff to step through files.")
|
7267
|
829 (emerge-defvar-local ediff-diff-error-buffer nil
|
7391
|
830 "Buffer containing the output of diff, when diff returns errors.")
|
7267
|
831
|
|
832 (emerge-defvar-local ediff-this-buffer-control-sessions nil
|
|
833 "Keeps the list of ediff-control buffers associated with each buffer A/B
|
|
834 involved in an ediff session.")
|
|
835
|
|
836 (defvar ediff-disturbed-overlays nil
|
|
837 "A list of difference overlays that were disturbed by copying or recovery
|
|
838 of the current diff.")
|
|
839
|
|
840 (defvar ediff-shaded-overlay-priority
|
|
841 (if (ediff-if-lucid)
|
|
842 (1+ mouse-highlight-priority)
|
|
843 100) ;; 100 is a kludge. There is a bug in insert-in-front-hooks
|
|
844 ;; in Emacs < 19.23. When this is fixed, I will get rid of
|
|
845 ;; this kludge.
|
|
846 "Priority of non-selected overlays.")
|
|
847
|
|
848
|
|
849 (if (ediff-if-lucid)
|
|
850 (progn
|
|
851 (fset 'ediff-overlayp (symbol-function 'extentp))
|
|
852 (fset 'ediff-make-overlay (symbol-function 'make-extent))
|
|
853 (fset 'ediff-delete-overlay (symbol-function 'delete-extent))
|
|
854 (fset 'ediff-overlay-put (symbol-function 'set-extent-property))
|
|
855 (fset 'ediff-move-overlay (symbol-function 'set-extent-endpoints))
|
|
856 (fset 'ediff-overlay-start (symbol-function 'extent-start-position))
|
|
857 (fset 'ediff-overlay-end (symbol-function 'extent-end-position))
|
|
858 (fset 'ediff-overlay-get (symbol-function 'extent-property)))
|
|
859 (fset 'ediff-overlayp (symbol-function 'overlayp))
|
|
860 (fset 'ediff-make-overlay (symbol-function 'make-overlay))
|
|
861 (fset 'ediff-delete-overlay (symbol-function 'delete-overlay))
|
|
862 (fset 'ediff-overlay-put (symbol-function 'overlay-put))
|
|
863 (fset 'ediff-move-overlay (symbol-function 'move-overlay))
|
|
864 (fset 'ediff-overlay-start (symbol-function 'overlay-start))
|
|
865 (fset 'ediff-overlay-end (symbol-function 'overlay-end))
|
|
866 (fset 'ediff-overlay-get (symbol-function 'overlay-get)))
|
|
867
|
|
868 (if window-system
|
|
869 (if (ediff-if-lucid)
|
|
870 (progn
|
|
871 (fset 'ediff-select-frame (symbol-function 'select-screen))
|
|
872 (fset 'ediff-window-frame (symbol-function 'window-screen))
|
|
873 (fset 'ediff-display-color-p (symbol-function 'x-color-display-p))
|
|
874 (fset 'ediff-get-face (symbol-function 'get-face)))
|
|
875 (fset 'ediff-window-frame (symbol-function 'window-frame))
|
|
876 (fset 'ediff-select-frame (symbol-function 'select-frame))
|
|
877 (fset 'ediff-display-color-p (symbol-function 'x-display-color-p))
|
|
878 (fset 'ediff-get-face (symbol-function 'internal-get-face)))
|
|
879 ;; not a window system
|
|
880 (fset 'ediff-window-frame (function (lambda (wind) (if wind 1 nil)) ))
|
|
881 (fset 'ediff-select-frame (symbol-function 'identity))
|
|
882 (fset 'ediff-make-current-diff-overlay (function (lambda (type) nil)))
|
|
883 (fset 'ediff-unhighlight-diffs-totally (function (lambda () nil))))
|
|
884
|
|
885
|
|
886 (if (not window-system)
|
|
887 ()
|
|
888 (defvar ediff-current-diff-face-A
|
|
889 (progn
|
|
890 (make-face 'ediff-current-diff-face-A)
|
|
891 (cond ((ediff-display-color-p)
|
|
892 (set-face-foreground 'ediff-current-diff-face-A "firebrick")
|
|
893 (set-face-background 'ediff-current-diff-face-A "pale green"))
|
|
894 (t
|
|
895 (if (ediff-if-lucid)
|
|
896 (copy-face 'modeline 'ediff-current-diff-face-A)
|
|
897 (copy-face 'highlight 'ediff-current-diff-face-A))
|
|
898 ))
|
|
899 (ediff-get-face 'ediff-current-diff-face-A))
|
|
900 "Face for highlighting the currently selected difference in buffer A of
|
|
901 the Ediff display")
|
|
902
|
|
903 (defvar ediff-current-diff-face-B
|
|
904 (progn
|
|
905 (make-face 'ediff-current-diff-face-B)
|
|
906 (cond ((ediff-display-color-p)
|
|
907 (set-face-foreground 'ediff-current-diff-face-B "DarkOrchid")
|
|
908 (set-face-background 'ediff-current-diff-face-B "Yellow"))
|
|
909 (t
|
|
910 (if (ediff-if-lucid)
|
|
911 (copy-face 'modeline 'ediff-current-diff-face-B)
|
|
912 (copy-face 'highlight 'ediff-current-diff-face-B))
|
|
913 ))
|
|
914 (ediff-get-face 'ediff-current-diff-face-B))
|
|
915 "Face for highlighting the currently selected difference in buffer B of
|
|
916 the Ediff display")
|
|
917
|
|
918 (defvar ediff-even-diff-face-A
|
|
919 (progn
|
|
920 (make-face 'ediff-even-diff-face-A)
|
|
921 (cond ((ediff-display-color-p)
|
|
922 (set-face-background 'ediff-even-diff-face-A "light grey"))
|
|
923 (t
|
|
924 (if (ediff-if-lucid)
|
|
925 (progn
|
|
926 (copy-face 'highlight 'ediff-even-diff-face-A)
|
|
927 (invert-face 'ediff-even-diff-face-A))
|
|
928 (make-face-italic 'ediff-even-diff-face-A))))
|
|
929 (ediff-get-face 'ediff-even-diff-face-A))
|
|
930 "Face used to highlight even-numbered differences in buffer A.")
|
|
931
|
|
932 (defvar ediff-even-diff-face-B
|
|
933 (progn
|
|
934 (make-face 'ediff-even-diff-face-B)
|
|
935 (cond ((ediff-display-color-p)
|
|
936 (set-face-foreground 'ediff-even-diff-face-B "White")
|
|
937 (set-face-background 'ediff-even-diff-face-B "Gray"))
|
|
938 (t
|
|
939 (if (ediff-if-lucid)
|
|
940 (copy-face 'highlight 'ediff-even-diff-face-B)
|
|
941 (make-face-italic 'ediff-even-diff-face-B))))
|
|
942 (ediff-get-face 'ediff-even-diff-face-B))
|
|
943 "Face used to highlight even-numbered differences in buffer B.")
|
|
944
|
|
945 (defvar ediff-odd-diff-face-A
|
|
946 (progn
|
|
947 (make-face 'ediff-odd-diff-face-A)
|
|
948 (cond ((ediff-display-color-p)
|
|
949 (set-face-foreground 'ediff-odd-diff-face-A "White")
|
|
950 (set-face-background 'ediff-odd-diff-face-A "Gray"))
|
|
951 (t
|
|
952 (if (ediff-if-lucid)
|
|
953 (copy-face 'highlight 'ediff-odd-diff-face-A)
|
|
954 (make-face-italic 'ediff-odd-diff-face-A))))
|
|
955 (ediff-get-face 'ediff-odd-diff-face-A))
|
|
956 "Face used to highlight odd-numbered differences in buffer A.")
|
|
957
|
|
958 (defvar ediff-odd-diff-face-B
|
|
959 (progn
|
|
960 (make-face 'ediff-odd-diff-face-B)
|
|
961 (cond ((ediff-display-color-p)
|
|
962 (set-face-foreground 'ediff-odd-diff-face-B "Black")
|
|
963 (set-face-background 'ediff-odd-diff-face-B "light grey"))
|
|
964 (t
|
|
965 (if (ediff-if-lucid)
|
|
966 (progn
|
|
967 (copy-face 'highlight 'ediff-odd-diff-face-B)
|
|
968 (invert-face 'ediff-odd-diff-face-B))
|
|
969 (make-face-italic 'ediff-odd-diff-face-B))))
|
|
970 (ediff-get-face 'ediff-odd-diff-face-B))
|
|
971 "Face used to highlight odd-numbered differences in buffer B.")
|
|
972
|
|
973
|
|
974 ;; Create *-var faces. These are the actual faces used to highlight
|
|
975 ;; odd-numbered difference regions.
|
|
976 ;; They are used as follows: when highlighting is turned on,
|
|
977 ;; ediff-odd/even-diff-face-A/B are copied
|
|
978 ;; into ediff-odd/even-diff-face-A/B-var, and all odd/even overlays become
|
|
979 ;; highlighted. When highlighting is turned off, then the face 'default is
|
|
980 ;; copied into ediff-odd/even-diff-face-A/B-var, thereby unhighlighting all
|
|
981 ;; difference regions.
|
|
982 (make-face 'ediff-even-diff-face-A-var)
|
|
983 (make-face 'ediff-even-diff-face-B-var)
|
|
984 (make-face 'ediff-odd-diff-face-A-var)
|
|
985 (make-face 'ediff-odd-diff-face-B-var)
|
|
986
|
|
987 ;; initialize *-var faces
|
|
988 (defun ediff-init-var-faces ()
|
|
989 (copy-face (if (and ediff-want-faces (null ediff-highlight-selected-only))
|
|
990 ediff-even-diff-face-A 'default)
|
|
991 'ediff-even-diff-face-A-var)
|
|
992 (copy-face (if (and ediff-want-faces (null ediff-highlight-selected-only))
|
|
993 ediff-even-diff-face-B 'default)
|
|
994 'ediff-even-diff-face-B-var)
|
|
995 (copy-face (if (and ediff-want-faces (null ediff-highlight-selected-only))
|
|
996 ediff-odd-diff-face-A 'default)
|
|
997 'ediff-odd-diff-face-A-var)
|
|
998 (copy-face (if (and ediff-want-faces (null ediff-highlight-selected-only))
|
|
999 ediff-odd-diff-face-B 'default)
|
|
1000 'ediff-odd-diff-face-B-var))
|
|
1001
|
|
1002
|
|
1003 ;;; Overlays
|
|
1004
|
|
1005 (emerge-defvar-local ediff-current-diff-overlay-A nil
|
|
1006 "Overlay in buffer A.")
|
|
1007 (emerge-defvar-local ediff-current-diff-overlay-B nil
|
|
1008 "Overlay in buffer B.")
|
|
1009
|
|
1010 (defun ediff-make-current-diff-overlay (type)
|
|
1011 (let ((overlay (if (eq type 'A)
|
|
1012 'ediff-current-diff-overlay-A
|
|
1013 'ediff-current-diff-overlay-B))
|
|
1014 (buffer (if (eq type 'A) ediff-A-buffer ediff-B-buffer))
|
|
1015 (face (if (eq type 'A)
|
|
1016 (face-name ediff-current-diff-face-A)
|
|
1017 (face-name ediff-current-diff-face-B))))
|
|
1018 (set overlay (ediff-make-overlay (point-max) (point-max) buffer))
|
|
1019 (ediff-overlay-put (eval overlay) 'face face)
|
|
1020 (ediff-overlay-put (eval overlay) 'ediff ediff-control-buffer)
|
|
1021 ))
|
|
1022
|
|
1023 ;; Computes priority of ediff overlay.
|
|
1024 (defun ediff-highest-priority (start end buffer)
|
|
1025 (let ((pos (max 1 (1- start)))
|
|
1026 ovr-list)
|
|
1027 (if (ediff-if-lucid)
|
|
1028 (+ 2 mouse-highlight-priority)
|
|
1029 (emerge-eval-in-buffer
|
|
1030 buffer
|
|
1031 (while (< pos (min (point-max) (1+ end)))
|
|
1032 (setq ovr-list (append (overlays-at pos) ovr-list))
|
|
1033 (setq pos (next-overlay-change pos)))
|
|
1034 (1+ (eval
|
|
1035 (cons '+
|
|
1036 (mapcar (function
|
|
1037 (lambda (ovr)
|
|
1038 (if ovr
|
|
1039 (or (ediff-overlay-get ovr 'priority) 0)
|
|
1040 0)))
|
|
1041 ovr-list)
|
|
1042 )))
|
|
1043 ))))
|
|
1044
|
|
1045 ) ; end of window-system-only code.
|
|
1046
|
|
1047
|
|
1048
|
|
1049 ;;; Misc
|
|
1050
|
|
1051 (defvar ediff-split-window-function 'split-window-vertically
|
|
1052 "* The function to be called to divide the main window between buffer-A
|
|
1053 and buffer-B. You can set it to be split horizontally instead of the
|
|
1054 default verstical split by setting this variable to
|
|
1055 'split-window-horizontally. You can also have your own function for fancy
|
|
1056 splits. This variable has no effect when buffer-A and buffer-B are shown in
|
|
1057 different frames. In this case, Ediff will use those frames to display
|
|
1058 these buffers.")
|
|
1059
|
|
1060 (defconst ediff-saved-variables
|
|
1061 '(buffer-read-only
|
|
1062 buffer-auto-save-file-name)
|
|
1063 "Variables and properties of a buffer which are saved, modified and restored
|
|
1064 during an Ediff session.")
|
|
1065
|
|
1066 (defconst ediff-working-values '(nil nil)
|
|
1067 "Values to be assigned to ediff-saved-variables during diff.")
|
|
1068
|
|
1069 (defvar ediff-use-last-dir nil
|
|
1070 "* If t, Ediff will use last directory it had seen as a default
|
|
1071 directory when prompting for file names.")
|
|
1072
|
|
1073 (defvar ediff-nix-help-in-control-buffer nil
|
|
1074 "*Don't want C-h to invoke Emacs help. Instead, C-h will jump to previous
|
|
1075 difference.")
|
|
1076
|
|
1077 (defvar ediff-temp-file-prefix
|
|
1078 (let ((env (getenv "TMPDIR"))
|
|
1079 d)
|
|
1080 (setq d (if (and env (> (length env) 0))
|
|
1081 env
|
|
1082 "/tmp"))
|
|
1083 (if (= (aref d (1- (length d))) ?/)
|
|
1084 (setq d (substring d 0 -1)))
|
|
1085 (concat d "/ediff"))
|
|
1086 "*Prefix to put on Ediff temporary file names.
|
|
1087 Do not start with `~/' or `~user-name/'.")
|
|
1088
|
|
1089 (defvar ediff-temp-file-mode 384 ; u=rw only
|
|
1090 "*Mode for Ediff temporary files.")
|
|
1091
|
|
1092 (defvar ediff-last-dir-A nil
|
|
1093 "Last directory used by an Ediff command for file-A.")
|
|
1094 (defvar ediff-last-dir-B nil
|
|
1095 "Last directory used by an Ediff command for file-B.")
|
|
1096
|
|
1097 ;; Build keymaps
|
|
1098
|
|
1099 (defvar ediff-mode-map nil
|
|
1100 "Local keymap used in Ediff mode.")
|
|
1101
|
|
1102
|
|
1103 (defun ediff-setup-keymap ()
|
|
1104 "Set up the keymap used in the control buffer of Ediff."
|
|
1105 (setq ediff-mode-map (make-sparse-keymap))
|
|
1106 (suppress-keymap ediff-mode-map)
|
|
1107
|
|
1108 (define-key ediff-mode-map "p" 'ediff-previous-difference)
|
|
1109 (define-key ediff-mode-map "\C-?" 'ediff-previous-difference)
|
|
1110 (define-key ediff-mode-map "\C-h" (if ediff-nix-help-in-control-buffer
|
|
1111 'ediff-previous-difference nil))
|
|
1112 (define-key ediff-mode-map "n" 'ediff-next-difference)
|
|
1113 (define-key ediff-mode-map " " 'ediff-next-difference)
|
|
1114 (define-key ediff-mode-map "j" 'ediff-jump-to-difference)
|
|
1115 (define-key ediff-mode-map "g" nil)
|
|
1116 (define-key ediff-mode-map "ga" 'ediff-jump-to-difference-at-point)
|
|
1117 (define-key ediff-mode-map "gb" 'ediff-jump-to-difference-at-point)
|
|
1118 (define-key ediff-mode-map "q" 'ediff-quit)
|
|
1119 (define-key ediff-mode-map "z" 'ediff-suspend)
|
|
1120 (define-key ediff-mode-map "c" 'ediff-recenter)
|
|
1121 (define-key ediff-mode-map "s" 'ediff-toggle-split)
|
|
1122 (define-key ediff-mode-map "h" 'ediff-toggle-hilit)
|
|
1123 (define-key ediff-mode-map "v" 'ediff-scroll-up)
|
|
1124 (define-key ediff-mode-map "\C-v" 'ediff-scroll-up)
|
|
1125 (define-key ediff-mode-map "^" 'ediff-scroll-down)
|
|
1126 (define-key ediff-mode-map "\M-v" 'ediff-scroll-down)
|
|
1127 (define-key ediff-mode-map "V" 'ediff-scroll-down)
|
|
1128 (define-key ediff-mode-map "<" 'ediff-scroll-left)
|
|
1129 (define-key ediff-mode-map ">" 'ediff-scroll-right)
|
|
1130 (define-key ediff-mode-map "f" 'ediff-file-names)
|
|
1131 (define-key ediff-mode-map "l" 'ediff-line-numbers)
|
|
1132 (define-key ediff-mode-map "?" 'ediff-toggle-help)
|
|
1133 (define-key ediff-mode-map "a" nil)
|
|
1134 (define-key ediff-mode-map "ab" 'ediff-diff-to-diff)
|
|
1135 (define-key ediff-mode-map "b" nil)
|
|
1136 (define-key ediff-mode-map "ba" 'ediff-diff-to-diff)
|
|
1137 (define-key ediff-mode-map "r" nil)
|
|
1138 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
|
|
1139 (define-key ediff-mode-map "rb" 'ediff-restore-diff)
|
|
1140 (define-key ediff-mode-map "o" nil)
|
|
1141 (define-key ediff-mode-map "A" 'ediff-toggle-read-only)
|
|
1142 (define-key ediff-mode-map "B" 'ediff-toggle-read-only)
|
|
1143 (define-key ediff-mode-map "w" nil)
|
|
1144 (define-key ediff-mode-map "wa" 'ediff-save-buffer)
|
|
1145 (define-key ediff-mode-map "wb" 'ediff-save-buffer)
|
|
1146 (define-key ediff-mode-map "k" nil)
|
|
1147 (define-key ediff-mode-map "kkk" 'ediff-reload-keymap) ;; for debug
|
|
1148 ;; Allow ediff-mode-map to be referenced indirectly
|
|
1149 (fset 'ediff-mode-map ediff-mode-map))
|
|
1150
|
|
1151
|
|
1152 ;;; Setup functions
|
|
1153
|
|
1154 (defun ediff-find-file (file buffer &optional last-dir)
|
|
1155 "Visits FILE for ediff.
|
|
1156 BUFFER is a variable symbol that is supposed to
|
|
1157 get the buffer into which FILE is read. LAST-DIR is the directory variable
|
|
1158 symbol where FILE's dir name should be returned.
|
|
1159 Arguments: (file 'buffer &optional 'last-dir)"
|
|
1160 (if (not (file-readable-p file))
|
|
1161 (error "File `%s' does not exist or is not readable" file))
|
|
1162
|
|
1163 ;; Record the buffer
|
|
1164 (set buffer (find-file-noselect file))
|
|
1165 ;; Record the directory of the file
|
|
1166 (if last-dir
|
|
1167 (set last-dir (expand-file-name (file-name-directory file))))
|
|
1168
|
|
1169 ;; Make sure the entire file is seen, and it reflects what is on disk
|
|
1170 (emerge-eval-in-buffer
|
|
1171 (eval buffer)
|
|
1172 (widen)
|
|
1173 (let ((temp (file-local-copy file))
|
|
1174 startup-hooks)
|
|
1175 (if temp
|
|
1176 (setq file temp
|
|
1177 startup-hooks
|
|
1178 (cons (` (lambda () (delete-file (, file))))
|
|
1179 startup-hooks))
|
|
1180 ;; Verify that the file matches the buffer
|
|
1181 (emerge-verify-file-buffer)))))
|
|
1182
|
|
1183 (defun ediff-files-internal (file-A file-B &optional startup-hooks)
|
|
1184 (let (buffer-A buffer-B)
|
|
1185 (message "Ediff: Reading file %s ... " file-A)(sit-for .5)
|
|
1186 (ediff-find-file file-A 'buffer-A 'ediff-last-dir-A)
|
|
1187 (message "Ediff: Reading file %s ... " file-B)(sit-for .5)
|
|
1188 (ediff-find-file file-B 'buffer-B 'ediff-last-dir-B)
|
|
1189 (ediff-setup buffer-A file-A buffer-B file-B startup-hooks)))
|
|
1190
|
|
1191 (defun ediff-get-patch-buffer (dir)
|
|
1192 "Obtain patch buffer. If patch is already in a buffer---use it.
|
|
1193 Else, read patch file into a new buffer."
|
|
1194 (if (y-or-n-p "Is the patch file already in a buffer? ")
|
|
1195 (setq ediff-patch-buf
|
|
1196 (get-buffer (read-buffer "Patch buffer name: " nil t))) ;must match
|
|
1197 (setq ediff-patch-buf
|
|
1198 (find-file-noselect (read-file-name "Patch file name: "
|
|
1199 dir))))
|
|
1200 (emerge-eval-in-buffer
|
|
1201 ediff-patch-buf
|
|
1202 (toggle-read-only 1))
|
|
1203 (setq ediff-patch-diagnostics
|
|
1204 (get-buffer-create "*ediff patch diagnostics*"))
|
|
1205 (emerge-eval-in-buffer
|
|
1206 ediff-patch-diagnostics
|
|
1207 (insert-buffer ediff-patch-buf))
|
|
1208 )
|
|
1209
|
|
1210 ;; Start up Ediff on two files
|
|
1211 (defun ediff-setup (buffer-A file-A buffer-B file-B startup-hooks)
|
|
1212 (setq file-A (expand-file-name file-A))
|
|
1213 (setq file-B (expand-file-name file-B))
|
|
1214 (let* ((control-buffer-name (emerge-unique-buffer-name "*ediff-control" "*"))
|
|
1215 (control-buffer (emerge-eval-in-buffer
|
|
1216 buffer-A
|
|
1217 (get-buffer-create control-buffer-name))))
|
|
1218 (emerge-eval-in-buffer
|
|
1219 control-buffer
|
|
1220 (ediff-mode) ;; in control buffer only
|
|
1221 (setq buffer-read-only nil)
|
|
1222 (setq ediff-A-buffer buffer-A)
|
|
1223 (setq ediff-B-buffer buffer-B)
|
|
1224 (setq ediff-control-buffer control-buffer)
|
|
1225 (setq ediff-control-buffer-suffix
|
|
1226 (if (string-match "<[0-9]*>" control-buffer-name)
|
|
1227 (substring control-buffer-name
|
|
1228 (match-beginning 0) (match-end 0))
|
|
1229 "<1>"))
|
|
1230 (ediff-remember-buffer-characteristics t) ;; remember at setup
|
|
1231
|
|
1232 (ediff-set-keys)
|
|
1233 (setq ediff-difference-vector (ediff-make-diff-list file-A file-B))
|
|
1234 (setq ediff-number-of-differences (length ediff-difference-vector))
|
|
1235 (setq ediff-current-difference -1)
|
|
1236 (ediff-make-current-diff-overlay 'A)
|
|
1237 (ediff-make-current-diff-overlay 'B)
|
|
1238 (if window-system
|
|
1239 (ediff-init-var-faces))
|
|
1240 (run-hooks 'ediff-before-setup-windows-hooks)
|
|
1241 (ediff-setup-windows buffer-A buffer-B control-buffer t)
|
|
1242
|
|
1243 ;; all these must be inside emerge-eval-in-buffer control-buffer,
|
|
1244 ;; since these vars are local to control-buffer
|
|
1245 ;; These won't run if there are errors in diff
|
|
1246 (emerge-eval-in-buffer
|
|
1247 ediff-A-buffer
|
|
1248 (run-hooks 'ediff-prepare-buffer-hooks)
|
|
1249 (add-hook 'local-write-file-hooks 'ediff-block-write-file)
|
|
1250 (setq before-change-function 'ediff-before-change-guard)
|
|
1251 ;; add control-buffer to the list of sessions
|
|
1252 (or (memq control-buffer ediff-this-buffer-control-sessions)
|
|
1253 (setq ediff-this-buffer-control-sessions
|
|
1254 (cons control-buffer ediff-this-buffer-control-sessions)))
|
|
1255 (setq mode-line-buffer-identification '("A: %b")))
|
|
1256 (emerge-eval-in-buffer
|
|
1257 ediff-B-buffer
|
|
1258 (run-hooks 'ediff-prepare-buffer-hooks)
|
|
1259 (add-hook 'local-write-file-hooks 'ediff-block-write-file)
|
|
1260 (setq before-change-function 'ediff-before-change-guard)
|
|
1261 ;; add control-buffer to the list of sessions
|
|
1262 (or (memq control-buffer ediff-this-buffer-control-sessions)
|
|
1263 (setq ediff-this-buffer-control-sessions
|
|
1264 (cons control-buffer ediff-this-buffer-control-sessions)))
|
|
1265 (setq mode-line-buffer-identification '("B: %b")))
|
|
1266
|
|
1267 (emerge-eval-in-buffer control-buffer
|
|
1268 (run-hooks 'startup-hooks 'ediff-startup-hooks)
|
|
1269 (setq buffer-read-only t)))))
|
|
1270
|
|
1271 ;; Generate the Ediff difference list between two files
|
|
1272 (defun ediff-make-diff-list (file-A file-B)
|
|
1273 (setq ediff-diff-buffer
|
|
1274 (get-buffer-create (emerge-unique-buffer-name "*ediff-diff" "*")))
|
|
1275 (emerge-eval-in-buffer
|
|
1276 ediff-diff-buffer
|
|
1277 (erase-buffer)
|
|
1278 ;; shell-command tends to display old shell command buffers even when it
|
|
1279 ;; puts output in another buffer---probably an Emacs bug.
|
|
1280 (ediff-kill-buffer-carefully "*Shell Command Output*")
|
|
1281 (let ((shell-file-name ediff-shell))
|
|
1282 (message "Ediff: Computing differences ...")(sit-for .5)
|
|
1283 (shell-command
|
|
1284 (format "%s %s %s %s"
|
|
1285 ediff-diff-program ediff-diff-options
|
|
1286 (emerge-protect-metachars file-A)
|
|
1287 (emerge-protect-metachars file-B))
|
|
1288 t)
|
|
1289 ))
|
|
1290 (ediff-prepare-error-list ediff-diff-ok-lines-regexp)
|
|
1291 (message "Ediff: Computing differences ... Done.")(sit-for .5)
|
|
1292 (ediff-convert-diffs-to-overlays
|
|
1293 ediff-A-buffer ediff-B-buffer
|
|
1294 (ediff-extract-diffs ediff-diff-buffer ediff-A-buffer ediff-B-buffer)))
|
|
1295
|
|
1296 (defun ediff-prepare-error-list (ok-regexp)
|
|
1297 (let ((diff-buff ediff-diff-buffer))
|
|
1298 (setq ediff-diff-error-buffer
|
|
1299 (get-buffer-create (emerge-unique-buffer-name
|
|
1300 "*ediff-diff-errors" "*")))
|
|
1301 (emerge-eval-in-buffer
|
|
1302 ediff-diff-error-buffer
|
|
1303 (erase-buffer)
|
|
1304 (insert-buffer diff-buff)
|
|
1305 (delete-matching-lines ok-regexp))))
|
|
1306
|
|
1307 ;;; Function to start Ediff by patching a file
|
|
1308
|
|
1309 ;;;###autoload
|
|
1310 (defun ediff-patch-file (file-to-patch &optional startup-hooks)
|
|
1311 "Run Ediff by patching FILE-TP-PATCH."
|
|
1312 (interactive "fFile to patch: ")
|
|
1313
|
|
1314 (ediff-get-patch-buffer (file-name-directory file-to-patch))
|
|
1315 (let ((buf (get-file-buffer file-to-patch)))
|
|
1316 (if buf
|
|
1317 (progn
|
|
1318 (emerge-eval-in-buffer
|
|
1319 buf
|
|
1320 (if (buffer-modified-p buf)
|
|
1321 (if (y-or-n-p
|
|
1322 (format
|
|
1323 "File '%s' is already in buffer %s. Save before killing? "
|
|
1324 file-to-patch (buffer-name buf)))
|
|
1325 (save-buffer buf)))
|
|
1326 (set-buffer-modified-p nil))
|
|
1327 (ediff-kill-buffer-carefully buf))))
|
|
1328 (emerge-eval-in-buffer
|
|
1329 ediff-patch-diagnostics
|
|
1330 (let ((shell-file-name ediff-shell))
|
|
1331 (message "Ediff: Applying patch ... ")(sit-for .5)
|
|
1332 (shell-command-on-region
|
|
1333 (point-min) (point-max)
|
|
1334 (format "%s %s %s"
|
|
1335 ediff-patch-program ediff-patch-options
|
|
1336 (expand-file-name file-to-patch))
|
|
1337 t)
|
|
1338 (message "Ediff: Applying patch ... Done.")(sit-for .5)
|
|
1339 ))
|
|
1340 (switch-to-buffer ediff-patch-diagnostics)
|
|
1341 (sit-for 0) ;; synchronize
|
|
1342
|
|
1343 (setq startup-hooks (cons 'ediff-toggle-read-only-A startup-hooks))
|
|
1344 (ediff-files (format "%s.orig" file-to-patch) file-to-patch startup-hooks)
|
|
1345
|
|
1346 (bury-buffer ediff-patch-diagnostics)
|
|
1347 (message "Patch diagnostics available in buffer %s."
|
|
1348 (buffer-name ediff-patch-diagnostics)))
|
|
1349
|
|
1350 (defalias 'epatch 'ediff-patch-file)
|
|
1351
|
|
1352 ;;; Function to start Ediff on files
|
|
1353
|
|
1354 ;;;###autoload
|
|
1355 (defun ediff-files (file-A file-B &optional startup-hooks)
|
|
1356 "Run Ediff on a pair files, FILE-A and FILE-B."
|
|
1357 (interactive
|
|
1358 (let (f)
|
|
1359 (list (setq f (ediff-read-file-name "File A to compare"
|
|
1360 (if ediff-use-last-dir
|
|
1361 ediff-last-dir-A
|
|
1362 default-directory)
|
|
1363 nil nil))
|
|
1364 (ediff-read-file-name "File B to compare"
|
|
1365 (if ediff-use-last-dir
|
|
1366 ediff-last-dir-B nil)
|
|
1367 f f)
|
|
1368 )))
|
|
1369 (ediff-files-internal file-A file-B startup-hooks))
|
|
1370
|
|
1371
|
|
1372 (defalias 'ediff 'ediff-files)
|
|
1373
|
|
1374
|
|
1375 ;;; Function to start Ediff on buffers
|
|
1376
|
|
1377 ;;;###autoload
|
|
1378 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks)
|
|
1379 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
|
|
1380 (interactive "bBuffer A to compare: \nbBuffer B to compare: ")
|
|
1381 (let (ediff-file-A ediff-file-B)
|
|
1382 (emerge-eval-in-buffer
|
|
1383 buffer-A
|
|
1384 (setq ediff-file-A
|
|
1385 (ediff-make-temp-file
|
|
1386 (format ".%s." (file-name-nondirectory (buffer-name)))))
|
|
1387 (write-region (point-min) (point-max) ediff-file-A nil 'no-message))
|
|
1388 (emerge-eval-in-buffer
|
|
1389 buffer-B
|
|
1390 (setq ediff-file-B
|
|
1391 (ediff-make-temp-file
|
|
1392 (format ".%s." (file-name-nondirectory (buffer-name)))))
|
|
1393 (write-region (point-min) (point-max) ediff-file-B nil 'no-message))
|
|
1394 (ediff-setup (get-buffer buffer-A) ediff-file-A
|
|
1395 (get-buffer buffer-B) ediff-file-B
|
|
1396 (cons (` (lambda ()
|
|
1397 (delete-file (, ediff-file-A))
|
|
1398 (delete-file (, ediff-file-B))))
|
|
1399 startup-hooks)
|
|
1400 )))
|
|
1401
|
|
1402 ;;;###autoload
|
|
1403 (defun ediff-patch-buffer (buffer-name &optional startup-hooks)
|
|
1404 "Run Ediff by patching BUFFER-NAME."
|
|
1405 (interactive "bBuffer to patch: ")
|
|
1406
|
|
1407 (let* ((file-buffer (get-buffer buffer-name))
|
|
1408 (file-name (if file-buffer (buffer-file-name file-buffer))))
|
|
1409 (if (not file-name)
|
|
1410 (error "Buffer %s doesn't exist or doesn't visit any file. Why patch?"
|
|
1411 file-name))
|
|
1412
|
|
1413 (ediff-patch-file file-name startup-hooks)))
|
|
1414
|
|
1415
|
|
1416 ;;; Versions Control functions
|
|
1417
|
|
1418 ;;;###autoload
|
|
1419 (defun vc-ediff (rev)
|
|
1420 "Run ediff on version REV of the current buffer in another window.
|
|
1421 If the current buffer is named `F', the version is named `F.~REV~'.
|
7391
|
1422 If `F.~REV~' already exists, it is used instead of being re-created."
|
7267
|
1423 (interactive "sVersion to ediff with (default is the latest version): ")
|
|
1424 (or (featurep 'vc)
|
|
1425 (if (locate-library "vc") ;; if vc.el is available
|
|
1426 (progn
|
|
1427 (require 'vc-hooks)
|
|
1428 (define-key vc-prefix-map "=" 'vc-ediff))
|
|
1429 (error "The VC package is apparently not installed.")))
|
|
1430 (let ((newvers (current-buffer))
|
|
1431 (oldvers (vc-version-other-window rev)))
|
|
1432 (ediff-buffers newvers oldvers)
|
|
1433 ))
|
|
1434
|
|
1435 (defun rcs-ediff-view-revision (&optional rev)
|
|
1436 "View previous RCS revison of current file.
|
|
1437 With prefix argument, prompts for a revision name."
|
|
1438 (interactive (list (if current-prefix-arg
|
|
1439 (read-string "Revision: "))))
|
|
1440 (let* ((filename (buffer-file-name (current-buffer)))
|
|
1441 (switches (append '("-p")
|
|
1442 (if rev (list (concat "-r" rev)) nil)))
|
|
1443 (buff (concat (file-name-nondirectory filename) ".~" rev "~")))
|
|
1444 (message "Working...")
|
|
1445 (setq filename (expand-file-name filename))
|
|
1446 (with-output-to-temp-buffer
|
|
1447 buff
|
|
1448 (let ((output-buffer (rcs-get-output-buffer filename buff)))
|
|
1449 (delete-windows-on output-buffer)
|
|
1450 (save-excursion
|
|
1451 (set-buffer output-buffer)
|
|
1452 (apply 'call-process "co" nil t nil
|
|
1453 ;; -q: quiet (no diagnostics)
|
|
1454 (append switches rcs-default-co-switches
|
|
1455 (list "-q" filename)))))
|
|
1456 (message "")
|
|
1457 buff)))
|
|
1458
|
|
1459 ;;;###autoload
|
|
1460 (defun rcs-ediff (&optional rev)
|
|
1461 "Run Ediff on the current buffer, comparing it with previous RCS revison.
|
|
1462 With prefix argument, prompts for revision name."
|
|
1463 (interactive (list (if current-prefix-arg
|
|
1464 (read-string "Revision: "))))
|
|
1465 (or (featurep 'rcs)
|
|
1466 (if (locate-library "rcs")
|
|
1467 (progn
|
|
1468 (require 'rcs)
|
|
1469 (global-set-key "\C-cD" 'rcs-ediff))
|
|
1470 (error "The RCS package is apparently not installed.")))
|
|
1471 (let ((newvers (current-buffer))
|
|
1472 (oldvers (rcs-ediff-view-revision rev)))
|
|
1473 (ediff-buffers newvers oldvers)
|
|
1474 ))
|
|
1475
|
|
1476
|
|
1477 ;;; Functions to start Ediff via remote request
|
|
1478
|
|
1479 ;;;###autoload
|
|
1480 (defun ediff-files-remote (file-a file-b)
|
|
1481 "Run Ediff on remote files, FILE-A and FILE-B."
|
|
1482 (ediff-files-internal file-a file-b nil)
|
|
1483 (throw 'client-wait nil))
|
|
1484
|
|
1485
|
|
1486 (defun ediff-remote-exit (exit-func)
|
|
1487 "Exit remote Ediff session."
|
|
1488 (ediff-really-quit)
|
|
1489 (funcall exit-func))
|
|
1490
|
|
1491
|
|
1492
|
|
1493 ;; Select the lowest window on the frame.
|
|
1494 (defun ediff-select-lowest-window ()
|
|
1495 (let* ((lowest-window (selected-window))
|
|
1496 (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
|
|
1497 (last-window (previous-window))
|
|
1498 (window-search t))
|
|
1499 (while window-search
|
|
1500 (let* ((this-window (next-window))
|
|
1501 (next-bottom-edge (car (cdr (cdr (cdr
|
|
1502 (window-edges this-window)))))))
|
|
1503 (if (< bottom-edge next-bottom-edge)
|
|
1504 (progn
|
|
1505 (setq bottom-edge next-bottom-edge)
|
|
1506 (setq lowest-window this-window)))
|
|
1507
|
|
1508 (select-window this-window)
|
|
1509 (if (eq last-window this-window)
|
|
1510 (progn
|
|
1511 (select-window lowest-window)
|
|
1512 (setq window-search nil)))))))
|
|
1513
|
|
1514 ;;; Common setup routines
|
|
1515
|
|
1516 ;; Set up the window configuration. If POS is given, set the points to
|
|
1517 ;; the beginnings of the buffers.
|
|
1518 (defun ediff-setup-windows (buffer-A buffer-B control-buffer &optional pos)
|
|
1519 ;; Make sure we are not in the minibuffer window when we try to delete
|
|
1520 ;; all other windows.
|
|
1521 (if (eq (selected-window) (minibuffer-window))
|
|
1522 (other-window 1))
|
|
1523 (delete-other-windows)
|
|
1524 (switch-to-buffer control-buffer)
|
|
1525 (ediff-refresh-mode-line)
|
|
1526
|
|
1527 (ediff-arrange-buffer buffer-A buffer-B (current-buffer) pos)
|
|
1528 (ediff-arrange-buffer buffer-B buffer-A (current-buffer) pos)
|
|
1529 ;; ediff-arrange-buffer always leaves in ctl buffer
|
|
1530 ;; setup ctl wind if it is not set.
|
|
1531 (ediff-setup-control-window)
|
|
1532
|
|
1533 ;; If diff reports errors, display them rather than then compare buffers.
|
|
1534 (if (/= 0 (emerge-eval-in-buffer ediff-diff-error-buffer (buffer-size)))
|
|
1535 (let ((diff-output-buf ediff-diff-buffer))
|
|
1536 (switch-to-buffer ediff-diff-error-buffer)
|
|
1537 (ediff-kill-buffer-carefully control-buffer)
|
|
1538 (error "Errors found in diff output. Diff output buffer is %s"
|
|
1539 diff-output-buf))))
|
|
1540
|
|
1541
|
|
1542 ;; Arranges goal-buf on the screen.
|
|
1543 (defun ediff-arrange-buffer (goal-buf other-buf ctl-buf &optional pos)
|
|
1544 (let* ((ctl-wind (get-buffer-window ctl-buf t))
|
|
1545 (goal-wind (get-buffer-window goal-buf t))
|
|
1546 (other-wind (get-buffer-window other-buf t))
|
|
1547 (ctl-frame (ediff-window-frame ctl-wind))
|
|
1548 (goal-frame (if goal-wind (ediff-window-frame goal-wind)))
|
|
1549 (other-frame (if other-wind (ediff-window-frame other-wind)))
|
|
1550 (ctl-frame-shared (or (eq ctl-frame goal-frame)
|
|
1551 (eq ctl-frame other-frame))))
|
|
1552
|
|
1553 (cond ((and goal-frame (not (eq goal-wind other-wind)))
|
|
1554 ;; goal buffer is visible and we are not comparing file
|
|
1555 ;; against itself (by mistake).
|
|
1556 ;; Note: goal-frame != ctl-frame, as we deleted other
|
|
1557 ;; windows on ctl-frame.
|
|
1558 (ediff-select-frame goal-frame)
|
|
1559 (select-window goal-wind)
|
|
1560 (delete-other-windows))
|
|
1561
|
|
1562 ;; goal-buf invisible, ctl-frame has only ctl-buf
|
|
1563 ;; then put goal-buf on ctl-frame
|
|
1564 ((null ctl-frame-shared)
|
|
1565 (ediff-select-frame ctl-frame)
|
|
1566 (split-window-vertically)
|
|
1567 (ediff-select-lowest-window)
|
|
1568 (setq ctl-wind (selected-window))
|
|
1569 (switch-to-buffer ctl-buf)
|
|
1570 (ediff-setup-control-window)
|
|
1571 (other-window 1)
|
|
1572 (switch-to-buffer goal-buf)) ; goal-buf set
|
|
1573 ;; goal-buf invisible, ctl-frame has ctl-buf and other-buf
|
|
1574 ;; So, put everything in one frame
|
|
1575 (other-frame ;; share with the other buf
|
|
1576 (ediff-select-frame ctl-frame)
|
|
1577 (select-window other-wind)
|
|
1578 (funcall ediff-split-window-function)
|
|
1579 (other-window 1)
|
|
1580 (switch-to-buffer goal-buf))
|
|
1581 (t ;; debug
|
|
1582 (error "Funny window combination (Ediff bug?)")))
|
|
1583
|
|
1584 (if pos
|
|
1585 (goto-char (point-min)))
|
|
1586
|
|
1587 (ediff-select-frame ctl-frame)
|
|
1588 (select-window ctl-wind)
|
|
1589 (switch-to-buffer ctl-buf)))
|
|
1590
|
|
1591 ;; This function assumes that we are in the window where control buffer is
|
|
1592 ;; to reside.
|
|
1593 (defun ediff-setup-control-window ()
|
|
1594 "Set up window for control buffer."
|
|
1595 (erase-buffer)
|
|
1596 (insert ediff-help-message)
|
|
1597 (shrink-window-if-larger-than-buffer)
|
|
1598 (setq ediff-control-window (selected-window))
|
|
1599 (goto-char (point-min))
|
|
1600 (skip-chars-forward " \t\n"))
|
|
1601
|
|
1602
|
|
1603 ;; Set up the keymap in the control buffer
|
|
1604 (defun ediff-set-keys ()
|
|
1605 "Set up Ediff keymap, if necessary."
|
|
1606 (if (null ediff-mode-map)
|
|
1607 (ediff-setup-keymap))
|
|
1608 (use-local-map ediff-mode-map))
|
|
1609
|
|
1610 ;; Reload Ediff keymap. For debugging only.
|
|
1611 (defun ediff-reload-keymap ()
|
|
1612 (interactive)
|
|
1613 (setq ediff-mode-map nil)
|
|
1614 (ediff-set-keys))
|
|
1615
|
|
1616 (defun ediff-before-change-guard (start end)
|
|
1617 "If buffer is highlighted with ASCII flags, remove highlighting before
|
|
1618 changing buf. Arguments, START and END are not used, but are provided
|
|
1619 because this is required by ``before-change-function''."
|
|
1620 (let (notify)
|
|
1621 (save-window-excursion
|
|
1622 (mapcar
|
|
1623 (function
|
|
1624 (lambda (buf)
|
|
1625 (if (ediff-buffer-live-p buf)
|
|
1626 (emerge-eval-in-buffer
|
|
1627 buf
|
|
1628 (if (eq ediff-highlighting-style 'ascii)
|
|
1629 (progn
|
|
1630 (ediff-unselect-and-select-difference
|
|
1631 ediff-current-difference
|
|
1632 'unselect-only 'no-recenter)
|
|
1633 (setq notify t)
|
|
1634 ))))))
|
|
1635 ediff-this-buffer-control-sessions)
|
|
1636 (if notify
|
|
1637 (error "ASCII flags removed. You can edit now. Hit 'c' to rehighlight."))
|
|
1638 )))
|
|
1639
|
|
1640
|
|
1641 (defun ediff-remember-buffer-characteristics (&optional arg)
|
|
1642 "Record certain properties of the buffers being compared.
|
|
1643 Must be called in the control buffer. Saves ``read-only'', ``modified'',
|
|
1644 and ``auto-save'' properties in buffer local variables. Turns off
|
|
1645 ``auto-save-mode''. These properties are restored via a call to
|
|
1646 ``ediff-restore-buffer-characteristics''."
|
|
1647
|
|
1648 ;; remember and alter buffer characteristics
|
|
1649 (set (if arg 'ediff-A-buffer-values-setup 'ediff-A-buffer-values)
|
|
1650 (emerge-eval-in-buffer
|
|
1651 ediff-A-buffer
|
|
1652 (prog1
|
|
1653 (emerge-save-variables ediff-saved-variables)
|
|
1654 (emerge-restore-variables ediff-saved-variables
|
|
1655 ediff-working-values))))
|
|
1656 (set (if arg 'ediff-B-buffer-values-setup 'ediff-B-buffer-values)
|
|
1657 (emerge-eval-in-buffer
|
|
1658 ediff-B-buffer
|
|
1659 (prog1
|
|
1660 (emerge-save-variables ediff-saved-variables)
|
|
1661 (emerge-restore-variables ediff-saved-variables
|
|
1662 ediff-working-values)))))
|
|
1663
|
|
1664 (defun ediff-restore-buffer-characteristics (&optional arg)
|
|
1665 "Restores properties saved by ``ediff-remember-buffer-characteristics''."
|
|
1666 (let ((A-values (if arg ediff-A-buffer-values-setup ediff-A-buffer-values))
|
|
1667 (B-values (if arg ediff-B-buffer-values-setup ediff-B-buffer-values)))
|
|
1668 (emerge-eval-in-buffer ediff-A-buffer
|
|
1669 (emerge-restore-variables ediff-saved-variables
|
|
1670 A-values))
|
|
1671 (emerge-eval-in-buffer ediff-B-buffer
|
|
1672 (emerge-restore-variables ediff-saved-variables
|
|
1673 B-values))))
|
|
1674
|
|
1675
|
|
1676 (defun ediff-extract-diffs (diff-buffer A-buffer B-buffer)
|
|
1677 (let (diff-list
|
|
1678 (a-prev 1) ;; this is needed to set the first diff line correctly
|
|
1679 (b-prev 1))
|
|
1680 (emerge-eval-in-buffer
|
|
1681 A-buffer
|
|
1682 (goto-char (point-min)))
|
|
1683 (emerge-eval-in-buffer
|
|
1684 B-buffer
|
|
1685 (goto-char (point-min)))
|
|
1686 (emerge-eval-in-buffer
|
|
1687 diff-buffer
|
|
1688 (goto-char (point-min))
|
|
1689 (while (re-search-forward ediff-match-diff-line nil t)
|
|
1690 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1)
|
|
1691 (match-end 1))))
|
|
1692 (a-end (let ((b (match-beginning 3))
|
|
1693 (e (match-end 3)))
|
|
1694 (if b
|
|
1695 (string-to-int (buffer-substring b e))
|
|
1696 a-begin)))
|
|
1697 (diff-type (buffer-substring (match-beginning 4) (match-end 4)))
|
|
1698 (b-begin (string-to-int (buffer-substring (match-beginning 5)
|
|
1699 (match-end 5))))
|
|
1700 (b-end (let ((b (match-beginning 7))
|
|
1701 (e (match-end 7)))
|
|
1702 (if b
|
|
1703 (string-to-int (buffer-substring b e))
|
|
1704 b-begin)))
|
|
1705 a-begin-pt a-end-pt b-begin-pt b-end-pt)
|
|
1706 ;; fix the beginning and end numbers, because diff is somewhat
|
|
1707 ;; strange about how it numbers lines
|
|
1708 (if (string-equal diff-type "a")
|
|
1709 (setq b-end (1+ b-end)
|
|
1710 a-begin (1+ a-begin)
|
|
1711 a-end a-begin)
|
|
1712 (if (string-equal diff-type "d")
|
|
1713 (setq a-end (1+ a-end)
|
|
1714 b-begin (1+ b-begin)
|
|
1715 b-end b-begin)
|
|
1716 ;; (string-equal diff-type "c")
|
|
1717 (setq a-end (1+ a-end)
|
|
1718 b-end (1+ b-end))))
|
|
1719 ;; convert to relative line numbers
|
|
1720 (emerge-eval-in-buffer
|
|
1721 A-buffer
|
|
1722 (forward-line (- a-begin a-prev))
|
|
1723 (setq a-begin-pt (point))
|
|
1724 (forward-line (- a-end a-begin))
|
|
1725 (setq a-end-pt (point)
|
|
1726 a-prev a-end))
|
|
1727 (emerge-eval-in-buffer
|
|
1728 B-buffer
|
|
1729 (forward-line (- b-begin b-prev))
|
|
1730 (setq b-begin-pt (point))
|
|
1731 (forward-line (- b-end b-begin))
|
|
1732 (setq b-end-pt (point)
|
|
1733 b-prev b-end))
|
|
1734 (setq diff-list (nconc diff-list (list (vector a-begin-pt a-end-pt
|
|
1735 b-begin-pt b-end-pt))))
|
|
1736 )))
|
|
1737 diff-list
|
|
1738 ))
|
|
1739
|
|
1740 (defun ediff-convert-diffs-to-overlays (A-buffer B-buffer diff-list)
|
|
1741 (let* ((current-diff -1)
|
|
1742 (total-diffs (length diff-list))
|
|
1743 (control-buffer-suffix ediff-control-buffer-suffix)
|
|
1744 diff-overlay-list list-element
|
|
1745 a-begin a-end b-begin b-end
|
|
1746 a-overlay b-overlay)
|
|
1747
|
|
1748 (while diff-list
|
|
1749 (setq current-diff (1+ current-diff)
|
|
1750 list-element (car diff-list)
|
|
1751 a-begin (aref list-element 0)
|
|
1752 a-end (aref list-element 1)
|
|
1753 b-begin (aref list-element 2)
|
|
1754 b-end (aref list-element 3))
|
|
1755
|
|
1756 ;; place overlays at the appropriate places in the buffers
|
|
1757 (setq a-overlay (ediff-make-overlay a-begin a-end A-buffer))
|
|
1758 ;; priority of a-overlay and b-overlay should be equal. otherwise it
|
|
1759 ;; won't work due to Emacs bug---insert-in-front-hooks will be called
|
|
1760 ;; only on behalf of the buffer with higher priority.
|
|
1761 (ediff-overlay-put a-overlay 'priority ediff-shaded-overlay-priority)
|
|
1762 (ediff-overlay-put a-overlay 'ediff-diff-num current-diff)
|
|
1763 (ediff-overlay-put a-overlay
|
|
1764 'insert-in-front-hooks '(ediff-insert-in-front))
|
|
1765 (ediff-overlay-put a-overlay
|
|
1766 'ediff-control-buffer control-buffer-suffix)
|
|
1767 (ediff-overlay-put a-overlay
|
|
1768 'face (if (ediff-odd-p current-diff) ;; odd diff
|
|
1769 'ediff-odd-diff-face-A-var
|
|
1770 'ediff-even-diff-face-A-var))
|
|
1771
|
|
1772 (setq b-overlay (ediff-make-overlay b-begin b-end B-buffer))
|
|
1773 (ediff-overlay-put b-overlay 'priority ediff-shaded-overlay-priority)
|
|
1774 (ediff-overlay-put b-overlay 'ediff-diff-num current-diff)
|
|
1775 (ediff-overlay-put b-overlay
|
|
1776 'insert-in-front-hooks '(ediff-insert-in-front))
|
|
1777 (ediff-overlay-put b-overlay
|
|
1778 'ediff-control-buffer control-buffer-suffix)
|
|
1779 (ediff-overlay-put b-overlay
|
|
1780 'face (if (ediff-odd-p current-diff) ;; odd diff
|
|
1781 'ediff-odd-diff-face-B-var
|
|
1782 'ediff-even-diff-face-B-var))
|
|
1783
|
|
1784 (if (ediff-if-lucid) ;; chars inserted at end will be inside extent
|
|
1785 (progn
|
|
1786 (ediff-overlay-put a-overlay
|
|
1787 'ediff-marker
|
|
1788 (move-marker (make-marker) a-begin A-buffer))
|
|
1789 (ediff-overlay-put b-overlay
|
|
1790 'ediff-marker
|
|
1791 (move-marker (make-marker) b-begin B-buffer))
|
|
1792 (ediff-overlay-put a-overlay 'end-open nil)
|
|
1793 (ediff-overlay-put b-overlay 'end-open nil)))
|
|
1794
|
|
1795 ;; record all overlays for this difference
|
|
1796 (setq diff-overlay-list
|
|
1797 (nconc diff-overlay-list (list (vector a-overlay b-overlay)))
|
|
1798 diff-list (cdr diff-list))
|
|
1799 (message "Ediff: Processing diff region %d of %d"
|
|
1800 current-diff total-diffs)
|
|
1801 ) ;; while
|
|
1802 ;; this is just to avoid confusing the user with diff num < total-diffs
|
|
1803 (message "Ediff: Processing diff region %d of %d"
|
|
1804 (1+ current-diff) total-diffs)
|
|
1805 ;; convert the list of difference information into a vector for
|
|
1806 ;; fast access
|
|
1807 (setq ediff-difference-vector
|
|
1808 (apply 'vector diff-overlay-list))))
|
|
1809
|
|
1810
|
|
1811
|
|
1812 ;;; Commands
|
|
1813
|
|
1814 (defun ediff-recenter (&optional no-rehighlight)
|
|
1815 "Bring the highlighted region of all buffers A and B into view.
|
|
1816 Reestablish the default three-window display."
|
|
1817 (interactive)
|
|
1818 (setq ediff-disturbed-overlays nil) ;; clear after use
|
|
1819 (let (buffer-read-only)
|
|
1820 (ediff-setup-windows ediff-A-buffer ediff-B-buffer ediff-control-buffer))
|
|
1821 ;; Redisplay whatever buffers are showing, if there is a selected difference
|
|
1822 (if (and (>= ediff-current-difference 0)
|
|
1823 (< ediff-current-difference ediff-number-of-differences))
|
|
1824 (let* ( ;; context must be saved before switching to windows A/B
|
|
1825 (buffer-A ediff-A-buffer)
|
|
1826 (buffer-B ediff-B-buffer)
|
|
1827 (wind (selected-window))
|
|
1828 (control-buf ediff-control-buffer)
|
|
1829 (before-flag-shift-A (if (eq ediff-highlighting-style 'ascii)
|
|
1830 (1- (length ediff-before-flag-A))
|
|
1831 0))
|
|
1832 (after-flag-shift-A (if (eq ediff-highlighting-style 'ascii)
|
|
1833 (1- (length ediff-after-flag-A))
|
|
1834 0))
|
|
1835 (before-flag-shift-B (if (eq ediff-highlighting-style 'ascii)
|
|
1836 (1- (length ediff-before-flag-B))
|
|
1837 0))
|
|
1838 (after-flag-shift-B (if (eq ediff-highlighting-style 'ascii)
|
|
1839 (1- (length ediff-after-flag-B))
|
|
1840 0))
|
|
1841 (window-A (get-buffer-window buffer-A t))
|
|
1842 (window-B (get-buffer-window buffer-B t)))
|
|
1843
|
|
1844 (or no-rehighlight
|
|
1845 (ediff-operate-on-flags 'insert))
|
|
1846
|
|
1847 (if window-A (progn
|
|
1848 (select-window window-A)
|
|
1849 (ediff-position-region
|
|
1850 (- (ediff-get-diff-posn 'A 'beg nil control-buf)
|
|
1851 before-flag-shift-A)
|
|
1852 (+ (ediff-get-diff-posn 'A 'end nil control-buf)
|
|
1853 after-flag-shift-A)
|
|
1854 (ediff-get-diff-posn 'A 'beg nil control-buf))))
|
|
1855 (if window-B (progn
|
|
1856 (select-window window-B)
|
|
1857 (ediff-position-region
|
|
1858 (- (ediff-get-diff-posn 'B 'beg nil control-buf)
|
|
1859 before-flag-shift-B)
|
|
1860 (+ (ediff-get-diff-posn 'B 'end nil control-buf)
|
|
1861 after-flag-shift-B)
|
|
1862 (ediff-get-diff-posn 'B 'beg nil control-buf))))
|
|
1863 (select-window wind))))
|
|
1864
|
|
1865 (defun ediff-toggle-split ()
|
|
1866 "Toggle vertical/horizontal window split.
|
|
1867 Does nothing if file-A and file-B are in different frames."
|
|
1868 (interactive)
|
|
1869 (let* ((wind-A (get-buffer-window ediff-A-buffer t))
|
|
1870 (wind-B (get-buffer-window ediff-B-buffer t))
|
|
1871 (frame-A (if wind-A (ediff-window-frame wind-A)))
|
|
1872 (frame-B (if wind-B (ediff-window-frame wind-B))))
|
|
1873 (if (eq frame-A frame-B)
|
|
1874 (setq ediff-split-window-function
|
|
1875 (if (eq ediff-split-window-function 'split-window-vertically)
|
|
1876 'split-window-horizontally
|
|
1877 'split-window-vertically))
|
|
1878 (message "Buffers A and B are residing in different frames. Why split?"))
|
|
1879 (ediff-recenter 'no-rehighlight)))
|
|
1880
|
|
1881 (defun ediff-toggle-hilit ()
|
|
1882 "Switch between highlighting using ASCII flags and highlighting using faces.
|
|
1883 On a dumb terminal, switches between ASCII highlighting and no highlighting."
|
|
1884 (interactive)
|
|
1885 (if (not window-system)
|
|
1886 (if (eq ediff-highlighting-style 'ascii)
|
|
1887 (progn
|
|
1888 (message "ASCII highlighting flags removed.")
|
|
1889 (ediff-unselect-and-select-difference ediff-current-difference
|
|
1890 'unselect-only)
|
|
1891 (setq ediff-highlighting-style 'off))
|
|
1892 (ediff-unselect-and-select-difference ediff-current-difference
|
|
1893 'select-only))
|
|
1894 (ediff-unselect-and-select-difference ediff-current-difference
|
|
1895 'unselect-only)
|
|
1896 ;; cycle through highlighting
|
|
1897 (cond ((and ediff-want-faces (null ediff-highlight-selected-only))
|
|
1898 (message "Ediff: Unhighlighted unselected difference regions.")
|
|
1899 (setq ediff-highlight-selected-only t))
|
|
1900 (ediff-want-faces
|
|
1901 (message "Ediff: Now using ASCII flags only.")
|
|
1902 (setq ediff-want-faces nil))
|
|
1903 (t
|
|
1904 (message "Ediff: Re-highlighted all difference regions.")
|
|
1905 (setq ediff-want-faces t
|
|
1906 ediff-highlight-selected-only nil)))
|
|
1907
|
|
1908 (if (and ediff-want-faces (null ediff-highlight-selected-only))
|
|
1909 (if (not (face-differs-from-default-p 'ediff-odd-diff-face-A-var))
|
|
1910 (progn
|
|
1911 (copy-face ediff-odd-diff-face-A 'ediff-odd-diff-face-A-var)
|
|
1912 (copy-face ediff-odd-diff-face-B 'ediff-odd-diff-face-B-var)
|
|
1913 (copy-face ediff-even-diff-face-A 'ediff-even-diff-face-A-var)
|
|
1914 (copy-face ediff-even-diff-face-B 'ediff-even-diff-face-B-var)))
|
|
1915 (copy-face 'default 'ediff-odd-diff-face-A-var)
|
|
1916 (copy-face 'default 'ediff-odd-diff-face-B-var)
|
|
1917 (copy-face 'default 'ediff-even-diff-face-A-var)
|
|
1918 (copy-face 'default 'ediff-even-diff-face-B-var))
|
|
1919
|
|
1920 (ediff-unselect-and-select-difference
|
|
1921 ediff-current-difference 'select-only))
|
|
1922 (ediff-operate-on-flags 'insert)
|
|
1923 )
|
|
1924
|
|
1925 (defun ediff-toggle-help ()
|
|
1926 "Toggle short/long help message."
|
|
1927 (interactive)
|
|
1928 (let (buffer-read-only)
|
|
1929 (erase-buffer)
|
|
1930 (if (string= ediff-help-message ediff-help-message-long)
|
|
1931 (setq ediff-help-message ediff-help-message-short)
|
|
1932 (setq ediff-help-message ediff-help-message-long)))
|
|
1933 (ediff-recenter 'no-rehighlight))
|
|
1934
|
|
1935
|
|
1936 (defun ediff-toggle-read-only-A ()
|
|
1937 "Used as a startup hook to set `.orig' patch file read-only."
|
|
1938 (let ((last-command-char ?A))
|
|
1939 (ediff-toggle-read-only)))
|
|
1940
|
|
1941 (defun ediff-toggle-read-only ()
|
|
1942 "Toggles buffer-read-only for buffer buffers A and B."
|
|
1943 (interactive)
|
|
1944 (emerge-eval-in-buffer
|
|
1945 (if (eq last-command-char ?A) ediff-A-buffer ediff-B-buffer)
|
|
1946 (setq buffer-read-only (null buffer-read-only))))
|
|
1947
|
|
1948 ;;; Window scrolling operations
|
|
1949 ;; These operations are designed to scroll all three windows the same amount,
|
|
1950 ;; so as to keep the text in them aligned.
|
|
1951
|
|
1952 ;; Perform some operation on two file windows (if they are showing).
|
|
1953 ;; Catches all errors on the operation in the A and B windows.
|
|
1954 ;; Usually, errors come from scrolling off the
|
|
1955 ;; beginning or end of the buffer, and this gives nice nice error messages.
|
|
1956 (defun ediff-operate-on-windows (operation arg)
|
|
1957 (let* ((buffer-A ediff-A-buffer)
|
|
1958 (buffer-B ediff-B-buffer)
|
|
1959 (wind (selected-window))
|
|
1960 (window-A (get-buffer-window buffer-A t))
|
|
1961 (window-B (get-buffer-window buffer-B t)))
|
|
1962 (if window-A (progn
|
|
1963 (select-window window-A)
|
|
1964 (condition-case nil
|
|
1965 (funcall operation arg)
|
|
1966 (error))))
|
|
1967 (if window-B (progn
|
|
1968 (select-window window-B)
|
|
1969 (condition-case nil
|
|
1970 (funcall operation arg)
|
|
1971 (error))))
|
|
1972 (select-window wind)
|
|
1973 ))
|
|
1974
|
|
1975 (defun ediff-scroll-up (&optional arg)
|
|
1976 "Scroll up buffers A and B, if they are in windows.
|
|
1977 With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
|
|
1978 the height of window-A."
|
|
1979 (interactive "P")
|
|
1980 (ediff-operate-on-windows
|
|
1981 'scroll-up
|
|
1982 ;; calculate argument to scroll-up
|
|
1983 ;; if there is an explicit argument
|
|
1984 (if (and arg (not (equal arg '-)))
|
|
1985 ;; use it
|
|
1986 (prefix-numeric-value arg)
|
|
1987 ;; if not, see if we can determine a default amount (the window height)
|
|
1988 (let* ((window-A (get-buffer-window ediff-A-buffer t))
|
|
1989 (window-B (get-buffer-window ediff-B-buffer t))
|
|
1990 default-amount)
|
|
1991 (if (or (null window-A) (null window-B))
|
|
1992 (setq default-amount 0)
|
|
1993 (setq default-amount
|
|
1994 (- (min (window-height window-A) (window-height window-B))
|
|
1995 1 next-screen-context-lines)))
|
|
1996 ;; the window was found
|
|
1997 (if arg
|
|
1998 ;; C-u as argument means half of default amount
|
|
1999 (/ default-amount 2)
|
|
2000 ;; no argument means default amount
|
|
2001 default-amount)))))
|
|
2002
|
|
2003 (defun ediff-scroll-down (&optional arg)
|
|
2004 "Scroll down buffers A and B, if they are in windows.
|
|
2005 With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
|
|
2006 the height of window-A."
|
|
2007 (interactive "P")
|
|
2008 (ediff-operate-on-windows
|
|
2009 'scroll-down
|
|
2010 ;; calculate argument to scroll-down
|
|
2011 ;; if there is an explicit argument
|
|
2012 (if (and arg (not (equal arg '-)))
|
|
2013 ;; use it
|
|
2014 (prefix-numeric-value arg)
|
|
2015 ;; if not, see if we can determine a default amount (the window height)
|
|
2016 (let* ((window-A (get-buffer-window ediff-A-buffer t))
|
|
2017 (window-B (get-buffer-window ediff-B-buffer t))
|
|
2018 default-amount)
|
|
2019 (if (or (null window-A) (null window-B))
|
|
2020 (setq default-amount 0)
|
|
2021 (setq default-amount
|
|
2022 (- (min (window-height window-A) (window-height window-B))
|
|
2023 1 next-screen-context-lines)))
|
|
2024 ;; the window was found
|
|
2025 (if arg
|
|
2026 ;; C-u as argument means half of default amount
|
|
2027 (/ default-amount 2)
|
|
2028 ;; no argument means default amount
|
|
2029 default-amount)))))
|
|
2030
|
|
2031 (defun ediff-scroll-left (&optional arg)
|
|
2032 "Scroll left buffer-A and buffer-B, if they are in windows.
|
|
2033 If an argument is given, that is how many columns are scrolled, else nearly
|
|
2034 the width of the A and B windows."
|
|
2035 (interactive "P")
|
|
2036 (ediff-operate-on-windows
|
|
2037 'scroll-left
|
|
2038 ;; calculate argument to scroll-left
|
|
2039 ;; if there is an explicit argument
|
|
2040 (if (and arg (not (equal arg '-)))
|
|
2041 ;; use it
|
|
2042 (prefix-numeric-value arg)
|
|
2043 ;; if not, see if we can determine a default amount
|
|
2044 ;; (half the window width)
|
|
2045 (if (null ediff-control-window)
|
|
2046 ;; no control window, use nil
|
|
2047 nil
|
|
2048 (let ((default-amount
|
|
2049 (- (/ (window-width ediff-control-window) 2) 3)))
|
|
2050 ;; the window was found
|
|
2051 (if arg
|
|
2052 ;; C-u as argument means half of default amount
|
|
2053 (/ default-amount 2)
|
|
2054 ;; no argument means default amount
|
|
2055 default-amount))))))
|
|
2056
|
|
2057 (defun ediff-scroll-right (&optional arg)
|
|
2058 "Scroll right buffer-A and buffer-B, if they are in windows.
|
|
2059 If an argument is given, that is how many columns are scrolled, else nearly
|
|
2060 the width of the A and B windows."
|
|
2061 (interactive "P")
|
|
2062 (ediff-operate-on-windows
|
|
2063 'scroll-right
|
|
2064 ;; calculate argument to scroll-right
|
|
2065 ;; if there is an explicit argument
|
|
2066 (if (and arg (not (equal arg '-)))
|
|
2067 ;; use it
|
|
2068 (prefix-numeric-value arg)
|
|
2069 ;; if not, see if we can determine a default amount
|
|
2070 ;; (half the window width)
|
|
2071 (if (null ediff-control-window)
|
|
2072 ;; no control window, use nil
|
|
2073 nil
|
|
2074 (let ((default-amount
|
|
2075 (- (/ (window-width ediff-control-window) 2) 3)))
|
|
2076 ;; the window was found
|
|
2077 (if arg
|
|
2078 ;; C-u as argument means half of default amount
|
|
2079 (/ default-amount 2)
|
|
2080 ;; no argument means default amount
|
|
2081 default-amount))))))
|
|
2082
|
|
2083 (defun ediff-position-region (beg end pos)
|
|
2084 "This is a variation on ``emerge-position-region''.
|
|
2085 The difference is that it always tries to align difference regions in
|
|
2086 buffer-A and buffer-B, so that it will be easier to compare them."
|
|
2087 (set-window-start (selected-window) beg)
|
|
2088 (if (pos-visible-in-window-p end)
|
|
2089 ;; Determine the number of lines that the region occupies
|
|
2090 (let ((lines 0))
|
|
2091 (while (> end (progn
|
|
2092 (move-to-window-line lines)
|
|
2093 (point)))
|
|
2094 (setq lines (1+ lines)))
|
|
2095 ;; And position the beginning on the right line
|
|
2096 (goto-char beg)
|
|
2097 (recenter (/ (1+ (max (- (1- (window-height (selected-window)))
|
|
2098 lines)
|
|
2099 1)
|
|
2100 )
|
|
2101 2))))
|
|
2102 (goto-char pos)
|
|
2103 )
|
|
2104
|
|
2105
|
|
2106 (defun ediff-next-difference (arg)
|
|
2107 "Advance to the next difference.
|
|
2108 With a prefix argument, go back that many differences."
|
|
2109 (interactive "P")
|
|
2110 (if (< ediff-current-difference ediff-number-of-differences)
|
|
2111 (let ((n (min ediff-number-of-differences
|
|
2112 (+ ediff-current-difference (if arg arg 1))))
|
|
2113 (buffer-read-only nil))
|
|
2114 (ediff-unselect-and-select-difference n))
|
|
2115 (error "At end of the difference list.")))
|
|
2116
|
|
2117 (defun ediff-previous-difference (arg)
|
|
2118 "Go to the previous difference.
|
|
2119 With a prefix argument, go back that many differences."
|
|
2120 (interactive "P")
|
|
2121 (if (> ediff-current-difference -1)
|
|
2122 (let ((n (max -1 (- ediff-current-difference (if arg arg 1))))
|
|
2123 (buffer-read-only nil))
|
|
2124 (ediff-unselect-and-select-difference n))
|
|
2125 (error "At beginning of the difference list.")))
|
|
2126
|
|
2127 (defun ediff-jump-to-difference (difference-number)
|
|
2128 "Go to the difference specified as a prefix argument."
|
|
2129 (interactive "p")
|
|
2130 (let ((buffer-read-only nil))
|
|
2131 (setq difference-number (1- difference-number))
|
|
2132 (if (and (>= difference-number -1)
|
|
2133 (< difference-number (1+ ediff-number-of-differences)))
|
|
2134 (ediff-unselect-and-select-difference difference-number)
|
|
2135 (error "Bad difference number"))))
|
|
2136
|
|
2137 (defun ediff-jump-to-difference-at-point ()
|
|
2138 "Go to the difference closest to the point in buffer A or B.
|
|
2139 If this command is invoked via `ja' or `ga' then the point in buffer A is
|
|
2140 used. Otherwise, buffer B is used."
|
|
2141 (interactive)
|
|
2142 (let ((buffer-read-only nil)
|
|
2143 (buf-type (if (eq last-command-char ?a) 'A 'B)))
|
|
2144
|
|
2145 (ediff-jump-to-difference (ediff-diff-at-point buf-type))))
|
|
2146
|
|
2147
|
|
2148 ;; find region "most related to the current point position
|
|
2149
|
|
2150 (defun ediff-diff-at-point (buf-type)
|
|
2151 (let ((buffer (if (eq buf-type 'A) ediff-A-buffer ediff-B-buffer))
|
|
2152 (ctl-buffer ediff-control-buffer)
|
|
2153 (diff-no -1)
|
|
2154 (prev-beg 0)
|
|
2155 (beg 0))
|
|
2156
|
|
2157 (emerge-eval-in-buffer
|
|
2158 buffer
|
|
2159 (while (or (< (point) prev-beg) (> (point) beg))
|
|
2160 (setq diff-no (1+ diff-no))
|
|
2161 (setq prev-beg beg)
|
|
2162 (setq beg (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer)))
|
|
2163
|
|
2164 (if (< (abs (- (point) prev-beg))
|
|
2165 (abs (- (point) beg)))
|
|
2166 diff-no
|
|
2167 (1+ diff-no)) ;; jump-to-diff works with diff nums higher by 1
|
|
2168 )))
|
|
2169
|
|
2170 ;;; Copying diffs.
|
|
2171
|
|
2172 (defun ediff-diff-to-diff (arg)
|
|
2173 "Copy buffer-A'th diff to buffer B.
|
|
2174 If numerical prefix argument, copy this diff specified in the arg.
|
|
2175 Otherwise, copy the difference given by ``ediff-current-difference''."
|
|
2176 (interactive "P")
|
|
2177 (if arg
|
|
2178 (ediff-jump-to-difference arg))
|
|
2179 (ediff-copy-diff ediff-current-difference
|
|
2180 (if (eq last-command-char ?a) 'B 'A))
|
|
2181 (ediff-recenter 'no-rehighlight))
|
|
2182
|
|
2183
|
|
2184 (defun ediff-copy-diff (n buf-type)
|
|
2185 "Copy diff N from BUF-TYPE \(given as 'A or 'B\)."
|
|
2186 (let* ((other-buf (if (eq buf-type 'A)
|
|
2187 ediff-B-buffer ediff-A-buffer))
|
|
2188 (buf (if (eq buf-type 'A)
|
|
2189 ediff-A-buffer ediff-B-buffer))
|
|
2190 (other-buf-type (if (eq buf-type 'A) 'B 'A))
|
|
2191 (ctrl-buf ediff-control-buffer)
|
|
2192 reg-to-copy reg-to-delete
|
|
2193 reg-to-delete-beg reg-to-delete-end)
|
|
2194
|
|
2195 (ediff-operate-on-flags 'remove)
|
|
2196 (setq reg-to-delete-beg
|
|
2197 (ediff-get-diff-posn other-buf-type 'beg n ctrl-buf))
|
|
2198 (setq reg-to-delete-end
|
|
2199 (ediff-get-diff-posn other-buf-type 'end n ctrl-buf))
|
|
2200 (setq reg-to-copy (emerge-eval-in-buffer
|
|
2201 buf
|
|
2202 (buffer-substring (ediff-get-diff-posn
|
|
2203 buf-type 'beg n ctrl-buf)
|
|
2204 (ediff-get-diff-posn
|
|
2205 buf-type 'end n ctrl-buf))))
|
|
2206 (setq reg-to-delete (emerge-eval-in-buffer
|
|
2207 other-buf
|
|
2208 (buffer-substring reg-to-delete-beg
|
|
2209 reg-to-delete-end)))
|
|
2210 (setq ediff-disturbed-overlays nil) ;; clear before use
|
|
2211
|
|
2212 (if (string= reg-to-delete reg-to-copy)
|
|
2213 (progn
|
|
2214 (ding)
|
|
2215 (message
|
|
2216 "Diff regions %d are identical in buffers A and B. Nothing copied."
|
|
2217 (1+ n)))
|
|
2218
|
|
2219 ;; seems ok to copy
|
|
2220 (if (ediff-test-save-region n other-buf-type)
|
|
2221 (condition-case conds
|
|
2222 (let (inhibit-read-only)
|
|
2223 (emerge-eval-in-buffer
|
|
2224 other-buf
|
|
2225 ;; to prevent flags from interfering if buffer is writable
|
|
2226 (setq inhibit-read-only (null buffer-read-only))
|
|
2227 (let ((before-change-function nil))
|
|
2228 (goto-char reg-to-delete-end)
|
|
2229 (insert-before-markers reg-to-copy)
|
|
2230 (if (ediff-if-lucid)
|
|
2231 (progn
|
|
2232 (ediff-collect-extents-lucid reg-to-delete-beg)
|
|
2233 (if (> reg-to-delete-end reg-to-delete-beg)
|
|
2234 (progn
|
|
2235 (kill-region reg-to-delete-beg
|
|
2236 reg-to-delete-end)
|
|
2237 (if (string= reg-to-copy "")
|
|
2238 (ediff-adjust-disturbed-extents-lucid
|
|
2239 reg-to-delete-beg)))))
|
|
2240 (if (> reg-to-delete-end reg-to-delete-beg)
|
|
2241 (kill-region reg-to-delete-beg reg-to-delete-end)
|
|
2242 (ediff-move-disturbed-overlays reg-to-delete-beg)))
|
|
2243 ))
|
|
2244 (ediff-save-diff-region n other-buf-type reg-to-delete))
|
|
2245 (error (message "%s %s"
|
|
2246 (car conds)
|
|
2247 (mapconcat 'prin1-to-string (cdr conds) " "))
|
|
2248 (beep 1))))
|
|
2249 )
|
|
2250 (ediff-operate-on-flags 'insert)
|
|
2251 ))
|
|
2252
|
|
2253 (defun ediff-save-diff-region (n buf-type reg)
|
|
2254 "Save N-th diff of buffer BUF-TYPE \('A or 'B\) on the
|
|
2255 ``ediff-killed-diffs-alist''. REG is the region to save.
|
|
2256 It is redundant here,but is passed anyway, for convenience."
|
|
2257
|
|
2258 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
|
|
2259 (this-buf-n-th-diff-saved (assoc buf-type (cdr n-th-diff-saved))))
|
|
2260
|
|
2261 (if this-buf-n-th-diff-saved
|
|
2262 ;; either nothing saved for n-th diff and buffer or we OK'ed
|
|
2263 ;; overriding
|
|
2264 (setcdr this-buf-n-th-diff-saved reg)
|
|
2265 (if n-th-diff-saved ;; n-th diff saved, but for another buffer
|
|
2266 (nconc n-th-diff-saved (list (cons buf-type reg)))
|
|
2267 (setq ediff-killed-diffs-alist ;; create record for n-th diff
|
|
2268 (cons (list n (cons buf-type reg))
|
|
2269 ediff-killed-diffs-alist))))
|
|
2270 (message "Saved diff region #%d for buffer %S. To recover hit '%s'."
|
|
2271 (1+ n) buf-type (if (eq buf-type 'A) "ra" "rb"))))
|
|
2272
|
|
2273 (defun ediff-test-save-region (n buf-type)
|
|
2274 "Test if saving N-th difference region of buffer BUF-TYPE is possible."
|
|
2275 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
|
|
2276 (this-buf-n-th-diff-saved (assoc buf-type (cdr n-th-diff-saved))))
|
|
2277
|
|
2278 (if this-buf-n-th-diff-saved
|
|
2279 (if (yes-or-no-p
|
|
2280 (format
|
|
2281 "You've previously copied diff %d from %S to %S. Confirm. "
|
|
2282 (1+ n) (if (eq buf-type 'A) 'B 'A) buf-type))
|
|
2283 t
|
|
2284 (error "Quit."))
|
|
2285 t)))
|
|
2286
|
|
2287 (defun ediff-pop-diff (n buf-type)
|
|
2288 "Pop last killed N-th diff region from buffer BUF-TYPE."
|
|
2289 (let* ((n-th-record (assoc n ediff-killed-diffs-alist))
|
|
2290 (saved-rec (assoc buf-type (cdr n-th-record)))
|
|
2291 (buf (if (eq buf-type 'A) ediff-A-buffer ediff-B-buffer))
|
|
2292 saved-diff reg-beg reg-end recovered)
|
|
2293
|
|
2294 (if (cdr saved-rec)
|
|
2295 (setq saved-diff (cdr saved-rec))
|
|
2296 (error "Nothing saved for diff %d in buffer %S." (1+ n) buf-type))
|
|
2297
|
|
2298 (ediff-operate-on-flags 'remove)
|
|
2299
|
|
2300 (setq reg-beg (ediff-get-diff-posn buf-type 'beg n ediff-control-buffer))
|
|
2301 (setq reg-end (ediff-get-diff-posn buf-type 'end n ediff-control-buffer))
|
|
2302 (setq ediff-disturbed-overlays nil) ;; clear before use
|
|
2303
|
|
2304 (condition-case conds
|
|
2305 (emerge-eval-in-buffer
|
|
2306 buf
|
|
2307 (let ((inhibit-read-only (null buffer-read-only))
|
|
2308 (before-change-function nil))
|
|
2309 (goto-char reg-end)
|
|
2310 (insert-before-markers saved-diff)
|
|
2311
|
|
2312 (if (ediff-if-lucid)
|
|
2313 (progn
|
|
2314 (ediff-collect-extents-lucid reg-beg)
|
|
2315 (if (> reg-end reg-beg)
|
|
2316 (progn
|
|
2317 (kill-region reg-beg reg-end)
|
|
2318 (if (string= saved-diff "")
|
|
2319 (ediff-adjust-disturbed-extents-lucid reg-beg)))))
|
|
2320 (if (> reg-end reg-beg)
|
|
2321 (kill-region reg-beg reg-end)
|
|
2322 (ediff-move-disturbed-overlays reg-beg)))
|
|
2323
|
|
2324 (setq recovered t)
|
|
2325 ))
|
|
2326 (error (message "%s %s"
|
|
2327 (car conds)
|
|
2328 (mapconcat 'prin1-to-string (cdr conds) " "))
|
|
2329 (beep 1)))
|
|
2330
|
|
2331 (ediff-operate-on-flags 'insert)
|
|
2332 (if recovered
|
|
2333 (progn
|
|
2334 (setq n-th-record (delq saved-rec n-th-record))
|
|
2335 (message "Diff region %d restored for buffer %S." (1+ n) buf-type)))
|
|
2336 ))
|
|
2337
|
|
2338 (defun ediff-restore-diff (arg)
|
|
2339 "Restore ARG-th diff from ediff-killed-diffs-alist.
|
|
2340 ARG is a prefix argument. If ARG is `nil', restore current-difference."
|
|
2341 (interactive "P")
|
|
2342 (if arg
|
|
2343 (ediff-jump-to-difference arg))
|
|
2344 (ediff-pop-diff ediff-current-difference
|
|
2345 (if (eq last-command-char ?a) 'A 'B))
|
|
2346 (ediff-recenter 'no-rehighlight))
|
|
2347
|
|
2348
|
|
2349 ;;; Quitting, suspending, etc.
|
|
2350 (defun ediff-quit ()
|
|
2351 "Finish an Ediff session and exit Ediff.
|
|
2352 Unselects the selected difference, if any, restores the read-only and modified
|
|
2353 flags of the compared file buffers, kills Ediff buffers for this session
|
|
2354 \(but not file-A and file-B\)."
|
|
2355 (interactive)
|
|
2356 (if (prog1
|
|
2357 (y-or-n-p "Do you really want to exit Ediff? ")
|
|
2358 (message ""))
|
|
2359 (ediff-really-quit)))
|
|
2360
|
|
2361 ;; Perform the quit operations.
|
|
2362 (defun ediff-really-quit ()
|
|
2363 (setq buffer-read-only nil)
|
|
2364 (ediff-unselect-and-select-difference -1)
|
|
2365 ;; null out the difference overlays so they won't slow down future editing
|
|
2366 ;; operations
|
|
2367 (mapcar (function (lambda (d)
|
|
2368 (ediff-delete-overlay (aref d 0))
|
|
2369 (ediff-delete-overlay (aref d 1))))
|
|
2370 ediff-difference-vector)
|
|
2371 ;; allow them to be garbage collected
|
|
2372 (setq ediff-difference-vector nil)
|
|
2373 (setq ediff-help-message ediff-help-message-long)
|
|
2374 (ediff-restore-buffer-characteristics t) ;; restore as they were at setup
|
|
2375 (ediff-unhighlight-diffs-totally)
|
|
2376
|
|
2377 ;; restore buffer mode line id's in buffer-A/B
|
|
2378 (let ((control-buffer ediff-control-buffer))
|
|
2379 (emerge-eval-in-buffer
|
|
2380 ediff-A-buffer
|
|
2381 (setq before-change-function nil)
|
|
2382 (setq ediff-this-buffer-control-sessions
|
|
2383 (delq control-buffer ediff-this-buffer-control-sessions))
|
|
2384 (if (null ediff-this-buffer-control-sessions)
|
|
2385 (setq local-write-file-hooks
|
|
2386 (delq 'ediff-block-write-file local-write-file-hooks)))
|
|
2387 (kill-local-variable 'mode-line-buffer-identification))
|
|
2388 (emerge-eval-in-buffer
|
|
2389 ediff-B-buffer
|
|
2390 (setq ediff-this-buffer-control-sessions
|
|
2391 (delq control-buffer ediff-this-buffer-control-sessions))
|
|
2392 (if (null ediff-this-buffer-control-sessions)
|
|
2393 (setq local-write-file-hooks
|
|
2394 (delq 'ediff-block-write-file local-write-file-hooks)))
|
|
2395 (setq before-change-function nil)
|
|
2396 (kill-local-variable 'mode-line-buffer-identification)))
|
|
2397
|
|
2398 (run-hooks 'ediff-quit-hooks))
|
|
2399
|
|
2400 (defun ediff-kill-buffer-carefully (buf)
|
|
2401 "Kill buffer BUF if it exists."
|
|
2402 (if (ediff-buffer-live-p buf)
|
|
2403 (kill-buffer (get-buffer buf))))
|
|
2404
|
|
2405 ;; The default way of quitting Ediff.
|
|
2406 ;; Kills control buffers and leaves the
|
|
2407 ;; frame split between the two diff'ed files.
|
|
2408 (defun ediff-default-quit-hook ()
|
|
2409 (let ((buff-A ediff-A-buffer)
|
|
2410 (buff-B ediff-B-buffer))
|
|
2411 (ediff-kill-buffer-carefully ediff-diff-buffer)
|
|
2412 (ediff-kill-buffer-carefully ediff-diff-error-buffer)
|
|
2413 (ediff-kill-buffer-carefully ediff-control-buffer)
|
|
2414 (ediff-kill-buffer-carefully ediff-patch-diagnostics)
|
|
2415 (delete-other-windows)
|
|
2416 (switch-to-buffer buff-B)
|
|
2417 (split-window-vertically)
|
|
2418 (switch-to-buffer buff-A)))
|
|
2419
|
|
2420 ;; The default way of suspending Ediff.
|
|
2421 ;; Buries Ediff buffers, kills all windows.
|
|
2422 (defun ediff-default-suspend-hook ()
|
|
2423 (let ((buf-A ediff-A-buffer)
|
|
2424 (buf-B ediff-B-buffer)
|
|
2425 (buf-patch ediff-patch-buf)
|
|
2426 (buf-patch-diag ediff-patch-diagnostics)
|
|
2427 (buf-err ediff-diff-error-buffer)
|
|
2428 (buf-diff ediff-diff-buffer))
|
|
2429 (bury-buffer) ;; ediff-control-buffer
|
|
2430 (delete-other-windows)
|
|
2431 (bury-buffer buf-err)
|
|
2432 (bury-buffer buf-diff)
|
|
2433 (bury-buffer buf-patch)
|
|
2434 (bury-buffer buf-patch-diag)
|
|
2435 (bury-buffer buf-A)
|
|
2436 (bury-buffer buf-B)))
|
|
2437
|
|
2438
|
|
2439 (defun ediff-suspend ()
|
|
2440 "Suspend Ediff. To resume, switch to the appropriate ``*ediff-control*''
|
|
2441 buffer and then hit ``\\[ediff-recenter]''. Ediff will automatically set
|
|
2442 up an appropriate window config."
|
|
2443 (interactive)
|
|
2444 (run-hooks 'ediff-suspend-hooks)
|
|
2445 (message
|
|
2446 "To resume, switch to *ediff-control* and hit 'c' (ediff-recenter)."))
|
|
2447
|
|
2448
|
|
2449 (defun ediff-file-names ()
|
|
2450 "Show the names of the buffers or files being operated on by Ediff.
|
|
2451 Hit ``\\[ediff-recenter]'' to reset the windows afterward."
|
|
2452 (interactive)
|
|
2453 (with-output-to-temp-buffer "*Help*"
|
|
2454 (emerge-eval-in-buffer ediff-A-buffer
|
|
2455 (if buffer-file-name
|
|
2456 (progn
|
|
2457 (princ "File A is: ")
|
|
2458 (princ buffer-file-name))
|
|
2459 (progn
|
|
2460 (princ "Buffer A is: ")
|
|
2461 (princ (buffer-name))))
|
|
2462 (princ "\n"))
|
|
2463 (emerge-eval-in-buffer ediff-B-buffer
|
|
2464 (if buffer-file-name
|
|
2465 (progn
|
|
2466 (princ "File B is: ")
|
|
2467 (princ buffer-file-name))
|
|
2468 (progn
|
|
2469 (princ "Buffer B is: ")
|
|
2470 (princ (buffer-name))))
|
|
2471 (princ "\n"))
|
|
2472 ))
|
|
2473
|
|
2474
|
|
2475
|
|
2476 (defun ediff-line-numbers ()
|
|
2477 "Display the current line numbers.
|
|
2478 This function displays the line numbers of the points in the A, B."
|
|
2479 (interactive)
|
|
2480 (let* ((A-line (emerge-eval-in-buffer ediff-A-buffer
|
|
2481 (count-lines (point-min) (point))))
|
|
2482 (B-line (emerge-eval-in-buffer ediff-B-buffer
|
|
2483 (count-lines (point-min) (point)))))
|
|
2484 (message "At lines: A = %d, B = %d" A-line B-line)))
|
|
2485
|
|
2486
|
|
2487 ;;; Support routines
|
|
2488
|
|
2489 ;; Select a difference by placing the ASCII flags around the appropriate
|
|
2490 ;; group of lines in the A, B buffers
|
|
2491 (defun ediff-select-difference (n)
|
|
2492 (if (and (>= n 0) (< n ediff-number-of-differences))
|
|
2493 (progn
|
|
2494 (ediff-remember-buffer-characteristics)
|
|
2495 (if (and window-system ediff-want-faces)
|
|
2496 (progn
|
|
2497 (ediff-highlight-diff n)
|
|
2498 (setq ediff-highlighting-style 'face))
|
|
2499 (setq ediff-highlighting-style 'ascii)
|
|
2500 (ediff-place-flags-in-buffer 'A ediff-A-buffer
|
|
2501 ediff-control-buffer n)
|
|
2502 (ediff-place-flags-in-buffer 'B ediff-B-buffer
|
|
2503 ediff-control-buffer n))
|
|
2504
|
|
2505 (ediff-restore-buffer-characteristics)
|
|
2506 (run-hooks 'ediff-select-hooks))))
|
|
2507
|
|
2508
|
|
2509 ;; Unselect a difference by removing the ASCII flags in the buffers.
|
|
2510 (defun ediff-unselect-difference (n)
|
|
2511 (if (and (>= n 0) (< n ediff-number-of-differences))
|
|
2512 (progn
|
|
2513 (ediff-remember-buffer-characteristics)
|
|
2514
|
|
2515 (cond ((and window-system ediff-want-faces)
|
|
2516 (ediff-unhighlight-diff))
|
|
2517 ((eq ediff-highlighting-style 'ascii)
|
|
2518 (ediff-remove-flags-from-buffer
|
|
2519 ediff-A-buffer
|
|
2520 (ediff-get-diff-posn 'A 'beg n)
|
|
2521 (ediff-get-diff-posn 'A 'end n)
|
|
2522 ediff-before-flag-A ediff-after-flag-A)
|
|
2523 (ediff-remove-flags-from-buffer
|
|
2524 ediff-B-buffer
|
|
2525 (ediff-get-diff-posn 'B 'beg n)
|
|
2526 (ediff-get-diff-posn 'B 'end n)
|
|
2527 ediff-before-flag-B ediff-after-flag-B)))
|
|
2528
|
|
2529 (ediff-restore-buffer-characteristics)
|
|
2530 (setq ediff-highlighting-style nil)
|
|
2531 (run-hooks 'ediff-unselect-hooks))))
|
|
2532
|
|
2533
|
|
2534 ;; Unselects prev diff and selects a new one, if FLAG has value other than
|
|
2535 ;; 'select-only or 'unselect-only. If FLAG is 'select-only, the
|
|
2536 ;; next difference is selected, but the current selection is not
|
|
2537 ;; unselected. If FLAG is 'unselect-only then the current selection is
|
|
2538 ;; unselected, but the next one is not selected. If NO-RECENTER is non-nil,
|
|
2539 ;; don't recenter buffers after selecting/unselecting.
|
|
2540 ;;
|
|
2541 ;; Don't use ``ediff-select-difference'' and ``ediff-unselect-difference''
|
|
2542 ;; directly,;; since this will screw up the undo info in the presence of
|
|
2543 ;; ASCII flags.
|
|
2544 ;; Instead, use ``ediff-unselect-and-select-difference'' with appropriate
|
|
2545 ;; flags.
|
|
2546
|
|
2547 (defun ediff-unselect-and-select-difference (n &optional flag no-recenter)
|
|
2548 (let ((wind (selected-window))
|
|
2549 ;; save buf modified info
|
|
2550 (buf-A-modified (buffer-modified-p ediff-A-buffer))
|
|
2551 (buf-B-modified (buffer-modified-p ediff-B-buffer))
|
|
2552 ;; temporarily disable undo so highlighting won't confuse the user
|
|
2553 buf-A-undo buf-B-undo)
|
|
2554
|
|
2555 (emerge-eval-in-buffer
|
|
2556 ediff-A-buffer
|
|
2557 (setq buf-A-undo buffer-undo-list))
|
|
2558 (emerge-eval-in-buffer
|
|
2559 ediff-B-buffer
|
|
2560 (setq buf-B-undo buffer-undo-list))
|
|
2561
|
|
2562 (buffer-disable-undo ediff-A-buffer)
|
|
2563 (buffer-disable-undo ediff-B-buffer)
|
|
2564
|
|
2565 (unwind-protect ;; we don't want to lose undo info due to error
|
|
2566 (progn
|
|
2567 (or (eq flag 'select-only)
|
|
2568 (ediff-unselect-difference ediff-current-difference))
|
|
2569
|
|
2570 ;; Auto-save buffers while Ediff flags are temporarily removed.
|
|
2571 (emerge-eval-in-buffer
|
|
2572 ediff-A-buffer
|
|
2573 (if buf-A-modified
|
|
2574 (do-auto-save)))
|
|
2575 (emerge-eval-in-buffer
|
|
2576 ediff-B-buffer
|
|
2577 (if buf-B-modified
|
|
2578 (do-auto-save)))
|
|
2579
|
|
2580 (or (eq flag 'unselect-only)
|
|
2581 (ediff-select-difference n))
|
|
2582 (setq ediff-current-difference n)
|
|
2583 ) ;; end protected section
|
|
2584
|
|
2585 (select-window wind) ;; must be before recenter!
|
|
2586 (ediff-refresh-mode-line)
|
|
2587 (or no-recenter
|
|
2588 (ediff-recenter 'no-rehighlight))
|
|
2589
|
|
2590 ;; restore undo and buffer-modified info
|
|
2591 (emerge-eval-in-buffer
|
|
2592 ediff-A-buffer
|
|
2593 (set-buffer-modified-p buf-A-modified)
|
|
2594 (setq buffer-undo-list buf-A-undo))
|
|
2595 (emerge-eval-in-buffer
|
|
2596 ediff-B-buffer
|
|
2597 (set-buffer-modified-p buf-B-modified)
|
|
2598 (setq buffer-undo-list buf-B-undo))
|
|
2599 )))
|
|
2600
|
|
2601 ;; Revise the mode line to display which difference we have selected
|
|
2602
|
|
2603 (defun ediff-refresh-mode-line ()
|
|
2604 (setq mode-line-buffer-identification
|
|
2605 (list (format "Ediff: %%b diff %d of %d"
|
|
2606 (1+ ediff-current-difference)
|
|
2607 ediff-number-of-differences)))
|
|
2608 ;; Force mode-line redisplay
|
|
2609 (set-buffer-modified-p (buffer-modified-p)))
|
|
2610
|
|
2611
|
|
2612
|
|
2613 ;; Verify that we have a difference selected.
|
|
2614 (defun ediff-validate-difference ()
|
|
2615 (if (not (and (>= ediff-current-difference 0)
|
|
2616 (< ediff-current-difference ediff-number-of-differences)))
|
|
2617 (error "No difference selected")))
|
|
2618
|
|
2619 ;; The following is added to take care of Lemacs.
|
|
2620
|
|
2621
|
|
2622 (defun ediff-read-file-name (prompt default-dir default-file A-file)
|
|
2623 ; This is a modified version of a similar function in ``emerge.el''.
|
|
2624 ; PROMPT should not have trailing ': ', so that it can be modified
|
|
2625 ; according to context.
|
|
2626 ; If both A-FILE and default-dir are set, the file constructed our of
|
|
2627 ; default-dir and the non-directory part of A-FILE is used as default and as
|
|
2628 ; initial input.
|
|
2629 ; If A-FILE is set (but default-dir is not), it is used as default and
|
|
2630 ; initial input.
|
|
2631 ; If default-file is set, it should be used as the default value.
|
|
2632 ; If default-dir is non-nil, use it as the default directory.
|
|
2633 ; Otherwise, use the value in Emacs's var default-directory.
|
|
2634 (cond
|
|
2635 ((and A-file default-dir)
|
|
2636 (read-file-name (format "%s (default %s%s): "
|
|
2637 prompt
|
|
2638 (abbreviate-file-name
|
|
2639 (expand-file-name default-dir))
|
|
2640 (file-name-nondirectory A-file))
|
|
2641 (expand-file-name default-dir)
|
|
2642 (concat (expand-file-name default-dir)
|
|
2643 (file-name-nondirectory A-file))
|
|
2644 'confirm (file-name-nondirectory A-file)))
|
|
2645 (A-file
|
|
2646 (read-file-name (format "%s (default %s): "
|
|
2647 prompt (file-name-nondirectory A-file))
|
|
2648 (expand-file-name (file-name-directory A-file))
|
|
2649 A-file
|
|
2650 'confirm (file-name-nondirectory A-file)))
|
|
2651 ;; If there is a default file, but no A-file, use it.
|
|
2652 (default-file
|
|
2653 (read-file-name (format "%s (default %s): " prompt default-file)
|
|
2654 default-dir ;; if nil then default-directory.
|
|
2655 nil 'confirm))
|
|
2656 (t
|
|
2657 (read-file-name (concat prompt ": ")
|
|
2658 default-dir ;; if nil then default-directory.
|
|
2659 nil 'confirm))))
|
|
2660
|
|
2661
|
|
2662 (defun ediff-make-temp-file (prefix)
|
|
2663 (let ((f (make-temp-name (concat ediff-temp-file-prefix prefix))))
|
|
2664 ;; create the file
|
|
2665 (write-region (point-min) (point-min) f nil 'no-message)
|
|
2666 (set-file-modes f ediff-temp-file-mode)
|
|
2667 f))
|
|
2668
|
|
2669 (defun ediff-block-write-file ()
|
|
2670 "Prevent writing files A and B directly."
|
|
2671 (if (ediff-check-for-ascii-flags)
|
|
2672 (error "Use 'wa' and 'wb' to save buffs A/B (first switch back to *ediff-control*.")))
|
|
2673
|
|
2674 (defun ediff-check-for-ascii-flags ()
|
|
2675 (eval
|
|
2676 (cons 'or
|
|
2677 (mapcar (function (lambda (buf)
|
|
2678 (emerge-eval-in-buffer
|
|
2679 buf
|
|
2680 (eq ediff-highlighting-style 'ascii))))
|
|
2681 ediff-this-buffer-control-sessions))))
|
|
2682
|
|
2683 (defun ediff-insert-in-front (overl beg end)
|
|
2684 "Capture overlays that had insertions in the front.
|
|
2685 Called when overlay OVERL gets insertion in front."
|
|
2686 (if (ediff-overlay-get overl 'ediff-diff-num)
|
|
2687 (setq ediff-disturbed-overlays
|
|
2688 (cons overl ediff-disturbed-overlays)))
|
|
2689 )
|
|
2690
|
|
2691 (defun ediff-collect-extents-lucid (pos)
|
|
2692 "Collects all extents at POS having property `ediff-diff-num'.
|
|
2693 Lucid Emacs causes headache by detaching empty extents, so I have to save
|
|
2694 them before they disappear."
|
|
2695 (let (lis elt)
|
|
2696 (while (setq elt (extent-at pos nil 'ediff-diff-num elt))
|
|
2697 (setq lis (cons elt lis)))
|
|
2698 (setq ediff-disturbed-overlays lis)))
|
|
2699
|
|
2700 (defun ediff-move-disturbed-overlays (posn)
|
|
2701 (mapcar (function (lambda (overl)
|
|
2702 (ediff-move-overlay overl
|
|
2703 posn
|
|
2704 (ediff-overlay-end overl))
|
|
2705 ))
|
|
2706 ediff-disturbed-overlays)
|
|
2707 (setq ediff-disturbed-overlays nil))
|
|
2708
|
|
2709 (defun ediff-adjust-disturbed-extents-lucid (posn &optional posn-type)
|
|
2710 ;; POSN-TYPE tells if POSN should become a new start of the extents
|
|
2711 ;; (if 'new-start) or a new end (if 'new-end). If POSN-TYPE is nil, then
|
|
2712 ;; POSN is both the new start and the new end.
|
|
2713 (mapcar (function (lambda (overl)
|
|
2714 (cond ((and (null posn-type)
|
|
2715 (equal (ediff-overlay-start overl)
|
|
2716 (ediff-overlay-end overl)))
|
|
2717 (ediff-move-overlay overl posn posn))
|
|
2718
|
|
2719 (posn-type
|
|
2720 (ediff-move-overlay
|
|
2721 overl
|
|
2722 (if (eq posn-type 'new-start)
|
|
2723 posn
|
|
2724 (ediff-overlay-start overl))
|
|
2725 (if (eq posn-type 'new-end)
|
|
2726 posn
|
|
2727 (ediff-overlay-end overl)))))))
|
|
2728 ediff-disturbed-overlays)
|
|
2729 (setq ediff-disturbed-overlays nil))
|
|
2730
|
|
2731 (defun ediff-save-buffer ()
|
|
2732 "Safe way of saving buffers A and B."
|
|
2733 (interactive)
|
|
2734 (let ((hooks local-write-file-hooks))
|
|
2735 (ediff-unselect-and-select-difference ediff-current-difference
|
|
2736 'unselect-only)
|
|
2737 (unwind-protect
|
|
2738 (emerge-eval-in-buffer
|
|
2739 (if (eq last-command-char ?a) ediff-A-buffer ediff-B-buffer)
|
|
2740 ;; temporarily remove writing block
|
|
2741 (setq hooks (delq 'ediff-block-write-file hooks))
|
|
2742 (let ((local-write-file-hooks hooks))
|
|
2743 (save-buffer)))
|
|
2744 (ediff-unselect-and-select-difference ediff-current-difference
|
|
2745 'select-only)
|
|
2746 )))
|
|
2747
|
|
2748
|
|
2749
|
|
2750 (defun ediff-remove-flags-from-buffer (buffer before-posn after-posn
|
|
2751 before-flag after-flag)
|
|
2752 "Essentially ``emerge-remove-flags-in-buffer'', modified to allow deletion
|
|
2753 of read-only flags."
|
|
2754 (emerge-eval-in-buffer
|
|
2755 buffer
|
|
2756 (let ((buffer-read-only nil)
|
|
2757 (before-change-function nil)
|
|
2758 (inhibit-read-only t)
|
|
2759 (before-flag-length (length before-flag))
|
|
2760 (after-flag-length (length after-flag))
|
|
2761 )
|
|
2762 (goto-char after-posn)
|
|
2763 (setq after-posn (point-marker)) ;; after-posn is now a marker
|
|
2764 ;; remove the flags, if they're there
|
|
2765 (goto-char (- before-posn before-flag-length))
|
|
2766 (if (ediff-if-lucid)
|
|
2767 (ediff-collect-extents-lucid (+ (point) before-flag-length)))
|
|
2768 (if (looking-at (regexp-quote before-flag))
|
|
2769 (delete-region (point) (+ (point) before-flag-length))
|
|
2770 ;; the flag isn't there
|
|
2771 (ding)
|
|
2772 (message "Trouble removing ASCII flag"))
|
|
2773 (if (ediff-if-lucid)
|
|
2774 (ediff-adjust-disturbed-extents-lucid (point)))
|
|
2775
|
|
2776 (if (ediff-if-lucid)
|
|
2777 (ediff-collect-extents-lucid (point)))
|
|
2778 (goto-char after-posn)
|
|
2779 (if (looking-at (regexp-quote after-flag))
|
|
2780 (delete-region (point) (+ (point) after-flag-length))
|
|
2781 ;; the flag isn't there
|
|
2782 (ding)
|
|
2783 (message "Trouble removing ASCII flag"))
|
|
2784 (if (ediff-if-lucid)
|
|
2785 (ediff-adjust-disturbed-extents-lucid (point)))
|
|
2786 (setq after-posn nil) ;; after has become a marker--garbage-collect
|
|
2787 )))
|
|
2788
|
|
2789
|
|
2790 (defun ediff-place-flags-in-buffer (buf-type buffer ctl-buffer difference)
|
|
2791 "This is a modified ``emerge-place-flags-in-buffer''."
|
|
2792 (emerge-eval-in-buffer
|
|
2793 buffer
|
|
2794 (ediff-place-flags-in-buffer1 buf-type ctl-buffer difference)))
|
|
2795
|
|
2796 (defun ediff-place-flags-in-buffer1 (buf-type ctl-buffer difference)
|
|
2797 "Modified ``emerge-place-flags-in-buffer1''."
|
|
2798 (let ((buffer-read-only nil)
|
|
2799 (inhibit-read-only t)
|
|
2800 (before-change-function nil)
|
|
2801 (before-flag-name (if (eq buf-type 'A)
|
|
2802 'ediff-before-flag-A
|
|
2803 'ediff-before-flag-B))
|
|
2804 (after-flag-name (if (eq buf-type 'A)
|
|
2805 'ediff-after-flag-A
|
|
2806 'ediff-after-flag-B))
|
|
2807 beg-of-line flag)
|
|
2808
|
|
2809 ;; insert the flag before the difference
|
|
2810 (let ((before (ediff-get-diff-posn buf-type 'beg difference ctl-buffer)))
|
|
2811 (goto-char before)
|
|
2812 (setq beg-of-line (bolp))
|
|
2813
|
|
2814 (setq flag (emerge-eval-in-buffer
|
|
2815 ctl-buffer
|
|
2816 (if beg-of-line
|
|
2817 (set before-flag-name ediff-before-flag-bol)
|
|
2818 (set before-flag-name ediff-before-flag-mol))))
|
|
2819
|
|
2820 ;; insert the flag itself
|
|
2821 (if (ediff-if-lucid)
|
|
2822 (ediff-collect-extents-lucid (point)))
|
|
2823 (insert-before-markers flag)
|
|
2824 (if (ediff-if-lucid)
|
|
2825 ;; Lucid's extent end-points behave strangely; they won't
|
|
2826 ;; respect insert-before-markers
|
|
2827 (ediff-adjust-disturbed-extents-lucid (point) 'new-start))
|
|
2828 )
|
|
2829 ;; insert the flag after the difference
|
|
2830 (let* ((after (ediff-get-diff-posn buf-type 'end difference ctl-buffer)))
|
|
2831 (goto-char after)
|
|
2832 (setq beg-of-line (bolp))
|
|
2833
|
|
2834 (setq flag (emerge-eval-in-buffer
|
|
2835 ctl-buffer
|
|
2836 (if beg-of-line
|
|
2837 (set after-flag-name ediff-after-flag-bol)
|
|
2838 (set after-flag-name ediff-after-flag-mol))))
|
|
2839
|
|
2840 ;; insert the flag itself
|
|
2841 (if (ediff-if-lucid)
|
|
2842 (ediff-collect-extents-lucid (point)))
|
|
2843 (insert flag)
|
|
2844 (if (ediff-if-lucid)
|
|
2845 (ediff-adjust-disturbed-extents-lucid after 'new-end))
|
|
2846 )))
|
|
2847
|
|
2848
|
|
2849 (defun ediff-get-diff-posn (buf-type pos &optional n control-buf)
|
|
2850 "Returns positions of difference sectors in the buffer denoted BUF-TYPE
|
|
2851 \('A or 'B\).
|
|
2852 POS is either 'beg or 'end. Specifies whether you want the position at the
|
|
2853 beginning of a difference of at the end. Optional N says which difference
|
|
2854 \(default: ``ediff-current-difference''\). Optional CONTROL-BUF says which
|
|
2855 control buffer is in effect in case it is not the current buffer."
|
|
2856
|
|
2857 (let (diff-overlay)
|
|
2858 (or control-buf
|
|
2859 (setq control-buf (current-buffer)))
|
|
2860
|
|
2861 (emerge-eval-in-buffer
|
|
2862 control-buf
|
|
2863 (or n (setq n ediff-current-difference))
|
|
2864 (if (or (< n 0) (>= n ediff-number-of-differences))
|
|
2865 (error "There is no diff %d in this session. Valid diffs are 1 to %d."
|
|
2866 (1+ n) ediff-number-of-differences))
|
|
2867 (setq diff-overlay (aref (aref ediff-difference-vector n)
|
|
2868 (if (eq buf-type 'A) 0 1))))
|
|
2869
|
|
2870 (if (ediff-overlay-get diff-overlay 'detached)
|
|
2871 (ediff-move-overlay diff-overlay
|
|
2872 (ediff-overlay-get diff-overlay 'ediff-marker)
|
|
2873 (ediff-overlay-get diff-overlay 'ediff-marker)))
|
|
2874 (if (eq pos 'beg)
|
|
2875 (ediff-overlay-start diff-overlay)
|
|
2876 (ediff-overlay-end diff-overlay))
|
|
2877 ))
|
|
2878
|
|
2879
|
|
2880
|
|
2881 ;; These would highlight differences under X
|
|
2882 (defun ediff-highlight-diff (n)
|
|
2883 "Put face on diff N. Invoked for X displays only."
|
|
2884 (let* ((last-A (emerge-eval-in-buffer ediff-A-buffer (point-max)))
|
|
2885 (last-B (emerge-eval-in-buffer ediff-B-buffer (point-max)))
|
|
2886 (begin-A (ediff-get-diff-posn 'A 'beg n))
|
|
2887 (end-A (ediff-get-diff-posn 'A 'end n))
|
|
2888 (xtraA (if (equal begin-A end-A) 1 0))
|
|
2889 (end-A-hilit (min last-A (+ end-A xtraA)))
|
|
2890
|
|
2891 (begin-B (ediff-get-diff-posn 'B 'beg n))
|
|
2892 (end-B (ediff-get-diff-posn 'B 'end n))
|
|
2893 (xtraB (if (equal begin-B end-B) 1 0))
|
|
2894 (end-B-hilit (min last-B (+ end-B xtraB))))
|
|
2895
|
|
2896 (if (ediff-if-lucid)
|
|
2897 (progn
|
|
2898 (ediff-move-overlay
|
|
2899 ediff-current-diff-overlay-A begin-A end-A-hilit)
|
|
2900 (ediff-move-overlay
|
|
2901 ediff-current-diff-overlay-B begin-B end-B-hilit))
|
7391
|
2902 ;; Emacs 19.22 has a bug, which requires that ediff-move-overlay will
|
|
2903 ;; have the buffer as a parameter. Believed fixed in 19.23.
|
7267
|
2904 (ediff-move-overlay ediff-current-diff-overlay-A
|
|
2905 begin-A end-A-hilit ediff-A-buffer)
|
|
2906 (ediff-move-overlay ediff-current-diff-overlay-B
|
|
2907 begin-B end-B-hilit ediff-B-buffer))
|
|
2908 ;; giving priority of 0 and then changing it may look funny, but
|
|
2909 ;; this is intended to overcome an Emacs bug.
|
|
2910 (ediff-overlay-put ediff-current-diff-overlay-A 'priority 0)
|
|
2911 (ediff-overlay-put ediff-current-diff-overlay-B 'priority 0)
|
|
2912 (ediff-overlay-put ediff-current-diff-overlay-A 'priority
|
|
2913 (ediff-highest-priority begin-A end-A-hilit ediff-A-buffer))
|
|
2914 (ediff-overlay-put ediff-current-diff-overlay-B 'priority
|
|
2915 (ediff-highest-priority begin-B end-B-hilit ediff-B-buffer))
|
|
2916
|
|
2917 (if (and (not (face-differs-from-default-p 'ediff-odd-diff-face-A-var))
|
|
2918 (null ediff-highlight-selected-only))
|
|
2919 (progn
|
|
2920 (copy-face ediff-odd-diff-face-A 'ediff-odd-diff-face-A-var)
|
|
2921 (copy-face ediff-odd-diff-face-B 'ediff-odd-diff-face-B-var)
|
|
2922 (copy-face ediff-even-diff-face-A 'ediff-even-diff-face-A-var)
|
|
2923 (copy-face ediff-even-diff-face-B 'ediff-even-diff-face-B-var)))
|
|
2924
|
|
2925 ;; unhighlight the background overlay for the diff n so they won't
|
|
2926 ;; interfere with the current diff overlay
|
|
2927 (ediff-overlay-put (aref (aref ediff-difference-vector n) 0) 'face nil)
|
|
2928 (ediff-overlay-put (aref (aref ediff-difference-vector n) 1) 'face nil)
|
|
2929
|
|
2930 (sit-for 0) ;; needs to synch for some reason
|
|
2931 ))
|
|
2932
|
|
2933
|
|
2934 (defun ediff-unhighlight-diff ()
|
|
2935 "Remove overlays from buffers A and B."
|
|
2936
|
|
2937 (ediff-move-overlay ediff-current-diff-overlay-A 1 1)
|
|
2938 (ediff-move-overlay ediff-current-diff-overlay-B 1 1)
|
|
2939
|
|
2940 ;; rehighlight the overlay in the background of the
|
|
2941 ;; current difference region
|
|
2942 (ediff-overlay-put (aref (aref ediff-difference-vector
|
|
2943 ediff-current-difference)
|
|
2944 0)
|
|
2945 'face (if (ediff-odd-p ediff-current-difference)
|
|
2946 'ediff-odd-diff-face-A-var
|
|
2947 'ediff-even-diff-face-A-var))
|
|
2948 (ediff-overlay-put (aref (aref ediff-difference-vector
|
|
2949 ediff-current-difference)
|
|
2950 1)
|
|
2951 'face (if (ediff-odd-p ediff-current-difference)
|
|
2952 'ediff-odd-diff-face-B-var
|
|
2953 'ediff-even-diff-face-B-var))
|
|
2954 )
|
|
2955
|
|
2956
|
|
2957 (defun ediff-unhighlight-diffs-totally ()
|
|
2958 (if (and window-system ediff-want-faces)
|
|
2959 (let ((inhibit-quit t))
|
|
2960 (if (face-differs-from-default-p 'ediff-odd-diff-face-A-var)
|
|
2961 (progn
|
|
2962 (copy-face 'default 'ediff-odd-diff-face-A-var)
|
|
2963 (copy-face 'default 'ediff-odd-diff-face-B-var)
|
|
2964 (copy-face 'default 'ediff-even-diff-face-A-var)
|
|
2965 (copy-face 'default 'ediff-even-diff-face-B-var)))
|
|
2966 (if (ediff-overlayp ediff-current-diff-overlay-A)
|
|
2967 (ediff-delete-overlay ediff-current-diff-overlay-A))
|
|
2968 (setq ediff-current-diff-overlay-A nil)
|
|
2969 (if (ediff-overlayp ediff-current-diff-overlay-B)
|
|
2970 (ediff-delete-overlay ediff-current-diff-overlay-B))
|
|
2971 (setq ediff-current-diff-overlay-B nil))))
|
|
2972
|
|
2973
|
|
2974 (defun ediff-operate-on-flags (action)
|
|
2975 "Re/unhighlights buffers A and B with all flags from all active Ediff
|
|
2976 sessions that involve these buffers. This is usually needed only when a
|
|
2977 buffer is involved in multiple Ediff sessions."
|
|
2978 (let* ((A-sessions (emerge-eval-in-buffer
|
|
2979 ediff-A-buffer
|
|
2980 ediff-this-buffer-control-sessions))
|
|
2981 (B-sessions (emerge-eval-in-buffer
|
|
2982 ediff-B-buffer
|
|
2983 ediff-this-buffer-control-sessions))
|
|
2984 (sessions (ediff-union A-sessions B-sessions))
|
|
2985 (flag (if (eq action 'remove) 'unselect-only 'select-only)))
|
|
2986
|
|
2987 (mapcar (function (lambda (buf)
|
|
2988 (emerge-eval-in-buffer
|
|
2989 buf
|
|
2990 (or (if (eq action 'insert)
|
|
2991 (memq ediff-highlighting-style '(ascii off))
|
|
2992 (not (eq ediff-highlighting-style 'ascii)))
|
|
2993 (ediff-unselect-and-select-difference
|
|
2994 ediff-current-difference
|
|
2995 flag 'no-recenter))
|
|
2996 )))
|
|
2997 sessions)))
|
|
2998
|
|
2999 (defun ediff-union (list1 list2)
|
|
3000 "Combine LIST1 and LIST2 using a set-union operation.
|
|
3001 The result list contains all items that appear in either LIST1 or LIST2.
|
|
3002 This is a non-destructive function; it makes a copy of the data if necessary
|
|
3003 to avoid corrupting the original LIST1 and LIST2.
|
|
3004 This is a slightly simplified version from ``cl-seq.el''. Added here to
|
|
3005 avoid loading cl-*."
|
|
3006 (cond ((null list1) list2) ((null list2) list1)
|
|
3007 ((equal list1 list2) list1)
|
|
3008 (t
|
|
3009 (or (>= (length list1) (length list2))
|
|
3010 (setq list1 (prog1 list2 (setq list2 list1))))
|
|
3011 (while list2
|
|
3012 (or (memq (car list2) list1)
|
|
3013 (setq list1 (cons (car list2) list1)))
|
|
3014 (setq list2 (cdr list2)))
|
|
3015 list1)))
|
|
3016
|
|
3017 (defun ediff-debug ()
|
|
3018 (interactive)
|
|
3019 (with-output-to-temp-buffer "*ediff-debug*"
|
|
3020 (princ
|
|
3021 (format "Ctl buffer: %S\n\nediff-difference-vector:\n"
|
|
3022 ediff-control-buffer))
|
|
3023 (mapcar (function
|
|
3024 (lambda (overl-vec)
|
|
3025 (princ (format "Diff %d: %S %S %S\n\t %S %S %S\n"
|
|
3026 (1+ (ediff-overlay-get (aref overl-vec 0)
|
|
3027 'ediff-diff-num))
|
|
3028 (ediff-overlay-get (aref overl-vec 0)
|
|
3029 'ediff-control-buffer)
|
|
3030 (ediff-overlay-get (aref overl-vec 0)
|
|
3031 'insert-in-front-hooks)
|
|
3032 (aref overl-vec 0)
|
|
3033 (ediff-overlay-get (aref overl-vec 1)
|
|
3034 'ediff-control-buffer)
|
|
3035 (ediff-overlay-get (aref overl-vec 0)
|
|
3036 'insert-in-front-hooks)
|
|
3037 (aref overl-vec 1)
|
|
3038 ))))
|
|
3039 ediff-difference-vector)
|
|
3040 (princ "\nediff-disturbed-overlays:\n")
|
|
3041 (mapcar (function
|
|
3042 (lambda (overl)
|
|
3043 (princ (format "%S %S\n"
|
|
3044 (ediff-overlay-get overl 'ediff-control-buffer)
|
|
3045 overl
|
|
3046 ))))
|
|
3047 ediff-disturbed-overlays)))
|
|
3048
|
|
3049
|
|
3050 (run-hooks 'ediff-load-hooks)
|
|
3051
|
|
3052
|
|
3053 (provide 'ediff)
|
|
3054
|
|
3055 ;;; ediff.el ends here
|