(ps-print-region-function): Fix :type.
[emacs.git] / lisp / ediff.el
blob5fd8e67ff255ec780fe2ce6f41152bd88d286ac1
1 ;;; ediff.el --- a comprehensive visual interface to diff & patch
3 ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
6 ;; Created: February 2, 1994
7 ;; Keywords: comparing, merging, patching, tools, unix
9 (defconst ediff-version "2.75" "The current version of Ediff")
10 (defconst ediff-date "January 19, 2001" "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)))
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" dir-A
203 (ediff-get-default-file-name)))
204 (ediff-read-file-name "File B to compare"
205 (setq dir-B
206 (if ediff-use-last-dir
207 ediff-last-dir-B
208 (file-name-directory f)))
209 (progn
210 (setq file-name-history
211 (cons (ediff-abbreviate-file-name
212 (expand-file-name
213 (file-name-nondirectory f)
214 dir-B))
215 file-name-history))
216 (ediff-get-default-file-name f 1)))
218 (ediff-files-internal file-A
219 (if (file-directory-p file-B)
220 (expand-file-name
221 (file-name-nondirectory file-A) file-B)
222 file-B)
223 nil ; file-C
224 startup-hooks
225 'ediff-files))
227 ;;;###autoload
228 (defun ediff-files3 (file-A file-B file-C &optional startup-hooks)
229 "Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
230 (interactive
231 (let ((dir-A (if ediff-use-last-dir
232 ediff-last-dir-A
233 default-directory))
234 dir-B dir-C f ff)
235 (list (setq f (ediff-read-file-name
236 "File A to compare" dir-A
237 (ediff-get-default-file-name)))
238 (setq ff (ediff-read-file-name "File B to compare"
239 (setq dir-B
240 (if ediff-use-last-dir
241 ediff-last-dir-B
242 (file-name-directory f)))
243 (progn
244 (setq file-name-history
245 (cons
246 (ediff-abbreviate-file-name
247 (expand-file-name
248 (file-name-nondirectory f)
249 dir-B))
250 file-name-history))
251 (ediff-get-default-file-name f 1))))
252 (ediff-read-file-name "File C to compare"
253 (setq dir-C (if ediff-use-last-dir
254 ediff-last-dir-C
255 (file-name-directory ff)))
256 (progn
257 (setq file-name-history
258 (cons (ediff-abbreviate-file-name
259 (expand-file-name
260 (file-name-nondirectory ff)
261 dir-C))
262 file-name-history))
263 (ediff-get-default-file-name ff 2)))
265 (ediff-files-internal file-A
266 (if (file-directory-p file-B)
267 (expand-file-name
268 (file-name-nondirectory file-A) file-B)
269 file-B)
270 (if (file-directory-p file-C)
271 (expand-file-name
272 (file-name-nondirectory file-A) file-C)
273 file-C)
274 startup-hooks
275 'ediff-files3))
277 ;;;###autoload
278 (defalias 'ediff3 'ediff-files3)
281 ;; Visit FILE and arrange its buffer to Ediff's liking.
282 ;; FILE is actually a variable symbol that must contain a true file name.
283 ;; BUFFER-NAME is a variable symbol, which will get the buffer object into
284 ;; which FILE is read.
285 ;; LAST-DIR is the directory variable symbol where FILE's
286 ;; directory name should be returned. HOOKS-VAR is a variable symbol that will
287 ;; be assigned the hook to be executed after `ediff-startup' is finished.
288 ;; `ediff-find-file' arranges that the temp files it might create will be
289 ;; deleted.
290 (defun ediff-find-file (file-var buffer-name &optional last-dir hooks-var)
291 (let* ((file (symbol-value file-var))
292 (file-magic (ediff-filename-magic-p file))
293 (temp-file-name-prefix (file-name-nondirectory file)))
294 (cond ((not (file-readable-p file))
295 (error "File `%s' does not exist or is not readable" file))
296 ((file-directory-p file)
297 (error "File `%s' is a directory" file)))
299 ;; some of the commands, below, require full file name
300 (setq file (expand-file-name file))
302 ;; Record the directory of the file
303 (if last-dir
304 (set last-dir (expand-file-name (file-name-directory file))))
306 ;; Setup the buffer
307 (set buffer-name (find-file-noselect file))
309 (ediff-with-current-buffer (symbol-value buffer-name)
310 (widen) ; Make sure the entire file is seen
311 (cond (file-magic ; file has a handler, such as jka-compr-handler or
312 ;;; ange-ftp-hook-function--arrange for temp file
313 (ediff-verify-file-buffer 'magic)
314 (setq file
315 (ediff-make-temp-file
316 (current-buffer) temp-file-name-prefix))
317 (set hooks-var (cons `(lambda () (delete-file ,file))
318 (symbol-value hooks-var))))
319 ;; file processed via auto-mode-alist, a la uncompress.el
320 ((not (equal (file-truename file)
321 (file-truename (buffer-file-name))))
322 (setq file
323 (ediff-make-temp-file
324 (current-buffer) temp-file-name-prefix))
325 (set hooks-var (cons `(lambda () (delete-file ,file))
326 (symbol-value hooks-var))))
327 (t ;; plain file---just check that the file matches the buffer
328 (ediff-verify-file-buffer))))
329 (set file-var file)))
331 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
332 (defun ediff-files-internal (file-A file-B file-C startup-hooks job-name
333 &optional merge-buffer-file)
334 (let (buf-A buf-B buf-C)
335 (message "Reading file %s ... " file-A)
336 ;;(sit-for 0)
337 (ediff-find-file 'file-A 'buf-A 'ediff-last-dir-A 'startup-hooks)
338 (message "Reading file %s ... " file-B)
339 ;;(sit-for 0)
340 (ediff-find-file 'file-B 'buf-B 'ediff-last-dir-B 'startup-hooks)
341 (if (stringp file-C)
342 (progn
343 (message "Reading file %s ... " file-C)
344 ;;(sit-for 0)
345 (ediff-find-file
346 'file-C 'buf-C
347 (if (eq job-name 'ediff-merge-files-with-ancestor)
348 'ediff-last-dir-ancestor 'ediff-last-dir-C)
349 'startup-hooks)))
350 (ediff-setup buf-A file-A
351 buf-B file-B
352 buf-C file-C
353 startup-hooks
354 (list (cons 'ediff-job-name job-name))
355 merge-buffer-file)))
358 ;;;###autoload
359 (defalias 'ediff 'ediff-files)
362 ;;;###autoload
363 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name)
364 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
365 (interactive
366 (let (bf)
367 (list (setq bf (read-buffer "Buffer A to compare: "
368 (ediff-other-buffer "") t))
369 (read-buffer "Buffer B to compare: "
370 (progn
371 ;; realign buffers so that two visible bufs will be
372 ;; at the top
373 (save-window-excursion (other-window 1))
374 (ediff-other-buffer bf))
375 t))))
376 (or job-name (setq job-name 'ediff-buffers))
377 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name))
379 ;;;###autoload
380 (defalias 'ebuffers 'ediff-buffers)
383 ;;;###autoload
384 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
385 &optional startup-hooks job-name)
386 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
387 (interactive
388 (let (bf bff)
389 (list (setq bf (read-buffer "Buffer A to compare: "
390 (ediff-other-buffer "") t))
391 (setq bff (read-buffer "Buffer B to compare: "
392 (progn
393 ;; realign buffers so that two visible
394 ;; bufs will be at the top
395 (save-window-excursion (other-window 1))
396 (ediff-other-buffer bf))
398 (read-buffer "Buffer C to compare: "
399 (progn
400 ;; realign buffers so that three visible
401 ;; bufs will be at the top
402 (save-window-excursion (other-window 1))
403 (ediff-other-buffer (list bf bff)))
406 (or job-name (setq job-name 'ediff-buffers3))
407 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name))
409 ;;;###autoload
410 (defalias 'ebuffers3 'ediff-buffers3)
414 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
415 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
416 &optional merge-buffer-file)
417 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
418 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
419 (buf-C-is-alive (ediff-buffer-live-p buf-C))
420 (buf-C-file-name (if buf-C-is-alive
421 (buffer-file-name (get-buffer buf-B))))
422 file-A file-B file-C)
423 (if (not (ediff-buffer-live-p buf-A))
424 (error "Buffer %S doesn't exist" buf-A))
425 (if (not (ediff-buffer-live-p buf-B))
426 (error "Buffer %S doesn't exist" buf-B))
427 (let ((ediff-job-name job-name))
428 (if (and ediff-3way-comparison-job
429 (not buf-C-is-alive))
430 (error "Buffer %S doesn't exist" buf-C)))
431 (if (stringp buf-A-file-name)
432 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
433 (if (stringp buf-B-file-name)
434 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
435 (if (stringp buf-C-file-name)
436 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
438 (setq file-A (ediff-make-temp-file buf-A buf-A-file-name)
439 file-B (ediff-make-temp-file buf-B buf-B-file-name))
440 (if buf-C-is-alive
441 (setq file-C (ediff-make-temp-file buf-C buf-C-file-name)))
443 (ediff-setup (get-buffer buf-A) file-A
444 (get-buffer buf-B) file-B
445 (if buf-C-is-alive (get-buffer buf-C))
446 file-C
447 (cons `(lambda ()
448 (delete-file ,file-A)
449 (delete-file ,file-B)
450 (if (stringp ,file-C) (delete-file ,file-C)))
451 startup-hooks)
452 (list (cons 'ediff-job-name job-name))
453 merge-buffer-file)))
456 ;;; Directory and file group operations
458 ;; Get appropriate default name for directory:
459 ;; If ediff-use-last-dir, use ediff-last-dir-A.
460 ;; In dired mode, use the directory that is under the point (if any);
461 ;; otherwise, use default-directory
462 (defun ediff-get-default-directory-name ()
463 (cond (ediff-use-last-dir ediff-last-dir-A)
464 ((eq major-mode 'dired-mode)
465 (let ((f (dired-get-filename nil 'noerror)))
466 (if (and (stringp f) (file-directory-p f))
468 default-directory)))
469 (t default-directory)))
472 ;;;###autoload
473 (defun ediff-directories (dir1 dir2 regexp)
474 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
475 the same name in both. The third argument, REGEXP, is a regular expression
476 that can be used to filter out certain file names."
477 (interactive
478 (let ((dir-A (ediff-get-default-directory-name))
480 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
481 (ediff-read-file-name "Directory B to compare:"
482 (if ediff-use-last-dir
483 ediff-last-dir-B
484 (ediff-strip-last-dir f))
485 nil)
486 (read-string "Filter through regular expression: "
487 nil 'ediff-filtering-regexp-history)
489 (ediff-directories-internal
490 dir1 dir2 nil regexp 'ediff-files 'ediff-directories
493 ;;;###autoload
494 (defalias 'edirs 'ediff-directories)
497 ;;;###autoload
498 (defun ediff-directory-revisions (dir1 regexp)
499 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
500 The second argument, REGEXP, is a regular expression that filters the file
501 names. Only the files that are under revision control are taken into account."
502 (interactive
503 (let ((dir-A (ediff-get-default-directory-name)))
504 (list (ediff-read-file-name
505 "Directory to compare with revision:" dir-A nil)
506 (read-string "Filter through regular expression: "
507 nil 'ediff-filtering-regexp-history)
509 (ediff-directory-revisions-internal
510 dir1 regexp 'ediff-revision 'ediff-directory-revisions
513 ;;;###autoload
514 (defalias 'edir-revisions 'ediff-directory-revisions)
517 ;;;###autoload
518 (defun ediff-directories3 (dir1 dir2 dir3 regexp)
519 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
520 have the same name in all three. The last argument, REGEXP, is a regular
521 expression that can be used to filter out certain file names."
522 (interactive
523 (let ((dir-A (ediff-get-default-directory-name))
525 (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
526 (setq f (ediff-read-file-name "Directory B to compare:"
527 (if ediff-use-last-dir
528 ediff-last-dir-B
529 (ediff-strip-last-dir f))
530 nil))
531 (ediff-read-file-name "Directory C to compare:"
532 (if ediff-use-last-dir
533 ediff-last-dir-C
534 (ediff-strip-last-dir f))
535 nil)
536 (read-string "Filter through regular expression: "
537 nil 'ediff-filtering-regexp-history)
539 (ediff-directories-internal
540 dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3
543 ;;;###autoload
544 (defalias 'edirs3 'ediff-directories3)
546 ;;;###autoload
547 (defun ediff-merge-directories (dir1 dir2 regexp &optional merge-autostore-dir)
548 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
549 the same name in both. The third argument, REGEXP, is a regular expression
550 that can be used to filter out certain file names."
551 (interactive
552 (let ((dir-A (ediff-get-default-directory-name))
554 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
555 (ediff-read-file-name "Directory B to merge:"
556 (if ediff-use-last-dir
557 ediff-last-dir-B
558 (ediff-strip-last-dir f))
559 nil)
560 (read-string "Filter through regular expression: "
561 nil 'ediff-filtering-regexp-history)
563 (ediff-directories-internal
564 dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories
565 nil merge-autostore-dir
568 ;;;###autoload
569 (defalias 'edirs-merge 'ediff-merge-directories)
571 ;;;###autoload
572 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
573 &optional
574 merge-autostore-dir)
575 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
576 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
577 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
578 without ancestor. The fourth argument, REGEXP, is a regular expression that
579 can be used to filter out certain file names."
580 (interactive
581 (let ((dir-A (ediff-get-default-directory-name))
583 (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
584 (setq f (ediff-read-file-name "Directory B to merge:"
585 (if ediff-use-last-dir
586 ediff-last-dir-B
587 (ediff-strip-last-dir f))
588 nil))
589 (ediff-read-file-name "Ancestor directory:"
590 (if ediff-use-last-dir
591 ediff-last-dir-C
592 (ediff-strip-last-dir f))
593 nil)
594 (read-string "Filter through regular expression: "
595 nil 'ediff-filtering-regexp-history)
597 (ediff-directories-internal
598 dir1 dir2 ancestor-dir regexp
599 'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor
600 nil merge-autostore-dir
603 ;;;###autoload
604 (defun ediff-merge-directory-revisions (dir1 regexp
605 &optional merge-autostore-dir)
606 "Run Ediff on a directory, DIR1, merging its files with their revisions.
607 The second argument, REGEXP, is a regular expression that filters the file
608 names. Only the files that are under revision control are taken into account."
609 (interactive
610 (let ((dir-A (ediff-get-default-directory-name)))
611 (list (ediff-read-file-name
612 "Directory to merge with revisions:" dir-A nil)
613 (read-string "Filter through regular expression: "
614 nil 'ediff-filtering-regexp-history)
616 (ediff-directory-revisions-internal
617 dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions
618 nil merge-autostore-dir
621 ;;;###autoload
622 (defalias 'edir-merge-revisions 'ediff-merge-directory-revisions)
624 ;;;###autoload
625 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
626 &optional
627 merge-autostore-dir)
628 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
629 The second argument, REGEXP, is a regular expression that filters the file
630 names. Only the files that are under revision control are taken into account."
631 (interactive
632 (let ((dir-A (ediff-get-default-directory-name)))
633 (list (ediff-read-file-name
634 "Directory to merge with revisions and ancestors:" dir-A nil)
635 (read-string "Filter through regular expression: "
636 nil 'ediff-filtering-regexp-history)
638 (ediff-directory-revisions-internal
639 dir1 regexp 'ediff-merge-revisions-with-ancestor
640 'ediff-merge-directory-revisions-with-ancestor
641 nil merge-autostore-dir
644 ;;;###autoload
645 (defalias
646 'edir-merge-revisions-with-ancestor
647 'ediff-merge-directory-revisions-with-ancestor)
649 ;;;###autoload
650 (defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor)
652 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
653 ;; on a pair of directories (three directories, in case of ancestor).
654 ;; The third argument, REGEXP, is a regular expression that can be used to
655 ;; filter out certain file names.
656 ;; JOBNAME is the symbol indicating the meta-job to be performed.
657 ;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
658 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
659 &optional startup-hooks
660 merge-autostore-dir)
661 ;; ediff-read-file-name is set to attach a previously entered file name if
662 ;; the currently entered file is a directory. This code takes care of that.
663 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1))
664 dir2 (if (file-directory-p dir2) dir2 (file-name-directory dir2)))
666 (if (stringp dir3)
667 (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))
669 (cond ((string= dir1 dir2)
670 (error "Directories A and B are the same: %s" dir1))
671 ((and (eq jobname 'ediff-directories3)
672 (string= dir1 dir3))
673 (error "Directories A and C are the same: %s" dir1))
674 ((and (eq jobname 'ediff-directories3)
675 (string= dir2 dir3))
676 (error "Directories B and C are the same: %s" dir1)))
678 (if merge-autostore-dir
679 (or (stringp merge-autostore-dir)
680 (error "%s: Directory for storing merged files must be a string"
681 jobname)))
682 (let (diffs ; var where ediff-intersect-directories returns the diff list
683 file-list meta-buf)
684 (if (and ediff-autostore-merges
685 (ediff-merge-metajob jobname)
686 (not merge-autostore-dir))
687 (setq merge-autostore-dir
688 (read-file-name "Save merged files in directory: "
689 (if ediff-use-last-dir
690 ediff-last-merge-autostore-dir
691 (ediff-strip-last-dir dir1))
693 'must-match)))
694 ;; verify we are not merging into an orig directory
695 (if merge-autostore-dir
696 (cond ((and (stringp dir1) (string= merge-autostore-dir dir1))
697 (or (y-or-n-p
698 "Directory for saving merged files = Directory A. Sure? ")
699 (error "Directory merge aborted")))
700 ((and (stringp dir2) (string= merge-autostore-dir dir2))
701 (or (y-or-n-p
702 "Directory for saving merged files = Directory B. Sure? ")
703 (error "Directory merge aborted")))
704 ((and (stringp dir3) (string= merge-autostore-dir dir3))
705 (or (y-or-n-p
706 "Directory for saving merged files = Ancestor Directory. Sure? ")
707 (error "Directory merge aborted")))))
709 (setq file-list (ediff-intersect-directories
710 jobname 'diffs
711 regexp dir1 dir2 dir3 merge-autostore-dir))
712 (setq startup-hooks
713 ;; this sets various vars in the meta buffer inside
714 ;; ediff-prepare-meta-buffer
715 (cons `(lambda ()
716 ;; tell what to do if the user clicks on a session record
717 (setq ediff-session-action-function (quote ,action))
718 ;; set ediff-dir-difference-list
719 (setq ediff-dir-difference-list (quote ,diffs)))
720 startup-hooks))
721 (setq meta-buf (ediff-prepare-meta-buffer
722 'ediff-filegroup-action
723 file-list
724 "*Ediff Session Group Panel"
725 'ediff-redraw-directory-group-buffer
726 jobname
727 startup-hooks))
728 (ediff-show-meta-buffer meta-buf)
731 ;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
732 ;; files
733 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
734 &optional startup-hooks
735 merge-autostore-dir)
736 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)))
738 (if merge-autostore-dir
739 (or (stringp merge-autostore-dir)
740 (error "%S: Directory for storing merged files must be a string"
741 jobname)))
742 (let (file-list meta-buf)
743 (if (and ediff-autostore-merges
744 (ediff-merge-metajob jobname)
745 (not merge-autostore-dir))
746 (setq merge-autostore-dir
747 (read-file-name "Save merged files in directory: "
748 (if ediff-use-last-dir
749 ediff-last-merge-autostore-dir
750 (ediff-strip-last-dir dir1))
752 'must-match)))
753 ;; verify merge-autostore-dir != dir1
754 (if (and merge-autostore-dir
755 (stringp dir1)
756 (string= merge-autostore-dir dir1))
757 (or (y-or-n-p
758 "Directory for saving merged file = directory A. Sure? ")
759 (error "Merge of directory revisions aborted")))
761 (setq file-list
762 (ediff-get-directory-files-under-revision
763 jobname regexp dir1 merge-autostore-dir))
764 (setq startup-hooks
765 ;; this sets various vars in the meta buffer inside
766 ;; ediff-prepare-meta-buffer
767 (cons `(lambda ()
768 ;; tell what to do if the user clicks on a session record
769 (setq ediff-session-action-function (quote ,action)))
770 startup-hooks))
771 (setq meta-buf (ediff-prepare-meta-buffer
772 'ediff-filegroup-action
773 file-list
774 "*Ediff Session Group Panel"
775 'ediff-redraw-directory-group-buffer
776 jobname
777 startup-hooks))
778 (ediff-show-meta-buffer meta-buf)
782 ;;; Compare regions and windows
784 ;;;###autoload
785 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks)
786 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
787 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
788 follows:
789 If WIND-A is nil, use selected window.
790 If WIND-B is nil, use window next to WIND-A."
791 (interactive "P")
792 (ediff-windows dumb-mode wind-A wind-B
793 startup-hooks 'ediff-windows-wordwise 'word-mode))
795 ;;;###autoload
796 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks)
797 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
798 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
799 follows:
800 If WIND-A is nil, use selected window.
801 If WIND-B is nil, use window next to WIND-A."
802 (interactive "P")
803 (ediff-windows dumb-mode wind-A wind-B
804 startup-hooks 'ediff-windows-linewise nil))
806 ;; Compare WIND-A and WIND-B, which are selected by clicking.
807 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
808 ;; works as follows:
809 ;; If WIND-A is nil, use selected window.
810 ;; If WIND-B is nil, use window next to WIND-A.
811 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode)
812 (if (or dumb-mode (not (ediff-window-display-p)))
813 (setq wind-A (ediff-get-next-window wind-A nil)
814 wind-B (ediff-get-next-window wind-B wind-A))
815 (setq wind-A (ediff-get-window-by-clicking wind-A nil 1)
816 wind-B (ediff-get-window-by-clicking wind-B wind-A 2)))
818 (let ((buffer-A (window-buffer wind-A))
819 (buffer-B (window-buffer wind-B))
820 beg-A end-A beg-B end-B)
822 (save-excursion
823 (save-window-excursion
824 (sit-for 0) ; sync before using window-start/end -- a precaution
825 (select-window wind-A)
826 (setq beg-A (window-start)
827 end-A (window-end))
828 (select-window wind-B)
829 (setq beg-B (window-start)
830 end-B (window-end))))
831 (ediff-regions-internal
832 buffer-A beg-A end-A buffer-B beg-B end-B
833 startup-hooks job-name word-mode nil)))
835 ;;;###autoload
836 (defun ediff-regions-wordwise (buffer-A buffer-B &optional startup-hooks)
837 "Run Ediff on a pair of regions in two different buffers.
838 Regions \(i.e., point and mark\) are assumed to be set in advance.
839 This function is effective only for relatively small regions, up to 200
840 lines. For large regions, use `ediff-regions-linewise'."
841 (interactive
842 (let (bf)
843 (list (setq bf (read-buffer "Region's A buffer: "
844 (ediff-other-buffer "") t))
845 (read-buffer "Region's B buffer: "
846 (progn
847 ;; realign buffers so that two visible bufs will be
848 ;; at the top
849 (save-window-excursion (other-window 1))
850 (ediff-other-buffer bf))
851 t))))
852 (if (not (ediff-buffer-live-p buffer-A))
853 (error "Buffer %S doesn't exist" buffer-A))
854 (if (not (ediff-buffer-live-p buffer-B))
855 (error "Buffer %S doesn't exist" buffer-B))
858 (let (reg-A-beg reg-A-end reg-B-beg reg-B-end)
859 (save-excursion
860 (set-buffer buffer-A)
861 (setq reg-A-beg (region-beginning)
862 reg-A-end (region-end))
863 (set-buffer buffer-B)
864 (setq reg-B-beg (region-beginning)
865 reg-B-end (region-end)))
867 (ediff-regions-internal
868 (get-buffer buffer-A) reg-A-beg reg-A-end
869 (get-buffer buffer-B) reg-B-beg reg-B-end
870 startup-hooks 'ediff-regions-wordwise 'word-mode nil)))
872 ;;;###autoload
873 (defun ediff-regions-linewise (buffer-A buffer-B &optional startup-hooks)
874 "Run Ediff on a pair of regions in two different buffers.
875 Regions \(i.e., point and mark\) are assumed to be set in advance.
876 Each region is enlarged to contain full lines.
877 This function is effective for large regions, over 100-200
878 lines. For small regions, use `ediff-regions-wordwise'."
879 (interactive
880 (let (bf)
881 (list (setq bf (read-buffer "Region A's buffer: "
882 (ediff-other-buffer "") t))
883 (read-buffer "Region B's buffer: "
884 (progn
885 ;; realign buffers so that two visible bufs will be
886 ;; at the top
887 (save-window-excursion (other-window 1))
888 (ediff-other-buffer bf))
889 t))))
890 (if (not (ediff-buffer-live-p buffer-A))
891 (error "Buffer %S doesn't exist" buffer-A))
892 (if (not (ediff-buffer-live-p buffer-B))
893 (error "Buffer %S doesn't exist" buffer-B))
895 (let (reg-A-beg reg-A-end reg-B-beg reg-B-end)
896 (save-excursion
897 (set-buffer buffer-A)
898 (setq reg-A-beg (region-beginning)
899 reg-A-end (region-end))
900 ;; enlarge the region to hold full lines
901 (goto-char reg-A-beg)
902 (beginning-of-line)
903 (setq reg-A-beg (point))
904 (goto-char reg-A-end)
905 (end-of-line)
906 (or (eobp) (forward-char)) ; include the newline char
907 (setq reg-A-end (point))
909 (set-buffer buffer-B)
910 (setq reg-B-beg (region-beginning)
911 reg-B-end (region-end))
912 ;; enlarge the region to hold full lines
913 (goto-char reg-B-beg)
914 (beginning-of-line)
915 (setq reg-B-beg (point))
916 (goto-char reg-B-end)
917 (end-of-line)
918 (or (eobp) (forward-char)) ; include the newline char
919 (setq reg-B-end (point))
920 ) ; save excursion
922 (ediff-regions-internal
923 (get-buffer buffer-A) reg-A-beg reg-A-end
924 (get-buffer buffer-B) reg-B-beg reg-B-end
925 startup-hooks 'ediff-regions-linewise nil nil))) ; no word mode
927 ;; compare region beg-A to end-A of buffer-A
928 ;; to regions beg-B -- end-B in buffer-B.
929 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
930 startup-hooks job-name word-mode
931 setup-parameters)
932 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
933 overl-A overl-B
934 file-A file-B)
936 ;; in case beg/end-A/B aren't markers--make them into markers
937 (ediff-with-current-buffer buffer-A
938 (setq beg-A (move-marker (make-marker) beg-A)
939 end-A (move-marker (make-marker) end-A)))
940 (ediff-with-current-buffer buffer-B
941 (setq beg-B (move-marker (make-marker) beg-B)
942 end-B (move-marker (make-marker) end-B)))
944 (if (and (eq buffer-A buffer-B)
945 (or (and (< beg-A end-B) (<= beg-B beg-A)) ; b-B b-A e-B
946 (and (< beg-B end-A) (<= end-A end-B)))) ; b-B e-A e-B
947 (progn
948 (with-output-to-temp-buffer ediff-msg-buffer
949 (ediff-with-current-buffer standard-output
950 (fundamental-mode))
951 (princ "
952 You have requested to compare overlapping regions of the same buffer.
954 In this case, Ediff's highlighting may be confusing---in the same window,
955 you may see highlighted regions that belong to different regions.
957 Continue anyway? (y/n) "))
959 (if (y-or-n-p "Continue anyway? ")
961 (error "%S aborted" job-name))))
963 ;; make file-A
964 (if word-mode
965 (ediff-wordify beg-A end-A buffer-A tmp-buffer)
966 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer))
967 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
969 ;; make file-B
970 (if word-mode
971 (ediff-wordify beg-B end-B buffer-B tmp-buffer)
972 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer))
973 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
975 (setq overl-A (ediff-make-bullet-proof-overlay beg-A end-A buffer-A))
976 (setq overl-B (ediff-make-bullet-proof-overlay beg-B end-B buffer-B))
977 (ediff-setup buffer-A file-A
978 buffer-B file-B
979 nil nil ; buffer & file C
980 (cons `(lambda ()
981 (delete-file ,file-A)
982 (delete-file ,file-B))
983 startup-hooks)
984 (append
985 (list (cons 'ediff-word-mode word-mode)
986 (cons 'ediff-narrow-bounds (list overl-A overl-B))
987 (cons 'ediff-job-name job-name))
988 setup-parameters))
992 ;;; Merge files and buffers
994 ;;;###autoload
995 (defalias 'ediff-merge 'ediff-merge-files)
997 (defsubst ediff-merge-on-startup ()
998 (ediff-do-merge 0)
999 (ediff-with-current-buffer ediff-buffer-C
1000 (set-buffer-modified-p nil)))
1002 ;;;###autoload
1003 (defun ediff-merge-files (file-A file-B
1004 ;; MERGE-BUFFER-FILE is the file to be
1005 ;; associated with the merge buffer
1006 &optional startup-hooks merge-buffer-file)
1007 "Merge two files without ancestor."
1008 (interactive
1009 (let ((dir-A (if ediff-use-last-dir
1010 ediff-last-dir-A
1011 default-directory))
1012 dir-B f)
1013 (list (setq f (ediff-read-file-name
1014 "File A to merge" dir-A
1015 (ediff-get-default-file-name)))
1016 (ediff-read-file-name "File B to merge"
1017 (setq dir-B
1018 (if ediff-use-last-dir
1019 ediff-last-dir-B
1020 (file-name-directory f)))
1021 (progn
1022 (setq file-name-history
1023 (cons (ediff-abbreviate-file-name
1024 (expand-file-name
1025 (file-name-nondirectory f)
1026 dir-B))
1027 file-name-history))
1028 (ediff-get-default-file-name f 1)))
1030 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1031 (ediff-files-internal file-A
1032 (if (file-directory-p file-B)
1033 (expand-file-name
1034 (file-name-nondirectory file-A) file-B)
1035 file-B)
1036 nil ; file-C
1037 startup-hooks
1038 'ediff-merge-files
1039 merge-buffer-file))
1041 ;;;###autoload
1042 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
1043 &optional
1044 startup-hooks
1045 ;; MERGE-BUFFER-FILE is the file
1046 ;; to be associated with the
1047 ;; merge buffer
1048 merge-buffer-file)
1049 "Merge two files with ancestor."
1050 (interactive
1051 (let ((dir-A (if ediff-use-last-dir
1052 ediff-last-dir-A
1053 default-directory))
1054 dir-B dir-ancestor f ff)
1055 (list (setq f (ediff-read-file-name
1056 "File A to merge" dir-A
1057 (ediff-get-default-file-name)))
1058 (setq ff (ediff-read-file-name "File B to merge"
1059 (setq dir-B
1060 (if ediff-use-last-dir
1061 ediff-last-dir-B
1062 (file-name-directory f)))
1063 (progn
1064 (setq file-name-history
1065 (cons
1066 (ediff-abbreviate-file-name
1067 (expand-file-name
1068 (file-name-nondirectory f)
1069 dir-B))
1070 file-name-history))
1071 (ediff-get-default-file-name f 1))))
1072 (ediff-read-file-name "Ancestor file"
1073 (setq dir-ancestor
1074 (if ediff-use-last-dir
1075 ediff-last-dir-ancestor
1076 (file-name-directory ff)))
1077 (progn
1078 (setq file-name-history
1079 (cons (ediff-abbreviate-file-name
1080 (expand-file-name
1081 (file-name-nondirectory ff)
1082 dir-ancestor))
1083 file-name-history))
1084 (ediff-get-default-file-name ff 2)))
1086 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1087 (ediff-files-internal file-A
1088 (if (file-directory-p file-B)
1089 (expand-file-name
1090 (file-name-nondirectory file-A) file-B)
1091 file-B)
1092 file-ancestor
1093 startup-hooks
1094 'ediff-merge-files-with-ancestor
1095 merge-buffer-file))
1097 ;;;###autoload
1098 (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor)
1100 ;;;###autoload
1101 (defun ediff-merge-buffers (buffer-A buffer-B
1102 &optional
1103 ;; MERGE-BUFFER-FILE is the file to be
1104 ;; associated with the merge buffer
1105 startup-hooks job-name merge-buffer-file)
1106 "Merge buffers without ancestor."
1107 (interactive
1108 (let (bf)
1109 (list (setq bf (read-buffer "Buffer A to merge: "
1110 (ediff-other-buffer "") t))
1111 (read-buffer "Buffer B to merge: "
1112 (progn
1113 ;; realign buffers so that two visible bufs will be
1114 ;; at the top
1115 (save-window-excursion (other-window 1))
1116 (ediff-other-buffer bf))
1117 t))))
1119 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1120 (or job-name (setq job-name 'ediff-merge-buffers))
1121 (ediff-buffers-internal
1122 buffer-A buffer-B nil startup-hooks job-name merge-buffer-file))
1124 ;;;###autoload
1125 (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
1126 &optional
1127 startup-hooks
1128 job-name
1129 ;; MERGE-BUFFER-FILE is the
1130 ;; file to be associated
1131 ;; with the merge buffer
1132 merge-buffer-file)
1133 "Merge buffers with ancestor."
1134 (interactive
1135 (let (bf bff)
1136 (list (setq bf (read-buffer "Buffer A to merge: "
1137 (ediff-other-buffer "") t))
1138 (setq bff (read-buffer "Buffer B to merge: "
1139 (progn
1140 ;; realign buffers so that two visible
1141 ;; bufs will be at the top
1142 (save-window-excursion (other-window 1))
1143 (ediff-other-buffer bf))
1145 (read-buffer "Ancestor buffer: "
1146 (progn
1147 ;; realign buffers so that three visible
1148 ;; bufs will be at the top
1149 (save-window-excursion (other-window 1))
1150 (ediff-other-buffer (list bf bff)))
1154 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1155 (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor))
1156 (ediff-buffers-internal
1157 buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file))
1160 ;;;###autoload
1161 (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file)
1162 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
1163 "Run Ediff by merging two revisions of a file.
1164 The file is the optional FILE argument or the file visited by the current
1165 buffer."
1166 (interactive)
1167 (if (stringp file) (find-file file))
1168 (let (rev1 rev2)
1169 (setq rev1
1170 (read-string
1171 (format
1172 "Version 1 to merge (default: %s's latest version): "
1173 (if (stringp file)
1174 (file-name-nondirectory file) "current buffer")))
1175 rev2
1176 (read-string
1177 (format
1178 "Version 2 to merge (default: %s): "
1179 (if (stringp file)
1180 (file-name-nondirectory file) "current buffer"))))
1181 (ediff-load-version-control)
1182 ;; ancestor-revision=nil
1183 (funcall
1184 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1185 rev1 rev2 nil startup-hooks merge-buffer-file)))
1188 ;;;###autoload
1189 (defun ediff-merge-revisions-with-ancestor (&optional
1190 file startup-hooks
1191 ;; MERGE-BUFFER-FILE is the file to
1192 ;; be associated with the merge
1193 ;; buffer
1194 merge-buffer-file)
1195 "Run Ediff by merging two revisions of a file with a common ancestor.
1196 The file is the the optional FILE argument or the file visited by the current
1197 buffer."
1198 (interactive)
1199 (if (stringp file) (find-file file))
1200 (let (rev1 rev2 ancestor-rev)
1201 (setq rev1
1202 (read-string
1203 (format
1204 "Version 1 to merge (default: %s's latest version): "
1205 (if (stringp file)
1206 (file-name-nondirectory file) "current buffer")))
1207 rev2
1208 (read-string
1209 (format
1210 "Version 2 to merge (default: %s): "
1211 (if (stringp file)
1212 (file-name-nondirectory file) "current buffer")))
1213 ancestor-rev
1214 (read-string
1215 (format
1216 "Ancestor version (default: %s's base revision): "
1217 (if (stringp file)
1218 (file-name-nondirectory file) "current buffer"))))
1219 (ediff-load-version-control)
1220 (funcall
1221 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1222 rev1 rev2 ancestor-rev startup-hooks merge-buffer-file)))
1224 ;;;###autoload
1225 (defun run-ediff-from-cvs-buffer (pos)
1226 "Run Ediff-merge on appropriate revisions of the selected file.
1227 First run after `M-x cvs-update'. Then place the cursor on a line describing a
1228 file and then run `run-ediff-from-cvs-buffer'."
1229 (interactive "d")
1230 (ediff-load-version-control)
1231 (let ((tin (tin-locate cvs-cookie-handle pos)))
1232 (if tin
1233 (cvs-run-ediff-on-file-descriptor tin)
1234 (error "There is no file to merge"))))
1237 ;;; Apply patch
1239 ;;;###autoload
1240 (defun ediff-patch-file (&optional arg patch-buf)
1241 "Run Ediff by patching SOURCE-FILENAME.
1242 If optional PATCH-BUF is given, use the patch in that buffer
1243 and don't ask the user.
1244 If prefix argument, then: if even argument, assume that the patch is in a
1245 buffer. If odd -- assume it is in a file."
1246 (interactive "P")
1247 (let (source-dir source-file)
1248 (require 'ediff-ptch)
1249 (setq patch-buf
1250 (ediff-get-patch-buffer
1251 (if arg (prefix-numeric-value arg)) patch-buf))
1252 (setq source-dir (cond (ediff-use-last-dir ediff-last-dir-patch)
1253 ((and (not ediff-patch-default-directory)
1254 (buffer-file-name patch-buf))
1255 (file-name-directory
1256 (expand-file-name
1257 (buffer-file-name patch-buf))))
1258 (t default-directory)))
1259 (setq source-file
1260 (read-file-name
1261 "File to patch (directory, if multifile patch): "
1262 ;; use an explicit initial file
1263 source-dir nil nil (ediff-get-default-file-name)))
1264 (ediff-dispatch-file-patching-job patch-buf source-file)))
1266 ;;;###autoload
1267 (defun ediff-patch-buffer (&optional arg patch-buf)
1268 "Run Ediff by patching BUFFER-NAME.
1269 Without prefix argument: asks if the patch is in some buffer and prompts for
1270 the buffer or a file, depending on the answer.
1271 With prefix arg=1: assumes the patch is in a file and prompts for the file.
1272 With prefix arg=2: assumes the patch is in a buffer and prompts for the buffer."
1273 (interactive "P")
1274 (require 'ediff-ptch)
1275 (setq patch-buf
1276 (ediff-get-patch-buffer
1277 (if arg (prefix-numeric-value arg)) patch-buf))
1278 (ediff-patch-buffer-internal
1279 patch-buf
1280 (read-buffer
1281 "Which buffer to patch? "
1282 (current-buffer))))
1285 ;;;###autoload
1286 (defalias 'epatch 'ediff-patch-file)
1287 ;;;###autoload
1288 (defalias 'epatch-buffer 'ediff-patch-buffer)
1293 ;;; Versions Control functions
1295 ;;;###autoload
1296 (defun ediff-revision (&optional file startup-hooks)
1297 "Run Ediff by comparing versions of a file.
1298 The file is an optional FILE argument or the file entered at the prompt.
1299 Default: the file visited by the current buffer.
1300 Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
1301 ;; if buffer is non-nil, use that buffer instead of the current buffer
1302 (interactive "P")
1303 (if (not (stringp file))
1304 (setq file
1305 (ediff-read-file-name "Compare revisions for file"
1306 (if ediff-use-last-dir
1307 ediff-last-dir-A
1308 default-directory)
1309 (ediff-get-default-file-name))))
1310 (find-file file)
1311 (if (and (buffer-modified-p)
1312 (y-or-n-p (message "Buffer %s is modified. Save buffer? "
1313 (buffer-name))))
1314 (save-buffer (current-buffer)))
1315 (let (rev1 rev2)
1316 (setq rev1
1317 (read-string
1318 (format "Version 1 to compare (default: %s's latest version): "
1319 (file-name-nondirectory file)))
1320 rev2
1321 (read-string
1322 (format "Version 2 to compare (default: %s): "
1323 (file-name-nondirectory file))))
1324 (ediff-load-version-control)
1325 (funcall
1326 (intern (format "ediff-%S-internal" ediff-version-control-package))
1327 rev1 rev2 startup-hooks)
1331 ;;;###autoload
1332 (defalias 'erevision 'ediff-revision)
1335 ;; Test if version control package is loaded and load if not
1336 ;; Is SILENT is non-nil, don't report error if package is not found.
1337 (defun ediff-load-version-control (&optional silent)
1338 (require 'ediff-vers)
1339 (or (featurep ediff-version-control-package)
1340 (if (locate-library (symbol-name ediff-version-control-package))
1341 (progn
1342 (message "") ; kill the message from `locate-library'
1343 (require ediff-version-control-package))
1344 (or silent
1345 (error "Version control package %S.el not found. Use vc.el instead"
1346 ediff-version-control-package)))))
1349 ;;;###autoload
1350 (defun ediff-version ()
1351 "Return string describing the version of Ediff.
1352 When called interactively, displays the version."
1353 (interactive)
1354 (if (interactive-p)
1355 (message (ediff-version))
1356 (format "Ediff %s of %s" ediff-version ediff-date)))
1359 ;;;###autoload
1360 (defun ediff-documentation (&optional node)
1361 "Display Ediff's manual.
1362 With optional NODE, goes to that node."
1363 (interactive)
1364 (let ((ctl-window ediff-control-window)
1365 (ctl-buf ediff-control-buffer))
1367 (ediff-skip-unsuitable-frames)
1368 (condition-case nil
1369 (progn
1370 (pop-to-buffer (get-buffer-create "*info*"))
1371 (info (if ediff-xemacs-p "ediff.info" "ediff"))
1372 (if node
1373 (Info-goto-node node)
1374 (message "Type `i' to search for a specific topic"))
1375 (raise-frame (selected-frame)))
1376 (error (beep 1)
1377 (with-output-to-temp-buffer ediff-msg-buffer
1378 (ediff-with-current-buffer standard-output
1379 (fundamental-mode))
1380 (princ ediff-BAD-INFO))
1381 (if (window-live-p ctl-window)
1382 (progn
1383 (select-window ctl-window)
1384 (set-window-buffer ctl-window ctl-buf)))))))
1389 ;;; Local Variables:
1390 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1391 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1392 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1393 ;;; End:
1395 (require 'ediff-util)
1397 (run-hooks 'ediff-load-hook)
1399 ;;; ediff.el ends here