(alternativnyj): Use new table.
[emacs.git] / lisp / ediff.el
blobd07075bbac8b53fb8082aa3b142ff3ed94675800
1 ;;; ediff.el --- a comprehensive visual interface to diff & patch
3 ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
6 ;; Created: February 2, 1994
7 ;; Keywords: comparing, merging, patching, tools, unix
9 (defconst ediff-version "2.76.1" "The current version of Ediff")
10 (defconst ediff-date "January 4, 2002" "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 number FILENO (or 0) in the list
167 ;; (all-selected-files, filename under the cursor), where directories are
168 ;; ignored. Otherwise, return DEFAULT file name, if non-nil. Else,
169 ;; if the buffer is visiting a file, return that file name.
170 (defun ediff-get-default-file-name (&optional default fileno)
171 (cond ((eq major-mode 'dired-mode)
172 (let ((current (dired-get-filename nil 'no-error))
173 (marked (condition-case nil
174 (dired-get-marked-files 'no-dir)
175 (error nil)))
176 aux-list choices result)
177 (or (integerp fileno) (setq fileno 0))
178 (if (stringp default)
179 (setq aux-list (cons default aux-list)))
180 (if (and (stringp current) (not (file-directory-p current)))
181 (setq aux-list (cons current aux-list)))
182 (setq choices (nconc marked aux-list))
183 (setq result (elt choices fileno))
184 (or result
185 default)))
186 ((stringp default) default)
187 ((buffer-file-name (current-buffer))
188 (file-name-nondirectory (buffer-file-name (current-buffer))))
191 ;;; Compare files/buffers
193 ;;;###autoload
194 (defun ediff-files (file-A file-B &optional startup-hooks)
195 "Run Ediff on a pair of files, FILE-A and FILE-B."
196 (interactive
197 (let ((dir-A (if ediff-use-last-dir
198 ediff-last-dir-A
199 default-directory))
200 dir-B f)
201 (list (setq f (ediff-read-file-name
202 "File A to compare"
203 dir-A
204 (ediff-get-default-file-name)
205 'no-dirs))
206 (ediff-read-file-name "File B to compare"
207 (setq dir-B
208 (if ediff-use-last-dir
209 ediff-last-dir-B
210 (file-name-directory f)))
211 (progn
212 (setq file-name-history
213 (cons (ediff-abbreviate-file-name
214 (expand-file-name
215 (file-name-nondirectory f)
216 dir-B))
217 file-name-history))
218 (ediff-get-default-file-name f 1)))
220 (ediff-files-internal file-A
221 (if (file-directory-p file-B)
222 (expand-file-name
223 (file-name-nondirectory file-A) file-B)
224 file-B)
225 nil ; file-C
226 startup-hooks
227 'ediff-files))
229 ;;;###autoload
230 (defun ediff-files3 (file-A file-B file-C &optional startup-hooks)
231 "Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
232 (interactive
233 (let ((dir-A (if ediff-use-last-dir
234 ediff-last-dir-A
235 default-directory))
236 dir-B dir-C f ff)
237 (list (setq f (ediff-read-file-name
238 "File A to compare"
239 dir-A
240 (ediff-get-default-file-name)
241 'no-dirs))
242 (setq ff (ediff-read-file-name "File B to compare"
243 (setq dir-B
244 (if ediff-use-last-dir
245 ediff-last-dir-B
246 (file-name-directory f)))
247 (progn
248 (setq file-name-history
249 (cons
250 (ediff-abbreviate-file-name
251 (expand-file-name
252 (file-name-nondirectory f)
253 dir-B))
254 file-name-history))
255 (ediff-get-default-file-name f 1))))
256 (ediff-read-file-name "File C to compare"
257 (setq dir-C (if ediff-use-last-dir
258 ediff-last-dir-C
259 (file-name-directory ff)))
260 (progn
261 (setq file-name-history
262 (cons (ediff-abbreviate-file-name
263 (expand-file-name
264 (file-name-nondirectory ff)
265 dir-C))
266 file-name-history))
267 (ediff-get-default-file-name ff 2)))
269 (ediff-files-internal file-A
270 (if (file-directory-p file-B)
271 (expand-file-name
272 (file-name-nondirectory file-A) file-B)
273 file-B)
274 (if (file-directory-p file-C)
275 (expand-file-name
276 (file-name-nondirectory file-A) file-C)
277 file-C)
278 startup-hooks
279 'ediff-files3))
281 ;;;###autoload
282 (defalias 'ediff3 'ediff-files3)
285 ;; Visit FILE and arrange its buffer to Ediff's liking.
286 ;; FILE is actually a variable symbol that must contain a true file name.
287 ;; BUFFER-NAME is a variable symbol, which will get the buffer object into
288 ;; which FILE is read.
289 ;; LAST-DIR is the directory variable symbol where FILE's
290 ;; directory name should be returned. HOOKS-VAR is a variable symbol that will
291 ;; be assigned the hook to be executed after `ediff-startup' is finished.
292 ;; `ediff-find-file' arranges that the temp files it might create will be
293 ;; deleted.
294 (defun ediff-find-file (file-var buffer-name &optional last-dir hooks-var)
295 (let* ((file (symbol-value file-var))
296 (file-magic (ediff-filename-magic-p file))
297 (temp-file-name-prefix (file-name-nondirectory file)))
298 (cond ((not (file-readable-p file))
299 (error "File `%s' does not exist or is not readable" file))
300 ((file-directory-p file)
301 (error "File `%s' is a directory" file)))
303 ;; some of the commands, below, require full file name
304 (setq file (expand-file-name file))
306 ;; Record the directory of the file
307 (if last-dir
308 (set last-dir (expand-file-name (file-name-directory file))))
310 ;; Setup the buffer
311 (set buffer-name (find-file-noselect file))
313 (ediff-with-current-buffer (symbol-value buffer-name)
314 (widen) ; Make sure the entire file is seen
315 (cond (file-magic ; file has a handler, such as jka-compr-handler or
316 ;;; ange-ftp-hook-function--arrange for temp file
317 (ediff-verify-file-buffer 'magic)
318 (setq file
319 (ediff-make-temp-file
320 (current-buffer) temp-file-name-prefix))
321 (set hooks-var (cons `(lambda () (delete-file ,file))
322 (symbol-value hooks-var))))
323 ;; file processed via auto-mode-alist, a la uncompress.el
324 ((not (equal (file-truename file)
325 (file-truename (buffer-file-name))))
326 (setq file
327 (ediff-make-temp-file
328 (current-buffer) temp-file-name-prefix))
329 (set hooks-var (cons `(lambda () (delete-file ,file))
330 (symbol-value hooks-var))))
331 (t ;; plain file---just check that the file matches the buffer
332 (ediff-verify-file-buffer))))
333 (set file-var file)))
335 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
336 (defun ediff-files-internal (file-A file-B file-C startup-hooks job-name
337 &optional merge-buffer-file)
338 (let (buf-A buf-B buf-C)
339 (if (string= file-A file-B)
340 (error "Files A and B are the same"))
341 (if (stringp file-C)
342 (or (and (string= file-A file-C) (error "Files A and C are the same"))
343 (and (string= file-B file-C) (error "Files B and C are the same"))))
344 (message "Reading file %s ... " file-A)
345 ;;(sit-for 0)
346 (ediff-find-file 'file-A 'buf-A 'ediff-last-dir-A 'startup-hooks)
347 (message "Reading file %s ... " file-B)
348 ;;(sit-for 0)
349 (ediff-find-file 'file-B 'buf-B 'ediff-last-dir-B 'startup-hooks)
350 (if (stringp file-C)
351 (progn
352 (message "Reading file %s ... " file-C)
353 ;;(sit-for 0)
354 (ediff-find-file
355 'file-C 'buf-C
356 (if (eq job-name 'ediff-merge-files-with-ancestor)
357 'ediff-last-dir-ancestor 'ediff-last-dir-C)
358 'startup-hooks)))
359 (ediff-setup buf-A file-A
360 buf-B file-B
361 buf-C file-C
362 startup-hooks
363 (list (cons 'ediff-job-name job-name))
364 merge-buffer-file)))
367 ;;;###autoload
368 (defalias 'ediff 'ediff-files)
371 ;;;###autoload
372 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name)
373 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
374 (interactive
375 (let (bf)
376 (list (setq bf (read-buffer "Buffer A to compare: "
377 (ediff-other-buffer "") t))
378 (read-buffer "Buffer B to compare: "
379 (progn
380 ;; realign buffers so that two visible bufs will be
381 ;; at the top
382 (save-window-excursion (other-window 1))
383 (ediff-other-buffer bf))
384 t))))
385 (or job-name (setq job-name 'ediff-buffers))
386 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name))
388 ;;;###autoload
389 (defalias 'ebuffers 'ediff-buffers)
392 ;;;###autoload
393 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
394 &optional startup-hooks job-name)
395 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
396 (interactive
397 (let (bf bff)
398 (list (setq bf (read-buffer "Buffer A to compare: "
399 (ediff-other-buffer "") t))
400 (setq bff (read-buffer "Buffer B to compare: "
401 (progn
402 ;; realign buffers so that two visible
403 ;; bufs will be at the top
404 (save-window-excursion (other-window 1))
405 (ediff-other-buffer bf))
407 (read-buffer "Buffer C to compare: "
408 (progn
409 ;; realign buffers so that three visible
410 ;; bufs will be at the top
411 (save-window-excursion (other-window 1))
412 (ediff-other-buffer (list bf bff)))
415 (or job-name (setq job-name 'ediff-buffers3))
416 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name))
418 ;;;###autoload
419 (defalias 'ebuffers3 'ediff-buffers3)
423 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
424 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
425 &optional merge-buffer-file)
426 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
427 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
428 (buf-C-is-alive (ediff-buffer-live-p buf-C))
429 (buf-C-file-name (if buf-C-is-alive
430 (buffer-file-name (get-buffer buf-B))))
431 file-A file-B file-C)
432 (if (not (ediff-buffer-live-p buf-A))
433 (error "Buffer %S doesn't exist" buf-A))
434 (if (not (ediff-buffer-live-p buf-B))
435 (error "Buffer %S doesn't exist" buf-B))
436 (let ((ediff-job-name job-name))
437 (if (and ediff-3way-comparison-job
438 (not buf-C-is-alive))
439 (error "Buffer %S doesn't exist" buf-C)))
440 (if (stringp buf-A-file-name)
441 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
442 (if (stringp buf-B-file-name)
443 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
444 (if (stringp buf-C-file-name)
445 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
447 (setq file-A (ediff-make-temp-file buf-A buf-A-file-name)
448 file-B (ediff-make-temp-file buf-B buf-B-file-name))
449 (if buf-C-is-alive
450 (setq file-C (ediff-make-temp-file buf-C buf-C-file-name)))
452 (ediff-setup (get-buffer buf-A) file-A
453 (get-buffer buf-B) file-B
454 (if buf-C-is-alive (get-buffer buf-C))
455 file-C
456 (cons `(lambda ()
457 (delete-file ,file-A)
458 (delete-file ,file-B)
459 (if (stringp ,file-C) (delete-file ,file-C)))
460 startup-hooks)
461 (list (cons 'ediff-job-name job-name))
462 merge-buffer-file)))
465 ;;; Directory and file group operations
467 ;; Get appropriate default name for directory:
468 ;; If ediff-use-last-dir, use ediff-last-dir-A.
469 ;; In dired mode, use the directory that is under the point (if any);
470 ;; otherwise, use default-directory
471 (defun ediff-get-default-directory-name ()
472 (cond (ediff-use-last-dir ediff-last-dir-A)
473 ((eq major-mode 'dired-mode)
474 (let ((f (dired-get-filename nil 'noerror)))
475 (if (and (stringp f) (file-directory-p f))
477 default-directory)))
478 (t default-directory)))
481 ;;;###autoload
482 (defun ediff-directories (dir1 dir2 regexp)
483 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
484 the same name in both. The third argument, REGEXP, is a regular expression
485 that can be used to filter out certain file names."
486 (interactive
487 (let ((dir-A (ediff-get-default-directory-name))
489 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
490 (ediff-read-file-name "Directory B to compare:"
491 (if ediff-use-last-dir
492 ediff-last-dir-B
493 (ediff-strip-last-dir f))
494 nil)
495 (read-string "Filter through regular expression: "
496 nil 'ediff-filtering-regexp-history)
498 (ediff-directories-internal
499 dir1 dir2 nil regexp 'ediff-files 'ediff-directories
502 ;;;###autoload
503 (defalias 'edirs 'ediff-directories)
506 ;;;###autoload
507 (defun ediff-directory-revisions (dir1 regexp)
508 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
509 The second argument, REGEXP, is a regular expression that filters the file
510 names. Only the files that are under revision control are taken into account."
511 (interactive
512 (let ((dir-A (ediff-get-default-directory-name)))
513 (list (ediff-read-file-name
514 "Directory to compare with revision:" dir-A nil)
515 (read-string "Filter through regular expression: "
516 nil 'ediff-filtering-regexp-history)
518 (ediff-directory-revisions-internal
519 dir1 regexp 'ediff-revision 'ediff-directory-revisions
522 ;;;###autoload
523 (defalias 'edir-revisions 'ediff-directory-revisions)
526 ;;;###autoload
527 (defun ediff-directories3 (dir1 dir2 dir3 regexp)
528 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
529 have the same name in all three. The last argument, REGEXP, is a regular
530 expression that can be used to filter out certain file names."
531 (interactive
532 (let ((dir-A (ediff-get-default-directory-name))
534 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
535 (setq f (ediff-read-file-name "Directory B to compare:"
536 (if ediff-use-last-dir
537 ediff-last-dir-B
538 (ediff-strip-last-dir f))
539 nil))
540 (ediff-read-file-name "Directory C to compare:"
541 (if ediff-use-last-dir
542 ediff-last-dir-C
543 (ediff-strip-last-dir f))
544 nil)
545 (read-string "Filter through regular expression: "
546 nil 'ediff-filtering-regexp-history)
548 (ediff-directories-internal
549 dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3
552 ;;;###autoload
553 (defalias 'edirs3 'ediff-directories3)
555 ;;;###autoload
556 (defun ediff-merge-directories (dir1 dir2 regexp &optional merge-autostore-dir)
557 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
558 the same name in both. The third argument, REGEXP, is a regular expression
559 that can be used to filter out certain file names."
560 (interactive
561 (let ((dir-A (ediff-get-default-directory-name))
563 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
564 (ediff-read-file-name "Directory B to merge:"
565 (if ediff-use-last-dir
566 ediff-last-dir-B
567 (ediff-strip-last-dir f))
568 nil)
569 (read-string "Filter through regular expression: "
570 nil 'ediff-filtering-regexp-history)
572 (ediff-directories-internal
573 dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories
574 nil merge-autostore-dir
577 ;;;###autoload
578 (defalias 'edirs-merge 'ediff-merge-directories)
580 ;;;###autoload
581 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
582 &optional
583 merge-autostore-dir)
584 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
585 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
586 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
587 without ancestor. The fourth argument, REGEXP, is a regular expression that
588 can be used to filter out certain file names."
589 (interactive
590 (let ((dir-A (ediff-get-default-directory-name))
592 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
593 (setq f (ediff-read-file-name "Directory B to merge:"
594 (if ediff-use-last-dir
595 ediff-last-dir-B
596 (ediff-strip-last-dir f))
597 nil))
598 (ediff-read-file-name "Ancestor directory:"
599 (if ediff-use-last-dir
600 ediff-last-dir-C
601 (ediff-strip-last-dir f))
602 nil)
603 (read-string "Filter through regular expression: "
604 nil 'ediff-filtering-regexp-history)
606 (ediff-directories-internal
607 dir1 dir2 ancestor-dir regexp
608 'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor
609 nil merge-autostore-dir
612 ;;;###autoload
613 (defun ediff-merge-directory-revisions (dir1 regexp
614 &optional merge-autostore-dir)
615 "Run Ediff on a directory, DIR1, merging its files with their revisions.
616 The second argument, REGEXP, is a regular expression that filters the file
617 names. Only the files that are under revision control are taken into account."
618 (interactive
619 (let ((dir-A (ediff-get-default-directory-name)))
620 (list (ediff-read-file-name
621 "Directory to merge with revisions:" dir-A nil)
622 (read-string "Filter through regular expression: "
623 nil 'ediff-filtering-regexp-history)
625 (ediff-directory-revisions-internal
626 dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions
627 nil merge-autostore-dir
630 ;;;###autoload
631 (defalias 'edir-merge-revisions 'ediff-merge-directory-revisions)
633 ;;;###autoload
634 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
635 &optional
636 merge-autostore-dir)
637 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
638 The second argument, REGEXP, is a regular expression that filters the file
639 names. Only the files that are under revision control are taken into account."
640 (interactive
641 (let ((dir-A (ediff-get-default-directory-name)))
642 (list (ediff-read-file-name
643 "Directory to merge with revisions and ancestors:" dir-A nil)
644 (read-string "Filter through regular expression: "
645 nil 'ediff-filtering-regexp-history)
647 (ediff-directory-revisions-internal
648 dir1 regexp 'ediff-merge-revisions-with-ancestor
649 'ediff-merge-directory-revisions-with-ancestor
650 nil merge-autostore-dir
653 ;;;###autoload
654 (defalias
655 'edir-merge-revisions-with-ancestor
656 'ediff-merge-directory-revisions-with-ancestor)
658 ;;;###autoload
659 (defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor)
661 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
662 ;; on a pair of directories (three directories, in case of ancestor).
663 ;; The third argument, REGEXP, is a regular expression that can be used to
664 ;; filter out certain file names.
665 ;; JOBNAME is the symbol indicating the meta-job to be performed.
666 ;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
667 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
668 &optional startup-hooks
669 merge-autostore-dir)
670 ;; ediff-read-file-name is set to attach a previously entered file name if
671 ;; the currently entered file is a directory. This code takes care of that.
672 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1))
673 dir2 (if (file-directory-p dir2) dir2 (file-name-directory dir2)))
675 (if (stringp dir3)
676 (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))
678 (cond ((string= dir1 dir2)
679 (error "Directories A and B are the same: %s" dir1))
680 ((and (eq jobname 'ediff-directories3)
681 (string= dir1 dir3))
682 (error "Directories A and C are the same: %s" dir1))
683 ((and (eq jobname 'ediff-directories3)
684 (string= dir2 dir3))
685 (error "Directories B and C are the same: %s" dir1)))
687 (if merge-autostore-dir
688 (or (stringp merge-autostore-dir)
689 (error "%s: Directory for storing merged files must be a string"
690 jobname)))
691 (let (diffs ; var where ediff-intersect-directories returns the diff list
692 file-list meta-buf)
693 (if (and ediff-autostore-merges
694 (ediff-merge-metajob jobname)
695 (not merge-autostore-dir))
696 (setq merge-autostore-dir
697 (read-file-name "Save merged files in directory: "
698 (if ediff-use-last-dir
699 ediff-last-merge-autostore-dir
700 (ediff-strip-last-dir dir1))
702 'must-match)))
703 ;; verify we are not merging into an orig directory
704 (if merge-autostore-dir
705 (cond ((and (stringp dir1) (string= merge-autostore-dir dir1))
706 (or (y-or-n-p
707 "Directory for saving merged files = Directory A. Sure? ")
708 (error "Directory merge aborted")))
709 ((and (stringp dir2) (string= merge-autostore-dir dir2))
710 (or (y-or-n-p
711 "Directory for saving merged files = Directory B. Sure? ")
712 (error "Directory merge aborted")))
713 ((and (stringp dir3) (string= merge-autostore-dir dir3))
714 (or (y-or-n-p
715 "Directory for saving merged files = Ancestor Directory. Sure? ")
716 (error "Directory merge aborted")))))
718 (setq file-list (ediff-intersect-directories
719 jobname 'diffs
720 regexp dir1 dir2 dir3 merge-autostore-dir))
721 (setq startup-hooks
722 ;; this sets various vars in the meta buffer inside
723 ;; ediff-prepare-meta-buffer
724 (cons `(lambda ()
725 ;; tell what to do if the user clicks on a session record
726 (setq ediff-session-action-function (quote ,action))
727 ;; set ediff-dir-difference-list
728 (setq ediff-dir-difference-list (quote ,diffs)))
729 startup-hooks))
730 (setq meta-buf (ediff-prepare-meta-buffer
731 'ediff-filegroup-action
732 file-list
733 "*Ediff Session Group Panel"
734 'ediff-redraw-directory-group-buffer
735 jobname
736 startup-hooks))
737 (ediff-show-meta-buffer meta-buf)
740 ;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
741 ;; files
742 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
743 &optional startup-hooks
744 merge-autostore-dir)
745 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)))
747 (if merge-autostore-dir
748 (or (stringp merge-autostore-dir)
749 (error "%S: Directory for storing merged files must be a string"
750 jobname)))
751 (let (file-list meta-buf)
752 (if (and ediff-autostore-merges
753 (ediff-merge-metajob jobname)
754 (not merge-autostore-dir))
755 (setq merge-autostore-dir
756 (read-file-name "Save merged files in directory: "
757 (if ediff-use-last-dir
758 ediff-last-merge-autostore-dir
759 (ediff-strip-last-dir dir1))
761 'must-match)))
762 ;; verify merge-autostore-dir != dir1
763 (if (and merge-autostore-dir
764 (stringp dir1)
765 (string= merge-autostore-dir dir1))
766 (or (y-or-n-p
767 "Directory for saving merged file = directory A. Sure? ")
768 (error "Merge of directory revisions aborted")))
770 (setq file-list
771 (ediff-get-directory-files-under-revision
772 jobname regexp dir1 merge-autostore-dir))
773 (setq startup-hooks
774 ;; this sets various vars in the meta buffer inside
775 ;; ediff-prepare-meta-buffer
776 (cons `(lambda ()
777 ;; tell what to do if the user clicks on a session record
778 (setq ediff-session-action-function (quote ,action)))
779 startup-hooks))
780 (setq meta-buf (ediff-prepare-meta-buffer
781 'ediff-filegroup-action
782 file-list
783 "*Ediff Session Group Panel"
784 'ediff-redraw-directory-group-buffer
785 jobname
786 startup-hooks))
787 (ediff-show-meta-buffer meta-buf)
791 ;;; Compare regions and windows
793 ;;;###autoload
794 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks)
795 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
796 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
797 follows:
798 If WIND-A is nil, use selected window.
799 If WIND-B is nil, use window next to WIND-A."
800 (interactive "P")
801 (ediff-windows dumb-mode wind-A wind-B
802 startup-hooks 'ediff-windows-wordwise 'word-mode))
804 ;;;###autoload
805 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks)
806 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
807 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
808 follows:
809 If WIND-A is nil, use selected window.
810 If WIND-B is nil, use window next to WIND-A."
811 (interactive "P")
812 (ediff-windows dumb-mode wind-A wind-B
813 startup-hooks 'ediff-windows-linewise nil))
815 ;; Compare WIND-A and WIND-B, which are selected by clicking.
816 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
817 ;; works as follows:
818 ;; If WIND-A is nil, use selected window.
819 ;; If WIND-B is nil, use window next to WIND-A.
820 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode)
821 (if (or dumb-mode (not (ediff-window-display-p)))
822 (setq wind-A (ediff-get-next-window wind-A nil)
823 wind-B (ediff-get-next-window wind-B wind-A))
824 (setq wind-A (ediff-get-window-by-clicking wind-A nil 1)
825 wind-B (ediff-get-window-by-clicking wind-B wind-A 2)))
827 (let ((buffer-A (window-buffer wind-A))
828 (buffer-B (window-buffer wind-B))
829 beg-A end-A beg-B end-B)
831 (save-excursion
832 (save-window-excursion
833 (sit-for 0) ; sync before using window-start/end -- a precaution
834 (select-window wind-A)
835 (setq beg-A (window-start)
836 end-A (window-end))
837 (select-window wind-B)
838 (setq beg-B (window-start)
839 end-B (window-end))))
840 (setq buffer-A
841 (ediff-clone-buffer-for-window-comparison
842 buffer-A wind-A "-Window1-")
843 buffer-B
844 (ediff-clone-buffer-for-window-comparison
845 buffer-B wind-B "-Window2-"))
846 (ediff-regions-internal
847 buffer-A beg-A end-A buffer-B beg-B end-B
848 startup-hooks job-name word-mode nil)))
850 ;; Suggested by Hannu Koivisto <azure@iki.fi>
851 (defun ediff-clone-buffer-for-region-comparison (buff-name region-name)
852 (let ((cloned-buff (ediff-make-indirect-buffer
853 buff-name
854 (concat buff-name region-name
855 (symbol-name (gensym)))))
856 (wind (ediff-get-visible-buffer-window buff-name)))
857 (ediff-with-current-buffer cloned-buff
858 (setq ediff-temp-indirect-buffer t))
859 (if (window-live-p wind)
860 (set-window-buffer wind cloned-buff))
861 (pop-to-buffer cloned-buff)
862 (message
863 "Mark a region in buffer %s; then type %s. Use %s to abort."
864 (buffer-name cloned-buff)
865 (ediff-format-bindings-of 'exit-recursive-edit)
866 (ediff-format-bindings-of 'abort-recursive-edit))
867 (recursive-edit)
868 cloned-buff))
870 (defun ediff-clone-buffer-for-window-comparison (buff wind region-name)
871 (let ((cloned-buff (ediff-make-indirect-buffer
872 buff
873 (concat (buffer-name buff)
874 region-name (symbol-name (gensym))))))
875 (ediff-with-current-buffer cloned-buff
876 (setq ediff-temp-indirect-buffer t))
877 (set-window-buffer wind cloned-buff)
878 cloned-buff))
880 (defun ediff-make-indirect-buffer (base-buf indirect-buf-name)
881 (ediff-cond-compile-for-xemacs-or-emacs
882 (make-indirect-buffer base-buf indirect-buf-name) ; xemacs
883 (make-indirect-buffer base-buf indirect-buf-name 'clone) ; emacs
886 ;;;###autoload
887 (defun ediff-regions-wordwise (buffer-A buffer-B &optional startup-hooks)
888 "Run Ediff on a pair of regions in specified buffers.
889 Regions \(i.e., point and mark\) are assumed to be set in advance except
890 for the second region in the case both regions are from the same buffer.
891 In such a case the user is asked to interactively establish the second
892 region.
893 This function is effective only for relatively small regions, up to 200
894 lines. For large regions, use `ediff-regions-linewise'."
895 (interactive
896 (let (bf)
897 (list (setq bf (read-buffer "Region's A buffer: "
898 (ediff-other-buffer "") t))
899 (read-buffer "Region's B buffer: "
900 (progn
901 ;; realign buffers so that two visible bufs will be
902 ;; at the top
903 (save-window-excursion (other-window 1))
904 (ediff-other-buffer bf))
905 t))))
906 (if (not (ediff-buffer-live-p buffer-A))
907 (error "Buffer %S doesn't exist" buffer-A))
908 (if (not (ediff-buffer-live-p buffer-B))
909 (error "Buffer %S doesn't exist" buffer-B))
912 (let ((buffer-A
913 (ediff-clone-buffer-for-region-comparison buffer-A "-Region1-"))
914 (buffer-B
915 (ediff-clone-buffer-for-region-comparison buffer-B "-Region2-"))
916 reg-A-beg reg-A-end reg-B-beg reg-B-end)
917 (save-excursion
918 (set-buffer buffer-A)
919 (setq reg-A-beg (region-beginning)
920 reg-A-end (region-end))
921 (set-buffer buffer-B)
922 (setq reg-B-beg (region-beginning)
923 reg-B-end (region-end)))
925 (ediff-regions-internal
926 (get-buffer buffer-A) reg-A-beg reg-A-end
927 (get-buffer buffer-B) reg-B-beg reg-B-end
928 startup-hooks 'ediff-regions-wordwise 'word-mode nil)))
930 ;;;###autoload
931 (defun ediff-regions-linewise (buffer-A buffer-B &optional startup-hooks)
932 "Run Ediff on a pair of regions in specified buffers.
933 Regions \(i.e., point and mark\) are assumed to be set in advance except
934 for the second region in the case both regions are from the same buffer.
935 In such a case the user is asked to interactively establish the second
936 region.
937 Each region is enlarged to contain full lines.
938 This function is effective for large regions, over 100-200
939 lines. For small regions, use `ediff-regions-wordwise'."
940 (interactive
941 (let (bf)
942 (list (setq bf (read-buffer "Region A's buffer: "
943 (ediff-other-buffer "") t))
944 (read-buffer "Region B's buffer: "
945 (progn
946 ;; realign buffers so that two visible bufs will be
947 ;; at the top
948 (save-window-excursion (other-window 1))
949 (ediff-other-buffer bf))
950 t))))
951 (if (not (ediff-buffer-live-p buffer-A))
952 (error "Buffer %S doesn't exist" buffer-A))
953 (if (not (ediff-buffer-live-p buffer-B))
954 (error "Buffer %S doesn't exist" buffer-B))
956 (let ((buffer-A
957 (ediff-clone-buffer-for-region-comparison buffer-A "-Region1-"))
958 (buffer-B
959 (ediff-clone-buffer-for-region-comparison buffer-B "-Region2-"))
960 reg-A-beg reg-A-end reg-B-beg reg-B-end)
961 (save-excursion
962 (set-buffer buffer-A)
963 (setq reg-A-beg (region-beginning)
964 reg-A-end (region-end))
965 ;; enlarge the region to hold full lines
966 (goto-char reg-A-beg)
967 (beginning-of-line)
968 (setq reg-A-beg (point))
969 (goto-char reg-A-end)
970 (end-of-line)
971 (or (eobp) (forward-char)) ; include the newline char
972 (setq reg-A-end (point))
974 (set-buffer buffer-B)
975 (setq reg-B-beg (region-beginning)
976 reg-B-end (region-end))
977 ;; enlarge the region to hold full lines
978 (goto-char reg-B-beg)
979 (beginning-of-line)
980 (setq reg-B-beg (point))
981 (goto-char reg-B-end)
982 (end-of-line)
983 (or (eobp) (forward-char)) ; include the newline char
984 (setq reg-B-end (point))
985 ) ; save excursion
987 (ediff-regions-internal
988 (get-buffer buffer-A) reg-A-beg reg-A-end
989 (get-buffer buffer-B) reg-B-beg reg-B-end
990 startup-hooks 'ediff-regions-linewise nil nil))) ; no word mode
992 ;; compare region beg-A to end-A of buffer-A
993 ;; to regions beg-B -- end-B in buffer-B.
994 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
995 startup-hooks job-name word-mode
996 setup-parameters)
997 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
998 overl-A overl-B
999 file-A file-B)
1001 ;; in case beg/end-A/B aren't markers--make them into markers
1002 (ediff-with-current-buffer buffer-A
1003 (setq beg-A (move-marker (make-marker) beg-A)
1004 end-A (move-marker (make-marker) end-A)))
1005 (ediff-with-current-buffer buffer-B
1006 (setq beg-B (move-marker (make-marker) beg-B)
1007 end-B (move-marker (make-marker) end-B)))
1009 ;; make file-A
1010 (if word-mode
1011 (ediff-wordify beg-A end-A buffer-A tmp-buffer)
1012 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer))
1013 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
1015 ;; make file-B
1016 (if word-mode
1017 (ediff-wordify beg-B end-B buffer-B tmp-buffer)
1018 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer))
1019 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
1021 (setq overl-A (ediff-make-bullet-proof-overlay beg-A end-A buffer-A))
1022 (setq overl-B (ediff-make-bullet-proof-overlay beg-B end-B buffer-B))
1023 (ediff-setup buffer-A file-A
1024 buffer-B file-B
1025 nil nil ; buffer & file C
1026 (cons `(lambda ()
1027 (delete-file ,file-A)
1028 (delete-file ,file-B))
1029 startup-hooks)
1030 (append
1031 (list (cons 'ediff-word-mode word-mode)
1032 (cons 'ediff-narrow-bounds (list overl-A overl-B))
1033 (cons 'ediff-job-name job-name))
1034 setup-parameters))
1038 ;;; Merge files and buffers
1040 ;;;###autoload
1041 (defalias 'ediff-merge 'ediff-merge-files)
1043 (defsubst ediff-merge-on-startup ()
1044 (ediff-do-merge 0)
1045 (ediff-with-current-buffer ediff-buffer-C
1046 (set-buffer-modified-p nil)))
1048 ;;;###autoload
1049 (defun ediff-merge-files (file-A file-B
1050 ;; MERGE-BUFFER-FILE is the file to be
1051 ;; associated with the merge buffer
1052 &optional startup-hooks merge-buffer-file)
1053 "Merge two files without ancestor."
1054 (interactive
1055 (let ((dir-A (if ediff-use-last-dir
1056 ediff-last-dir-A
1057 default-directory))
1058 dir-B f)
1059 (list (setq f (ediff-read-file-name
1060 "File A to merge"
1061 dir-A
1062 (ediff-get-default-file-name)
1063 'no-dirs))
1064 (ediff-read-file-name "File B to merge"
1065 (setq dir-B
1066 (if ediff-use-last-dir
1067 ediff-last-dir-B
1068 (file-name-directory f)))
1069 (progn
1070 (setq file-name-history
1071 (cons (ediff-abbreviate-file-name
1072 (expand-file-name
1073 (file-name-nondirectory f)
1074 dir-B))
1075 file-name-history))
1076 (ediff-get-default-file-name f 1)))
1078 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1079 (ediff-files-internal file-A
1080 (if (file-directory-p file-B)
1081 (expand-file-name
1082 (file-name-nondirectory file-A) file-B)
1083 file-B)
1084 nil ; file-C
1085 startup-hooks
1086 'ediff-merge-files
1087 merge-buffer-file))
1089 ;;;###autoload
1090 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
1091 &optional
1092 startup-hooks
1093 ;; MERGE-BUFFER-FILE is the file
1094 ;; to be associated with the
1095 ;; merge buffer
1096 merge-buffer-file)
1097 "Merge two files with ancestor."
1098 (interactive
1099 (let ((dir-A (if ediff-use-last-dir
1100 ediff-last-dir-A
1101 default-directory))
1102 dir-B dir-ancestor f ff)
1103 (list (setq f (ediff-read-file-name
1104 "File A to merge"
1105 dir-A
1106 (ediff-get-default-file-name)
1107 'no-dirs))
1108 (setq ff (ediff-read-file-name "File B to merge"
1109 (setq dir-B
1110 (if ediff-use-last-dir
1111 ediff-last-dir-B
1112 (file-name-directory f)))
1113 (progn
1114 (setq file-name-history
1115 (cons
1116 (ediff-abbreviate-file-name
1117 (expand-file-name
1118 (file-name-nondirectory f)
1119 dir-B))
1120 file-name-history))
1121 (ediff-get-default-file-name f 1))))
1122 (ediff-read-file-name "Ancestor file"
1123 (setq dir-ancestor
1124 (if ediff-use-last-dir
1125 ediff-last-dir-ancestor
1126 (file-name-directory ff)))
1127 (progn
1128 (setq file-name-history
1129 (cons (ediff-abbreviate-file-name
1130 (expand-file-name
1131 (file-name-nondirectory ff)
1132 dir-ancestor))
1133 file-name-history))
1134 (ediff-get-default-file-name ff 2)))
1136 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1137 (ediff-files-internal file-A
1138 (if (file-directory-p file-B)
1139 (expand-file-name
1140 (file-name-nondirectory file-A) file-B)
1141 file-B)
1142 file-ancestor
1143 startup-hooks
1144 'ediff-merge-files-with-ancestor
1145 merge-buffer-file))
1147 ;;;###autoload
1148 (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor)
1150 ;;;###autoload
1151 (defun ediff-merge-buffers (buffer-A buffer-B
1152 &optional
1153 ;; MERGE-BUFFER-FILE is the file to be
1154 ;; associated with the merge buffer
1155 startup-hooks job-name merge-buffer-file)
1156 "Merge buffers without ancestor."
1157 (interactive
1158 (let (bf)
1159 (list (setq bf (read-buffer "Buffer A to merge: "
1160 (ediff-other-buffer "") t))
1161 (read-buffer "Buffer B to merge: "
1162 (progn
1163 ;; realign buffers so that two visible bufs will be
1164 ;; at the top
1165 (save-window-excursion (other-window 1))
1166 (ediff-other-buffer bf))
1167 t))))
1169 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1170 (or job-name (setq job-name 'ediff-merge-buffers))
1171 (ediff-buffers-internal
1172 buffer-A buffer-B nil startup-hooks job-name merge-buffer-file))
1174 ;;;###autoload
1175 (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
1176 &optional
1177 startup-hooks
1178 job-name
1179 ;; MERGE-BUFFER-FILE is the
1180 ;; file to be associated
1181 ;; with the merge buffer
1182 merge-buffer-file)
1183 "Merge buffers with ancestor."
1184 (interactive
1185 (let (bf bff)
1186 (list (setq bf (read-buffer "Buffer A to merge: "
1187 (ediff-other-buffer "") t))
1188 (setq bff (read-buffer "Buffer B to merge: "
1189 (progn
1190 ;; realign buffers so that two visible
1191 ;; bufs will be at the top
1192 (save-window-excursion (other-window 1))
1193 (ediff-other-buffer bf))
1195 (read-buffer "Ancestor buffer: "
1196 (progn
1197 ;; realign buffers so that three visible
1198 ;; bufs will be at the top
1199 (save-window-excursion (other-window 1))
1200 (ediff-other-buffer (list bf bff)))
1204 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1205 (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor))
1206 (ediff-buffers-internal
1207 buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file))
1210 ;;;###autoload
1211 (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file)
1212 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
1213 "Run Ediff by merging two revisions of a file.
1214 The file is the optional FILE argument or the file visited by the current
1215 buffer."
1216 (interactive)
1217 (if (stringp file) (find-file file))
1218 (let (rev1 rev2)
1219 (setq rev1
1220 (read-string
1221 (format
1222 "Version 1 to merge (default: %s's latest version): "
1223 (if (stringp file)
1224 (file-name-nondirectory file) "current buffer")))
1225 rev2
1226 (read-string
1227 (format
1228 "Version 2 to merge (default: %s): "
1229 (if (stringp file)
1230 (file-name-nondirectory file) "current buffer"))))
1231 (ediff-load-version-control)
1232 ;; ancestor-revision=nil
1233 (funcall
1234 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1235 rev1 rev2 nil startup-hooks merge-buffer-file)))
1238 ;;;###autoload
1239 (defun ediff-merge-revisions-with-ancestor (&optional
1240 file startup-hooks
1241 ;; MERGE-BUFFER-FILE is the file to
1242 ;; be associated with the merge
1243 ;; buffer
1244 merge-buffer-file)
1245 "Run Ediff by merging two revisions of a file with a common ancestor.
1246 The file is the optional FILE argument or the file visited by the current
1247 buffer."
1248 (interactive)
1249 (if (stringp file) (find-file file))
1250 (let (rev1 rev2 ancestor-rev)
1251 (setq rev1
1252 (read-string
1253 (format
1254 "Version 1 to merge (default: %s's latest version): "
1255 (if (stringp file)
1256 (file-name-nondirectory file) "current buffer")))
1257 rev2
1258 (read-string
1259 (format
1260 "Version 2 to merge (default: %s): "
1261 (if (stringp file)
1262 (file-name-nondirectory file) "current buffer")))
1263 ancestor-rev
1264 (read-string
1265 (format
1266 "Ancestor version (default: %s's base revision): "
1267 (if (stringp file)
1268 (file-name-nondirectory file) "current buffer"))))
1269 (ediff-load-version-control)
1270 (funcall
1271 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1272 rev1 rev2 ancestor-rev startup-hooks merge-buffer-file)))
1274 ;; MK: Check. This function doesn't seem to be used any more by pcvs or pcl-cvs
1275 ;;;###autoload
1276 (defun run-ediff-from-cvs-buffer (pos)
1277 "Run Ediff-merge on appropriate revisions of the selected file.
1278 First run after `M-x cvs-update'. Then place the cursor on a line describing a
1279 file and then run `run-ediff-from-cvs-buffer'."
1280 (interactive "d")
1281 (ediff-load-version-control)
1282 (let ((tin (tin-locate cvs-cookie-handle pos)))
1283 (if tin
1284 (cvs-run-ediff-on-file-descriptor tin)
1285 (error "There is no file to merge"))))
1288 ;;; Apply patch
1290 ;;;###autoload
1291 (defun ediff-patch-file (&optional arg patch-buf)
1292 "Run Ediff by patching SOURCE-FILENAME.
1293 If optional PATCH-BUF is given, use the patch in that buffer
1294 and don't ask the user.
1295 If prefix argument, then: if even argument, assume that the patch is in a
1296 buffer. If odd -- assume it is in a file."
1297 (interactive "P")
1298 (let (source-dir source-file)
1299 (require 'ediff-ptch)
1300 (setq patch-buf
1301 (ediff-get-patch-buffer
1302 (if arg (prefix-numeric-value arg)) patch-buf))
1303 (setq source-dir (cond (ediff-use-last-dir ediff-last-dir-patch)
1304 ((and (not ediff-patch-default-directory)
1305 (buffer-file-name patch-buf))
1306 (file-name-directory
1307 (expand-file-name
1308 (buffer-file-name patch-buf))))
1309 (t default-directory)))
1310 (setq source-file
1311 (read-file-name
1312 "File to patch (directory, if multifile patch): "
1313 ;; use an explicit initial file
1314 source-dir nil nil (ediff-get-default-file-name)))
1315 (ediff-dispatch-file-patching-job patch-buf source-file)))
1317 ;;;###autoload
1318 (defun ediff-patch-buffer (&optional arg patch-buf)
1319 "Run Ediff by patching BUFFER-NAME.
1320 Without prefix argument: asks if the patch is in some buffer and prompts for
1321 the buffer or a file, depending on the answer.
1322 With prefix arg=1: assumes the patch is in a file and prompts for the file.
1323 With prefix arg=2: assumes the patch is in a buffer and prompts for the buffer."
1324 (interactive "P")
1325 (require 'ediff-ptch)
1326 (setq patch-buf
1327 (ediff-get-patch-buffer
1328 (if arg (prefix-numeric-value arg)) patch-buf))
1329 (ediff-patch-buffer-internal
1330 patch-buf
1331 (read-buffer
1332 "Which buffer to patch? "
1333 (current-buffer))))
1336 ;;;###autoload
1337 (defalias 'epatch 'ediff-patch-file)
1338 ;;;###autoload
1339 (defalias 'epatch-buffer 'ediff-patch-buffer)
1344 ;;; Versions Control functions
1346 ;;;###autoload
1347 (defun ediff-revision (&optional file startup-hooks)
1348 "Run Ediff by comparing versions of a file.
1349 The file is an optional FILE argument or the file entered at the prompt.
1350 Default: the file visited by the current buffer.
1351 Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
1352 ;; if buffer is non-nil, use that buffer instead of the current buffer
1353 (interactive "P")
1354 (if (not (stringp file))
1355 (setq file
1356 (ediff-read-file-name "Compare revisions for file"
1357 (if ediff-use-last-dir
1358 ediff-last-dir-A
1359 default-directory)
1360 (ediff-get-default-file-name)
1361 'no-dirs)))
1362 (find-file file)
1363 (if (and (buffer-modified-p)
1364 (y-or-n-p (message "Buffer %s is modified. Save buffer? "
1365 (buffer-name))))
1366 (save-buffer (current-buffer)))
1367 (let (rev1 rev2)
1368 (setq rev1
1369 (read-string
1370 (format "Version 1 to compare (default: %s's latest version): "
1371 (file-name-nondirectory file)))
1372 rev2
1373 (read-string
1374 (format "Version 2 to compare (default: %s): "
1375 (file-name-nondirectory file))))
1376 (ediff-load-version-control)
1377 (funcall
1378 (intern (format "ediff-%S-internal" ediff-version-control-package))
1379 rev1 rev2 startup-hooks)
1383 ;;;###autoload
1384 (defalias 'erevision 'ediff-revision)
1387 ;; Test if version control package is loaded and load if not
1388 ;; Is SILENT is non-nil, don't report error if package is not found.
1389 (defun ediff-load-version-control (&optional silent)
1390 (require 'ediff-vers)
1391 (or (featurep ediff-version-control-package)
1392 (if (locate-library (symbol-name ediff-version-control-package))
1393 (progn
1394 (message "") ; kill the message from `locate-library'
1395 (require ediff-version-control-package))
1396 (or silent
1397 (error "Version control package %S.el not found. Use vc.el instead"
1398 ediff-version-control-package)))))
1401 ;;;###autoload
1402 (defun ediff-version ()
1403 "Return string describing the version of Ediff.
1404 When called interactively, displays the version."
1405 (interactive)
1406 (if (interactive-p)
1407 (message (ediff-version))
1408 (format "Ediff %s of %s" ediff-version ediff-date)))
1411 ;;;###autoload
1412 (defun ediff-documentation (&optional node)
1413 "Display Ediff's manual.
1414 With optional NODE, goes to that node."
1415 (interactive)
1416 (let ((ctl-window ediff-control-window)
1417 (ctl-buf ediff-control-buffer))
1419 (ediff-skip-unsuitable-frames)
1420 (condition-case nil
1421 (progn
1422 (pop-to-buffer (get-buffer-create "*info*"))
1423 (info (if ediff-xemacs-p "ediff.info" "ediff"))
1424 (if node
1425 (Info-goto-node node)
1426 (message "Type `i' to search for a specific topic"))
1427 (raise-frame (selected-frame)))
1428 (error (beep 1)
1429 (with-output-to-temp-buffer ediff-msg-buffer
1430 (ediff-with-current-buffer standard-output
1431 (fundamental-mode))
1432 (princ ediff-BAD-INFO))
1433 (if (window-live-p ctl-window)
1434 (progn
1435 (select-window ctl-window)
1436 (set-window-buffer ctl-window ctl-buf)))))))
1441 ;;; Local Variables:
1442 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1443 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1444 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1445 ;;; End:
1447 (require 'ediff-util)
1449 (run-hooks 'ediff-load-hook)
1451 ;;; ediff.el ends here