(define-minor-mode): Use `symbol-value' to keep the byte-compiler quiet.
[emacs.git] / lisp / ediff.el
blobefab0dec0d1af2c9f2c0589e10a3e5a6e11acbde
1 ;;; ediff.el --- a comprehensive visual interface to diff & patch
3 ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
6 ;; Created: February 2, 1994
7 ;; Keywords: comparing, merging, patching, version control.
9 (defconst ediff-version "2.74" "The current version of Ediff")
10 (defconst ediff-date "October 31, 1999" "Date of last update")
13 ;; This file is part of GNU Emacs.
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.
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.
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.
30 ;;; Commentary:
32 ;; Never read that diff output again!
33 ;; Apply patch interactively!
34 ;; Merge with ease!
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).
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.
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).
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.
62 ;; Finally, Ediff supports directory-level comparison, merging and patching.
63 ;; See the on-line manual for details.
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.
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.
76 ;;; Bugs:
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.)
84 ;; If at any point you feel that difference regions are no longer correct,
85 ;; you can hit '!' to recompute the differences.
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.
100 ;;; Acknowledgements:
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.
107 ;;; Code:
109 (provide 'ediff)
111 ;; Compiler pacifier
112 (defvar cvs-cookie-handle)
113 (defvar ediff-last-dir-patch)
114 (defvar ediff-patch-default-directory)
116 (and noninteractive
117 (eval-when-compile
118 (load-library "dired")
119 (load-library "info")
120 (load "pcl-cvs" 'noerror)))
121 (eval-when-compile
122 (let ((load-path (cons (expand-file-name ".") load-path)))
123 (or (featurep 'ediff-init)
124 (load "ediff-init.el" nil nil 'nosuffix))
125 (or (featurep 'ediff-mult)
126 (load "ediff-mult.el" nil nil 'nosuffix))
127 (or (featurep 'ediff-ptch)
128 (load "ediff-ptch.el" nil nil 'nosuffix))
129 (or (featurep 'ediff-vers)
130 (load "ediff-vers.el" nil nil 'nosuffix))
132 ;; end pacifier
134 (require 'ediff-init)
135 (require 'ediff-mult) ; required because of the registry stuff
137 (defgroup ediff nil
138 "A comprehensive visual interface to diff & patch"
139 :tag "Ediff"
140 :group 'tools)
143 (defcustom ediff-use-last-dir nil
144 "*If t, Ediff will use previous directory as default when reading file name."
145 :type 'boolean
146 :group 'ediff)
148 ;; Last directory used by an Ediff command for file-A.
149 (defvar ediff-last-dir-A nil)
150 ;; Last directory used by an Ediff command for file-B.
151 (defvar ediff-last-dir-B nil)
152 ;; Last directory used by an Ediff command for file-C.
153 (defvar ediff-last-dir-C nil)
154 ;; Last directory used by an Ediff command for the ancestor file.
155 (defvar ediff-last-dir-ancestor nil)
156 ;; Last directory used by an Ediff command as the output directory for merge.
157 (defvar ediff-last-merge-autostore-dir)
160 ;; Used as a startup hook to set `_orig' patch file read-only.
161 (defun ediff-set-read-only-in-buf-A ()
162 (ediff-with-current-buffer ediff-buffer-A
163 (toggle-read-only 1)))
165 ;; Return a plausible default for ediff's first file:
166 ;; In dired, return the file name under the point, unless it is a directory
167 ;; If the buffer has a file name, return that file name.
168 (defun ediff-get-default-file-name ()
169 (cond ((eq major-mode 'dired-mode)
170 (let ((f (dired-get-filename nil 'no-error)))
171 (if (and (stringp f) (not (file-directory-p f)))
172 f)))
173 ((buffer-file-name (current-buffer))
174 (file-name-nondirectory (buffer-file-name (current-buffer))))
177 ;;; Compare files/buffers
179 ;;;###autoload
180 (defun ediff-files (file-A file-B &optional startup-hooks)
181 "Run Ediff on a pair of files, FILE-A and FILE-B."
182 (interactive
183 (let ((dir-A (if ediff-use-last-dir
184 ediff-last-dir-A
185 default-directory))
186 dir-B f)
187 (list (setq f (ediff-read-file-name
188 "File A to compare" dir-A
189 (ediff-get-default-file-name)))
190 (ediff-read-file-name "File B to compare"
191 (setq dir-B
192 (if ediff-use-last-dir
193 ediff-last-dir-B
194 (file-name-directory f)))
195 (progn
196 (setq file-name-history
197 (cons (ediff-abbreviate-file-name
198 (expand-file-name
199 (file-name-nondirectory f)
200 dir-B))
201 file-name-history))
204 (ediff-files-internal file-A
205 (if (file-directory-p file-B)
206 (expand-file-name
207 (file-name-nondirectory file-A) file-B)
208 file-B)
209 nil ; file-C
210 startup-hooks
211 'ediff-files))
213 ;;;###autoload
214 (defun ediff-files3 (file-A file-B file-C &optional startup-hooks)
215 "Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
216 (interactive
217 (let ((dir-A (if ediff-use-last-dir
218 ediff-last-dir-A
219 default-directory))
220 dir-B dir-C f ff)
221 (list (setq f (ediff-read-file-name
222 "File A to compare" dir-A
223 (ediff-get-default-file-name)))
224 (setq ff (ediff-read-file-name "File B to compare"
225 (setq dir-B
226 (if ediff-use-last-dir
227 ediff-last-dir-B
228 (file-name-directory f)))
229 (progn
230 (setq file-name-history
231 (cons
232 (ediff-abbreviate-file-name
233 (expand-file-name
234 (file-name-nondirectory f)
235 dir-B))
236 file-name-history))
237 f)))
238 (ediff-read-file-name "File C to compare"
239 (setq dir-C (if ediff-use-last-dir
240 ediff-last-dir-C
241 (file-name-directory ff)))
242 (progn
243 (setq file-name-history
244 (cons (ediff-abbreviate-file-name
245 (expand-file-name
246 (file-name-nondirectory ff)
247 dir-C))
248 file-name-history))
249 ff))
251 (ediff-files-internal file-A
252 (if (file-directory-p file-B)
253 (expand-file-name
254 (file-name-nondirectory file-A) file-B)
255 file-B)
256 (if (file-directory-p file-C)
257 (expand-file-name
258 (file-name-nondirectory file-A) file-C)
259 file-C)
260 startup-hooks
261 'ediff-files3))
263 ;;;###autoload
264 (defalias 'ediff3 'ediff-files3)
267 ;; Visit FILE and arrange its buffer to Ediff's liking.
268 ;; FILE is actually a variable symbol that must contain a true file name.
269 ;; BUFFER-NAME is a variable symbol, which will get the buffer object into
270 ;; which FILE is read.
271 ;; LAST-DIR is the directory variable symbol where FILE's
272 ;; directory name should be returned. HOOKS-VAR is a variable symbol that will
273 ;; be assigned the hook to be executed after `ediff-startup' is finished.
274 ;; `ediff-find-file' arranges that the temp files it might create will be
275 ;; deleted.
276 (defun ediff-find-file (file-var buffer-name &optional last-dir hooks-var)
277 (let* ((file (symbol-value file-var))
278 (file-magic (ediff-filename-magic-p file))
279 (temp-file-name-prefix (file-name-nondirectory file)))
280 (cond ((not (file-readable-p file))
281 (error "File `%s' does not exist or is not readable" file))
282 ((file-directory-p file)
283 (error "File `%s' is a directory" file)))
285 ;; some of the commands, below, require full file name
286 (setq file (expand-file-name file))
288 ;; Record the directory of the file
289 (if last-dir
290 (set last-dir (expand-file-name (file-name-directory file))))
292 ;; Setup the buffer
293 (set buffer-name (find-file-noselect file))
295 (ediff-with-current-buffer (symbol-value buffer-name)
296 (widen) ; Make sure the entire file is seen
297 (cond (file-magic ; file has a handler, such as jka-compr-handler or
298 ;;; ange-ftp-hook-function--arrange for temp file
299 (ediff-verify-file-buffer 'magic)
300 (setq file
301 (ediff-make-temp-file
302 (current-buffer) temp-file-name-prefix))
303 (set hooks-var (cons `(lambda () (delete-file ,file))
304 (symbol-value hooks-var))))
305 ;; file processed via auto-mode-alist, a la uncompress.el
306 ((not (equal (file-truename file)
307 (file-truename (buffer-file-name))))
308 (setq file
309 (ediff-make-temp-file
310 (current-buffer) temp-file-name-prefix))
311 (set hooks-var (cons `(lambda () (delete-file ,file))
312 (symbol-value hooks-var))))
313 (t ;; plain file---just check that the file matches the buffer
314 (ediff-verify-file-buffer))))
315 (set file-var file)))
317 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
318 (defun ediff-files-internal (file-A file-B file-C startup-hooks job-name
319 &optional merge-buffer-file)
320 (let (buf-A buf-B buf-C)
321 (message "Reading file %s ... " file-A)
322 ;;(sit-for 0)
323 (ediff-find-file 'file-A 'buf-A 'ediff-last-dir-A 'startup-hooks)
324 (message "Reading file %s ... " file-B)
325 ;;(sit-for 0)
326 (ediff-find-file 'file-B 'buf-B 'ediff-last-dir-B 'startup-hooks)
327 (if (stringp file-C)
328 (progn
329 (message "Reading file %s ... " file-C)
330 ;;(sit-for 0)
331 (ediff-find-file
332 'file-C 'buf-C
333 (if (eq job-name 'ediff-merge-files-with-ancestor)
334 'ediff-last-dir-ancestor 'ediff-last-dir-C)
335 'startup-hooks)))
336 (ediff-setup buf-A file-A
337 buf-B file-B
338 buf-C file-C
339 startup-hooks
340 (list (cons 'ediff-job-name job-name))
341 merge-buffer-file)))
344 ;;;###autoload
345 (defalias 'ediff 'ediff-files)
348 ;;;###autoload
349 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name)
350 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
351 (interactive
352 (let (bf)
353 (list (setq bf (read-buffer "Buffer A to compare: "
354 (ediff-other-buffer "") t))
355 (read-buffer "Buffer B to compare: "
356 (progn
357 ;; realign buffers so that two visible bufs will be
358 ;; at the top
359 (save-window-excursion (other-window 1))
360 (ediff-other-buffer bf))
361 t))))
362 (or job-name (setq job-name 'ediff-buffers))
363 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name))
365 ;;;###autoload
366 (defalias 'ebuffers 'ediff-buffers)
369 ;;;###autoload
370 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
371 &optional startup-hooks job-name)
372 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
373 (interactive
374 (let (bf bff)
375 (list (setq bf (read-buffer "Buffer A to compare: "
376 (ediff-other-buffer "") t))
377 (setq bff (read-buffer "Buffer B to compare: "
378 (progn
379 ;; realign buffers so that two visible
380 ;; bufs will be at the top
381 (save-window-excursion (other-window 1))
382 (ediff-other-buffer bf))
384 (read-buffer "Buffer C to compare: "
385 (progn
386 ;; realign buffers so that three visible
387 ;; bufs will be at the top
388 (save-window-excursion (other-window 1))
389 (ediff-other-buffer (list bf bff)))
392 (or job-name (setq job-name 'ediff-buffers3))
393 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name))
395 ;;;###autoload
396 (defalias 'ebuffers3 'ediff-buffers3)
400 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
401 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
402 &optional merge-buffer-file)
403 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
404 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
405 (buf-C-is-alive (ediff-buffer-live-p buf-C))
406 (buf-C-file-name (if buf-C-is-alive
407 (buffer-file-name (get-buffer buf-B))))
408 file-A file-B file-C)
409 (if (not (ediff-buffer-live-p buf-A))
410 (error "Buffer %S doesn't exist" buf-A))
411 (if (not (ediff-buffer-live-p buf-B))
412 (error "Buffer %S doesn't exist" buf-B))
413 (let ((ediff-job-name job-name))
414 (if (and ediff-3way-comparison-job
415 (not buf-C-is-alive))
416 (error "Buffer %S doesn't exist" buf-C)))
417 (if (stringp buf-A-file-name)
418 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
419 (if (stringp buf-B-file-name)
420 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
421 (if (stringp buf-C-file-name)
422 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
424 (setq file-A (ediff-make-temp-file buf-A buf-A-file-name)
425 file-B (ediff-make-temp-file buf-B buf-B-file-name))
426 (if buf-C-is-alive
427 (setq file-C (ediff-make-temp-file buf-C buf-C-file-name)))
429 (ediff-setup (get-buffer buf-A) file-A
430 (get-buffer buf-B) file-B
431 (if buf-C-is-alive (get-buffer buf-C))
432 file-C
433 (cons `(lambda ()
434 (delete-file ,file-A)
435 (delete-file ,file-B)
436 (if (stringp ,file-C) (delete-file ,file-C)))
437 startup-hooks)
438 (list (cons 'ediff-job-name job-name))
439 merge-buffer-file)))
442 ;;; Directory and file group operations
444 ;; Get appropriate default name for directory:
445 ;; If ediff-use-last-dir, use ediff-last-dir-A.
446 ;; In dired mode, use the directory that is under the point (if any);
447 ;; otherwise, use default-directory
448 (defun ediff-get-default-directory-name ()
449 (cond (ediff-use-last-dir ediff-last-dir-A)
450 ((eq major-mode 'dired-mode)
451 (let ((f (dired-get-filename nil 'noerror)))
452 (if (and (stringp f) (file-directory-p f))
454 default-directory)))
455 (t default-directory)))
458 ;;;###autoload
459 (defun ediff-directories (dir1 dir2 regexp)
460 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
461 the same name in both. The third argument, REGEXP, is a regular expression
462 that can be used to filter out certain file names."
463 (interactive
464 (let ((dir-A (ediff-get-default-directory-name))
466 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
467 (ediff-read-file-name "Directory B to compare:"
468 (if ediff-use-last-dir
469 ediff-last-dir-B
470 (ediff-strip-last-dir f))
471 nil)
472 (read-string "Filter through regular expression: "
473 nil 'ediff-filtering-regexp-history)
475 (ediff-directories-internal
476 dir1 dir2 nil regexp 'ediff-files 'ediff-directories
479 ;;;###autoload
480 (defalias 'edirs 'ediff-directories)
483 ;;;###autoload
484 (defun ediff-directory-revisions (dir1 regexp)
485 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
486 The second argument, REGEXP, is a regular expression that filters the file
487 names. Only the files that are under revision control are taken into account."
488 (interactive
489 (let ((dir-A (ediff-get-default-directory-name)))
490 (list (ediff-read-file-name
491 "Directory to compare with revision:" dir-A nil)
492 (read-string "Filter through regular expression: "
493 nil 'ediff-filtering-regexp-history)
495 (ediff-directory-revisions-internal
496 dir1 regexp 'ediff-revision 'ediff-directory-revisions
499 ;;;###autoload
500 (defalias 'edir-revisions 'ediff-directory-revisions)
503 ;;;###autoload
504 (defun ediff-directories3 (dir1 dir2 dir3 regexp)
505 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
506 have the same name in all three. The last argument, REGEXP, is a regular
507 expression that can be used to filter out certain file names."
508 (interactive
509 (let ((dir-A (ediff-get-default-directory-name))
511 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
512 (setq f (ediff-read-file-name "Directory B to compare:"
513 (if ediff-use-last-dir
514 ediff-last-dir-B
515 (ediff-strip-last-dir f))
516 nil))
517 (ediff-read-file-name "Directory C to compare:"
518 (if ediff-use-last-dir
519 ediff-last-dir-C
520 (ediff-strip-last-dir f))
521 nil)
522 (read-string "Filter through regular expression: "
523 nil 'ediff-filtering-regexp-history)
525 (ediff-directories-internal
526 dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3
529 ;;;###autoload
530 (defalias 'edirs3 'ediff-directories3)
532 ;;;###autoload
533 (defun ediff-merge-directories (dir1 dir2 regexp &optional merge-autostore-dir)
534 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
535 the same name in both. The third argument, REGEXP, is a regular expression
536 that can be used to filter out certain file names."
537 (interactive
538 (let ((dir-A (ediff-get-default-directory-name))
540 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
541 (ediff-read-file-name "Directory B to merge:"
542 (if ediff-use-last-dir
543 ediff-last-dir-B
544 (ediff-strip-last-dir f))
545 nil)
546 (read-string "Filter through regular expression: "
547 nil 'ediff-filtering-regexp-history)
549 (ediff-directories-internal
550 dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories
551 nil merge-autostore-dir
554 ;;;###autoload
555 (defalias 'edirs-merge 'ediff-merge-directories)
557 ;;;###autoload
558 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
559 &optional
560 merge-autostore-dir)
561 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
562 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
563 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
564 without ancestor. The fourth argument, REGEXP, is a regular expression that
565 can be used to filter out certain file names."
566 (interactive
567 (let ((dir-A (ediff-get-default-directory-name))
569 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
570 (setq f (ediff-read-file-name "Directory B to merge:"
571 (if ediff-use-last-dir
572 ediff-last-dir-B
573 (ediff-strip-last-dir f))
574 nil))
575 (ediff-read-file-name "Ancestor directory:"
576 (if ediff-use-last-dir
577 ediff-last-dir-C
578 (ediff-strip-last-dir f))
579 nil)
580 (read-string "Filter through regular expression: "
581 nil 'ediff-filtering-regexp-history)
583 (ediff-directories-internal
584 dir1 dir2 ancestor-dir regexp
585 'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor
586 nil merge-autostore-dir
589 ;;;###autoload
590 (defun ediff-merge-directory-revisions (dir1 regexp
591 &optional merge-autostore-dir)
592 "Run Ediff on a directory, DIR1, merging its files with their revisions.
593 The second argument, REGEXP, is a regular expression that filters the file
594 names. Only the files that are under revision control are taken into account."
595 (interactive
596 (let ((dir-A (ediff-get-default-directory-name)))
597 (list (ediff-read-file-name
598 "Directory to merge with revisions:" dir-A nil)
599 (read-string "Filter through regular expression: "
600 nil 'ediff-filtering-regexp-history)
602 (ediff-directory-revisions-internal
603 dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions
604 nil merge-autostore-dir
607 ;;;###autoload
608 (defalias 'edir-merge-revisions 'ediff-merge-directory-revisions)
610 ;;;###autoload
611 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
612 &optional
613 merge-autostore-dir)
614 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
615 The second argument, REGEXP, is a regular expression that filters the file
616 names. Only the files that are under revision control are taken into account."
617 (interactive
618 (let ((dir-A (ediff-get-default-directory-name)))
619 (list (ediff-read-file-name
620 "Directory to merge with revisions and ancestors:" dir-A nil)
621 (read-string "Filter through regular expression: "
622 nil 'ediff-filtering-regexp-history)
624 (ediff-directory-revisions-internal
625 dir1 regexp 'ediff-merge-revisions-with-ancestor
626 'ediff-merge-directory-revisions-with-ancestor
627 nil merge-autostore-dir
630 ;;;###autoload
631 (defalias
632 'edir-merge-revisions-with-ancestor
633 'ediff-merge-directory-revisions-with-ancestor)
635 ;;;###autoload
636 (defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor)
638 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
639 ;; on a pair of directories (three directories, in case of ancestor).
640 ;; The third argument, REGEXP, is a regular expression that can be used to
641 ;; filter out certain file names.
642 ;; JOBNAME is the symbol indicating the meta-job to be performed.
643 ;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
644 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
645 &optional startup-hooks
646 merge-autostore-dir)
647 ;; ediff-read-file-name is set to attach a previously entered file name if
648 ;; the currently entered file is a directory. This code takes care of that.
649 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1))
650 dir2 (if (file-directory-p dir2) dir2 (file-name-directory dir2)))
652 (if (stringp dir3)
653 (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))
655 (cond ((string= dir1 dir2)
656 (error "Directories A and B are the same: %s" dir1))
657 ((and (eq jobname 'ediff-directories3)
658 (string= dir1 dir3))
659 (error "Directories A and C are the same: %s" dir1))
660 ((and (eq jobname 'ediff-directories3)
661 (string= dir2 dir3))
662 (error "Directories B and C are the same: %s" dir1)))
664 (if merge-autostore-dir
665 (or (stringp merge-autostore-dir)
666 (error "%s: Directory for storing merged files must be a string"
667 jobname)))
668 (let (diffs ; var where ediff-intersect-directories returns the diff list
669 file-list meta-buf)
670 (if (and ediff-autostore-merges
671 (ediff-merge-metajob jobname)
672 (not merge-autostore-dir))
673 (setq merge-autostore-dir
674 (read-file-name "Save merged files in directory: "
675 (if ediff-use-last-dir
676 ediff-last-merge-autostore-dir
677 (ediff-strip-last-dir dir1))
679 'must-match)))
680 ;; verify we are not merging into an orig directory
681 (if merge-autostore-dir
682 (cond ((and (stringp dir1) (string= merge-autostore-dir dir1))
683 (or (y-or-n-p
684 "Directory for saving merged files = Directory A. Sure? ")
685 (error "Directory merge aborted")))
686 ((and (stringp dir2) (string= merge-autostore-dir dir2))
687 (or (y-or-n-p
688 "Directory for saving merged files = Directory B. Sure? ")
689 (error "Directory merge aborted")))
690 ((and (stringp dir3) (string= merge-autostore-dir dir3))
691 (or (y-or-n-p
692 "Directory for saving merged files = Ancestor Directory. Sure? ")
693 (error "Directory merge aborted")))))
695 (setq file-list (ediff-intersect-directories
696 jobname 'diffs
697 regexp dir1 dir2 dir3 merge-autostore-dir))
698 (setq startup-hooks
699 ;; this sets various vars in the meta buffer inside
700 ;; ediff-prepare-meta-buffer
701 (cons `(lambda ()
702 ;; tell what to do if the user clicks on a session record
703 (setq ediff-session-action-function (quote ,action))
704 ;; set ediff-dir-difference-list
705 (setq ediff-dir-difference-list (quote ,diffs)))
706 startup-hooks))
707 (setq meta-buf (ediff-prepare-meta-buffer
708 'ediff-filegroup-action
709 file-list
710 "*Ediff Session Group Panel"
711 'ediff-redraw-directory-group-buffer
712 jobname
713 startup-hooks))
714 (ediff-show-meta-buffer meta-buf)
717 ;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
718 ;; files
719 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
720 &optional startup-hooks
721 merge-autostore-dir)
722 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)))
724 (if merge-autostore-dir
725 (or (stringp merge-autostore-dir)
726 (error "%S: Directory for storing merged files must be a string"
727 jobname)))
728 (let (file-list meta-buf)
729 (if (and ediff-autostore-merges
730 (ediff-merge-metajob jobname)
731 (not merge-autostore-dir))
732 (setq merge-autostore-dir
733 (read-file-name "Save merged files in directory: "
734 (if ediff-use-last-dir
735 ediff-last-merge-autostore-dir
736 (ediff-strip-last-dir dir1))
738 'must-match)))
739 ;; verify merge-autostore-dir != dir1
740 (if (and merge-autostore-dir
741 (stringp dir1)
742 (string= merge-autostore-dir dir1))
743 (or (y-or-n-p
744 "Directory for saving merged file = directory A. Sure? ")
745 (error "Merge of directory revisions aborted")))
747 (setq file-list
748 (ediff-get-directory-files-under-revision
749 jobname regexp dir1 merge-autostore-dir))
750 (setq startup-hooks
751 ;; this sets various vars in the meta buffer inside
752 ;; ediff-prepare-meta-buffer
753 (cons `(lambda ()
754 ;; tell what to do if the user clicks on a session record
755 (setq ediff-session-action-function (quote ,action)))
756 startup-hooks))
757 (setq meta-buf (ediff-prepare-meta-buffer
758 'ediff-filegroup-action
759 file-list
760 "*Ediff Session Group Panel"
761 'ediff-redraw-directory-group-buffer
762 jobname
763 startup-hooks))
764 (ediff-show-meta-buffer meta-buf)
768 ;;; Compare regions and windows
770 ;;;###autoload
771 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks)
772 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
773 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
774 follows:
775 If WIND-A is nil, use selected window.
776 If WIND-B is nil, use window next to WIND-A."
777 (interactive "P")
778 (ediff-windows dumb-mode wind-A wind-B
779 startup-hooks 'ediff-windows-wordwise 'word-mode))
781 ;;;###autoload
782 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks)
783 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
784 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
785 follows:
786 If WIND-A is nil, use selected window.
787 If WIND-B is nil, use window next to WIND-A."
788 (interactive "P")
789 (ediff-windows dumb-mode wind-A wind-B
790 startup-hooks 'ediff-windows-linewise nil))
792 ;; Compare WIND-A and WIND-B, which are selected by clicking.
793 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
794 ;; works as follows:
795 ;; If WIND-A is nil, use selected window.
796 ;; If WIND-B is nil, use window next to WIND-A.
797 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode)
798 (if (or dumb-mode (not (ediff-window-display-p)))
799 (setq wind-A (ediff-get-next-window wind-A nil)
800 wind-B (ediff-get-next-window wind-B wind-A))
801 (setq wind-A (ediff-get-window-by-clicking wind-A nil 1)
802 wind-B (ediff-get-window-by-clicking wind-B wind-A 2)))
804 (let ((buffer-A (window-buffer wind-A))
805 (buffer-B (window-buffer wind-B))
806 beg-A end-A beg-B end-B)
808 (save-excursion
809 (save-window-excursion
810 (sit-for 0) ; sync before using window-start/end -- a precaution
811 (select-window wind-A)
812 (setq beg-A (window-start)
813 end-A (window-end))
814 (select-window wind-B)
815 (setq beg-B (window-start)
816 end-B (window-end))))
817 (ediff-regions-internal
818 buffer-A beg-A end-A buffer-B beg-B end-B
819 startup-hooks job-name word-mode nil)))
821 ;;;###autoload
822 (defun ediff-regions-wordwise (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 This function is effective only for relatively small regions, up to 200
826 lines. For large regions, use `ediff-regions-linewise'."
827 (interactive
828 (let (bf)
829 (list (setq bf (read-buffer "Region's A buffer: "
830 (ediff-other-buffer "") t))
831 (read-buffer "Region's B buffer: "
832 (progn
833 ;; realign buffers so that two visible bufs will be
834 ;; at the top
835 (save-window-excursion (other-window 1))
836 (ediff-other-buffer bf))
837 t))))
838 (if (not (ediff-buffer-live-p buffer-A))
839 (error "Buffer %S doesn't exist" buffer-A))
840 (if (not (ediff-buffer-live-p buffer-B))
841 (error "Buffer %S doesn't exist" buffer-B))
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 (set-buffer buffer-B)
850 (setq reg-B-beg (region-beginning)
851 reg-B-end (region-end)))
853 (ediff-regions-internal
854 (get-buffer buffer-A) reg-A-beg reg-A-end
855 (get-buffer buffer-B) reg-B-beg reg-B-end
856 startup-hooks 'ediff-regions-wordwise 'word-mode nil)))
858 ;;;###autoload
859 (defun ediff-regions-linewise (buffer-A buffer-B &optional startup-hooks)
860 "Run Ediff on a pair of regions in two different buffers.
861 Regions \(i.e., point and mark\) are assumed to be set in advance.
862 Each region is enlarged to contain full lines.
863 This function is effective for large regions, over 100-200
864 lines. For small regions, use `ediff-regions-wordwise'."
865 (interactive
866 (let (bf)
867 (list (setq bf (read-buffer "Region A's buffer: "
868 (ediff-other-buffer "") t))
869 (read-buffer "Region B's buffer: "
870 (progn
871 ;; realign buffers so that two visible bufs will be
872 ;; at the top
873 (save-window-excursion (other-window 1))
874 (ediff-other-buffer bf))
875 t))))
876 (if (not (ediff-buffer-live-p buffer-A))
877 (error "Buffer %S doesn't exist" buffer-A))
878 (if (not (ediff-buffer-live-p buffer-B))
879 (error "Buffer %S doesn't exist" buffer-B))
881 (let (reg-A-beg reg-A-end reg-B-beg reg-B-end)
882 (save-excursion
883 (set-buffer buffer-A)
884 (setq reg-A-beg (region-beginning)
885 reg-A-end (region-end))
886 ;; enlarge the region to hold full lines
887 (goto-char reg-A-beg)
888 (beginning-of-line)
889 (setq reg-A-beg (point))
890 (goto-char reg-A-end)
891 (end-of-line)
892 (or (eobp) (forward-char)) ; include the newline char
893 (setq reg-A-end (point))
895 (set-buffer buffer-B)
896 (setq reg-B-beg (region-beginning)
897 reg-B-end (region-end))
898 ;; enlarge the region to hold full lines
899 (goto-char reg-B-beg)
900 (beginning-of-line)
901 (setq reg-B-beg (point))
902 (goto-char reg-B-end)
903 (end-of-line)
904 (or (eobp) (forward-char)) ; include the newline char
905 (setq reg-B-end (point))
906 ) ; save excursion
908 (ediff-regions-internal
909 (get-buffer buffer-A) reg-A-beg reg-A-end
910 (get-buffer buffer-B) reg-B-beg reg-B-end
911 startup-hooks 'ediff-regions-linewise nil nil))) ; no word mode
913 ;; compare region beg-A to end-A of buffer-A
914 ;; to regions beg-B -- end-B in buffer-B.
915 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
916 startup-hooks job-name word-mode
917 setup-parameters)
918 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
919 overl-A overl-B
920 file-A file-B)
922 ;; in case beg/end-A/B aren't markers--make them into markers
923 (ediff-with-current-buffer buffer-A
924 (setq beg-A (move-marker (make-marker) beg-A)
925 end-A (move-marker (make-marker) end-A)))
926 (ediff-with-current-buffer buffer-B
927 (setq beg-B (move-marker (make-marker) beg-B)
928 end-B (move-marker (make-marker) end-B)))
930 (if (and (eq buffer-A buffer-B)
931 (or (and (< beg-A end-B) (<= beg-B beg-A)) ; b-B b-A e-B
932 (and (< beg-B end-A) (<= end-A end-B)))) ; b-B e-A e-B
933 (progn
934 (with-output-to-temp-buffer ediff-msg-buffer
935 (princ "
936 You have requested to compare overlapping regions of the same buffer.
938 In this case, Ediff's highlighting may be confusing---in the same window,
939 you may see highlighted regions that belong to different regions.
941 Continue anyway? (y/n) "))
943 (if (y-or-n-p "Continue anyway? ")
945 (error "%S aborted" job-name))))
947 ;; make file-A
948 (if word-mode
949 (ediff-wordify beg-A end-A buffer-A tmp-buffer)
950 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer))
951 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
953 ;; make file-B
954 (if word-mode
955 (ediff-wordify beg-B end-B buffer-B tmp-buffer)
956 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer))
957 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
959 (setq overl-A (ediff-make-bullet-proof-overlay beg-A end-A buffer-A))
960 (setq overl-B (ediff-make-bullet-proof-overlay beg-B end-B buffer-B))
961 (ediff-setup buffer-A file-A
962 buffer-B file-B
963 nil nil ; buffer & file C
964 (cons `(lambda ()
965 (delete-file ,file-A)
966 (delete-file ,file-B))
967 startup-hooks)
968 (append
969 (list (cons 'ediff-word-mode word-mode)
970 (cons 'ediff-narrow-bounds (list overl-A overl-B))
971 (cons 'ediff-job-name job-name))
972 setup-parameters))
976 ;;; Merge files and buffers
978 ;;;###autoload
979 (defalias 'ediff-merge 'ediff-merge-files)
981 (defsubst ediff-merge-on-startup ()
982 (ediff-do-merge 0)
983 (ediff-with-current-buffer ediff-buffer-C
984 (set-buffer-modified-p nil)))
986 ;;;###autoload
987 (defun ediff-merge-files (file-A file-B
988 ;; MERGE-BUFFER-FILE is the file to be
989 ;; associated with the merge buffer
990 &optional startup-hooks merge-buffer-file)
991 "Merge two files without ancestor."
992 (interactive
993 (let ((dir-A (if ediff-use-last-dir
994 ediff-last-dir-A
995 default-directory))
996 dir-B f)
997 (list (setq f (ediff-read-file-name
998 "File A to merge" dir-A
999 (ediff-get-default-file-name)))
1000 (ediff-read-file-name "File B to merge"
1001 (setq dir-B
1002 (if ediff-use-last-dir
1003 ediff-last-dir-B
1004 (file-name-directory f)))
1005 (progn
1006 (setq file-name-history
1007 (cons (ediff-abbreviate-file-name
1008 (expand-file-name
1009 (file-name-nondirectory f)
1010 dir-B))
1011 file-name-history))
1014 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1015 (ediff-files-internal file-A
1016 (if (file-directory-p file-B)
1017 (expand-file-name
1018 (file-name-nondirectory file-A) file-B)
1019 file-B)
1020 nil ; file-C
1021 startup-hooks
1022 'ediff-merge-files
1023 merge-buffer-file))
1025 ;;;###autoload
1026 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
1027 &optional
1028 startup-hooks
1029 ;; MERGE-BUFFER-FILE is the file
1030 ;; to be associated with the
1031 ;; merge buffer
1032 merge-buffer-file)
1033 "Merge two files with ancestor."
1034 (interactive
1035 (let ((dir-A (if ediff-use-last-dir
1036 ediff-last-dir-A
1037 default-directory))
1038 dir-B dir-ancestor f ff)
1039 (list (setq f (ediff-read-file-name
1040 "File A to merge" dir-A
1041 (ediff-get-default-file-name)))
1042 (setq ff (ediff-read-file-name "File B to merge"
1043 (setq dir-B
1044 (if ediff-use-last-dir
1045 ediff-last-dir-B
1046 (file-name-directory f)))
1047 (progn
1048 (setq file-name-history
1049 (cons
1050 (ediff-abbreviate-file-name
1051 (expand-file-name
1052 (file-name-nondirectory f)
1053 dir-B))
1054 file-name-history))
1055 f)))
1056 (ediff-read-file-name "Ancestor file"
1057 (setq dir-ancestor
1058 (if ediff-use-last-dir
1059 ediff-last-dir-ancestor
1060 (file-name-directory ff)))
1061 (progn
1062 (setq file-name-history
1063 (cons (ediff-abbreviate-file-name
1064 (expand-file-name
1065 (file-name-nondirectory ff)
1066 dir-ancestor))
1067 file-name-history))
1068 ff))
1070 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1071 (ediff-files-internal file-A
1072 (if (file-directory-p file-B)
1073 (expand-file-name
1074 (file-name-nondirectory file-A) file-B)
1075 file-B)
1076 file-ancestor
1077 startup-hooks
1078 'ediff-merge-files-with-ancestor
1079 merge-buffer-file))
1081 ;;;###autoload
1082 (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor)
1084 ;;;###autoload
1085 (defun ediff-merge-buffers (buffer-A buffer-B
1086 &optional
1087 ;; MERGE-BUFFER-FILE is the file to be
1088 ;; associated with the merge buffer
1089 startup-hooks job-name merge-buffer-file)
1090 "Merge buffers without ancestor."
1091 (interactive
1092 (let (bf)
1093 (list (setq bf (read-buffer "Buffer A to merge: "
1094 (ediff-other-buffer "") t))
1095 (read-buffer "Buffer B to merge: "
1096 (progn
1097 ;; realign buffers so that two visible bufs will be
1098 ;; at the top
1099 (save-window-excursion (other-window 1))
1100 (ediff-other-buffer bf))
1101 t))))
1103 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1104 (or job-name (setq job-name 'ediff-merge-buffers))
1105 (ediff-buffers-internal
1106 buffer-A buffer-B nil startup-hooks job-name merge-buffer-file))
1108 ;;;###autoload
1109 (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
1110 &optional
1111 startup-hooks
1112 job-name
1113 ;; MERGE-BUFFER-FILE is the
1114 ;; file to be associated
1115 ;; with the merge buffer
1116 merge-buffer-file)
1117 "Merge buffers with ancestor."
1118 (interactive
1119 (let (bf bff)
1120 (list (setq bf (read-buffer "Buffer A to merge: "
1121 (ediff-other-buffer "") t))
1122 (setq bff (read-buffer "Buffer B to merge: "
1123 (progn
1124 ;; realign buffers so that two visible
1125 ;; bufs will be at the top
1126 (save-window-excursion (other-window 1))
1127 (ediff-other-buffer bf))
1129 (read-buffer "Ancestor buffer: "
1130 (progn
1131 ;; realign buffers so that three visible
1132 ;; bufs will be at the top
1133 (save-window-excursion (other-window 1))
1134 (ediff-other-buffer (list bf bff)))
1138 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1139 (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor))
1140 (ediff-buffers-internal
1141 buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file))
1144 ;;;###autoload
1145 (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file)
1146 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
1147 "Run Ediff by merging two revisions of a file.
1148 The file is the optional FILE argument or the file visited by the current
1149 buffer."
1150 (interactive)
1151 (if (stringp file) (find-file file))
1152 (let (rev1 rev2)
1153 (setq rev1
1154 (read-string
1155 (format
1156 "Version 1 to merge (default: %s's latest version): "
1157 (if (stringp file)
1158 (file-name-nondirectory file) "current buffer")))
1159 rev2
1160 (read-string
1161 (format
1162 "Version 2 to merge (default: %s): "
1163 (if (stringp file)
1164 (file-name-nondirectory file) "current buffer"))))
1165 (ediff-load-version-control)
1166 ;; ancestor-revision=nil
1167 (funcall
1168 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1169 rev1 rev2 nil startup-hooks merge-buffer-file)))
1172 ;;;###autoload
1173 (defun ediff-merge-revisions-with-ancestor (&optional
1174 file startup-hooks
1175 ;; MERGE-BUFFER-FILE is the file to
1176 ;; be associated with the merge
1177 ;; buffer
1178 merge-buffer-file)
1179 "Run Ediff by merging two revisions of a file with a common ancestor.
1180 The file is the the optional FILE argument or the file visited by the current
1181 buffer."
1182 (interactive)
1183 (if (stringp file) (find-file file))
1184 (let (rev1 rev2 ancestor-rev)
1185 (setq rev1
1186 (read-string
1187 (format
1188 "Version 1 to merge (default: %s's latest version): "
1189 (if (stringp file)
1190 (file-name-nondirectory file) "current buffer")))
1191 rev2
1192 (read-string
1193 (format
1194 "Version 2 to merge (default: %s): "
1195 (if (stringp file)
1196 (file-name-nondirectory file) "current buffer")))
1197 ancestor-rev
1198 (read-string
1199 (format
1200 "Ancestor version (default: %s's base revision): "
1201 (if (stringp file)
1202 (file-name-nondirectory file) "current buffer"))))
1203 (ediff-load-version-control)
1204 (funcall
1205 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1206 rev1 rev2 ancestor-rev startup-hooks merge-buffer-file)))
1208 ;;;###autoload
1209 (defun run-ediff-from-cvs-buffer (pos)
1210 "Run Ediff-merge on appropriate revisions of the selected file.
1211 First run after `M-x cvs-update'. Then place the cursor on a line describing a
1212 file and then run `run-ediff-from-cvs-buffer'."
1213 (interactive "d")
1214 (ediff-load-version-control)
1215 (let ((tin (tin-locate cvs-cookie-handle pos)))
1216 (if tin
1217 (cvs-run-ediff-on-file-descriptor tin)
1218 (error "There is no file to merge"))))
1221 ;;; Apply patch
1223 ;;;###autoload
1224 (defun ediff-patch-file (&optional arg patch-buf)
1225 "Run Ediff by patching SOURCE-FILENAME.
1226 If optional PATCH-BUF is given, use the patch in that buffer
1227 and don't ask the user.
1228 If prefix argument, then: if even argument, assume that the patch is in a
1229 buffer. If odd -- assume it is in a file."
1230 (interactive "P")
1231 (let (source-dir source-file)
1232 (require 'ediff-ptch)
1233 (setq patch-buf
1234 (ediff-get-patch-buffer
1235 (if arg (prefix-numeric-value arg)) patch-buf))
1236 (setq source-dir (cond (ediff-use-last-dir ediff-last-dir-patch)
1237 ((and (not ediff-patch-default-directory)
1238 (buffer-file-name patch-buf))
1239 (file-name-directory
1240 (expand-file-name
1241 (buffer-file-name patch-buf))))
1242 (t default-directory)))
1243 (setq source-file
1244 ;; the default is the directory, not the visited file name
1245 (read-file-name
1246 "File to patch (directory, if multifile patch): "
1247 source-dir (ediff-get-default-file-name)))
1248 (ediff-dispatch-file-patching-job patch-buf source-file)))
1250 ;;;###autoload
1251 (defun ediff-patch-buffer (&optional arg patch-buf)
1252 "Run Ediff by patching BUFFER-NAME."
1253 (interactive "P")
1254 (require 'ediff-ptch)
1255 (setq patch-buf
1256 (ediff-get-patch-buffer
1257 (if arg (prefix-numeric-value arg)) patch-buf))
1258 (ediff-patch-buffer-internal
1259 patch-buf
1260 (read-buffer
1261 "Which buffer to patch? "
1262 (ediff-prompt-for-patch-buffer))))
1265 ;;;###autoload
1266 (defalias 'epatch 'ediff-patch-file)
1267 ;;;###autoload
1268 (defalias 'epatch-buffer 'ediff-patch-buffer)
1273 ;;; Versions Control functions
1275 ;;;###autoload
1276 (defun ediff-revision (&optional file startup-hooks)
1277 "Run Ediff by comparing versions of a file.
1278 The file is an optional FILE argument or the file visited by the current
1279 buffer. Use `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
1280 ;; if buffer is non-nil, use that buffer instead of the current buffer
1281 (interactive "P")
1282 (if (stringp file) (find-file file))
1283 (let (rev1 rev2)
1284 (setq rev1
1285 (read-string
1286 (format "Version 1 to compare (default: %s's latest version): "
1287 (if (stringp file)
1288 (file-name-nondirectory file) "current buffer")))
1289 rev2
1290 (read-string
1291 (format "Version 2 to compare (default: %s): "
1292 (if (stringp file)
1293 (file-name-nondirectory file) "current buffer"))))
1294 (ediff-load-version-control)
1295 (funcall
1296 (intern (format "ediff-%S-internal" ediff-version-control-package))
1297 rev1 rev2 startup-hooks)
1301 ;;;###autoload
1302 (defalias 'erevision 'ediff-revision)
1305 ;; Test if version control package is loaded and load if not
1306 ;; Is SILENT is non-nil, don't report error if package is not found.
1307 (defun ediff-load-version-control (&optional silent)
1308 (require 'ediff-vers)
1309 (or (featurep ediff-version-control-package)
1310 (if (locate-library (symbol-name ediff-version-control-package))
1311 (progn
1312 (message "") ; kill the message from `locate-library'
1313 (require ediff-version-control-package))
1314 (or silent
1315 (error "Version control package %S.el not found. Use vc.el instead"
1316 ediff-version-control-package)))))
1319 ;;;###autoload
1320 (defun ediff-version ()
1321 "Return string describing the version of Ediff.
1322 When called interactively, displays the version."
1323 (interactive)
1324 (if (interactive-p)
1325 (message (ediff-version))
1326 (format "Ediff %s of %s" ediff-version ediff-date)))
1329 ;;;###autoload
1330 (defun ediff-documentation (&optional node)
1331 "Display Ediff's manual.
1332 With optional NODE, goes to that node."
1333 (interactive)
1334 (let ((ctl-window ediff-control-window)
1335 (ctl-buf ediff-control-buffer))
1337 (ediff-skip-unsuitable-frames)
1338 (condition-case nil
1339 (progn
1340 (pop-to-buffer (get-buffer-create "*info*"))
1341 (info (if ediff-xemacs-p "ediff.info" "ediff"))
1342 (if node
1343 (Info-goto-node node)
1344 (message "Type `i' to search for a specific topic"))
1345 (raise-frame (selected-frame)))
1346 (error (beep 1)
1347 (with-output-to-temp-buffer ediff-msg-buffer
1348 (princ ediff-BAD-INFO))
1349 (if (window-live-p ctl-window)
1350 (progn
1351 (select-window ctl-window)
1352 (set-window-buffer ctl-window ctl-buf)))))))
1357 ;;; Local Variables:
1358 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1359 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1360 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1361 ;;; End:
1363 (require 'ediff-util)
1365 (run-hooks 'ediff-load-hook)
1367 ;;; ediff.el ends here