(defcustom): Doc fix.
[emacs.git] / lisp / ediff.el
blob5b0f85d05cd22e75cbd16da91c2254b7ee5a27f7
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.77" "The current version of Ediff")
10 (defconst ediff-date "March 5, 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 nil)
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)
370 ;;;###autoload
371 (defun ediff-backup (file)
372 "Run Ediff on FILE and its backup file.
373 Uses the latest backup, if there are several numerical backups.
374 If this file is a backup, `ediff' it with its original."
375 (interactive (list (read-file-name "Ediff (file with backup): ")))
376 ;; The code is taken from `diff-backup'.
377 (require 'diff)
378 (let (bak ori)
379 (if (backup-file-name-p file)
380 (setq bak file
381 ori (file-name-sans-versions file))
382 (setq bak (or (diff-latest-backup-file file)
383 (error "No backup found for %s" file))
384 ori file))
385 (ediff-files bak ori)))
387 ;;;###autoload
388 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name)
389 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
390 (interactive
391 (let (bf)
392 (list (setq bf (read-buffer "Buffer A to compare: "
393 (ediff-other-buffer "") t))
394 (read-buffer "Buffer B to compare: "
395 (progn
396 ;; realign buffers so that two visible bufs will be
397 ;; at the top
398 (save-window-excursion (other-window 1))
399 (ediff-other-buffer bf))
400 t))))
401 (or job-name (setq job-name 'ediff-buffers))
402 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name))
404 ;;;###autoload
405 (defalias 'ebuffers 'ediff-buffers)
408 ;;;###autoload
409 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
410 &optional startup-hooks job-name)
411 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
412 (interactive
413 (let (bf bff)
414 (list (setq bf (read-buffer "Buffer A to compare: "
415 (ediff-other-buffer "") t))
416 (setq bff (read-buffer "Buffer B to compare: "
417 (progn
418 ;; realign buffers so that two visible
419 ;; bufs will be at the top
420 (save-window-excursion (other-window 1))
421 (ediff-other-buffer bf))
423 (read-buffer "Buffer C to compare: "
424 (progn
425 ;; realign buffers so that three visible
426 ;; bufs will be at the top
427 (save-window-excursion (other-window 1))
428 (ediff-other-buffer (list bf bff)))
431 (or job-name (setq job-name 'ediff-buffers3))
432 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name))
434 ;;;###autoload
435 (defalias 'ebuffers3 'ediff-buffers3)
439 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
440 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
441 &optional merge-buffer-file)
442 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
443 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
444 (buf-C-is-alive (ediff-buffer-live-p buf-C))
445 (buf-C-file-name (if buf-C-is-alive
446 (buffer-file-name (get-buffer buf-B))))
447 file-A file-B file-C)
448 (if (not (ediff-buffer-live-p buf-A))
449 (error "Buffer %S doesn't exist" buf-A))
450 (if (not (ediff-buffer-live-p buf-B))
451 (error "Buffer %S doesn't exist" buf-B))
452 (let ((ediff-job-name job-name))
453 (if (and ediff-3way-comparison-job
454 (not buf-C-is-alive))
455 (error "Buffer %S doesn't exist" buf-C)))
456 (if (stringp buf-A-file-name)
457 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
458 (if (stringp buf-B-file-name)
459 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
460 (if (stringp buf-C-file-name)
461 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
463 (setq file-A (ediff-make-temp-file buf-A buf-A-file-name)
464 file-B (ediff-make-temp-file buf-B buf-B-file-name))
465 (if buf-C-is-alive
466 (setq file-C (ediff-make-temp-file buf-C buf-C-file-name)))
468 (ediff-setup (get-buffer buf-A) file-A
469 (get-buffer buf-B) file-B
470 (if buf-C-is-alive (get-buffer buf-C))
471 file-C
472 (cons `(lambda ()
473 (delete-file ,file-A)
474 (delete-file ,file-B)
475 (if (stringp ,file-C) (delete-file ,file-C)))
476 startup-hooks)
477 (list (cons 'ediff-job-name job-name))
478 merge-buffer-file)))
481 ;;; Directory and file group operations
483 ;; Get appropriate default name for directory:
484 ;; If ediff-use-last-dir, use ediff-last-dir-A.
485 ;; In dired mode, use the directory that is under the point (if any);
486 ;; otherwise, use default-directory
487 (defun ediff-get-default-directory-name ()
488 (cond (ediff-use-last-dir ediff-last-dir-A)
489 ((eq major-mode 'dired-mode)
490 (let ((f (dired-get-filename nil 'noerror)))
491 (if (and (stringp f) (file-directory-p f))
493 default-directory)))
494 (t default-directory)))
497 ;;;###autoload
498 (defun ediff-directories (dir1 dir2 regexp)
499 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
500 the same name in both. The third argument, REGEXP, is a regular expression
501 that can be used to filter out certain file names."
502 (interactive
503 (let ((dir-A (ediff-get-default-directory-name))
505 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
506 (ediff-read-file-name "Directory B to compare:"
507 (if ediff-use-last-dir
508 ediff-last-dir-B
509 (ediff-strip-last-dir f))
510 nil)
511 (read-string "Filter through regular expression: "
512 nil 'ediff-filtering-regexp-history)
514 (ediff-directories-internal
515 dir1 dir2 nil regexp 'ediff-files 'ediff-directories
518 ;;;###autoload
519 (defalias 'edirs 'ediff-directories)
522 ;;;###autoload
523 (defun ediff-directory-revisions (dir1 regexp)
524 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
525 The second argument, REGEXP, is a regular expression that filters the file
526 names. Only the files that are under revision control are taken into account."
527 (interactive
528 (let ((dir-A (ediff-get-default-directory-name)))
529 (list (ediff-read-file-name
530 "Directory to compare with revision:" dir-A nil)
531 (read-string "Filter through regular expression: "
532 nil 'ediff-filtering-regexp-history)
534 (ediff-directory-revisions-internal
535 dir1 regexp 'ediff-revision 'ediff-directory-revisions
538 ;;;###autoload
539 (defalias 'edir-revisions 'ediff-directory-revisions)
542 ;;;###autoload
543 (defun ediff-directories3 (dir1 dir2 dir3 regexp)
544 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
545 have the same name in all three. The last argument, REGEXP, is a regular
546 expression that can be used to filter out certain file names."
547 (interactive
548 (let ((dir-A (ediff-get-default-directory-name))
550 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
551 (setq f (ediff-read-file-name "Directory B to compare:"
552 (if ediff-use-last-dir
553 ediff-last-dir-B
554 (ediff-strip-last-dir f))
555 nil))
556 (ediff-read-file-name "Directory C to compare:"
557 (if ediff-use-last-dir
558 ediff-last-dir-C
559 (ediff-strip-last-dir f))
560 nil)
561 (read-string "Filter through regular expression: "
562 nil 'ediff-filtering-regexp-history)
564 (ediff-directories-internal
565 dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3
568 ;;;###autoload
569 (defalias 'edirs3 'ediff-directories3)
571 ;;;###autoload
572 (defun ediff-merge-directories (dir1 dir2 regexp &optional merge-autostore-dir)
573 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
574 the same name in both. The third argument, REGEXP, is a regular expression
575 that can be used to filter out certain file names."
576 (interactive
577 (let ((dir-A (ediff-get-default-directory-name))
579 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
580 (ediff-read-file-name "Directory B to merge:"
581 (if ediff-use-last-dir
582 ediff-last-dir-B
583 (ediff-strip-last-dir f))
584 nil)
585 (read-string "Filter through regular expression: "
586 nil 'ediff-filtering-regexp-history)
588 (ediff-directories-internal
589 dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories
590 nil merge-autostore-dir
593 ;;;###autoload
594 (defalias 'edirs-merge 'ediff-merge-directories)
596 ;;;###autoload
597 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
598 &optional
599 merge-autostore-dir)
600 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
601 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
602 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
603 without ancestor. The fourth argument, REGEXP, is a regular expression that
604 can be used to filter out certain file names."
605 (interactive
606 (let ((dir-A (ediff-get-default-directory-name))
608 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
609 (setq f (ediff-read-file-name "Directory B to merge:"
610 (if ediff-use-last-dir
611 ediff-last-dir-B
612 (ediff-strip-last-dir f))
613 nil))
614 (ediff-read-file-name "Ancestor directory:"
615 (if ediff-use-last-dir
616 ediff-last-dir-C
617 (ediff-strip-last-dir f))
618 nil)
619 (read-string "Filter through regular expression: "
620 nil 'ediff-filtering-regexp-history)
622 (ediff-directories-internal
623 dir1 dir2 ancestor-dir regexp
624 'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor
625 nil merge-autostore-dir
628 ;;;###autoload
629 (defun ediff-merge-directory-revisions (dir1 regexp
630 &optional merge-autostore-dir)
631 "Run Ediff on a directory, DIR1, merging its files with their revisions.
632 The second argument, REGEXP, is a regular expression that filters the file
633 names. Only the files that are under revision control are taken into account."
634 (interactive
635 (let ((dir-A (ediff-get-default-directory-name)))
636 (list (ediff-read-file-name
637 "Directory to merge with revisions:" dir-A nil)
638 (read-string "Filter through regular expression: "
639 nil 'ediff-filtering-regexp-history)
641 (ediff-directory-revisions-internal
642 dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions
643 nil merge-autostore-dir
646 ;;;###autoload
647 (defalias 'edir-merge-revisions 'ediff-merge-directory-revisions)
649 ;;;###autoload
650 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
651 &optional
652 merge-autostore-dir)
653 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
654 The second argument, REGEXP, is a regular expression that filters the file
655 names. Only the files that are under revision control are taken into account."
656 (interactive
657 (let ((dir-A (ediff-get-default-directory-name)))
658 (list (ediff-read-file-name
659 "Directory to merge with revisions and ancestors:" dir-A nil)
660 (read-string "Filter through regular expression: "
661 nil 'ediff-filtering-regexp-history)
663 (ediff-directory-revisions-internal
664 dir1 regexp 'ediff-merge-revisions-with-ancestor
665 'ediff-merge-directory-revisions-with-ancestor
666 nil merge-autostore-dir
669 ;;;###autoload
670 (defalias
671 'edir-merge-revisions-with-ancestor
672 'ediff-merge-directory-revisions-with-ancestor)
674 ;;;###autoload
675 (defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor)
677 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
678 ;; on a pair of directories (three directories, in case of ancestor).
679 ;; The third argument, REGEXP, is a regular expression that can be used to
680 ;; filter out certain file names.
681 ;; JOBNAME is the symbol indicating the meta-job to be performed.
682 ;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
683 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
684 &optional startup-hooks
685 merge-autostore-dir)
686 ;; ediff-read-file-name is set to attach a previously entered file name if
687 ;; the currently entered file is a directory. This code takes care of that.
688 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1))
689 dir2 (if (file-directory-p dir2) dir2 (file-name-directory dir2)))
691 (if (stringp dir3)
692 (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))
694 (cond ((string= dir1 dir2)
695 (error "Directories A and B are the same: %s" dir1))
696 ((and (eq jobname 'ediff-directories3)
697 (string= dir1 dir3))
698 (error "Directories A and C are the same: %s" dir1))
699 ((and (eq jobname 'ediff-directories3)
700 (string= dir2 dir3))
701 (error "Directories B and C are the same: %s" dir1)))
703 (if merge-autostore-dir
704 (or (stringp merge-autostore-dir)
705 (error "%s: Directory for storing merged files must be a string"
706 jobname)))
707 (let (;; dir-diff-struct is of the form (common-list diff-list)
708 ;; It is a structure where ediff-intersect-directories returns
709 ;; commonalities and differences among directories
710 dir-diff-struct
711 meta-buf)
712 (if (and ediff-autostore-merges
713 (ediff-merge-metajob jobname)
714 (not merge-autostore-dir))
715 (setq merge-autostore-dir
716 (read-file-name "Save merged files in directory: "
717 (if ediff-use-last-dir
718 ediff-last-merge-autostore-dir
719 (ediff-strip-last-dir dir1))
721 'must-match)))
722 ;; verify we are not merging into an orig directory
723 (if merge-autostore-dir
724 (cond ((and (stringp dir1) (string= merge-autostore-dir dir1))
725 (or (y-or-n-p
726 "Directory for saving merged files = Directory A. Sure? ")
727 (error "Directory merge aborted")))
728 ((and (stringp dir2) (string= merge-autostore-dir dir2))
729 (or (y-or-n-p
730 "Directory for saving merged files = Directory B. Sure? ")
731 (error "Directory merge aborted")))
732 ((and (stringp dir3) (string= merge-autostore-dir dir3))
733 (or (y-or-n-p
734 "Directory for saving merged files = Ancestor Directory. Sure? ")
735 (error "Directory merge aborted")))))
737 (setq dir-diff-struct (ediff-intersect-directories
738 jobname
739 regexp dir1 dir2 dir3 merge-autostore-dir))
740 (setq startup-hooks
741 ;; this sets various vars in the meta buffer inside
742 ;; ediff-prepare-meta-buffer
743 (cons `(lambda ()
744 ;; tell what to do if the user clicks on a session record
745 (setq ediff-session-action-function (quote ,action))
746 ;; set ediff-dir-difference-list
747 (setq ediff-dir-difference-list
748 (cdr (quote ,dir-diff-struct))))
749 startup-hooks))
750 (setq meta-buf (ediff-prepare-meta-buffer
751 'ediff-filegroup-action
752 (car dir-diff-struct)
753 "*Ediff Session Group Panel"
754 'ediff-redraw-directory-group-buffer
755 jobname
756 startup-hooks))
757 (ediff-show-meta-buffer meta-buf)
760 ;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
761 ;; files
762 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
763 &optional startup-hooks
764 merge-autostore-dir)
765 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)))
767 (if merge-autostore-dir
768 (or (stringp merge-autostore-dir)
769 (error "%S: Directory for storing merged files must be a string"
770 jobname)))
771 (let (file-list meta-buf)
772 (if (and ediff-autostore-merges
773 (ediff-merge-metajob jobname)
774 (not merge-autostore-dir))
775 (setq merge-autostore-dir
776 (read-file-name "Save merged files in directory: "
777 (if ediff-use-last-dir
778 ediff-last-merge-autostore-dir
779 (ediff-strip-last-dir dir1))
781 'must-match)))
782 ;; verify merge-autostore-dir != dir1
783 (if (and merge-autostore-dir
784 (stringp dir1)
785 (string= merge-autostore-dir dir1))
786 (or (y-or-n-p
787 "Directory for saving merged file = directory A. Sure? ")
788 (error "Merge of directory revisions aborted")))
790 (setq file-list
791 (ediff-get-directory-files-under-revision
792 jobname regexp dir1 merge-autostore-dir))
793 (setq startup-hooks
794 ;; this sets various vars in the meta buffer inside
795 ;; ediff-prepare-meta-buffer
796 (cons `(lambda ()
797 ;; tell what to do if the user clicks on a session record
798 (setq ediff-session-action-function (quote ,action)))
799 startup-hooks))
800 (setq meta-buf (ediff-prepare-meta-buffer
801 'ediff-filegroup-action
802 file-list
803 "*Ediff Session Group Panel"
804 'ediff-redraw-directory-group-buffer
805 jobname
806 startup-hooks))
807 (ediff-show-meta-buffer meta-buf)
811 ;;; Compare regions and windows
813 ;;;###autoload
814 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks)
815 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
816 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
817 follows:
818 If WIND-A is nil, use selected window.
819 If WIND-B is nil, use window next to WIND-A."
820 (interactive "P")
821 (ediff-windows dumb-mode wind-A wind-B
822 startup-hooks 'ediff-windows-wordwise 'word-mode))
824 ;;;###autoload
825 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks)
826 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
827 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
828 follows:
829 If WIND-A is nil, use selected window.
830 If WIND-B is nil, use window next to WIND-A."
831 (interactive "P")
832 (ediff-windows dumb-mode wind-A wind-B
833 startup-hooks 'ediff-windows-linewise nil))
835 ;; Compare WIND-A and WIND-B, which are selected by clicking.
836 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
837 ;; works as follows:
838 ;; If WIND-A is nil, use selected window.
839 ;; If WIND-B is nil, use window next to WIND-A.
840 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode)
841 (if (or dumb-mode (not (ediff-window-display-p)))
842 (setq wind-A (ediff-get-next-window wind-A nil)
843 wind-B (ediff-get-next-window wind-B wind-A))
844 (setq wind-A (ediff-get-window-by-clicking wind-A nil 1)
845 wind-B (ediff-get-window-by-clicking wind-B wind-A 2)))
847 (let ((buffer-A (window-buffer wind-A))
848 (buffer-B (window-buffer wind-B))
849 beg-A end-A beg-B end-B)
851 (save-excursion
852 (save-window-excursion
853 (sit-for 0) ; sync before using window-start/end -- a precaution
854 (select-window wind-A)
855 (setq beg-A (window-start)
856 end-A (window-end))
857 (select-window wind-B)
858 (setq beg-B (window-start)
859 end-B (window-end))))
860 (setq buffer-A
861 (ediff-clone-buffer-for-window-comparison
862 buffer-A wind-A "-Window.A-")
863 buffer-B
864 (ediff-clone-buffer-for-window-comparison
865 buffer-B wind-B "-Window.B-"))
866 (ediff-regions-internal
867 buffer-A beg-A end-A buffer-B beg-B end-B
868 startup-hooks job-name word-mode nil)))
871 ;;;###autoload
872 (defun ediff-regions-wordwise (buffer-A buffer-B &optional startup-hooks)
873 "Run Ediff on a pair of regions in specified buffers.
874 Regions \(i.e., point and mark\) are assumed to be set in advance except
875 for the second region in the case both regions are from the same buffer.
876 In such a case the user is asked to interactively establish the second
877 region.
878 This function is effective only for relatively small regions, up to 200
879 lines. For large regions, use `ediff-regions-linewise'."
880 (interactive
881 (let (bf)
882 (list (setq bf (read-buffer "Region's A buffer: "
883 (ediff-other-buffer "") t))
884 (read-buffer "Region's B buffer: "
885 (progn
886 ;; realign buffers so that two visible bufs will be
887 ;; at the top
888 (save-window-excursion (other-window 1))
889 (ediff-other-buffer bf))
890 t))))
891 (if (not (ediff-buffer-live-p buffer-A))
892 (error "Buffer %S doesn't exist" buffer-A))
893 (if (not (ediff-buffer-live-p buffer-B))
894 (error "Buffer %S doesn't exist" buffer-B))
897 (let ((buffer-A
898 (ediff-clone-buffer-for-region-comparison buffer-A "-Region.A-"))
899 (buffer-B
900 (ediff-clone-buffer-for-region-comparison buffer-B "-Region.B-"))
901 reg-A-beg reg-A-end reg-B-beg reg-B-end)
902 (save-excursion
903 (set-buffer buffer-A)
904 (setq reg-A-beg (region-beginning)
905 reg-A-end (region-end))
906 (set-buffer buffer-B)
907 (setq reg-B-beg (region-beginning)
908 reg-B-end (region-end)))
910 (ediff-regions-internal
911 (get-buffer buffer-A) reg-A-beg reg-A-end
912 (get-buffer buffer-B) reg-B-beg reg-B-end
913 startup-hooks 'ediff-regions-wordwise 'word-mode nil)))
915 ;;;###autoload
916 (defun ediff-regions-linewise (buffer-A buffer-B &optional startup-hooks)
917 "Run Ediff on a pair of regions in specified buffers.
918 Regions \(i.e., point and mark\) are assumed to be set in advance except
919 for the second region in the case both regions are from the same buffer.
920 In such a case the user is asked to interactively establish the second
921 region.
922 Each region is enlarged to contain full lines.
923 This function is effective for large regions, over 100-200
924 lines. For small regions, use `ediff-regions-wordwise'."
925 (interactive
926 (let (bf)
927 (list (setq bf (read-buffer "Region A's buffer: "
928 (ediff-other-buffer "") t))
929 (read-buffer "Region B's buffer: "
930 (progn
931 ;; realign buffers so that two visible bufs will be
932 ;; at the top
933 (save-window-excursion (other-window 1))
934 (ediff-other-buffer bf))
935 t))))
936 (if (not (ediff-buffer-live-p buffer-A))
937 (error "Buffer %S doesn't exist" buffer-A))
938 (if (not (ediff-buffer-live-p buffer-B))
939 (error "Buffer %S doesn't exist" buffer-B))
941 (let ((buffer-A
942 (ediff-clone-buffer-for-region-comparison buffer-A "-Region.A-"))
943 (buffer-B
944 (ediff-clone-buffer-for-region-comparison buffer-B "-Region.B-"))
945 reg-A-beg reg-A-end reg-B-beg reg-B-end)
946 (save-excursion
947 (set-buffer buffer-A)
948 (setq reg-A-beg (region-beginning)
949 reg-A-end (region-end))
950 ;; enlarge the region to hold full lines
951 (goto-char reg-A-beg)
952 (beginning-of-line)
953 (setq reg-A-beg (point))
954 (goto-char reg-A-end)
955 (end-of-line)
956 (or (eobp) (forward-char)) ; include the newline char
957 (setq reg-A-end (point))
959 (set-buffer buffer-B)
960 (setq reg-B-beg (region-beginning)
961 reg-B-end (region-end))
962 ;; enlarge the region to hold full lines
963 (goto-char reg-B-beg)
964 (beginning-of-line)
965 (setq reg-B-beg (point))
966 (goto-char reg-B-end)
967 (end-of-line)
968 (or (eobp) (forward-char)) ; include the newline char
969 (setq reg-B-end (point))
970 ) ; save excursion
972 (ediff-regions-internal
973 (get-buffer buffer-A) reg-A-beg reg-A-end
974 (get-buffer buffer-B) reg-B-beg reg-B-end
975 startup-hooks 'ediff-regions-linewise nil nil))) ; no word mode
977 ;; compare region beg-A to end-A of buffer-A
978 ;; to regions beg-B -- end-B in buffer-B.
979 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
980 startup-hooks job-name word-mode
981 setup-parameters)
982 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
983 overl-A overl-B
984 file-A file-B)
986 ;; in case beg/end-A/B aren't markers--make them into markers
987 (ediff-with-current-buffer buffer-A
988 (setq beg-A (move-marker (make-marker) beg-A)
989 end-A (move-marker (make-marker) end-A)))
990 (ediff-with-current-buffer buffer-B
991 (setq beg-B (move-marker (make-marker) beg-B)
992 end-B (move-marker (make-marker) end-B)))
994 ;; make file-A
995 (if word-mode
996 (ediff-wordify beg-A end-A buffer-A tmp-buffer)
997 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer))
998 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
1000 ;; make file-B
1001 (if word-mode
1002 (ediff-wordify beg-B end-B buffer-B tmp-buffer)
1003 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer))
1004 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
1006 (setq overl-A (ediff-make-bullet-proof-overlay beg-A end-A buffer-A))
1007 (setq overl-B (ediff-make-bullet-proof-overlay beg-B end-B buffer-B))
1008 (ediff-setup buffer-A file-A
1009 buffer-B file-B
1010 nil nil ; buffer & file C
1011 (cons `(lambda ()
1012 (delete-file ,file-A)
1013 (delete-file ,file-B))
1014 startup-hooks)
1015 (append
1016 (list (cons 'ediff-word-mode word-mode)
1017 (cons 'ediff-narrow-bounds (list overl-A overl-B))
1018 (cons 'ediff-job-name job-name))
1019 setup-parameters))
1023 ;;; Merge files and buffers
1025 ;;;###autoload
1026 (defalias 'ediff-merge 'ediff-merge-files)
1028 (defsubst ediff-merge-on-startup ()
1029 (ediff-do-merge 0)
1030 (ediff-with-current-buffer ediff-buffer-C
1031 (set-buffer-modified-p nil)))
1033 ;;;###autoload
1034 (defun ediff-merge-files (file-A file-B
1035 ;; MERGE-BUFFER-FILE is the file to be
1036 ;; associated with the merge buffer
1037 &optional startup-hooks merge-buffer-file)
1038 "Merge two files without ancestor."
1039 (interactive
1040 (let ((dir-A (if ediff-use-last-dir
1041 ediff-last-dir-A
1042 default-directory))
1043 dir-B f)
1044 (list (setq f (ediff-read-file-name
1045 "File A to merge"
1046 dir-A
1047 (ediff-get-default-file-name)
1048 'no-dirs))
1049 (ediff-read-file-name "File B to merge"
1050 (setq dir-B
1051 (if ediff-use-last-dir
1052 ediff-last-dir-B
1053 (file-name-directory f)))
1054 (progn
1055 (setq file-name-history
1056 (cons (ediff-abbreviate-file-name
1057 (expand-file-name
1058 (file-name-nondirectory f)
1059 dir-B))
1060 file-name-history))
1061 (ediff-get-default-file-name f 1)))
1063 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1064 (ediff-files-internal file-A
1065 (if (file-directory-p file-B)
1066 (expand-file-name
1067 (file-name-nondirectory file-A) file-B)
1068 file-B)
1069 nil ; file-C
1070 startup-hooks
1071 'ediff-merge-files
1072 merge-buffer-file))
1074 ;;;###autoload
1075 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
1076 &optional
1077 startup-hooks
1078 ;; MERGE-BUFFER-FILE is the file
1079 ;; to be associated with the
1080 ;; merge buffer
1081 merge-buffer-file)
1082 "Merge two files with ancestor."
1083 (interactive
1084 (let ((dir-A (if ediff-use-last-dir
1085 ediff-last-dir-A
1086 default-directory))
1087 dir-B dir-ancestor f ff)
1088 (list (setq f (ediff-read-file-name
1089 "File A to merge"
1090 dir-A
1091 (ediff-get-default-file-name)
1092 'no-dirs))
1093 (setq ff (ediff-read-file-name "File B to merge"
1094 (setq dir-B
1095 (if ediff-use-last-dir
1096 ediff-last-dir-B
1097 (file-name-directory f)))
1098 (progn
1099 (setq file-name-history
1100 (cons
1101 (ediff-abbreviate-file-name
1102 (expand-file-name
1103 (file-name-nondirectory f)
1104 dir-B))
1105 file-name-history))
1106 (ediff-get-default-file-name f 1))))
1107 (ediff-read-file-name "Ancestor file"
1108 (setq dir-ancestor
1109 (if ediff-use-last-dir
1110 ediff-last-dir-ancestor
1111 (file-name-directory ff)))
1112 (progn
1113 (setq file-name-history
1114 (cons (ediff-abbreviate-file-name
1115 (expand-file-name
1116 (file-name-nondirectory ff)
1117 dir-ancestor))
1118 file-name-history))
1119 (ediff-get-default-file-name ff 2)))
1121 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1122 (ediff-files-internal file-A
1123 (if (file-directory-p file-B)
1124 (expand-file-name
1125 (file-name-nondirectory file-A) file-B)
1126 file-B)
1127 file-ancestor
1128 startup-hooks
1129 'ediff-merge-files-with-ancestor
1130 merge-buffer-file))
1132 ;;;###autoload
1133 (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor)
1135 ;;;###autoload
1136 (defun ediff-merge-buffers (buffer-A buffer-B
1137 &optional
1138 ;; MERGE-BUFFER-FILE is the file to be
1139 ;; associated with the merge buffer
1140 startup-hooks job-name merge-buffer-file)
1141 "Merge buffers without ancestor."
1142 (interactive
1143 (let (bf)
1144 (list (setq bf (read-buffer "Buffer A to merge: "
1145 (ediff-other-buffer "") t))
1146 (read-buffer "Buffer B to merge: "
1147 (progn
1148 ;; realign buffers so that two visible bufs will be
1149 ;; at the top
1150 (save-window-excursion (other-window 1))
1151 (ediff-other-buffer bf))
1152 t))))
1154 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1155 (or job-name (setq job-name 'ediff-merge-buffers))
1156 (ediff-buffers-internal
1157 buffer-A buffer-B nil startup-hooks job-name merge-buffer-file))
1159 ;;;###autoload
1160 (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
1161 &optional
1162 startup-hooks
1163 job-name
1164 ;; MERGE-BUFFER-FILE is the
1165 ;; file to be associated
1166 ;; with the merge buffer
1167 merge-buffer-file)
1168 "Merge buffers with ancestor."
1169 (interactive
1170 (let (bf bff)
1171 (list (setq bf (read-buffer "Buffer A to merge: "
1172 (ediff-other-buffer "") t))
1173 (setq bff (read-buffer "Buffer B to merge: "
1174 (progn
1175 ;; realign buffers so that two visible
1176 ;; bufs will be at the top
1177 (save-window-excursion (other-window 1))
1178 (ediff-other-buffer bf))
1180 (read-buffer "Ancestor buffer: "
1181 (progn
1182 ;; realign buffers so that three visible
1183 ;; bufs will be at the top
1184 (save-window-excursion (other-window 1))
1185 (ediff-other-buffer (list bf bff)))
1189 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1190 (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor))
1191 (ediff-buffers-internal
1192 buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file))
1195 ;;;###autoload
1196 (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file)
1197 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
1198 "Run Ediff by merging two revisions of a file.
1199 The file is the optional FILE argument or the file visited by the current
1200 buffer."
1201 (interactive)
1202 (if (stringp file) (find-file file))
1203 (let (rev1 rev2)
1204 (setq rev1
1205 (read-string
1206 (format
1207 "Version 1 to merge (default: %s's working version): "
1208 (if (stringp file)
1209 (file-name-nondirectory file) "current buffer")))
1210 rev2
1211 (read-string
1212 (format
1213 "Version 2 to merge (default: %s): "
1214 (if (stringp file)
1215 (file-name-nondirectory file) "current buffer"))))
1216 (ediff-load-version-control)
1217 ;; ancestor-revision=nil
1218 (funcall
1219 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1220 rev1 rev2 nil startup-hooks merge-buffer-file)))
1223 ;;;###autoload
1224 (defun ediff-merge-revisions-with-ancestor (&optional
1225 file startup-hooks
1226 ;; MERGE-BUFFER-FILE is the file to
1227 ;; be associated with the merge
1228 ;; buffer
1229 merge-buffer-file)
1230 "Run Ediff by merging two revisions of a file with a common ancestor.
1231 The file is the optional FILE argument or the file visited by the current
1232 buffer."
1233 (interactive)
1234 (if (stringp file) (find-file file))
1235 (let (rev1 rev2 ancestor-rev)
1236 (setq rev1
1237 (read-string
1238 (format
1239 "Version 1 to merge (default: %s's working version): "
1240 (if (stringp file)
1241 (file-name-nondirectory file) "current buffer")))
1242 rev2
1243 (read-string
1244 (format
1245 "Version 2 to merge (default: %s): "
1246 (if (stringp file)
1247 (file-name-nondirectory file) "current buffer")))
1248 ancestor-rev
1249 (read-string
1250 (format
1251 "Ancestor version (default: %s's base revision): "
1252 (if (stringp file)
1253 (file-name-nondirectory file) "current buffer"))))
1254 (ediff-load-version-control)
1255 (funcall
1256 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1257 rev1 rev2 ancestor-rev startup-hooks merge-buffer-file)))
1259 ;; MK: Check. This function doesn't seem to be used any more by pcvs or pcl-cvs
1260 ;;;###autoload
1261 (defun run-ediff-from-cvs-buffer (pos)
1262 "Run Ediff-merge on appropriate revisions of the selected file.
1263 First run after `M-x cvs-update'. Then place the cursor on a line describing a
1264 file and then run `run-ediff-from-cvs-buffer'."
1265 (interactive "d")
1266 (ediff-load-version-control)
1267 (let ((tin (tin-locate cvs-cookie-handle pos)))
1268 (if tin
1269 (cvs-run-ediff-on-file-descriptor tin)
1270 (error "There is no file to merge"))))
1273 ;;; Apply patch
1275 ;;;###autoload
1276 (defun ediff-patch-file (&optional arg patch-buf)
1277 "Run Ediff by patching SOURCE-FILENAME.
1278 If optional PATCH-BUF is given, use the patch in that buffer
1279 and don't ask the user.
1280 If prefix argument, then: if even argument, assume that the patch is in a
1281 buffer. If odd -- assume it is in a file."
1282 (interactive "P")
1283 (let (source-dir source-file)
1284 (require 'ediff-ptch)
1285 (setq patch-buf
1286 (ediff-get-patch-buffer
1287 (if arg (prefix-numeric-value arg)) patch-buf))
1288 (setq source-dir (cond (ediff-use-last-dir ediff-last-dir-patch)
1289 ((and (not ediff-patch-default-directory)
1290 (buffer-file-name patch-buf))
1291 (file-name-directory
1292 (expand-file-name
1293 (buffer-file-name patch-buf))))
1294 (t default-directory)))
1295 (setq source-file
1296 (read-file-name
1297 "File to patch (directory, if multifile patch): "
1298 ;; use an explicit initial file
1299 source-dir nil nil (ediff-get-default-file-name)))
1300 (ediff-dispatch-file-patching-job patch-buf source-file)))
1302 ;;;###autoload
1303 (defun ediff-patch-buffer (&optional arg patch-buf)
1304 "Run Ediff by patching BUFFER-NAME.
1305 Without prefix argument: asks if the patch is in some buffer and prompts for
1306 the buffer or a file, depending on the answer.
1307 With prefix arg=1: assumes the patch is in a file and prompts for the file.
1308 With prefix arg=2: assumes the patch is in a buffer and prompts for the buffer."
1309 (interactive "P")
1310 (require 'ediff-ptch)
1311 (setq patch-buf
1312 (ediff-get-patch-buffer
1313 (if arg (prefix-numeric-value arg)) patch-buf))
1314 (ediff-patch-buffer-internal
1315 patch-buf
1316 (read-buffer
1317 "Which buffer to patch? "
1318 (current-buffer))))
1321 ;;;###autoload
1322 (defalias 'epatch 'ediff-patch-file)
1323 ;;;###autoload
1324 (defalias 'epatch-buffer 'ediff-patch-buffer)
1329 ;;; Versions Control functions
1331 ;;;###autoload
1332 (defun ediff-revision (&optional file startup-hooks)
1333 "Run Ediff by comparing versions of a file.
1334 The file is an optional FILE argument or the file entered at the prompt.
1335 Default: the file visited by the current buffer.
1336 Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
1337 ;; if buffer is non-nil, use that buffer instead of the current buffer
1338 (interactive "P")
1339 (if (not (stringp file))
1340 (setq file
1341 (ediff-read-file-name "Compare revisions for file"
1342 (if ediff-use-last-dir
1343 ediff-last-dir-A
1344 default-directory)
1345 (ediff-get-default-file-name)
1346 'no-dirs)))
1347 (find-file file)
1348 (if (and (buffer-modified-p)
1349 (y-or-n-p (message "Buffer %s is modified. Save buffer? "
1350 (buffer-name))))
1351 (save-buffer (current-buffer)))
1352 (let (rev1 rev2)
1353 (setq rev1
1354 (read-string
1355 (format "Version 1 to compare (default: %s's working version): "
1356 (file-name-nondirectory file)))
1357 rev2
1358 (read-string
1359 (format "Version 2 to compare (default: %s): "
1360 (file-name-nondirectory file))))
1361 (ediff-load-version-control)
1362 (funcall
1363 (intern (format "ediff-%S-internal" ediff-version-control-package))
1364 rev1 rev2 startup-hooks)
1368 ;;;###autoload
1369 (defalias 'erevision 'ediff-revision)
1372 ;; Test if version control package is loaded and load if not
1373 ;; Is SILENT is non-nil, don't report error if package is not found.
1374 (defun ediff-load-version-control (&optional silent)
1375 (require 'ediff-vers)
1376 (or (featurep ediff-version-control-package)
1377 (if (locate-library (symbol-name ediff-version-control-package))
1378 (progn
1379 (message "") ; kill the message from `locate-library'
1380 (require ediff-version-control-package))
1381 (or silent
1382 (error "Version control package %S.el not found. Use vc.el instead"
1383 ediff-version-control-package)))))
1386 ;;;###autoload
1387 (defun ediff-version ()
1388 "Return string describing the version of Ediff.
1389 When called interactively, displays the version."
1390 (interactive)
1391 (if (interactive-p)
1392 (message (ediff-version))
1393 (format "Ediff %s of %s" ediff-version ediff-date)))
1396 ;;;###autoload
1397 (defun ediff-documentation (&optional node)
1398 "Display Ediff's manual.
1399 With optional NODE, goes to that node."
1400 (interactive)
1401 (let ((ctl-window ediff-control-window)
1402 (ctl-buf ediff-control-buffer))
1404 (ediff-skip-unsuitable-frames)
1405 (condition-case nil
1406 (progn
1407 (pop-to-buffer (get-buffer-create "*info*"))
1408 (info (if ediff-xemacs-p "ediff.info" "ediff"))
1409 (if node
1410 (Info-goto-node node)
1411 (message "Type `i' to search for a specific topic"))
1412 (raise-frame (selected-frame)))
1413 (error (beep 1)
1414 (with-output-to-temp-buffer ediff-msg-buffer
1415 (ediff-with-current-buffer standard-output
1416 (fundamental-mode))
1417 (princ ediff-BAD-INFO))
1418 (if (window-live-p ctl-window)
1419 (progn
1420 (select-window ctl-window)
1421 (set-window-buffer ctl-window ctl-buf)))))))
1426 ;;; Local Variables:
1427 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1428 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1429 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1430 ;;; End:
1432 (require 'ediff-util)
1434 (run-hooks 'ediff-load-hook)
1436 ;;; ediff.el ends here