1 ;;; ediff.el --- a comprehensive visual interface to diff & patch
3 ;; Copyright (C) 1994-2013 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
6 ;; Created: February 2, 1994
7 ;; Keywords: comparing, merging, patching, vc, tools, unix
10 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
11 ;; file on 20/3/2008, and the maintainer agreed that when a bug is
12 ;; filed in the Emacs bug reporting system against this file, a copy
13 ;; of the bug report be sent to the maintainer's email address.
15 (defconst ediff-version
"2.81.4" "The current version of Ediff")
16 (defconst ediff-date
"December 7, 2009" "Date of last update")
19 ;; This file is part of GNU Emacs.
21 ;; GNU Emacs is free software: you can redistribute it and/or modify
22 ;; it under the terms of the GNU General Public License as published by
23 ;; the Free Software Foundation, either version 3 of the License, or
24 ;; (at your option) any later version.
26 ;; GNU Emacs is distributed in the hope that it will be useful,
27 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
28 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 ;; GNU General Public License for more details.
31 ;; You should have received a copy of the GNU General Public License
32 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
36 ;; Never read that diff output again!
37 ;; Apply patch interactively!
40 ;; This package provides a convenient way of simultaneous browsing through
41 ;; the differences between a pair (or a triple) of files or buffers. The
42 ;; files being compared, file-A, file-B, and file-C (if applicable) are
43 ;; shown in separate windows (side by side, one above the another, or in
44 ;; separate frames), and the differences are highlighted as you step
45 ;; through them. You can also copy difference regions from one buffer to
46 ;; another (and recover old differences if you change your mind).
48 ;; Ediff also supports merging operations on files and buffers, including
49 ;; merging using ancestor versions. Both comparison and merging operations can
50 ;; be performed on directories, i.e., by pairwise comparison of files in those
53 ;; In addition, Ediff can apply a patch to a file and then let you step
54 ;; though both files, the patched and the original one, simultaneously,
55 ;; difference-by-difference. You can even apply a patch right out of a
56 ;; mail buffer, i.e., patches received by mail don't even have to be saved.
57 ;; Since Ediff lets you copy differences between buffers, you can, in
58 ;; effect, apply patches selectively (i.e., you can copy a difference
59 ;; region from file_orig to file, thereby undoing any particular patch that
62 ;; Ediff is aware of version control, which lets the user compare
63 ;; files with their older versions. Ediff can also work with remote and
64 ;; compressed files. Details are given below.
66 ;; Finally, Ediff supports directory-level comparison, merging and patching.
67 ;; See the on-line manual for details.
69 ;; This package builds upon the ideas borrowed from emerge.el and several
70 ;; Ediff's functions are adaptations from emerge.el. Much of the functionality
71 ;; Ediff provides is also influenced by emerge.el.
73 ;; The present version of Ediff supersedes Emerge. It provides a superior user
74 ;; interface and has numerous major features not found in Emerge. In
75 ;; particular, it can do patching, and 2-way and 3-way file comparison,
76 ;; merging, and directory operations.
82 ;; 1. The undo command doesn't restore deleted regions well. That is, if
83 ;; you delete all characters in a difference region and then invoke
84 ;; `undo', the reinstated text will most likely be inserted outside of
85 ;; what Ediff thinks is the current difference region. (This problem
86 ;; doesn't seem to exist with XEmacs.)
88 ;; If at any point you feel that difference regions are no longer correct,
89 ;; you can hit '!' to recompute the differences.
91 ;; 2. On a monochrome display, the repertoire of faces with which to
92 ;; highlight fine differences is limited. By default, Ediff is using
93 ;; underlining. However, if the region is already underlined by some other
94 ;; overlays, there is no simple way to temporarily remove that residual
95 ;; underlining. This problem occurs when a buffer is highlighted with
96 ;; hilit19.el or font-lock.el packages. If this residual highlighting gets
97 ;; in the way, you can do the following. Both font-lock.el and hilit19.el
98 ;; provide commands for unhighlighting buffers. You can either place these
99 ;; commands in `ediff-prepare-buffer-hook' (which will unhighlight every
100 ;; buffer used by Ediff) or you can execute them interactively, at any time
101 ;; and on any buffer.
106 ;; Ediff was inspired by Dale R. Worley's <drw@math.mit.edu> emerge.el.
107 ;; Ediff would not have been possible without the help and encouragement of
108 ;; its many users. See Ediff on-line Info for the full list of those who
109 ;; helped. Improved defaults in Ediff file-name reading commands.
117 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
119 (require 'ediff-util
)
122 (require 'ediff-init
)
123 (require 'ediff-mult
) ; required because of the registry stuff
126 "Comprehensive visual interface to `diff' and `patch'."
131 (defcustom ediff-use-last-dir nil
132 "If t, Ediff will use previous directory as default when reading file name."
136 ;; Last directory used by an Ediff command for file-A.
137 (defvar ediff-last-dir-A nil
)
138 ;; Last directory used by an Ediff command for file-B.
139 (defvar ediff-last-dir-B nil
)
140 ;; Last directory used by an Ediff command for file-C.
141 (defvar ediff-last-dir-C nil
)
142 ;; Last directory used by an Ediff command for the ancestor file.
143 (defvar ediff-last-dir-ancestor nil
)
144 ;; Last directory used by an Ediff command as the output directory for merge.
145 (defvar ediff-last-merge-autostore-dir nil
)
148 ;; Used as a startup hook to set `_orig' patch file read-only.
149 (defun ediff-set-read-only-in-buf-A ()
150 (ediff-with-current-buffer ediff-buffer-A
151 (setq buffer-read-only t
)))
153 (declare-function dired-get-filename
"dired"
154 (&optional localp no-error-if-not-filep
))
155 (declare-function dired-get-marked-files
"dired"
156 (&optional localp arg filter distinguish-one-marked
))
158 ;; Return a plausible default for ediff's first file:
159 ;; In dired, return the file number FILENO (or 0) in the list
160 ;; (all-selected-files, filename under the cursor), where directories are
161 ;; ignored. Otherwise, return DEFAULT file name, if non-nil. Else,
162 ;; if the buffer is visiting a file, return that file name.
163 (defun ediff-get-default-file-name (&optional default fileno
)
164 (cond ((eq major-mode
'dired-mode
)
165 (let ((current (dired-get-filename nil
'no-error
))
166 (marked (condition-case nil
167 (dired-get-marked-files 'no-dir
)
169 aux-list choices result
)
170 (or (integerp fileno
) (setq fileno
0))
171 (if (stringp default
)
172 (setq aux-list
(cons default aux-list
)))
173 (if (and (stringp current
) (not (file-directory-p current
)))
174 (setq aux-list
(cons current aux-list
)))
175 (setq choices
(nconc marked aux-list
))
176 (setq result
(elt choices fileno
))
179 ((stringp default
) default
)
180 ((buffer-file-name (current-buffer))
181 (file-name-nondirectory (buffer-file-name (current-buffer))))
184 ;;; Compare files/buffers
187 (defun ediff-files (file-A file-B
&optional startup-hooks
)
188 "Run Ediff on a pair of files, FILE-A and FILE-B."
190 (let ((dir-A (if ediff-use-last-dir
194 (list (setq f
(ediff-read-file-name
197 (ediff-get-default-file-name)
199 (ediff-read-file-name "File B to compare"
201 (if ediff-use-last-dir
203 (file-name-directory f
)))
205 (ediff-add-to-history
207 (ediff-abbreviate-file-name
209 (file-name-nondirectory f
)
211 (ediff-get-default-file-name f
1)))
213 (ediff-files-internal file-A
214 (if (file-directory-p file-B
)
216 (file-name-nondirectory file-A
) file-B
)
223 (defun ediff-files3 (file-A file-B file-C
&optional startup-hooks
)
224 "Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
226 (let ((dir-A (if ediff-use-last-dir
230 (list (setq f
(ediff-read-file-name
233 (ediff-get-default-file-name)
235 (setq ff
(ediff-read-file-name "File B to compare"
237 (if ediff-use-last-dir
239 (file-name-directory f
)))
241 (ediff-add-to-history
243 (ediff-abbreviate-file-name
245 (file-name-nondirectory f
)
247 (ediff-get-default-file-name f
1))))
248 (ediff-read-file-name "File C to compare"
249 (setq dir-C
(if ediff-use-last-dir
251 (file-name-directory ff
)))
253 (ediff-add-to-history
255 (ediff-abbreviate-file-name
257 (file-name-nondirectory ff
)
259 (ediff-get-default-file-name ff
2)))
261 (ediff-files-internal file-A
262 (if (file-directory-p file-B
)
264 (file-name-nondirectory file-A
) file-B
)
266 (if (file-directory-p file-C
)
268 (file-name-nondirectory file-A
) file-C
)
274 (defalias 'ediff3
'ediff-files3
)
277 (defun ediff-find-file (file-var buffer-name
&optional last-dir hooks-var
)
278 "Visit FILE and arrange its buffer to Ediff's liking.
279 FILE-VAR is actually a variable symbol whose value must contain a true
281 BUFFER-NAME is a variable symbol, which will get the buffer object into
283 LAST-DIR is the directory variable symbol where FILE's
284 directory name should be returned. HOOKS-VAR is a variable symbol that will
285 be assigned the hook to be executed after `ediff-startup' is finished.
286 `ediff-find-file' arranges that the temp files it might create will be
288 (let* ((file (symbol-value file-var
))
289 (file-magic (ediff-filename-magic-p file
))
290 (temp-file-name-prefix (file-name-nondirectory file
)))
291 (cond ((not (file-readable-p file
))
292 (error "File `%s' does not exist or is not readable" file
))
293 ((file-directory-p file
)
294 (error "File `%s' is a directory" file
)))
296 ;; some of the commands, below, require full file name
297 (setq file
(expand-file-name file
))
299 ;; Record the directory of the file
301 (set last-dir
(expand-file-name (file-name-directory file
))))
304 (set buffer-name
(find-file-noselect file
))
306 (ediff-with-current-buffer (symbol-value buffer-name
)
307 (widen) ; Make sure the entire file is seen
308 (cond (file-magic ; file has a handler, such as jka-compr-handler or
309 ;;; ange-ftp-hook-function--arrange for temp file
310 (ediff-verify-file-buffer 'magic
)
312 (ediff-make-temp-file
313 (current-buffer) temp-file-name-prefix
))
314 (set hooks-var
(cons `(lambda () (delete-file ,file
))
315 (symbol-value hooks-var
))))
316 ;; file processed via auto-mode-alist, a la uncompress.el
317 ((not (equal (file-truename file
)
318 (file-truename (buffer-file-name))))
320 (ediff-make-temp-file
321 (current-buffer) temp-file-name-prefix
))
322 (set hooks-var
(cons `(lambda () (delete-file ,file
))
323 (symbol-value hooks-var
))))
324 (t ;; plain file---just check that the file matches the buffer
325 (ediff-verify-file-buffer))))
326 (set file-var file
)))
328 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
329 (defun ediff-files-internal (file-A file-B file-C startup-hooks job-name
330 &optional merge-buffer-file
)
331 (let (buf-A buf-B buf-C
)
332 (if (string= file-A file-B
)
333 (error "Files A and B are the same"))
335 (or (and (string= file-A file-C
) (error "Files A and C are the same"))
336 (and (string= file-B file-C
) (error "Files B and C are the same"))))
337 (message "Reading file %s ... " file-A
)
339 (ediff-find-file 'file-A
'buf-A
'ediff-last-dir-A
'startup-hooks
)
340 (message "Reading file %s ... " file-B
)
342 (ediff-find-file 'file-B
'buf-B
'ediff-last-dir-B
'startup-hooks
)
345 (message "Reading file %s ... " file-C
)
349 (if (eq job-name
'ediff-merge-files-with-ancestor
)
350 'ediff-last-dir-ancestor
'ediff-last-dir-C
)
352 (ediff-setup buf-A file-A
356 (list (cons 'ediff-job-name job-name
))
359 (declare-function diff-latest-backup-file
"diff" (fn))
362 (defalias 'ediff
'ediff-files
)
365 (defun ediff-current-file ()
366 "Start ediff between current buffer and its file on disk.
367 This command can be used instead of `revert-buffer'. If there is
368 nothing to revert then this command fails."
370 (unless (or revert-buffer-function
371 revert-buffer-insert-file-contents-function
372 (and buffer-file-number
373 (or (buffer-modified-p)
374 (not (verify-visited-file-modtime
375 (current-buffer))))))
376 (error "Nothing to revert"))
377 (let* ((auto-save-p (and (recent-auto-save-p)
378 buffer-auto-save-file-name
379 (file-readable-p buffer-auto-save-file-name
)
381 "Buffer has been auto-saved recently. Compare with auto-save file? ")))
382 (file-name (if auto-save-p
383 buffer-auto-save-file-name
385 (revert-buf-name (concat "FILE=" file-name
))
386 (revert-buf (get-buffer revert-buf-name
))
387 (current-major major-mode
))
389 (error "Buffer does not seem to be associated with any file"))
391 (kill-buffer revert-buf
)
392 (setq revert-buf nil
))
393 (setq revert-buf
(get-buffer-create revert-buf-name
))
394 (with-current-buffer revert-buf
395 (insert-file-contents file-name
)
396 ;; Assume same modes:
397 (funcall current-major
))
398 (ediff-buffers revert-buf
(current-buffer))))
402 (defun ediff-backup (file)
403 "Run Ediff on FILE and its backup file.
404 Uses the latest backup, if there are several numerical backups.
405 If this file is a backup, `ediff' it with its original."
406 (interactive (list (read-file-name "Ediff (file with backup): ")))
407 ;; The code is taken from `diff-backup'.
410 (if (backup-file-name-p file
)
412 ori
(file-name-sans-versions file
))
413 (setq bak
(or (diff-latest-backup-file file
)
414 (error "No backup found for %s" file
))
416 (ediff-files bak ori
)))
419 (defun ediff-buffers (buffer-A buffer-B
&optional startup-hooks job-name
)
420 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
423 (list (setq bf
(read-buffer "Buffer A to compare: "
424 (ediff-other-buffer "") t
))
425 (read-buffer "Buffer B to compare: "
427 ;; realign buffers so that two visible bufs will be
429 (save-window-excursion (other-window 1))
430 (ediff-other-buffer bf
))
432 (or job-name
(setq job-name
'ediff-buffers
))
433 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name
))
436 (defalias 'ebuffers
'ediff-buffers
)
440 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
441 &optional startup-hooks job-name
)
442 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
445 (list (setq bf
(read-buffer "Buffer A to compare: "
446 (ediff-other-buffer "") t
))
447 (setq bff
(read-buffer "Buffer B to compare: "
449 ;; realign buffers so that two visible
450 ;; bufs will be at the top
451 (save-window-excursion (other-window 1))
452 (ediff-other-buffer bf
))
454 (read-buffer "Buffer C to compare: "
456 ;; realign buffers so that three visible
457 ;; bufs will be at the top
458 (save-window-excursion (other-window 1))
459 (ediff-other-buffer (list bf bff
)))
462 (or job-name
(setq job-name
'ediff-buffers3
))
463 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name
))
466 (defalias 'ebuffers3
'ediff-buffers3
)
470 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
471 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
472 &optional merge-buffer-file
)
473 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A
)))
474 (buf-B-file-name (buffer-file-name (get-buffer buf-B
)))
475 (buf-C-is-alive (ediff-buffer-live-p buf-C
))
476 (buf-C-file-name (if buf-C-is-alive
477 (buffer-file-name (get-buffer buf-B
))))
478 file-A file-B file-C
)
481 (if (not (ediff-buffer-live-p buf-A
))
482 (error "Buffer %S doesn't exist" buf-A
))
483 (if (not (ediff-buffer-live-p buf-B
))
484 (error "Buffer %S doesn't exist" buf-B
))
485 (let ((ediff-job-name job-name
))
486 (if (and ediff-3way-comparison-job
487 (not buf-C-is-alive
))
488 (error "Buffer %S doesn't exist" buf-C
)))
489 (if (stringp buf-A-file-name
)
490 (setq buf-A-file-name
(file-name-nondirectory buf-A-file-name
)))
491 (if (stringp buf-B-file-name
)
492 (setq buf-B-file-name
(file-name-nondirectory buf-B-file-name
)))
493 (if (stringp buf-C-file-name
)
494 (setq buf-C-file-name
(file-name-nondirectory buf-C-file-name
)))
496 (setq file-A
(ediff-make-temp-file buf-A buf-A-file-name
)
497 file-B
(ediff-make-temp-file buf-B buf-B-file-name
))
499 (setq file-C
(ediff-make-temp-file buf-C buf-C-file-name
)))
501 (ediff-setup (get-buffer buf-A
) file-A
502 (get-buffer buf-B
) file-B
503 (if buf-C-is-alive
(get-buffer buf-C
))
506 (delete-file ,file-A
)
507 (delete-file ,file-B
)
508 (if (stringp ,file-C
) (delete-file ,file-C
)))
510 (list (cons 'ediff-job-name job-name
))
512 (if (and (stringp file-A
) (file-exists-p file-A
))
513 (delete-file file-A
))
514 (if (and (stringp file-B
) (file-exists-p file-B
))
515 (delete-file file-B
))
516 (if (and (stringp file-C
) (file-exists-p file-C
))
517 (delete-file file-C
)))))
520 ;;; Directory and file group operations
522 ;; Get appropriate default name for directory:
523 ;; If ediff-use-last-dir, use ediff-last-dir-A.
524 ;; In dired mode, use the directory that is under the point (if any);
525 ;; otherwise, use default-directory
526 (defun ediff-get-default-directory-name ()
527 (cond (ediff-use-last-dir ediff-last-dir-A
)
528 ((eq major-mode
'dired-mode
)
529 (let ((f (dired-get-filename nil
'noerror
)))
530 (if (and (stringp f
) (file-directory-p f
))
533 (t default-directory
)))
537 (defun ediff-directories (dir1 dir2 regexp
)
538 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
539 the same name in both. The third argument, REGEXP, is nil or a regular
540 expression; only file names that match the regexp are considered."
542 (let ((dir-A (ediff-get-default-directory-name))
543 (default-regexp (eval ediff-default-filtering-regexp
))
545 (list (setq f
(read-directory-name
546 "Directory A to compare: " dir-A nil
'must-match
))
547 (read-directory-name "Directory B to compare: "
548 (if ediff-use-last-dir
550 (ediff-strip-last-dir f
))
553 (if (stringp default-regexp
)
554 (format "Filter through regular expression (default %s): "
556 "Filter through regular expression: ")
558 'ediff-filtering-regexp-history
559 (eval ediff-default-filtering-regexp
))
561 (ediff-directories-internal
562 dir1 dir2 nil regexp
'ediff-files
'ediff-directories
566 (defalias 'edirs
'ediff-directories
)
570 (defun ediff-directory-revisions (dir1 regexp
)
571 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
572 The second argument, REGEXP, is a regular expression that filters the file
573 names. Only the files that are under revision control are taken into account."
575 (let ((dir-A (ediff-get-default-directory-name))
576 (default-regexp (eval ediff-default-filtering-regexp
))
578 (list (read-directory-name
579 "Directory to compare with revision:" dir-A nil
'must-match
)
581 (if (stringp default-regexp
)
582 (format "Filter through regular expression (default %s): "
584 "Filter through regular expression: ")
586 'ediff-filtering-regexp-history
587 (eval ediff-default-filtering-regexp
))
589 (ediff-directory-revisions-internal
590 dir1 regexp
'ediff-revision
'ediff-directory-revisions
594 (defalias 'edir-revisions
'ediff-directory-revisions
)
598 (defun ediff-directories3 (dir1 dir2 dir3 regexp
)
599 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
600 have the same name in all three. The last argument, REGEXP, is nil or a
601 regular expression; only file names that match the regexp are considered."
604 (let ((dir-A (ediff-get-default-directory-name))
605 (default-regexp (eval ediff-default-filtering-regexp
))
607 (list (setq f
(read-directory-name "Directory A to compare:" dir-A nil
))
608 (setq f
(read-directory-name "Directory B to compare:"
609 (if ediff-use-last-dir
611 (ediff-strip-last-dir f
))
613 (read-directory-name "Directory C to compare:"
614 (if ediff-use-last-dir
616 (ediff-strip-last-dir f
))
619 (if (stringp default-regexp
)
620 (format "Filter through regular expression (default %s): "
622 "Filter through regular expression: ")
624 'ediff-filtering-regexp-history
625 (eval ediff-default-filtering-regexp
))
627 (ediff-directories-internal
628 dir1 dir2 dir3 regexp
'ediff-files3
'ediff-directories3
632 (defalias 'edirs3
'ediff-directories3
)
635 (defun ediff-merge-directories (dir1 dir2 regexp
&optional merge-autostore-dir
)
636 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
637 the same name in both. The third argument, REGEXP, is nil or a regular
638 expression; only file names that match the regexp are considered."
640 (let ((dir-A (ediff-get-default-directory-name))
641 (default-regexp (eval ediff-default-filtering-regexp
))
643 (list (setq f
(read-directory-name "Directory A to merge:"
644 dir-A nil
'must-match
))
645 (read-directory-name "Directory B to merge:"
646 (if ediff-use-last-dir
648 (ediff-strip-last-dir f
))
651 (if (stringp default-regexp
)
652 (format "Filter through regular expression (default %s): "
654 "Filter through regular expression: ")
656 'ediff-filtering-regexp-history
657 (eval ediff-default-filtering-regexp
))
659 (ediff-directories-internal
660 dir1 dir2 nil regexp
'ediff-merge-files
'ediff-merge-directories
661 nil merge-autostore-dir
665 (defalias 'edirs-merge
'ediff-merge-directories
)
668 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
671 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
672 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
673 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
674 without ancestor. The fourth argument, REGEXP, is nil or a regular expression;
675 only file names that match the regexp are considered."
677 (let ((dir-A (ediff-get-default-directory-name))
678 (default-regexp (eval ediff-default-filtering-regexp
))
680 (list (setq f
(read-directory-name "Directory A to merge:" dir-A nil
))
681 (setq f
(read-directory-name "Directory B to merge:"
682 (if ediff-use-last-dir
684 (ediff-strip-last-dir f
))
686 (read-directory-name "Ancestor directory:"
687 (if ediff-use-last-dir
689 (ediff-strip-last-dir f
))
692 (if (stringp default-regexp
)
693 (format "Filter through regular expression (default %s): "
695 "Filter through regular expression: ")
697 'ediff-filtering-regexp-history
698 (eval ediff-default-filtering-regexp
))
700 (ediff-directories-internal
701 dir1 dir2 ancestor-dir regexp
702 'ediff-merge-files-with-ancestor
'ediff-merge-directories-with-ancestor
703 nil merge-autostore-dir
707 (defun ediff-merge-directory-revisions (dir1 regexp
708 &optional merge-autostore-dir
)
709 "Run Ediff on a directory, DIR1, merging its files with their revisions.
710 The second argument, REGEXP, is a regular expression that filters the file
711 names. Only the files that are under revision control are taken into account."
713 (let ((dir-A (ediff-get-default-directory-name))
714 (default-regexp (eval ediff-default-filtering-regexp
))
716 (list (read-directory-name
717 "Directory to merge with revisions:" dir-A nil
'must-match
)
719 (if (stringp default-regexp
)
720 (format "Filter through regular expression (default %s): "
722 "Filter through regular expression: ")
724 'ediff-filtering-regexp-history
725 (eval ediff-default-filtering-regexp
))
727 (ediff-directory-revisions-internal
728 dir1 regexp
'ediff-merge-revisions
'ediff-merge-directory-revisions
729 nil merge-autostore-dir
733 (defalias 'edir-merge-revisions
'ediff-merge-directory-revisions
)
736 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
739 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
740 The second argument, REGEXP, is a regular expression that filters the file
741 names. Only the files that are under revision control are taken into account."
743 (let ((dir-A (ediff-get-default-directory-name))
744 (default-regexp (eval ediff-default-filtering-regexp
))
746 (list (read-directory-name
747 "Directory to merge with revisions and ancestors:"
748 dir-A nil
'must-match
)
750 (if (stringp default-regexp
)
751 (format "Filter through regular expression (default %s): "
753 "Filter through regular expression: ")
755 'ediff-filtering-regexp-history
756 (eval ediff-default-filtering-regexp
))
758 (ediff-directory-revisions-internal
759 dir1 regexp
'ediff-merge-revisions-with-ancestor
760 'ediff-merge-directory-revisions-with-ancestor
761 nil merge-autostore-dir
766 'edir-merge-revisions-with-ancestor
767 'ediff-merge-directory-revisions-with-ancestor
)
770 (defalias 'edirs-merge-with-ancestor
'ediff-merge-directories-with-ancestor
)
772 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
773 ;; on a pair of directories (three directories, in case of ancestor).
774 ;; The third argument, REGEXP, is nil or a regular expression;
775 ;; only file names that match the regexp are considered.
776 ;; JOBNAME is the symbol indicating the meta-job to be performed.
777 ;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
778 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
779 &optional startup-hooks
782 (setq dir3
(if (file-directory-p dir3
) dir3
(file-name-directory dir3
))))
784 (cond ((string= dir1 dir2
)
785 (error "Directories A and B are the same: %s" dir1
))
786 ((and (eq jobname
'ediff-directories3
)
788 (error "Directories A and C are the same: %s" dir1
))
789 ((and (eq jobname
'ediff-directories3
)
791 (error "Directories B and C are the same: %s" dir1
)))
793 (if merge-autostore-dir
794 (or (stringp merge-autostore-dir
)
795 (error "%s: Directory for storing merged files must be a string"
797 (let (;; dir-diff-struct is of the form (common-list diff-list)
798 ;; It is a structure where ediff-intersect-directories returns
799 ;; commonalities and differences among directories
802 (if (and ediff-autostore-merges
803 (ediff-merge-metajob jobname
)
804 (not merge-autostore-dir
))
805 (setq merge-autostore-dir
806 (read-directory-name "Save merged files in directory: "
807 (if ediff-use-last-dir
808 ediff-last-merge-autostore-dir
809 (ediff-strip-last-dir dir1
))
812 ;; verify we are not merging into an orig directory
813 (if merge-autostore-dir
814 (cond ((and (stringp dir1
) (string= merge-autostore-dir dir1
))
816 "Directory for saving merged files = Directory A. Sure? ")
817 (error "Directory merge aborted")))
818 ((and (stringp dir2
) (string= merge-autostore-dir dir2
))
820 "Directory for saving merged files = Directory B. Sure? ")
821 (error "Directory merge aborted")))
822 ((and (stringp dir3
) (string= merge-autostore-dir dir3
))
824 "Directory for saving merged files = Ancestor Directory. Sure? ")
825 (error "Directory merge aborted")))))
827 (setq dir-diff-struct
(ediff-intersect-directories
829 regexp dir1 dir2 dir3 merge-autostore-dir
))
831 ;; this sets various vars in the meta buffer inside
832 ;; ediff-prepare-meta-buffer
834 ;; tell what to do if the user clicks on a session record
835 (setq ediff-session-action-function
(quote ,action
))
836 ;; set ediff-dir-difference-list
837 (setq ediff-dir-difference-list
838 (cdr (quote ,dir-diff-struct
))))
840 (setq meta-buf
(ediff-prepare-meta-buffer
841 'ediff-filegroup-action
842 (car dir-diff-struct
)
843 "*Ediff Session Group Panel"
844 'ediff-redraw-directory-group-buffer
847 (ediff-show-meta-buffer meta-buf
)
850 ;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
852 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
853 &optional startup-hooks
855 (setq dir1
(if (file-directory-p dir1
) dir1
(file-name-directory dir1
)))
857 (if merge-autostore-dir
858 (or (stringp merge-autostore-dir
)
859 (error "%S: Directory for storing merged files must be a string"
861 (let (file-list meta-buf
)
862 (if (and ediff-autostore-merges
863 (ediff-merge-metajob jobname
)
864 (not merge-autostore-dir
))
865 (setq merge-autostore-dir
866 (read-directory-name "Save merged files in directory: "
867 (if ediff-use-last-dir
868 ediff-last-merge-autostore-dir
869 (ediff-strip-last-dir dir1
))
872 ;; verify merge-autostore-dir != dir1
873 (if (and merge-autostore-dir
875 (string= merge-autostore-dir dir1
))
877 "Directory for saving merged file = directory A. Sure? ")
878 (error "Merge of directory revisions aborted")))
881 (ediff-get-directory-files-under-revision
882 jobname regexp dir1 merge-autostore-dir
))
884 ;; this sets various vars in the meta buffer inside
885 ;; ediff-prepare-meta-buffer
887 ;; tell what to do if the user clicks on a session record
888 (setq ediff-session-action-function
(quote ,action
)))
890 (setq meta-buf
(ediff-prepare-meta-buffer
891 'ediff-filegroup-action
893 "*Ediff Session Group Panel"
894 'ediff-redraw-directory-group-buffer
897 (ediff-show-meta-buffer meta-buf
)
901 ;;; Compare regions and windows
904 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks
)
905 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
906 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
908 If WIND-A is nil, use selected window.
909 If WIND-B is nil, use window next to WIND-A."
911 (ediff-windows dumb-mode wind-A wind-B
912 startup-hooks
'ediff-windows-wordwise
'word-mode
))
915 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks
)
916 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
917 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
919 If WIND-A is nil, use selected window.
920 If WIND-B is nil, use window next to WIND-A."
922 (ediff-windows dumb-mode wind-A wind-B
923 startup-hooks
'ediff-windows-linewise nil
))
925 ;; Compare WIND-A and WIND-B, which are selected by clicking.
926 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
928 ;; If WIND-A is nil, use selected window.
929 ;; If WIND-B is nil, use window next to WIND-A.
930 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode
)
931 (if (or dumb-mode
(not (ediff-window-display-p)))
932 (setq wind-A
(ediff-get-next-window wind-A nil
)
933 wind-B
(ediff-get-next-window wind-B wind-A
))
934 (setq wind-A
(ediff-get-window-by-clicking wind-A nil
1)
935 wind-B
(ediff-get-window-by-clicking wind-B wind-A
2)))
937 (let ((buffer-A (window-buffer wind-A
))
938 (buffer-B (window-buffer wind-B
))
939 beg-A end-A beg-B end-B
)
942 (save-window-excursion
943 (sit-for 0) ; sync before using window-start/end -- a precaution
944 (select-window wind-A
)
945 (setq beg-A
(window-start)
947 (select-window wind-B
)
948 (setq beg-B
(window-start)
949 end-B
(window-end))))
951 (ediff-clone-buffer-for-window-comparison
952 buffer-A wind-A
"-Window.A-")
954 (ediff-clone-buffer-for-window-comparison
955 buffer-B wind-B
"-Window.B-"))
956 (ediff-regions-internal
957 buffer-A beg-A end-A buffer-B beg-B end-B
958 startup-hooks job-name word-mode nil
)))
962 (defun ediff-regions-wordwise (buffer-A buffer-B
&optional startup-hooks
)
963 "Run Ediff on a pair of regions in specified buffers.
964 Regions \(i.e., point and mark\) can be set in advance or marked interactively.
965 This function is effective only for relatively small regions, up to 200
966 lines. For large regions, use `ediff-regions-linewise'."
969 (list (setq bf
(read-buffer "Region's A buffer: "
970 (ediff-other-buffer "") t
))
971 (read-buffer "Region's B buffer: "
973 ;; realign buffers so that two visible bufs will be
975 (save-window-excursion (other-window 1))
976 (ediff-other-buffer bf
))
978 (if (not (ediff-buffer-live-p buffer-A
))
979 (error "Buffer %S doesn't exist" buffer-A
))
980 (if (not (ediff-buffer-live-p buffer-B
))
981 (error "Buffer %S doesn't exist" buffer-B
))
985 (ediff-clone-buffer-for-region-comparison buffer-A
"-Region.A-"))
987 (ediff-clone-buffer-for-region-comparison buffer-B
"-Region.B-"))
988 reg-A-beg reg-A-end reg-B-beg reg-B-end
)
989 (with-current-buffer buffer-A
990 (setq reg-A-beg
(region-beginning)
991 reg-A-end
(region-end))
992 (set-buffer buffer-B
)
993 (setq reg-B-beg
(region-beginning)
994 reg-B-end
(region-end)))
996 (ediff-regions-internal
997 (get-buffer buffer-A
) reg-A-beg reg-A-end
998 (get-buffer buffer-B
) reg-B-beg reg-B-end
999 startup-hooks
'ediff-regions-wordwise
'word-mode nil
)))
1002 (defun ediff-regions-linewise (buffer-A buffer-B
&optional startup-hooks
)
1003 "Run Ediff on a pair of regions in specified buffers.
1004 Regions \(i.e., point and mark\) can be set in advance or marked interactively.
1005 Each region is enlarged to contain full lines.
1006 This function is effective for large regions, over 100-200
1007 lines. For small regions, use `ediff-regions-wordwise'."
1010 (list (setq bf
(read-buffer "Region A's buffer: "
1011 (ediff-other-buffer "") t
))
1012 (read-buffer "Region B's buffer: "
1014 ;; realign buffers so that two visible bufs will be
1016 (save-window-excursion (other-window 1))
1017 (ediff-other-buffer bf
))
1019 (if (not (ediff-buffer-live-p buffer-A
))
1020 (error "Buffer %S doesn't exist" buffer-A
))
1021 (if (not (ediff-buffer-live-p buffer-B
))
1022 (error "Buffer %S doesn't exist" buffer-B
))
1025 (ediff-clone-buffer-for-region-comparison buffer-A
"-Region.A-"))
1027 (ediff-clone-buffer-for-region-comparison buffer-B
"-Region.B-"))
1028 reg-A-beg reg-A-end reg-B-beg reg-B-end
)
1029 (with-current-buffer buffer-A
1030 (setq reg-A-beg
(region-beginning)
1031 reg-A-end
(region-end))
1032 ;; enlarge the region to hold full lines
1033 (goto-char reg-A-beg
)
1035 (setq reg-A-beg
(point))
1036 (goto-char reg-A-end
)
1038 (or (eobp) (forward-char)) ; include the newline char
1039 (setq reg-A-end
(point))
1041 (set-buffer buffer-B
)
1042 (setq reg-B-beg
(region-beginning)
1043 reg-B-end
(region-end))
1044 ;; enlarge the region to hold full lines
1045 (goto-char reg-B-beg
)
1047 (setq reg-B-beg
(point))
1048 (goto-char reg-B-end
)
1050 (or (eobp) (forward-char)) ; include the newline char
1051 (setq reg-B-end
(point))
1054 (ediff-regions-internal
1055 (get-buffer buffer-A
) reg-A-beg reg-A-end
1056 (get-buffer buffer-B
) reg-B-beg reg-B-end
1057 startup-hooks
'ediff-regions-linewise nil nil
))) ; no word mode
1059 ;; compare region beg-A to end-A of buffer-A
1060 ;; to regions beg-B -- end-B in buffer-B.
1061 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
1062 startup-hooks job-name word-mode
1064 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer
))
1069 ;; in case beg/end-A/B aren't markers--make them into markers
1070 (ediff-with-current-buffer buffer-A
1071 (setq beg-A
(move-marker (make-marker) beg-A
)
1072 end-A
(move-marker (make-marker) end-A
)))
1073 (ediff-with-current-buffer buffer-B
1074 (setq beg-B
(move-marker (make-marker) beg-B
)
1075 end-B
(move-marker (make-marker) end-B
)))
1079 (ediff-wordify beg-A end-A buffer-A tmp-buffer
)
1080 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer
))
1081 (setq file-A
(ediff-make-temp-file tmp-buffer
"regA"))
1085 (ediff-wordify beg-B end-B buffer-B tmp-buffer
)
1086 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer
))
1087 (setq file-B
(ediff-make-temp-file tmp-buffer
"regB"))
1089 (setq overl-A
(ediff-make-bullet-proof-overlay beg-A end-A buffer-A
))
1090 (setq overl-B
(ediff-make-bullet-proof-overlay beg-B end-B buffer-B
))
1091 (ediff-setup buffer-A file-A
1093 nil nil
; buffer & file C
1095 (delete-file ,file-A
)
1096 (delete-file ,file-B
))
1099 (list (cons 'ediff-word-mode word-mode
)
1100 (cons 'ediff-narrow-bounds
(list overl-A overl-B
))
1101 (cons 'ediff-job-name job-name
))
1103 (if (and (stringp file-A
) (file-exists-p file-A
))
1104 (delete-file file-A
))
1105 (if (and (stringp file-B
) (file-exists-p file-B
))
1106 (delete-file file-B
)))
1110 ;;; Merge files and buffers
1113 (defalias 'ediff-merge
'ediff-merge-files
)
1115 (defsubst ediff-merge-on-startup
()
1117 ;; Can't remember why this is here, but it may cause the automatically merged
1118 ;; buffer to be lost. So, keep the buffer modified.
1119 ;;(ediff-with-current-buffer ediff-buffer-C
1120 ;; (set-buffer-modified-p nil))
1124 (defun ediff-merge-files (file-A file-B
1125 ;; MERGE-BUFFER-FILE is the file to be
1126 ;; associated with the merge buffer
1127 &optional startup-hooks merge-buffer-file
)
1128 "Merge two files without ancestor."
1130 (let ((dir-A (if ediff-use-last-dir
1134 (list (setq f
(ediff-read-file-name
1137 (ediff-get-default-file-name)
1139 (ediff-read-file-name "File B to merge"
1141 (if ediff-use-last-dir
1143 (file-name-directory f
)))
1145 (ediff-add-to-history
1147 (ediff-abbreviate-file-name
1149 (file-name-nondirectory f
)
1151 (ediff-get-default-file-name f
1)))
1153 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1154 (ediff-files-internal file-A
1155 (if (file-directory-p file-B
)
1157 (file-name-nondirectory file-A
) file-B
)
1165 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
1168 ;; MERGE-BUFFER-FILE is the file
1169 ;; to be associated with the
1172 "Merge two files with ancestor."
1174 (let ((dir-A (if ediff-use-last-dir
1177 dir-B dir-ancestor f ff
)
1178 (list (setq f
(ediff-read-file-name
1181 (ediff-get-default-file-name)
1183 (setq ff
(ediff-read-file-name "File B to merge"
1185 (if ediff-use-last-dir
1187 (file-name-directory f
)))
1189 (ediff-add-to-history
1191 (ediff-abbreviate-file-name
1193 (file-name-nondirectory f
)
1195 (ediff-get-default-file-name f
1))))
1196 (ediff-read-file-name "Ancestor file"
1198 (if ediff-use-last-dir
1199 ediff-last-dir-ancestor
1200 (file-name-directory ff
)))
1202 (ediff-add-to-history
1204 (ediff-abbreviate-file-name
1206 (file-name-nondirectory ff
)
1208 (ediff-get-default-file-name ff
2)))
1210 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1211 (ediff-files-internal file-A
1212 (if (file-directory-p file-B
)
1214 (file-name-nondirectory file-A
) file-B
)
1218 'ediff-merge-files-with-ancestor
1222 (defalias 'ediff-merge-with-ancestor
'ediff-merge-files-with-ancestor
)
1225 (defun ediff-merge-buffers (buffer-A buffer-B
1227 ;; MERGE-BUFFER-FILE is the file to be
1228 ;; associated with the merge buffer
1229 startup-hooks job-name merge-buffer-file
)
1230 "Merge buffers without ancestor."
1233 (list (setq bf
(read-buffer "Buffer A to merge: "
1234 (ediff-other-buffer "") t
))
1235 (read-buffer "Buffer B to merge: "
1237 ;; realign buffers so that two visible bufs will be
1239 (save-window-excursion (other-window 1))
1240 (ediff-other-buffer bf
))
1243 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1244 (or job-name
(setq job-name
'ediff-merge-buffers
))
1245 (ediff-buffers-internal
1246 buffer-A buffer-B nil startup-hooks job-name merge-buffer-file
))
1249 (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
1253 ;; MERGE-BUFFER-FILE is the
1254 ;; file to be associated
1255 ;; with the merge buffer
1257 "Merge buffers with ancestor."
1260 (list (setq bf
(read-buffer "Buffer A to merge: "
1261 (ediff-other-buffer "") t
))
1262 (setq bff
(read-buffer "Buffer B to merge: "
1264 ;; realign buffers so that two visible
1265 ;; bufs will be at the top
1266 (save-window-excursion (other-window 1))
1267 (ediff-other-buffer bf
))
1269 (read-buffer "Ancestor buffer: "
1271 ;; realign buffers so that three visible
1272 ;; bufs will be at the top
1273 (save-window-excursion (other-window 1))
1274 (ediff-other-buffer (list bf bff
)))
1278 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1279 (or job-name
(setq job-name
'ediff-merge-buffers-with-ancestor
))
1280 (ediff-buffers-internal
1281 buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file
))
1285 (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file
)
1286 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
1287 "Run Ediff by merging two revisions of a file.
1288 The file is the optional FILE argument or the file visited by the current
1291 (if (stringp file
) (find-file file
))
1296 "Version 1 to merge (default %s's working version): "
1298 (file-name-nondirectory file
) "current buffer")))
1302 "Version 2 to merge (default %s): "
1304 (file-name-nondirectory file
) "current buffer"))))
1305 (ediff-load-version-control)
1306 ;; ancestor-revision=nil
1308 (intern (format "ediff-%S-merge-internal" ediff-version-control-package
))
1309 rev1 rev2 nil startup-hooks merge-buffer-file
)))
1313 (defun ediff-merge-revisions-with-ancestor (&optional
1315 ;; MERGE-BUFFER-FILE is the file to
1316 ;; be associated with the merge
1319 "Run Ediff by merging two revisions of a file with a common ancestor.
1320 The file is the optional FILE argument or the file visited by the current
1323 (if (stringp file
) (find-file file
))
1324 (let (rev1 rev2 ancestor-rev
)
1328 "Version 1 to merge (default %s's working version): "
1330 (file-name-nondirectory file
) "current buffer")))
1334 "Version 2 to merge (default %s): "
1336 (file-name-nondirectory file
) "current buffer")))
1340 "Ancestor version (default %s's base revision): "
1342 (file-name-nondirectory file
) "current buffer"))))
1343 (ediff-load-version-control)
1345 (intern (format "ediff-%S-merge-internal" ediff-version-control-package
))
1346 rev1 rev2 ancestor-rev startup-hooks merge-buffer-file
)))
1349 (defvar ediff-last-dir-patch
)
1350 (defvar ediff-patch-default-directory
)
1351 (declare-function ediff-get-patch-buffer
"ediff-ptch"
1352 (&optional arg patch-buf
))
1353 (declare-function ediff-dispatch-file-patching-job
"ediff-ptch"
1354 (patch-buf filename
&optional startup-hooks
))
1357 (defun ediff-patch-file (&optional arg patch-buf
)
1358 "Query for a file name, and then run Ediff by patching that file.
1359 If optional PATCH-BUF is given, use the patch in that buffer
1360 and don't ask the user.
1361 If prefix argument, then: if even argument, assume that the patch is in a
1362 buffer. If odd -- assume it is in a file."
1364 (let (source-dir source-file
)
1365 (require 'ediff-ptch
)
1367 (ediff-get-patch-buffer
1368 (if arg
(prefix-numeric-value arg
)) patch-buf
))
1369 (setq source-dir
(cond (ediff-use-last-dir ediff-last-dir-patch
)
1370 ((and (not ediff-patch-default-directory
)
1371 (buffer-file-name patch-buf
))
1372 (file-name-directory
1374 (buffer-file-name patch-buf
))))
1375 (t default-directory
)))
1378 "File to patch (directory, if multifile patch): "
1379 ;; use an explicit initial file
1380 source-dir nil nil
(ediff-get-default-file-name)))
1381 (ediff-dispatch-file-patching-job patch-buf source-file
)))
1383 (declare-function ediff-patch-buffer-internal
"ediff-ptch"
1384 (patch-buf buf-to-patch-name
&optional startup-hooks
))
1387 (defun ediff-patch-buffer (&optional arg patch-buf
)
1388 "Run Ediff by patching the buffer specified at prompt.
1389 Without the optional prefix ARG, asks if the patch is in some buffer and
1390 prompts for the buffer or a file, depending on the answer.
1391 With ARG=1, assumes the patch is in a file and prompts for the file.
1392 With ARG=2, assumes the patch is in a buffer and prompts for the buffer.
1393 PATCH-BUF is an optional argument, which specifies the buffer that contains the
1394 patch. If not given, the user is prompted according to the prefix argument."
1396 (require 'ediff-ptch
)
1398 (ediff-get-patch-buffer
1399 (if arg
(prefix-numeric-value arg
)) patch-buf
))
1400 (ediff-patch-buffer-internal
1403 "Which buffer to patch? "
1404 (ediff-other-buffer patch-buf
))))
1408 (defalias 'epatch
'ediff-patch-file
)
1410 (defalias 'epatch-buffer
'ediff-patch-buffer
)
1415 ;;; Versions Control functions
1418 (defun ediff-revision (&optional file startup-hooks
)
1419 "Run Ediff by comparing versions of a file.
1420 The file is an optional FILE argument or the file entered at the prompt.
1421 Default: the file visited by the current buffer.
1422 Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
1423 ;; if buffer is non-nil, use that buffer instead of the current buffer
1425 (if (not (stringp file
))
1427 (ediff-read-file-name "Compare revisions for file"
1428 (if ediff-use-last-dir
1431 (ediff-get-default-file-name)
1434 (if (and (buffer-modified-p)
1435 (y-or-n-p (format "Buffer %s is modified. Save buffer? "
1437 (save-buffer (current-buffer)))
1441 (format "Revision 1 to compare (default %s's latest revision): "
1442 (file-name-nondirectory file
)))
1445 (format "Revision 2 to compare (default %s's current state): "
1446 (file-name-nondirectory file
))))
1447 (ediff-load-version-control)
1449 (intern (format "ediff-%S-internal" ediff-version-control-package
))
1450 rev1 rev2 startup-hooks
)
1455 (defalias 'erevision
'ediff-revision
)
1458 ;; Test if version control package is loaded and load if not
1459 ;; Is SILENT is non-nil, don't report error if package is not found.
1460 (defun ediff-load-version-control (&optional silent
)
1461 (require 'ediff-vers
)
1462 (or (featurep ediff-version-control-package
)
1463 (if (locate-library (symbol-name ediff-version-control-package
))
1465 (message "") ; kill the message from `locate-library'
1466 (require ediff-version-control-package
))
1468 (error "Version control package %S.el not found. Use vc.el instead"
1469 ediff-version-control-package
)))))
1473 (defun ediff-version ()
1474 "Return string describing the version of Ediff.
1475 When called interactively, displays the version."
1477 (if (if (featurep 'xemacs
)
1479 (called-interactively-p 'interactive
))
1480 (message "%s" (ediff-version))
1481 (format "Ediff %s of %s" ediff-version ediff-date
)))
1483 ;; info is run first, and will autoload info.el.
1484 (declare-function Info-goto-node
"info" (nodename &optional fork
))
1487 (defun ediff-documentation (&optional node
)
1488 "Display Ediff's manual.
1489 With optional NODE, goes to that node."
1491 (let ((ctl-window ediff-control-window
)
1492 (ctl-buf ediff-control-buffer
))
1494 (ediff-skip-unsuitable-frames)
1497 (pop-to-buffer (get-buffer-create "*info*"))
1498 (info (if (featurep 'xemacs
) "ediff.info" "ediff"))
1500 (Info-goto-node node
)
1501 (message "Type `i' to search for a specific topic"))
1502 (raise-frame (selected-frame)))
1504 (with-output-to-temp-buffer ediff-msg-buffer
1505 (ediff-with-current-buffer standard-output
1507 (princ ediff-BAD-INFO
))
1508 (if (window-live-p ctl-window
)
1510 (select-window ctl-window
)
1511 (set-window-buffer ctl-window ctl-buf
)))))))
1514 (dolist (mess '("^Errors in diff output. Diff output is in "
1515 "^Hmm... I don't see an Ediff command around here...$"
1516 "^Undocumented command! Type `G' in Ediff Control Panel to drop a note to the Ediff maintainer$"
1517 ": This command runs in Ediff Control Buffer only!$"
1518 ": Invalid op in ediff-check-version$"
1519 "^ediff-shrink-window-C can be used only for merging jobs$"
1520 "^Lost difference info on these directories$"
1521 "^This command is inapplicable in the present context$"
1522 "^This session group has no parent$"
1523 "^Can't hide active session, $"
1524 "^Ediff: something wrong--no multiple diffs buffer$"
1525 "^Can't make context diff for Session $"
1526 "^The patch buffer wasn't found$"
1528 "^This Ediff session is not part of a session group$"
1529 "^No active Ediff sessions or corrupted session registry$"
1530 "^No session info in this line$"
1531 "^`.*' is not an ordinary file$"
1532 "^Patch appears to have failed$"
1533 "^Recomputation of differences cancelled$"
1534 "^No fine differences in this mode$"
1535 "^Lost connection to ancestor buffer...sorry$"
1536 "^Not merging with ancestor$"
1537 "^Don't know how to toggle read-only in buffer "
1538 "Emacs is not running as a window application$"
1539 "^This command makes sense only when merging with an ancestor$"
1540 "^At end of the difference list$"
1541 "^At beginning of the difference list$"
1542 "^Nothing saved for diff .* in buffer "
1543 "^Buffer is out of sync for file "
1544 "^Buffer out of sync for file "
1545 "^Output from `diff' not found$"
1546 "^You forgot to specify a region in buffer "
1547 "^All right. Make up your mind and come back...$"
1548 "^Current buffer is not visiting any file$"
1549 "^Failed to retrieve revision: $"
1550 "^Can't determine display width.$"
1551 "^File `.*' does not exist or is not readable$"
1552 "^File `.*' is a directory$"
1553 "^Buffer .* doesn't exist$"
1554 "^Directories . and . are the same: "
1555 "^Directory merge aborted$"
1556 "^Merge of directory revisions aborted$"
1557 "^Buffer .* doesn't exist$"
1558 "^There is no file to merge$"
1559 "^Version control package .*.el not found. Use vc.el instead$"))
1560 (add-to-list 'debug-ignored-errors mess
))
1563 (require 'ediff-util
)
1565 (run-hooks 'ediff-load-hook
)
1569 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1570 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1571 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1574 ;;; ediff.el ends here