0
|
1 ;;; ediff.el --- a comprehensive visual interface to diff & patch
|
|
2
|
82
|
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
|
0
|
4
|
|
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
|
|
6 ;; Created: February 2, 1994
|
|
7 ;; Keywords: comparing, merging, patching, version control.
|
|
8
|
80
|
9 (defconst ediff-version "2.64" "The current version of Ediff")
|
82
|
10 (defconst ediff-date "January 7, 1997" "Date of last update")
|
0
|
11
|
|
12
|
|
13 ;; This file is part of GNU Emacs.
|
|
14
|
|
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
16 ;; it under the terms of the GNU General Public License as published by
|
|
17 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
18 ;; any later version.
|
|
19
|
|
20 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23 ;; GNU General Public License for more details.
|
|
24
|
|
25 ;; You should have received a copy of the GNU General Public License
|
|
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
28 ;; Boston, MA 02111-1307, USA.
|
|
29
|
|
30 ;;; Commentary:
|
|
31
|
|
32 ;; Never read that diff output again!
|
|
33 ;; Apply patch interactively!
|
|
34 ;; Merge with ease!
|
|
35
|
|
36 ;; This package provides a convenient way of simultaneous browsing through
|
|
37 ;; the differences between a pair (or a triple) of files or buffers. The
|
|
38 ;; files being compared, file-A, file-B, and file-C (if applicable) are
|
|
39 ;; shown in separate windows (side by side, one above the another, or in
|
|
40 ;; separate frames), and the differences are highlighted as you step
|
|
41 ;; through them. You can also copy difference regions from one buffer to
|
|
42 ;; another (and recover old differences if you change your mind).
|
|
43
|
|
44 ;; Ediff also supports merging operations on files and buffers, including
|
|
45 ;; merging using ancestor versions. Both comparison and merging operations can
|
|
46 ;; be performed on directories, i.e., by pairwise comparison of files in those
|
|
47 ;; directories.
|
|
48
|
|
49 ;; In addition, Ediff can apply a patch to a file and then let you step
|
|
50 ;; though both files, the patched and the original one, simultaneously,
|
|
51 ;; difference-by-difference. You can even apply a patch right out of a
|
|
52 ;; mail buffer, i.e., patches received by mail don't even have to be saved.
|
|
53 ;; Since Ediff lets you copy differences between buffers, you can, in
|
|
54 ;; effect, apply patches selectively (i.e., you can copy a difference
|
|
55 ;; region from file_orig to file, thereby undoing any particular patch that
|
|
56 ;; you don't like).
|
|
57
|
|
58 ;; Ediff is aware of version control, which lets the user compare
|
|
59 ;; files with their older versions. Ediff can also work with remote and
|
|
60 ;; compressed files. Details are given below.
|
|
61
|
|
62 ;; Finally, Ediff supports directory-level comparison, merging and patching.
|
|
63 ;; See the on-line manual for details.
|
|
64
|
|
65 ;; This package builds upon the ideas borrowed from emerge.el and several
|
|
66 ;; Ediff's functions are adaptations from emerge.el. Much of the functionality
|
|
67 ;; Ediff provides is also influenced by emerge.el.
|
|
68
|
|
69 ;; The present version of Ediff supersedes Emerge. It provides a superior user
|
|
70 ;; interface and has numerous major features not found in Emerge. In
|
|
71 ;; particular, it can do patching, and 2-way and 3-way file comparison,
|
|
72 ;; merging, and directory operations.
|
|
73
|
|
74
|
|
75
|
|
76 ;;; Bugs:
|
|
77
|
|
78 ;; 1. The undo command doesn't restore deleted regions well. That is, if
|
|
79 ;; you delete all characters in a difference region and then invoke
|
|
80 ;; `undo', the reinstated text will most likely be inserted outside of
|
|
81 ;; what Ediff thinks is the current difference region. (This problem
|
|
82 ;; doesn't seem to exist with XEmacs.)
|
|
83 ;;
|
|
84 ;; If at any point you feel that difference regions are no longer correct,
|
|
85 ;; you can hit '!' to recompute the differences.
|
|
86
|
|
87 ;; 2. On a monochrome display, the repertoire of faces with which to
|
|
88 ;; highlight fine differences is limited. By default, Ediff is using
|
|
89 ;; underlining. However, if the region is already underlined by some other
|
|
90 ;; overlays, there is no simple way to temporarily remove that residual
|
|
91 ;; underlining. This problem occurs when a buffer is highlighted with
|
|
92 ;; hilit19.el or font-lock.el packages. If this residual highlighting gets
|
|
93 ;; in the way, you can do the following. Both font-lock.el and hilit19.el
|
|
94 ;; provide commands for unhighlighting buffers. You can either place these
|
|
95 ;; commands in `ediff-prepare-buffer-hook' (which will unhighlight every
|
|
96 ;; buffer used by Ediff) or you can execute them interactively, at any time
|
|
97 ;; and on any buffer.
|
|
98
|
|
99
|
|
100 ;;; Acknowledgements:
|
|
101
|
|
102 ;; Ediff was inspired by Dale R. Worley's <drw@math.mit.edu> emerge.el.
|
|
103 ;; Ediff would not have been possible without the help and encouragement of
|
|
104 ;; its many users. See Ediff on-line Info for the full list of those who
|
|
105 ;; helped. Improved defaults in Ediff file-name reading commands.
|
|
106
|
|
107 ;;; Code:
|
|
108
|
80
|
109 (provide 'ediff)
|
0
|
110
|
80
|
111 ;; Compiler pacifier
|
82
|
112 (and noninteractive
|
|
113 (eval-when-compile
|
|
114 (load-library "dired")
|
|
115 (load-library "info")
|
|
116 (load "pcl-cvs" 'noerror)))
|
80
|
117 (eval-when-compile
|
82
|
118 (let ((load-path (cons (expand-file-name ".") load-path)))
|
80
|
119 (or (featurep 'ediff-init)
|
|
120 (load "ediff-init.el" nil nil 'nosuffix))
|
|
121 (or (featurep 'ediff-mult)
|
|
122 (load "ediff-mult.el" nil nil 'nosuffix))
|
|
123 (or (featurep 'ediff-ptch)
|
|
124 (load "ediff-ptch.el" nil nil 'nosuffix))
|
|
125 (or (featurep 'ediff-vers)
|
|
126 (load "ediff-vers.el" nil nil 'nosuffix))
|
|
127 ))
|
|
128 ;; end pacifier
|
|
129
|
|
130 (require 'ediff-init)
|
|
131 (require 'ediff-mult) ; required because of the registry stuff
|
0
|
132
|
|
133 (defvar ediff-use-last-dir nil
|
|
134 "*If t, Ediff uses previous directory as default when reading file name.")
|
|
135
|
|
136 (defvar ediff-last-dir-A nil
|
|
137 "Last directory used by an Ediff command for file-A.")
|
|
138 (defvar ediff-last-dir-B nil
|
|
139 "Last directory used by an Ediff command for file-B.")
|
|
140 (defvar ediff-last-dir-C nil
|
|
141 "Last directory used by an Ediff command for file-C.")
|
|
142 (defvar ediff-last-dir-ancestor nil
|
|
143 "Last directory used by an Ediff command for the ancestor file.")
|
78
|
144 (defvar ediff-last-merge-autostore-dir
|
|
145 "Last directory used by an Ediff command as the output directory for merge.")
|
0
|
146
|
|
147 ;; Some defvars to reduce the number of compiler warnings
|
|
148 (defvar cvs-cookie-handle)
|
|
149 (defvar ediff-last-dir-patch)
|
|
150 (defvar ediff-patch-default-directory)
|
|
151 ;; end of compiler pacifier
|
|
152
|
|
153
|
|
154 ;; Used as a startup hook to set `_orig' patch file read-only.
|
|
155 (defun ediff-set-read-only-in-buf-A ()
|
|
156 (ediff-eval-in-buffer ediff-buffer-A
|
|
157 (toggle-read-only 1)))
|
|
158
|
|
159 ;; Return a plausible default for ediff's first file:
|
|
160 ;; In dired, return the file name under the point, unless it is a directory
|
|
161 ;; If the buffer has a file name, return that file name.
|
|
162 (defun ediff-get-default-file-name ()
|
|
163 (cond ((eq major-mode 'dired-mode)
|
|
164 (let ((f (dired-get-filename nil 'no-error)))
|
|
165 (if (and (stringp f) (not (file-directory-p f)))
|
|
166 f)))
|
|
167 ((buffer-file-name (current-buffer))
|
|
168 (file-name-nondirectory (buffer-file-name (current-buffer))))
|
|
169 ))
|
|
170
|
|
171 ;;; Compare files/buffers
|
|
172
|
|
173 ;;;###autoload
|
|
174 (defun ediff-files (file-A file-B &optional startup-hooks)
|
|
175 "Run Ediff on a pair of files, FILE-A and FILE-B."
|
|
176 (interactive
|
|
177 (let ((dir-A (if ediff-use-last-dir
|
|
178 ediff-last-dir-A
|
|
179 default-directory))
|
|
180 dir-B f)
|
|
181 (list (setq f (ediff-read-file-name
|
|
182 "File A to compare" dir-A
|
|
183 (ediff-get-default-file-name)))
|
|
184 (ediff-read-file-name "File B to compare"
|
|
185 (setq dir-B
|
|
186 (if ediff-use-last-dir
|
|
187 ediff-last-dir-B
|
|
188 (file-name-directory f)))
|
|
189 (progn
|
|
190 (setq file-name-history
|
|
191 (cons (ediff-abbreviate-file-name
|
|
192 (expand-file-name
|
|
193 (file-name-nondirectory f)
|
|
194 dir-B))
|
|
195 file-name-history))
|
|
196 f))
|
|
197 )))
|
|
198 (ediff-files-internal file-A
|
|
199 (if (file-directory-p file-B)
|
|
200 (expand-file-name
|
|
201 (file-name-nondirectory file-A) file-B)
|
|
202 file-B)
|
|
203 nil ; file-C
|
|
204 startup-hooks
|
|
205 'ediff-files))
|
|
206
|
|
207 ;;;###autoload
|
|
208 (defun ediff-files3 (file-A file-B file-C &optional startup-hooks)
|
|
209 "Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
|
|
210 (interactive
|
|
211 (let ((dir-A (if ediff-use-last-dir
|
|
212 ediff-last-dir-A
|
|
213 default-directory))
|
|
214 dir-B dir-C f ff)
|
|
215 (list (setq f (ediff-read-file-name
|
|
216 "File A to compare" dir-A
|
|
217 (ediff-get-default-file-name)))
|
|
218 (setq ff (ediff-read-file-name "File B to compare"
|
|
219 (setq dir-B
|
|
220 (if ediff-use-last-dir
|
|
221 ediff-last-dir-B
|
|
222 (file-name-directory f)))
|
|
223 (progn
|
|
224 (setq file-name-history
|
|
225 (cons
|
|
226 (ediff-abbreviate-file-name
|
|
227 (expand-file-name
|
|
228 (file-name-nondirectory f)
|
|
229 dir-B))
|
|
230 file-name-history))
|
|
231 f)))
|
|
232 (ediff-read-file-name "File C to compare"
|
|
233 (setq dir-C (if ediff-use-last-dir
|
|
234 ediff-last-dir-C
|
|
235 (file-name-directory ff)))
|
|
236 (progn
|
|
237 (setq file-name-history
|
|
238 (cons (ediff-abbreviate-file-name
|
|
239 (expand-file-name
|
|
240 (file-name-nondirectory ff)
|
|
241 dir-C))
|
|
242 file-name-history))
|
|
243 ff))
|
|
244 )))
|
|
245 (ediff-files-internal file-A
|
|
246 (if (file-directory-p file-B)
|
|
247 (expand-file-name
|
|
248 (file-name-nondirectory file-A) file-B)
|
|
249 file-B)
|
|
250 (if (file-directory-p file-C)
|
|
251 (expand-file-name
|
|
252 (file-name-nondirectory file-A) file-C)
|
|
253 file-C)
|
|
254 startup-hooks
|
|
255 'ediff-files3))
|
|
256
|
|
257 ;;;###autoload
|
|
258 (defalias 'ediff3 'ediff-files3)
|
|
259
|
|
260
|
|
261 ;; Visit FILE and arrange its buffer to Ediff's liking.
|
|
262 ;; FILE is actually a variable symbol that must contain a true file name.
|
|
263 ;; BUFFER-NAME is a variable symbol, which will get the buffer object into
|
|
264 ;; which FILE is read.
|
|
265 ;; LAST-DIR is the directory variable symbol where FILE's
|
|
266 ;; directory name should be returned. HOOKS-VAR is a variable symbol that will
|
|
267 ;; be assigned the hook to be executed after `ediff-startup' is finished.
|
|
268 ;; `ediff-find-file' arranges that the temp files it might create will be
|
|
269 ;; deleted.
|
|
270 (defun ediff-find-file (file-var buffer-name &optional last-dir hooks-var)
|
|
271 (let* ((file (symbol-value file-var))
|
|
272 (file-magic (find-file-name-handler file 'find-file-noselect))
|
|
273 (temp-file-name-prefix (file-name-nondirectory file)))
|
|
274 (cond ((not (file-readable-p file))
|
|
275 (error "File `%s' does not exist or is not readable" file))
|
|
276 ((file-directory-p file)
|
|
277 (error "File `%s' is a directory" file)))
|
|
278
|
|
279 ;; some of the commands, below, require full file name
|
|
280 (setq file (expand-file-name file))
|
|
281
|
|
282 ;; Record the directory of the file
|
|
283 (if last-dir
|
|
284 (set last-dir (expand-file-name (file-name-directory file))))
|
|
285
|
|
286 ;; Setup the buffer
|
|
287 (set buffer-name (find-file-noselect file))
|
|
288
|
|
289 (ediff-eval-in-buffer (symbol-value buffer-name)
|
|
290 (widen) ; Make sure the entire file is seen
|
82
|
291 (cond (file-magic ; file has a handler, such as jka-compr-handler or
|
|
292 ;;; ange-ftp-hook-function--arrange for temp file
|
0
|
293 (ediff-verify-file-buffer 'magic)
|
|
294 (setq file
|
|
295 (ediff-make-temp-file
|
|
296 (current-buffer) temp-file-name-prefix))
|
|
297 (set hooks-var (cons (` (lambda () (delete-file (, file))))
|
|
298 (symbol-value hooks-var))))
|
|
299 ;; file processed via auto-mode-alist, a la uncompress.el
|
|
300 ((not (equal (file-truename file)
|
|
301 (file-truename (buffer-file-name))))
|
|
302 (setq file
|
|
303 (ediff-make-temp-file
|
|
304 (current-buffer) temp-file-name-prefix))
|
|
305 (set hooks-var (cons (` (lambda () (delete-file (, file))))
|
|
306 (symbol-value hooks-var))))
|
|
307 (t ;; plain file---just check that the file matches the buffer
|
|
308 (ediff-verify-file-buffer))))
|
|
309 (set file-var file)))
|
|
310
|
|
311 (defun ediff-files-internal (file-A file-B file-C startup-hooks job-name)
|
|
312 (let (buf-A buf-B buf-C)
|
|
313 (message "Reading file %s ... " file-A)
|
|
314 ;;(sit-for 0)
|
|
315 (ediff-find-file 'file-A 'buf-A 'ediff-last-dir-A 'startup-hooks)
|
|
316 (message "Reading file %s ... " file-B)
|
|
317 ;;(sit-for 0)
|
|
318 (ediff-find-file 'file-B 'buf-B 'ediff-last-dir-B 'startup-hooks)
|
|
319 (if (stringp file-C)
|
|
320 (progn
|
|
321 (message "Reading file %s ... " file-C)
|
|
322 ;;(sit-for 0)
|
|
323 (ediff-find-file
|
|
324 'file-C 'buf-C
|
|
325 (if (eq job-name 'ediff-merge-files-with-ancestor)
|
|
326 'ediff-last-dir-ancestor 'ediff-last-dir-C)
|
|
327 'startup-hooks)))
|
|
328 (ediff-setup buf-A file-A
|
|
329 buf-B file-B
|
|
330 buf-C file-C
|
|
331 startup-hooks
|
|
332 (list (cons 'ediff-job-name job-name)))))
|
|
333
|
|
334
|
|
335 ;;;###autoload
|
|
336 (defalias 'ediff 'ediff-files)
|
|
337
|
|
338
|
|
339 ;;;###autoload
|
|
340 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name)
|
|
341 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
|
|
342 (interactive
|
|
343 (let (bf)
|
|
344 (list (setq bf (read-buffer "Buffer A to compare: "
|
|
345 (ediff-other-buffer "") t))
|
|
346 (read-buffer "Buffer B to compare: "
|
|
347 (progn
|
|
348 ;; realign buffers so that two visible bufs will be
|
|
349 ;; at the top
|
|
350 (save-window-excursion (other-window 1))
|
|
351 (ediff-other-buffer bf))
|
|
352 t))))
|
|
353 (or job-name (setq job-name 'ediff-buffers))
|
|
354 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name))
|
|
355
|
|
356 ;;;###autoload
|
|
357 (defalias 'ebuffers 'ediff-buffers)
|
|
358
|
|
359
|
|
360 ;;;###autoload
|
|
361 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
|
|
362 &optional startup-hooks job-name)
|
|
363 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
|
|
364 (interactive
|
|
365 (let (bf bff)
|
|
366 (list (setq bf (read-buffer "Buffer A to compare: "
|
|
367 (ediff-other-buffer "") t))
|
|
368 (setq bff (read-buffer "Buffer B to compare: "
|
|
369 (progn
|
|
370 ;; realign buffers so that two visible
|
|
371 ;; bufs will be at the top
|
|
372 (save-window-excursion (other-window 1))
|
|
373 (ediff-other-buffer bf))
|
|
374 t))
|
|
375 (read-buffer "Buffer C to compare: "
|
|
376 (progn
|
|
377 ;; realign buffers so that three visible
|
|
378 ;; bufs will be at the top
|
|
379 (save-window-excursion (other-window 1))
|
|
380 (ediff-other-buffer (list bf bff)))
|
|
381 t)
|
|
382 )))
|
|
383 (or job-name (setq job-name 'ediff-buffers3))
|
|
384 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name))
|
|
385
|
|
386 ;;;###autoload
|
|
387 (defalias 'ebuffers3 'ediff-buffers3)
|
|
388
|
|
389
|
|
390
|
|
391 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name)
|
|
392 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
|
|
393 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
|
|
394 (buf-C-is-alive (ediff-buffer-live-p buf-C))
|
|
395 (buf-C-file-name (if buf-C-is-alive
|
|
396 (buffer-file-name (get-buffer buf-B))))
|
|
397 file-A file-B file-C)
|
|
398 (if (not (ediff-buffer-live-p buf-A))
|
|
399 (error "Buffer %S doesn't exist" buf-A))
|
|
400 (if (not (ediff-buffer-live-p buf-B))
|
|
401 (error "Buffer %S doesn't exist" buf-B))
|
|
402 (let ((ediff-job-name job-name))
|
|
403 (if (and ediff-3way-comparison-job
|
|
404 (not buf-C-is-alive))
|
|
405 (error "Buffer %S doesn't exist" buf-C)))
|
|
406 (if (stringp buf-A-file-name)
|
|
407 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
|
|
408 (if (stringp buf-B-file-name)
|
|
409 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
|
|
410 (if (stringp buf-C-file-name)
|
|
411 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
|
|
412
|
|
413 (setq file-A (ediff-make-temp-file buf-A buf-A-file-name)
|
|
414 file-B (ediff-make-temp-file buf-B buf-B-file-name))
|
|
415 (if buf-C-is-alive
|
|
416 (setq file-C (ediff-make-temp-file buf-C buf-C-file-name)))
|
|
417
|
|
418 (ediff-setup (get-buffer buf-A) file-A
|
|
419 (get-buffer buf-B) file-B
|
|
420 (if buf-C-is-alive (get-buffer buf-C))
|
|
421 file-C
|
|
422 (cons (` (lambda ()
|
|
423 (delete-file (, file-A))
|
|
424 (delete-file (, file-B))
|
|
425 (if (stringp (, file-C)) (delete-file (, file-C)))
|
|
426 ))
|
|
427 startup-hooks)
|
|
428 (list (cons 'ediff-job-name job-name))
|
|
429 )))
|
|
430
|
|
431
|
|
432 ;;; Directory and file group operations
|
|
433
|
|
434 ;; Get appropriate default name for directory:
|
|
435 ;; If ediff-use-last-dir, use ediff-last-dir-A.
|
|
436 ;; In dired mode, use the directory that is under the point (if any);
|
|
437 ;; otherwise, use default-directory
|
|
438 (defun ediff-get-default-directory-name ()
|
|
439 (cond (ediff-use-last-dir ediff-last-dir-A)
|
|
440 ((eq major-mode 'dired-mode)
|
|
441 (let ((f (dired-get-filename nil 'noerror)))
|
|
442 (if (and (stringp f) (file-directory-p f))
|
|
443 f
|
|
444 default-directory)))
|
|
445 (t default-directory)))
|
|
446
|
|
447
|
|
448 ;;;###autoload
|
|
449 (defun ediff-directories (dir1 dir2 regexp)
|
|
450 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
|
|
451 the same name in both. The third argument, REGEXP, is a regular expression that
|
|
452 can be used to filter out certain file names."
|
|
453 (interactive
|
|
454 (let ((dir-A (ediff-get-default-directory-name))
|
|
455 f)
|
|
456 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
|
|
457 (ediff-read-file-name "Directory B to compare:"
|
|
458 (if ediff-use-last-dir
|
|
459 ediff-last-dir-B
|
|
460 (ediff-strip-last-dir f))
|
|
461 nil)
|
|
462 (read-string "Filter through regular expression: "
|
|
463 nil 'ediff-filtering-regexp-history)
|
|
464 )))
|
|
465 (ediff-directories-internal
|
|
466 dir1 dir2 nil regexp 'ediff-files 'ediff-directories
|
|
467 ))
|
|
468
|
|
469 ;;;###autoload
|
|
470 (defalias 'edirs 'ediff-directories)
|
|
471
|
|
472
|
|
473 ;;;###autoload
|
|
474 (defun ediff-directory-revisions (dir1 regexp)
|
|
475 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
|
|
476 The second argument, REGEXP, is a regular expression that filters the file
|
|
477 names. Only the files that are under revision control are taken into account."
|
|
478 (interactive
|
|
479 (let ((dir-A (ediff-get-default-directory-name)))
|
|
480 (list (ediff-read-file-name
|
|
481 "Directory to compare with revision:" dir-A nil)
|
|
482 (read-string "Filter through regular expression: "
|
|
483 nil 'ediff-filtering-regexp-history)
|
|
484 )))
|
|
485 (ediff-directory-revisions-internal
|
|
486 dir1 regexp 'ediff-revision 'ediff-directory-revisions
|
|
487 ))
|
|
488
|
|
489 ;;;###autoload
|
|
490 (defalias 'edir-revisions 'ediff-directory-revisions)
|
|
491
|
|
492
|
|
493 ;;;###autoload
|
|
494 (defun ediff-directories3 (dir1 dir2 dir3 regexp)
|
|
495 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
|
|
496 have the same name in all three. The last argument, REGEXP, is a regular
|
|
497 expression that can be used to filter out certain file names."
|
|
498 (interactive
|
|
499 (let ((dir-A (ediff-get-default-directory-name))
|
|
500 f)
|
|
501 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
|
|
502 (setq f (ediff-read-file-name "Directory B to compare:"
|
|
503 (if ediff-use-last-dir
|
|
504 ediff-last-dir-B
|
|
505 (ediff-strip-last-dir f))
|
|
506 nil))
|
|
507 (ediff-read-file-name "Directory C to compare:"
|
|
508 (if ediff-use-last-dir
|
|
509 ediff-last-dir-C
|
|
510 (ediff-strip-last-dir f))
|
|
511 nil)
|
|
512 (read-string "Filter through regular expression: "
|
|
513 nil 'ediff-filtering-regexp-history)
|
|
514 )))
|
|
515 (ediff-directories-internal
|
|
516 dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3
|
|
517 ))
|
|
518
|
|
519 ;;;###autoload
|
|
520 (defalias 'edirs3 'ediff-directories3)
|
|
521
|
|
522 ;;;###autoload
|
|
523 (defun ediff-merge-directories (dir1 dir2 regexp)
|
|
524 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
|
|
525 the same name in both. The third argument, REGEXP, is a regular expression that
|
|
526 can be used to filter out certain file names."
|
|
527 (interactive
|
|
528 (let ((dir-A (ediff-get-default-directory-name))
|
|
529 f)
|
|
530 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
|
|
531 (ediff-read-file-name "Directory B to merge:"
|
|
532 (if ediff-use-last-dir
|
|
533 ediff-last-dir-B
|
|
534 (ediff-strip-last-dir f))
|
|
535 nil)
|
|
536 (read-string "Filter through regular expression: "
|
|
537 nil 'ediff-filtering-regexp-history)
|
|
538 )))
|
|
539 (ediff-directories-internal
|
|
540 dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories
|
|
541 ))
|
|
542
|
|
543 ;;;###autoload
|
|
544 (defalias 'edirs-merge 'ediff-merge-directories)
|
|
545
|
|
546 ;;;###autoload
|
|
547 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp)
|
|
548 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
|
|
549 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
|
|
550 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
|
|
551 without ancestor. The fourth argument, REGEXP, is a regular expression that
|
|
552 can be used to filter out certain file names."
|
|
553 (interactive
|
|
554 (let ((dir-A (ediff-get-default-directory-name))
|
|
555 f)
|
|
556 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
|
|
557 (setq f (ediff-read-file-name "Directory B to merge:"
|
|
558 (if ediff-use-last-dir
|
|
559 ediff-last-dir-B
|
|
560 (ediff-strip-last-dir f))
|
|
561 nil))
|
|
562 (ediff-read-file-name "Ancestor directory:"
|
|
563 (if ediff-use-last-dir
|
|
564 ediff-last-dir-C
|
|
565 (ediff-strip-last-dir f))
|
|
566 nil)
|
|
567 (read-string "Filter through regular expression: "
|
|
568 nil 'ediff-filtering-regexp-history)
|
|
569 )))
|
|
570 (ediff-directories-internal
|
|
571 dir1 dir2 ancestor-dir regexp
|
|
572 'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor
|
|
573 ))
|
|
574
|
|
575 ;;;###autoload
|
|
576 (defun ediff-merge-directory-revisions (dir1 regexp)
|
|
577 "Run Ediff on a directory, DIR1, merging its files with their revisions.
|
|
578 The second argument, REGEXP, is a regular expression that filters the file
|
|
579 names. Only the files that are under revision control are taken into account."
|
|
580 (interactive
|
|
581 (let ((dir-A (ediff-get-default-directory-name)))
|
|
582 (list (ediff-read-file-name
|
|
583 "Directory to merge with revisions:" dir-A nil)
|
|
584 (read-string "Filter through regular expression: "
|
|
585 nil 'ediff-filtering-regexp-history)
|
|
586 )))
|
|
587 (ediff-directory-revisions-internal
|
|
588 dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions
|
|
589 ))
|
|
590
|
|
591 ;;;###autoload
|
|
592 (defalias 'edir-merge-revisions 'ediff-merge-directory-revisions)
|
|
593
|
|
594 ;;;###autoload
|
|
595 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp)
|
|
596 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
|
|
597 The second argument, REGEXP, is a regular expression that filters the file
|
|
598 names. Only the files that are under revision control are taken into account."
|
|
599 (interactive
|
|
600 (let ((dir-A (ediff-get-default-directory-name)))
|
|
601 (list (ediff-read-file-name
|
|
602 "Directory to merge with revisions and ancestors:" dir-A nil)
|
|
603 (read-string "Filter through regular expression: "
|
|
604 nil 'ediff-filtering-regexp-history)
|
|
605 )))
|
|
606 (ediff-directory-revisions-internal
|
|
607 dir1 regexp 'ediff-merge-revisions-with-ancestor
|
|
608 'ediff-merge-directory-revisions-with-ancestor
|
|
609 ))
|
|
610
|
|
611 ;;;###autoload
|
|
612 (defalias
|
|
613 'edir-merge-revisions-with-ancestor
|
|
614 'ediff-merge-directory-revisions-with-ancestor)
|
|
615
|
|
616 ;;;###autoload
|
|
617 (defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor)
|
|
618
|
|
619 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
|
|
620 ;; on a pair of directories (three directories, in case of ancestor).
|
|
621 ;; The third argument, REGEXP, is a regular expression that can be used to
|
|
622 ;; filter out certain file names.
|
|
623 ;; JOBNAME is the symbol indicating the meta-job to be performed.
|
78
|
624 ;; MERGE-DIR is the directory in which to store merged files.
|
|
625 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
|
0
|
626 &optional startup-hooks)
|
|
627 ;; ediff-read-file-name is set to attach a previously entered file name if
|
|
628 ;; the currently entered file is a directory. This code takes care of that.
|
|
629 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1))
|
|
630 dir2 (if (file-directory-p dir2) dir2 (file-name-directory dir2)))
|
|
631
|
|
632 (if (stringp dir3)
|
|
633 (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))
|
|
634
|
|
635 (cond ((string= dir1 dir2)
|
|
636 (error "Directories A and B are the same: %s" dir1))
|
|
637 ((and (eq jobname 'ediff-directories3)
|
|
638 (string= dir1 dir3))
|
|
639 (error "Directories A and C are the same: %s" dir1))
|
|
640 ((and (eq jobname 'ediff-directories3)
|
|
641 (string= dir2 dir3))
|
|
642 (error "Directories B and C are the same: %s" dir1)))
|
|
643
|
|
644 (let (diffs ; var where ediff-intersect-directories returns the diff list
|
78
|
645 merge-autostore-dir
|
0
|
646 file-list meta-buf)
|
78
|
647 (if (and ediff-autostore-merges (ediff-merge-metajob jobname))
|
|
648 (setq merge-autostore-dir
|
|
649 (ediff-read-file-name "Directory to save merged files:"
|
|
650 (if ediff-use-last-dir
|
|
651 ediff-last-merge-autostore-dir
|
|
652 (ediff-strip-last-dir dir1))
|
|
653 nil)))
|
|
654 ;; verify we are not merging into an orig directory
|
|
655 (if (stringp merge-autostore-dir)
|
|
656 (cond ((and (stringp dir1) (string= merge-autostore-dir dir1))
|
|
657 (or (y-or-n-p "Merge directory same as directory A, sure? ")
|
|
658 (error "Directory merge aborted")))
|
|
659 ((and (stringp dir2) (string= merge-autostore-dir dir2))
|
|
660 (or (y-or-n-p "Merge directory same as directory B, sure? ")
|
|
661 (error "Directory merge aborted")))
|
|
662 ((and (stringp dir3) (string= merge-autostore-dir dir3))
|
|
663 (or (y-or-n-p
|
|
664 "Merge directory same as ancestor directory, sure? ")
|
|
665 (error "Directory merge aborted")))))
|
|
666
|
0
|
667 (setq file-list (ediff-intersect-directories
|
78
|
668 jobname 'diffs
|
|
669 regexp dir1 dir2 dir3 merge-autostore-dir))
|
0
|
670 (setq startup-hooks
|
|
671 ;; this sets various vars in the meta buffer inside
|
|
672 ;; ediff-prepare-meta-buffer
|
|
673 (cons (` (lambda ()
|
|
674 ;; tell what to do if the user clicks on a session record
|
|
675 (setq ediff-session-action-function (quote (, action)))
|
|
676 ;; set ediff-dir-difference-list
|
|
677 (setq ediff-dir-difference-list (quote (, diffs)))))
|
|
678 startup-hooks))
|
|
679 (setq meta-buf (ediff-prepare-meta-buffer
|
|
680 'ediff-filegroup-action
|
|
681 file-list
|
|
682 "*Ediff Session Group Panel"
|
|
683 'ediff-redraw-directory-group-buffer
|
|
684 jobname
|
|
685 startup-hooks))
|
|
686 (ediff-show-meta-buffer meta-buf)
|
|
687 ))
|
|
688
|
|
689 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
|
|
690 &optional startup-hooks)
|
|
691 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)))
|
78
|
692
|
|
693 (let (file-list meta-buf merge-autostore-dir)
|
|
694 (if (and ediff-autostore-merges (ediff-merge-metajob jobname))
|
|
695 (setq merge-autostore-dir
|
|
696 (ediff-read-file-name "Directory to save merged files:"
|
|
697 (if ediff-use-last-dir
|
|
698 ediff-last-merge-autostore-dir
|
|
699 (ediff-strip-last-dir dir1))
|
|
700 nil)))
|
|
701 ;; verify merge-autostore-dir != dir1
|
|
702 (if (and (stringp merge-autostore-dir)
|
|
703 (stringp dir1)
|
|
704 (string= merge-autostore-dir dir1))
|
|
705 (or (y-or-n-p
|
|
706 "Directory for saving merges is the same as directory A. Sure? ")
|
|
707 (error "Merge of directory revisions aborted")))
|
80
|
708
|
0
|
709 (setq file-list
|
78
|
710 (ediff-get-directory-files-under-revision
|
|
711 jobname regexp dir1 merge-autostore-dir))
|
0
|
712 (setq startup-hooks
|
|
713 ;; this sets various vars in the meta buffer inside
|
|
714 ;; ediff-prepare-meta-buffer
|
|
715 (cons (` (lambda ()
|
|
716 ;; tell what to do if the user clicks on a session record
|
|
717 (setq ediff-session-action-function (quote (, action)))
|
|
718 ))
|
|
719 startup-hooks))
|
|
720 (setq meta-buf (ediff-prepare-meta-buffer
|
|
721 'ediff-filegroup-action
|
|
722 file-list
|
|
723 "*Ediff Session Group Panel"
|
|
724 'ediff-redraw-directory-group-buffer
|
|
725 jobname
|
|
726 startup-hooks))
|
|
727 (ediff-show-meta-buffer meta-buf)
|
|
728 ))
|
|
729
|
|
730
|
|
731 ;;; Compare regions and windows
|
|
732
|
|
733 ;;;###autoload
|
|
734 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks)
|
|
735 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
|
|
736 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
|
|
737 follows:
|
|
738 If WIND-A is nil, use selected window.
|
|
739 If WIND-B is nil, use window next to WIND-A."
|
|
740 (interactive "P")
|
|
741 (ediff-windows dumb-mode wind-A wind-B
|
|
742 startup-hooks 'ediff-windows-wordwise 'word-mode))
|
|
743
|
|
744 ;;;###autoload
|
|
745 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks)
|
|
746 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
|
|
747 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
|
|
748 follows:
|
|
749 If WIND-A is nil, use selected window.
|
|
750 If WIND-B is nil, use window next to WIND-A."
|
|
751 (interactive "P")
|
|
752 (ediff-windows dumb-mode wind-A wind-B
|
|
753 startup-hooks 'ediff-windows-linewise nil))
|
|
754
|
|
755 ;; Compare WIND-A and WIND-B, which are selected by clicking.
|
|
756 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
|
|
757 ;; works as follows:
|
|
758 ;; If WIND-A is nil, use selected window.
|
|
759 ;; If WIND-B is nil, use window next to WIND-A.
|
|
760 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode)
|
|
761 (if (or dumb-mode (not (ediff-window-display-p)))
|
|
762 (setq wind-A (ediff-get-next-window wind-A nil)
|
|
763 wind-B (ediff-get-next-window wind-B wind-A))
|
|
764 (setq wind-A (ediff-get-window-by-clicking wind-A nil 1)
|
|
765 wind-B (ediff-get-window-by-clicking wind-B wind-A 2)))
|
|
766
|
|
767 (let ((buffer-A (window-buffer wind-A))
|
|
768 (buffer-B (window-buffer wind-B))
|
|
769 beg-A end-A beg-B end-B)
|
|
770
|
|
771 (save-excursion
|
|
772 (save-window-excursion
|
|
773 (sit-for 0) ; sync before using window-start/end -- a precaution
|
|
774 (select-window wind-A)
|
|
775 (setq beg-A (window-start)
|
|
776 end-A (window-end))
|
|
777 (select-window wind-B)
|
|
778 (setq beg-B (window-start)
|
|
779 end-B (window-end))))
|
|
780 (ediff-regions-internal
|
|
781 buffer-A beg-A end-A buffer-B beg-B end-B
|
|
782 startup-hooks job-name word-mode)))
|
|
783
|
|
784 ;;;###autoload
|
|
785 (defun ediff-regions-wordwise (buffer-A buffer-B &optional startup-hooks)
|
|
786 "Run Ediff on a pair of regions in two different buffers.
|
|
787 Regions \(i.e., point and mark\) are assumed to be set in advance.
|
|
788 This function is effective only for relatively small regions, up to 200
|
|
789 lines. For large regions, use `ediff-regions-linewise'."
|
|
790 (interactive
|
|
791 (let (bf)
|
|
792 (list (setq bf (read-buffer "Region's A buffer: "
|
|
793 (ediff-other-buffer "") t))
|
|
794 (read-buffer "Region's B buffer: "
|
|
795 (progn
|
|
796 ;; realign buffers so that two visible bufs will be
|
|
797 ;; at the top
|
|
798 (save-window-excursion (other-window 1))
|
|
799 (ediff-other-buffer bf))
|
|
800 t))))
|
|
801 (if (not (ediff-buffer-live-p buffer-A))
|
|
802 (error "Buffer %S doesn't exist" buffer-A))
|
|
803 (if (not (ediff-buffer-live-p buffer-B))
|
|
804 (error "Buffer %S doesn't exist" buffer-B))
|
|
805
|
|
806
|
|
807 (let (reg-A-beg reg-A-end reg-B-beg reg-B-end)
|
|
808 (save-excursion
|
|
809 (set-buffer buffer-A)
|
|
810 (setq reg-A-beg (region-beginning)
|
|
811 reg-A-end (region-end))
|
|
812 (set-buffer buffer-B)
|
|
813 (setq reg-B-beg (region-beginning)
|
|
814 reg-B-end (region-end)))
|
|
815
|
|
816 (ediff-regions-internal
|
|
817 (get-buffer buffer-A) reg-A-beg reg-A-end
|
|
818 (get-buffer buffer-B) reg-B-beg reg-B-end
|
|
819 startup-hooks 'ediff-regions-wordwise 'word-mode)))
|
|
820
|
|
821 ;;;###autoload
|
|
822 (defun ediff-regions-linewise (buffer-A buffer-B &optional startup-hooks)
|
|
823 "Run Ediff on a pair of regions in two different buffers.
|
|
824 Regions \(i.e., point and mark\) are assumed to be set in advance.
|
|
825 Each region is enlarged to contain full lines.
|
|
826 This function is effective for large regions, over 100-200
|
|
827 lines. For small regions, use `ediff-regions-wordwise'."
|
|
828 (interactive
|
|
829 (let (bf)
|
|
830 (list (setq bf (read-buffer "Region A's buffer: "
|
|
831 (ediff-other-buffer "") t))
|
|
832 (read-buffer "Region B's buffer: "
|
|
833 (progn
|
|
834 ;; realign buffers so that two visible bufs will be
|
|
835 ;; at the top
|
|
836 (save-window-excursion (other-window 1))
|
|
837 (ediff-other-buffer bf))
|
|
838 t))))
|
|
839 (if (not (ediff-buffer-live-p buffer-A))
|
|
840 (error "Buffer %S doesn't exist" buffer-A))
|
|
841 (if (not (ediff-buffer-live-p buffer-B))
|
|
842 (error "Buffer %S doesn't exist" buffer-B))
|
|
843
|
|
844 (let (reg-A-beg reg-A-end reg-B-beg reg-B-end)
|
|
845 (save-excursion
|
|
846 (set-buffer buffer-A)
|
|
847 (setq reg-A-beg (region-beginning)
|
|
848 reg-A-end (region-end))
|
|
849 ;; enlarge the region to hold full lines
|
|
850 (goto-char reg-A-beg)
|
|
851 (beginning-of-line)
|
|
852 (setq reg-A-beg (point))
|
|
853 (goto-char reg-A-end)
|
|
854 (end-of-line)
|
|
855 (or (eobp) (forward-char)) ; include the newline char
|
|
856 (setq reg-A-end (point))
|
|
857
|
|
858 (set-buffer buffer-B)
|
|
859 (setq reg-B-beg (region-beginning)
|
|
860 reg-B-end (region-end))
|
|
861 ;; enlarge the region to hold full lines
|
|
862 (goto-char reg-B-beg)
|
|
863 (beginning-of-line)
|
|
864 (setq reg-B-beg (point))
|
|
865 (goto-char reg-B-end)
|
|
866 (end-of-line)
|
|
867 (or (eobp) (forward-char)) ; include the newline char
|
|
868 (setq reg-B-end (point))
|
|
869 ) ; save excursion
|
|
870
|
|
871 (ediff-regions-internal
|
|
872 (get-buffer buffer-A) reg-A-beg reg-A-end
|
|
873 (get-buffer buffer-B) reg-B-beg reg-B-end
|
|
874 startup-hooks 'ediff-regions-linewise nil))) ; no word mode
|
|
875
|
|
876 ;; compare region beg-A to end-A of buffer-A
|
|
877 ;; to regions beg-B -- end-B in buffer-B.
|
|
878 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
|
|
879 startup-hooks job-name word-mode)
|
|
880 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
|
|
881 overl-A overl-B
|
|
882 file-A file-B)
|
|
883
|
|
884 ;; in case beg/end-A/B aren't markers--make them into markers
|
|
885 (ediff-eval-in-buffer buffer-A
|
|
886 (setq beg-A (move-marker (make-marker) beg-A)
|
|
887 end-A (move-marker (make-marker) end-A)))
|
|
888 (ediff-eval-in-buffer buffer-B
|
|
889 (setq beg-B (move-marker (make-marker) beg-B)
|
|
890 end-B (move-marker (make-marker) end-B)))
|
|
891
|
|
892 (if (and (eq buffer-A buffer-B)
|
|
893 (or (and (< beg-A end-B) (<= beg-B beg-A)) ; b-B b-A e-B
|
|
894 (and (< beg-B end-A) (<= end-A end-B)))) ; b-B e-A e-B
|
|
895 (progn
|
|
896 (with-output-to-temp-buffer ediff-msg-buffer
|
|
897 (princ "
|
|
898 You have requested to compare overlapping regions of the same buffer.
|
|
899
|
|
900 In this case, Ediff's highlighting may be confusing---in the same window,
|
|
901 you may see highlighted regions that belong to different regions.
|
|
902
|
|
903 Continue anyway? (y/n) "))
|
|
904
|
|
905 (if (y-or-n-p "Continue anyway? ")
|
|
906 ()
|
|
907 (error "%S aborted" job-name))))
|
|
908
|
|
909 ;; make file-A
|
|
910 (if word-mode
|
|
911 (ediff-wordify beg-A end-A buffer-A tmp-buffer)
|
|
912 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer))
|
|
913 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
|
|
914
|
|
915 ;; make file-B
|
|
916 (if word-mode
|
|
917 (ediff-wordify beg-B end-B buffer-B tmp-buffer)
|
|
918 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer))
|
|
919 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
|
|
920
|
|
921 (setq overl-A (ediff-make-bullet-proof-overlay beg-A end-A buffer-A))
|
|
922 (setq overl-B (ediff-make-bullet-proof-overlay beg-B end-B buffer-B))
|
|
923 (ediff-setup buffer-A file-A
|
|
924 buffer-B file-B
|
|
925 nil nil ; buffer & file C
|
|
926 (cons (` (lambda ()
|
|
927 (delete-file (, file-A))
|
|
928 (delete-file (, file-B))))
|
|
929 startup-hooks)
|
|
930 (list (cons 'ediff-word-mode word-mode)
|
|
931 (cons 'ediff-narrow-bounds (list overl-A overl-B))
|
|
932 (cons 'ediff-job-name job-name))
|
|
933 )
|
|
934 ))
|
|
935
|
|
936
|
|
937 ;;; Merge files and buffers
|
|
938
|
|
939 ;;;###autoload
|
|
940 (defalias 'ediff-merge 'ediff-merge-files)
|
|
941
|
|
942 (defsubst ediff-merge-on-startup ()
|
|
943 (ediff-do-merge 0)
|
|
944 (ediff-eval-in-buffer ediff-buffer-C
|
|
945 (set-buffer-modified-p nil)))
|
|
946
|
|
947 ;;;###autoload
|
|
948 (defun ediff-merge-files (file-A file-B &optional startup-hooks)
|
|
949 "Merge two files without ancestor."
|
|
950 (interactive
|
|
951 (let ((dir-A (if ediff-use-last-dir
|
|
952 ediff-last-dir-A
|
|
953 default-directory))
|
|
954 dir-B f)
|
|
955 (list (setq f (ediff-read-file-name
|
|
956 "File A to merge" dir-A
|
|
957 (ediff-get-default-file-name)))
|
|
958 (ediff-read-file-name "File B to merge"
|
|
959 (setq dir-B
|
|
960 (if ediff-use-last-dir
|
|
961 ediff-last-dir-B
|
|
962 (file-name-directory f)))
|
|
963 (progn
|
|
964 (setq file-name-history
|
|
965 (cons (ediff-abbreviate-file-name
|
|
966 (expand-file-name
|
|
967 (file-name-nondirectory f)
|
|
968 dir-B))
|
|
969 file-name-history))
|
|
970 f))
|
|
971 )))
|
|
972 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
|
|
973 (ediff-files-internal file-A
|
|
974 (if (file-directory-p file-B)
|
|
975 (expand-file-name
|
|
976 (file-name-nondirectory file-A) file-B)
|
|
977 file-B)
|
|
978 nil ; file-C
|
|
979 startup-hooks
|
|
980 'ediff-merge-files))
|
|
981
|
|
982 ;;;###autoload
|
|
983 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
|
|
984 &optional startup-hooks)
|
|
985 "Merge two files with ancestor."
|
|
986 (interactive
|
|
987 (let ((dir-A (if ediff-use-last-dir
|
|
988 ediff-last-dir-A
|
|
989 default-directory))
|
|
990 dir-B dir-ancestor f ff)
|
|
991 (list (setq f (ediff-read-file-name
|
|
992 "File A to merge" dir-A
|
|
993 (ediff-get-default-file-name)))
|
|
994 (setq ff (ediff-read-file-name "File B to merge"
|
|
995 (setq dir-B
|
|
996 (if ediff-use-last-dir
|
|
997 ediff-last-dir-B
|
|
998 (file-name-directory f)))
|
|
999 (progn
|
|
1000 (setq file-name-history
|
|
1001 (cons
|
|
1002 (ediff-abbreviate-file-name
|
|
1003 (expand-file-name
|
|
1004 (file-name-nondirectory f)
|
|
1005 dir-B))
|
|
1006 file-name-history))
|
|
1007 f)))
|
|
1008 (ediff-read-file-name "Ancestor file"
|
|
1009 (setq dir-ancestor
|
|
1010 (if ediff-use-last-dir
|
|
1011 ediff-last-dir-ancestor
|
|
1012 (file-name-directory ff)))
|
|
1013 (progn
|
|
1014 (setq file-name-history
|
|
1015 (cons (ediff-abbreviate-file-name
|
|
1016 (expand-file-name
|
|
1017 (file-name-nondirectory ff)
|
|
1018 dir-ancestor))
|
|
1019 file-name-history))
|
|
1020 ff))
|
|
1021 )))
|
|
1022 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
|
|
1023 (ediff-files-internal file-A
|
|
1024 (if (file-directory-p file-B)
|
|
1025 (expand-file-name
|
|
1026 (file-name-nondirectory file-A) file-B)
|
|
1027 file-B)
|
|
1028 file-ancestor
|
|
1029 startup-hooks
|
|
1030 'ediff-merge-files-with-ancestor))
|
|
1031
|
|
1032 ;;;###autoload
|
|
1033 (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor)
|
|
1034
|
|
1035 ;;;###autoload
|
|
1036 (defun ediff-merge-buffers (buffer-A buffer-B &optional startup-hooks job-name)
|
|
1037 "Merge buffers without ancestor."
|
|
1038 (interactive
|
|
1039 (let (bf)
|
|
1040 (list (setq bf (read-buffer "Buffer A to merge: "
|
|
1041 (ediff-other-buffer "") t))
|
|
1042 (read-buffer "Buffer B to merge: "
|
|
1043 (progn
|
|
1044 ;; realign buffers so that two visible bufs will be
|
|
1045 ;; at the top
|
|
1046 (save-window-excursion (other-window 1))
|
|
1047 (ediff-other-buffer bf))
|
|
1048 t))))
|
|
1049
|
|
1050 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
|
|
1051 (or job-name (setq job-name 'ediff-merge-buffers))
|
|
1052 (ediff-buffers-internal
|
|
1053 buffer-A buffer-B nil startup-hooks job-name))
|
|
1054
|
|
1055 ;;;###autoload
|
|
1056 (defun ediff-merge-buffers-with-ancestor (buffer-A
|
|
1057 buffer-B buffer-ancestor
|
|
1058 &optional startup-hooks job-name)
|
|
1059 "Merge buffers with ancestor."
|
|
1060 (interactive
|
|
1061 (let (bf bff)
|
|
1062 (list (setq bf (read-buffer "Buffer A to merge: "
|
|
1063 (ediff-other-buffer "") t))
|
|
1064 (setq bff (read-buffer "Buffer B to merge: "
|
|
1065 (progn
|
|
1066 ;; realign buffers so that two visible
|
|
1067 ;; bufs will be at the top
|
|
1068 (save-window-excursion (other-window 1))
|
|
1069 (ediff-other-buffer bf))
|
|
1070 t))
|
|
1071 (read-buffer "Ancestor buffer: "
|
|
1072 (progn
|
|
1073 ;; realign buffers so that three visible
|
|
1074 ;; bufs will be at the top
|
|
1075 (save-window-excursion (other-window 1))
|
|
1076 (ediff-other-buffer (list bf bff)))
|
|
1077 t)
|
|
1078 )))
|
|
1079
|
|
1080 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
|
|
1081 (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor))
|
|
1082 (ediff-buffers-internal
|
|
1083 buffer-A buffer-B buffer-ancestor startup-hooks job-name))
|
|
1084
|
|
1085
|
|
1086 ;;;###autoload
|
|
1087 (defun ediff-merge-revisions (&optional file startup-hooks)
|
|
1088 "Run Ediff by merging two revisions of a file.
|
|
1089 The file is the optional FILE argument or the file visited by the current
|
|
1090 buffer."
|
|
1091 (interactive)
|
|
1092 (if (stringp file) (find-file file))
|
|
1093 (let (rev1 rev2)
|
|
1094 (setq rev1
|
|
1095 (read-string
|
|
1096 (format
|
|
1097 "Version 1 to merge (default: %s's latest version): "
|
|
1098 (if (stringp file)
|
|
1099 (file-name-nondirectory file) "current buffer")))
|
|
1100 rev2
|
|
1101 (read-string
|
|
1102 (format
|
|
1103 "Version 2 to merge (default: %s): "
|
|
1104 (if (stringp file)
|
|
1105 (file-name-nondirectory file) "current buffer"))))
|
|
1106 (ediff-load-version-control)
|
|
1107 ;; ancestor-revision=nil
|
|
1108 (funcall
|
78
|
1109 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
|
0
|
1110 rev1 rev2 nil startup-hooks)))
|
|
1111
|
|
1112
|
|
1113 ;;;###autoload
|
|
1114 (defun ediff-merge-revisions-with-ancestor (&optional file startup-hooks)
|
|
1115 "Run Ediff by merging two revisions of a file with a common ancestor.
|
80
|
1116 The file is the the optional FILE argument or the file visited by the current
|
0
|
1117 buffer."
|
|
1118 (interactive)
|
|
1119 (if (stringp file) (find-file file))
|
|
1120 (let (rev1 rev2 ancestor-rev)
|
|
1121 (setq rev1
|
|
1122 (read-string
|
|
1123 (format
|
|
1124 "Version 1 to merge (default: %s's latest version): "
|
|
1125 (if (stringp file)
|
|
1126 (file-name-nondirectory file) "current buffer")))
|
|
1127 rev2
|
|
1128 (read-string
|
|
1129 (format
|
|
1130 "Version 2 to merge (default: %s): "
|
|
1131 (if (stringp file)
|
|
1132 (file-name-nondirectory file) "current buffer")))
|
|
1133 ancestor-rev
|
|
1134 (read-string
|
|
1135 (format
|
|
1136 "Ancestor version (default: %s): "
|
|
1137 (if (stringp file)
|
|
1138 (file-name-nondirectory file) "current buffer"))))
|
|
1139 (ediff-load-version-control)
|
|
1140 (funcall
|
78
|
1141 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
|
0
|
1142 rev1 rev2 ancestor-rev startup-hooks)))
|
|
1143
|
|
1144 ;;;###autoload
|
|
1145 (defun run-ediff-from-cvs-buffer (pos)
|
|
1146 "Run Ediff-merge on appropriate revisions of the selected file.
|
|
1147 First run after `M-x cvs-update'. Then place the cursor on a lide describing a
|
|
1148 file and then run `run-ediff-from-cvs-buffer'."
|
|
1149 (interactive "d")
|
|
1150 (ediff-load-version-control)
|
|
1151 (let ((tin (tin-locate cvs-cookie-handle pos)))
|
|
1152 (if tin
|
|
1153 (cvs-run-ediff-on-file-descriptor tin)
|
|
1154 (error "There is no file to merge"))))
|
|
1155
|
|
1156
|
|
1157 ;;; Apply patch
|
|
1158
|
|
1159 ;;;###autoload
|
|
1160 (defun ediff-patch-file ()
|
|
1161 "Run Ediff by patching SOURCE-FILENAME."
|
|
1162 ;; This now returns the control buffer
|
|
1163 (interactive)
|
|
1164 (let (source-dir source-file patch-buf)
|
|
1165 (require 'ediff-ptch)
|
|
1166 (setq patch-buf (ediff-get-patch-buffer))
|
|
1167 (setq source-dir (cond (ediff-use-last-dir ediff-last-dir-patch)
|
|
1168 ((and (not ediff-patch-default-directory)
|
|
1169 (buffer-file-name patch-buf))
|
|
1170 (file-name-directory
|
|
1171 (expand-file-name
|
|
1172 (buffer-file-name patch-buf))))
|
|
1173 (t default-directory)))
|
|
1174 (setq source-file
|
|
1175 ;; the default is the directory, not the visited file name
|
|
1176 (ediff-read-file-name "Which file to patch? " source-dir source-dir))
|
|
1177 (ediff-dispatch-file-patching-job patch-buf source-file)))
|
|
1178
|
|
1179 ;;;###autoload
|
|
1180 (defun ediff-patch-buffer ()
|
|
1181 "Run Ediff by patching BUFFER-NAME."
|
|
1182 (interactive)
|
|
1183 (let (patch-buf)
|
|
1184 (require 'ediff-ptch)
|
|
1185 (setq patch-buf (ediff-get-patch-buffer))
|
|
1186 (ediff-patch-buffer-internal
|
|
1187 patch-buf
|
|
1188 (read-buffer "Which buffer to patch? "
|
|
1189 (cond ((eq patch-buf (current-buffer))
|
|
1190 (window-buffer (other-window 1)))
|
|
1191 (t (current-buffer)))
|
|
1192 'must-match))))
|
|
1193
|
|
1194 ;;;###autoload
|
|
1195 (defalias 'epatch 'ediff-patch-file)
|
|
1196 ;;;###autoload
|
|
1197 (defalias 'epatch-buffer 'ediff-patch-buffer)
|
|
1198
|
|
1199
|
|
1200
|
|
1201
|
|
1202 ;;; Versions Control functions
|
|
1203
|
|
1204 ;;;###autoload
|
|
1205 (defun ediff-revision (&optional file startup-hooks)
|
|
1206 "Run Ediff by comparing versions of a file.
|
|
1207 The file is an optional FILE argument or the file visited by the current
|
|
1208 buffer. Use `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
|
|
1209 ;; if buffer is non-nil, use that buffer instead of the current buffer
|
|
1210 (interactive "P")
|
|
1211 (if (stringp file) (find-file file))
|
|
1212 (let (rev1 rev2)
|
|
1213 (setq rev1
|
|
1214 (read-string
|
|
1215 (format "Version 1 to compare (default: %s's latest version): "
|
|
1216 (if (stringp file)
|
|
1217 (file-name-nondirectory file) "current buffer")))
|
|
1218 rev2
|
|
1219 (read-string
|
|
1220 (format "Version 2 to compare (default: %s): "
|
|
1221 (if (stringp file)
|
|
1222 (file-name-nondirectory file) "current buffer"))))
|
|
1223 (ediff-load-version-control)
|
|
1224 (funcall
|
78
|
1225 (intern (format "ediff-%S-internal" ediff-version-control-package))
|
0
|
1226 rev1 rev2 startup-hooks)
|
|
1227 ))
|
|
1228
|
|
1229
|
|
1230 ;; Test if version control package is loaded and load if not
|
|
1231 ;; Is SILENT is non-nil, don't report error if package is not found.
|
|
1232 (defun ediff-load-version-control (&optional silent)
|
|
1233 (require 'ediff-vers)
|
|
1234 (or (featurep ediff-version-control-package)
|
|
1235 (if (locate-library (symbol-name ediff-version-control-package))
|
|
1236 (progn
|
|
1237 (message "") ; kill the message from `locate-library'
|
|
1238 (require ediff-version-control-package))
|
|
1239 (or silent
|
|
1240 (error "Version control package %S.el not found. Use vc.el instead"
|
|
1241 ediff-version-control-package)))))
|
|
1242
|
|
1243
|
|
1244 ;;;###autoload
|
|
1245 (defun ediff-version ()
|
|
1246 "Return string describing the version of Ediff.
|
|
1247 When called interactively, displays the version."
|
|
1248 (interactive)
|
|
1249 (if (interactive-p)
|
|
1250 (message (ediff-version))
|
|
1251 (format "Ediff %s of %s" ediff-version ediff-date)))
|
|
1252
|
|
1253
|
|
1254 ;;;###autoload
|
78
|
1255 (defun ediff-documentation (&optional node)
|
|
1256 "Display Ediff's manual.
|
|
1257 With optional NODE, goes to that node."
|
0
|
1258 (interactive)
|
|
1259 (let ((ctl-window ediff-control-window)
|
|
1260 (ctl-buf ediff-control-buffer))
|
|
1261
|
|
1262 (ediff-skip-unsuitable-frames)
|
|
1263 (condition-case nil
|
|
1264 (progn
|
|
1265 (pop-to-buffer (get-buffer-create "*info*"))
|
|
1266 (info (if ediff-xemacs-p "ediff.info" "ediff"))
|
78
|
1267 (if node
|
|
1268 (Info-goto-node node)
|
|
1269 (message "Type `i' to search for a specific topic"))
|
|
1270 (raise-frame (selected-frame)))
|
0
|
1271 (error (beep 1)
|
|
1272 (with-output-to-temp-buffer ediff-msg-buffer
|
78
|
1273 (princ ediff-BAD-INFO))
|
0
|
1274 (if (window-live-p ctl-window)
|
|
1275 (progn
|
|
1276 (select-window ctl-window)
|
|
1277 (set-window-buffer ctl-window ctl-buf)))))))
|
|
1278
|
|
1279
|
|
1280
|
|
1281
|
|
1282 ;;; Local Variables:
|
|
1283 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
|
|
1284 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
|
78
|
1285 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
|
0
|
1286 ;;; End:
|
|
1287
|
|
1288 (require 'ediff-util)
|
|
1289
|
|
1290 ;;; ediff.el ends here
|