1 ;;; ediff.el --- a comprehensive visual interface to diff & patch
3 ;; Copyright (C) 1994-2014 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.5" "The current version of Ediff")
16 (defconst ediff-date
"July 4, 2013" "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 Ediff 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 ;; This duplicates code from menu-bar.el.
371 (unless (or (not (eq revert-buffer-function
'revert-buffer--default
))
372 (not (eq revert-buffer-insert-file-contents-function
373 'revert-buffer-insert-file-contents--default-function
))
374 (and buffer-file-number
375 (or (buffer-modified-p)
376 (not (verify-visited-file-modtime
377 (current-buffer))))))
378 (error "Nothing to revert"))
379 (let* ((auto-save-p (and (recent-auto-save-p)
380 buffer-auto-save-file-name
381 (file-readable-p buffer-auto-save-file-name
)
383 "Buffer has been auto-saved recently. Compare with auto-save file? ")))
384 (file-name (if auto-save-p
385 buffer-auto-save-file-name
387 (revert-buf-name (concat "FILE=" file-name
))
388 (revert-buf (get-buffer revert-buf-name
))
389 (current-major major-mode
))
391 (error "Buffer does not seem to be associated with any file"))
393 (kill-buffer revert-buf
)
394 (setq revert-buf nil
))
395 (setq revert-buf
(get-buffer-create revert-buf-name
))
396 (with-current-buffer revert-buf
397 (insert-file-contents file-name
)
398 ;; Assume same modes:
399 (funcall current-major
))
400 (ediff-buffers revert-buf
(current-buffer))))
404 (defun ediff-backup (file)
405 "Run Ediff on FILE and its backup file.
406 Uses the latest backup, if there are several numerical backups.
407 If this file is a backup, `ediff' it with its original."
408 (interactive (list (read-file-name "Ediff (file with backup): ")))
409 ;; The code is taken from `diff-backup'.
412 (if (backup-file-name-p file
)
414 ori
(file-name-sans-versions file
))
415 (setq bak
(or (diff-latest-backup-file file
)
416 (error "No backup found for %s" file
))
418 (ediff-files bak ori
)))
421 (defun ediff-buffers (buffer-A buffer-B
&optional startup-hooks job-name
)
422 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
425 (list (setq bf
(read-buffer "Buffer A to compare: "
426 (ediff-other-buffer "") t
))
427 (read-buffer "Buffer B to compare: "
429 ;; realign buffers so that two visible bufs will be
431 (save-window-excursion (other-window 1))
432 (ediff-other-buffer bf
))
434 (or job-name
(setq job-name
'ediff-buffers
))
435 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name
))
438 (defalias 'ebuffers
'ediff-buffers
)
442 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
443 &optional startup-hooks job-name
)
444 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
447 (list (setq bf
(read-buffer "Buffer A to compare: "
448 (ediff-other-buffer "") t
))
449 (setq bff
(read-buffer "Buffer B to compare: "
451 ;; realign buffers so that two visible
452 ;; bufs will be at the top
453 (save-window-excursion (other-window 1))
454 (ediff-other-buffer bf
))
456 (read-buffer "Buffer C to compare: "
458 ;; realign buffers so that three visible
459 ;; bufs will be at the top
460 (save-window-excursion (other-window 1))
461 (ediff-other-buffer (list bf bff
)))
464 (or job-name
(setq job-name
'ediff-buffers3
))
465 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name
))
468 (defalias 'ebuffers3
'ediff-buffers3
)
472 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
473 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
474 &optional merge-buffer-file
)
475 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A
)))
476 (buf-B-file-name (buffer-file-name (get-buffer buf-B
)))
477 (buf-C-is-alive (ediff-buffer-live-p buf-C
))
478 (buf-C-file-name (if buf-C-is-alive
479 (buffer-file-name (get-buffer buf-B
))))
480 file-A file-B file-C
)
483 (if (not (ediff-buffer-live-p buf-A
))
484 (error "Buffer %S doesn't exist" buf-A
))
485 (if (not (ediff-buffer-live-p buf-B
))
486 (error "Buffer %S doesn't exist" buf-B
))
487 (let ((ediff-job-name job-name
))
488 (if (and ediff-3way-comparison-job
489 (not buf-C-is-alive
))
490 (error "Buffer %S doesn't exist" buf-C
)))
491 (if (stringp buf-A-file-name
)
492 (setq buf-A-file-name
(file-name-nondirectory buf-A-file-name
)))
493 (if (stringp buf-B-file-name
)
494 (setq buf-B-file-name
(file-name-nondirectory buf-B-file-name
)))
495 (if (stringp buf-C-file-name
)
496 (setq buf-C-file-name
(file-name-nondirectory buf-C-file-name
)))
498 (setq file-A
(ediff-make-temp-file buf-A buf-A-file-name
)
499 file-B
(ediff-make-temp-file buf-B buf-B-file-name
))
501 (setq file-C
(ediff-make-temp-file buf-C buf-C-file-name
)))
503 (ediff-setup (get-buffer buf-A
) file-A
504 (get-buffer buf-B
) file-B
505 (if buf-C-is-alive
(get-buffer buf-C
))
508 (delete-file ,file-A
)
509 (delete-file ,file-B
)
510 (if (stringp ,file-C
) (delete-file ,file-C
)))
512 (list (cons 'ediff-job-name job-name
))
514 (if (and (stringp file-A
) (file-exists-p file-A
))
515 (delete-file file-A
))
516 (if (and (stringp file-B
) (file-exists-p file-B
))
517 (delete-file file-B
))
518 (if (and (stringp file-C
) (file-exists-p file-C
))
519 (delete-file file-C
)))))
522 ;;; Directory and file group operations
524 ;; Get appropriate default name for directory:
525 ;; If ediff-use-last-dir, use ediff-last-dir-A.
526 ;; In dired mode, use the directory that is under the point (if any);
527 ;; otherwise, use default-directory
528 (defun ediff-get-default-directory-name ()
529 (cond (ediff-use-last-dir ediff-last-dir-A
)
530 ((eq major-mode
'dired-mode
)
531 (let ((f (dired-get-filename nil
'noerror
)))
532 (if (and (stringp f
) (file-directory-p f
))
535 (t default-directory
)))
539 (defun ediff-directories (dir1 dir2 regexp
)
540 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
541 the same name in both. The third argument, REGEXP, is nil or a regular
542 expression; only file names that match the regexp are considered."
544 (let ((dir-A (ediff-get-default-directory-name))
545 (default-regexp (eval ediff-default-filtering-regexp
))
547 (list (setq f
(read-directory-name
548 "Directory A to compare: " dir-A nil
'must-match
))
549 (read-directory-name "Directory B to compare: "
550 (if ediff-use-last-dir
552 (ediff-strip-last-dir f
))
555 (if (stringp default-regexp
)
556 (format "Filter through regular expression (default %s): "
558 "Filter through regular expression: ")
560 'ediff-filtering-regexp-history
561 (eval ediff-default-filtering-regexp
))
563 (ediff-directories-internal
564 dir1 dir2 nil regexp
'ediff-files
'ediff-directories
568 (defalias 'edirs
'ediff-directories
)
572 (defun ediff-directory-revisions (dir1 regexp
)
573 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
574 The second argument, REGEXP, is a regular expression that filters the file
575 names. Only the files that are under revision control are taken into account."
577 (let ((dir-A (ediff-get-default-directory-name))
578 (default-regexp (eval ediff-default-filtering-regexp
))
580 (list (read-directory-name
581 "Directory to compare with revision:" dir-A nil
'must-match
)
583 (if (stringp default-regexp
)
584 (format "Filter through regular expression (default %s): "
586 "Filter through regular expression: ")
588 'ediff-filtering-regexp-history
589 (eval ediff-default-filtering-regexp
))
591 (ediff-directory-revisions-internal
592 dir1 regexp
'ediff-revision
'ediff-directory-revisions
596 (defalias 'edir-revisions
'ediff-directory-revisions
)
600 (defun ediff-directories3 (dir1 dir2 dir3 regexp
)
601 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
602 have the same name in all three. The last argument, REGEXP, is nil or a
603 regular expression; only file names that match the regexp are considered."
606 (let ((dir-A (ediff-get-default-directory-name))
607 (default-regexp (eval ediff-default-filtering-regexp
))
609 (list (setq f
(read-directory-name "Directory A to compare:" dir-A nil
))
610 (setq f
(read-directory-name "Directory B to compare:"
611 (if ediff-use-last-dir
613 (ediff-strip-last-dir f
))
615 (read-directory-name "Directory C to compare:"
616 (if ediff-use-last-dir
618 (ediff-strip-last-dir f
))
621 (if (stringp default-regexp
)
622 (format "Filter through regular expression (default %s): "
624 "Filter through regular expression: ")
626 'ediff-filtering-regexp-history
627 (eval ediff-default-filtering-regexp
))
629 (ediff-directories-internal
630 dir1 dir2 dir3 regexp
'ediff-files3
'ediff-directories3
634 (defalias 'edirs3
'ediff-directories3
)
637 (defun ediff-merge-directories (dir1 dir2 regexp
&optional merge-autostore-dir
)
638 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
639 the same name in both. The third argument, REGEXP, is nil or a regular
640 expression; only file names that match the regexp are considered."
642 (let ((dir-A (ediff-get-default-directory-name))
643 (default-regexp (eval ediff-default-filtering-regexp
))
645 (list (setq f
(read-directory-name "Directory A to merge:"
646 dir-A nil
'must-match
))
647 (read-directory-name "Directory B to merge:"
648 (if ediff-use-last-dir
650 (ediff-strip-last-dir f
))
653 (if (stringp default-regexp
)
654 (format "Filter through regular expression (default %s): "
656 "Filter through regular expression: ")
658 'ediff-filtering-regexp-history
659 (eval ediff-default-filtering-regexp
))
661 (ediff-directories-internal
662 dir1 dir2 nil regexp
'ediff-merge-files
'ediff-merge-directories
663 nil merge-autostore-dir
667 (defalias 'edirs-merge
'ediff-merge-directories
)
670 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
673 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
674 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
675 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
676 without ancestor. The fourth argument, REGEXP, is nil or a regular expression;
677 only file names that match the regexp are considered."
679 (let ((dir-A (ediff-get-default-directory-name))
680 (default-regexp (eval ediff-default-filtering-regexp
))
682 (list (setq f
(read-directory-name "Directory A to merge:" dir-A nil
))
683 (setq f
(read-directory-name "Directory B to merge:"
684 (if ediff-use-last-dir
686 (ediff-strip-last-dir f
))
688 (read-directory-name "Ancestor directory:"
689 (if ediff-use-last-dir
691 (ediff-strip-last-dir f
))
694 (if (stringp default-regexp
)
695 (format "Filter through regular expression (default %s): "
697 "Filter through regular expression: ")
699 'ediff-filtering-regexp-history
700 (eval ediff-default-filtering-regexp
))
702 (ediff-directories-internal
703 dir1 dir2 ancestor-dir regexp
704 'ediff-merge-files-with-ancestor
'ediff-merge-directories-with-ancestor
705 nil merge-autostore-dir
709 (defun ediff-merge-directory-revisions (dir1 regexp
710 &optional merge-autostore-dir
)
711 "Run Ediff on a directory, DIR1, merging its files with their revisions.
712 The second argument, REGEXP, is a regular expression that filters the file
713 names. Only the files that are under revision control are taken into account."
715 (let ((dir-A (ediff-get-default-directory-name))
716 (default-regexp (eval ediff-default-filtering-regexp
))
718 (list (read-directory-name
719 "Directory to merge with revisions:" dir-A nil
'must-match
)
721 (if (stringp default-regexp
)
722 (format "Filter through regular expression (default %s): "
724 "Filter through regular expression: ")
726 'ediff-filtering-regexp-history
727 (eval ediff-default-filtering-regexp
))
729 (ediff-directory-revisions-internal
730 dir1 regexp
'ediff-merge-revisions
'ediff-merge-directory-revisions
731 nil merge-autostore-dir
735 (defalias 'edir-merge-revisions
'ediff-merge-directory-revisions
)
738 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
741 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
742 The second argument, REGEXP, is a regular expression that filters the file
743 names. Only the files that are under revision control are taken into account."
745 (let ((dir-A (ediff-get-default-directory-name))
746 (default-regexp (eval ediff-default-filtering-regexp
))
748 (list (read-directory-name
749 "Directory to merge with revisions and ancestors:"
750 dir-A nil
'must-match
)
752 (if (stringp default-regexp
)
753 (format "Filter through regular expression (default %s): "
755 "Filter through regular expression: ")
757 'ediff-filtering-regexp-history
758 (eval ediff-default-filtering-regexp
))
760 (ediff-directory-revisions-internal
761 dir1 regexp
'ediff-merge-revisions-with-ancestor
762 'ediff-merge-directory-revisions-with-ancestor
763 nil merge-autostore-dir
768 'edir-merge-revisions-with-ancestor
769 'ediff-merge-directory-revisions-with-ancestor
)
772 (defalias 'edirs-merge-with-ancestor
'ediff-merge-directories-with-ancestor
)
774 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
775 ;; on a pair of directories (three directories, in case of ancestor).
776 ;; The third argument, REGEXP, is nil or a regular expression;
777 ;; only file names that match the regexp are considered.
778 ;; JOBNAME is the symbol indicating the meta-job to be performed.
779 ;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
780 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
781 &optional startup-hooks
784 (setq dir3
(if (file-directory-p dir3
) dir3
(file-name-directory dir3
))))
786 (cond ((string= dir1 dir2
)
787 (error "Directories A and B are the same: %s" dir1
))
788 ((and (eq jobname
'ediff-directories3
)
790 (error "Directories A and C are the same: %s" dir1
))
791 ((and (eq jobname
'ediff-directories3
)
793 (error "Directories B and C are the same: %s" dir1
)))
795 (if merge-autostore-dir
796 (or (stringp merge-autostore-dir
)
797 (error "%s: Directory for storing merged files must be a string"
799 (let (;; dir-diff-struct is of the form (common-list diff-list)
800 ;; It is a structure where ediff-intersect-directories returns
801 ;; commonalities and differences among directories
804 (if (and ediff-autostore-merges
805 (ediff-merge-metajob jobname
)
806 (not merge-autostore-dir
))
807 (setq merge-autostore-dir
808 (read-directory-name "Save merged files in directory: "
809 (if ediff-use-last-dir
810 ediff-last-merge-autostore-dir
811 (ediff-strip-last-dir dir1
))
814 ;; verify we are not merging into an orig directory
815 (if merge-autostore-dir
816 (cond ((and (stringp dir1
) (string= merge-autostore-dir dir1
))
818 "Directory for saving merged files = Directory A. Sure? ")
819 (error "Directory merge aborted")))
820 ((and (stringp dir2
) (string= merge-autostore-dir dir2
))
822 "Directory for saving merged files = Directory B. Sure? ")
823 (error "Directory merge aborted")))
824 ((and (stringp dir3
) (string= merge-autostore-dir dir3
))
826 "Directory for saving merged files = Ancestor Directory. Sure? ")
827 (error "Directory merge aborted")))))
829 (setq dir-diff-struct
(ediff-intersect-directories
831 regexp dir1 dir2 dir3 merge-autostore-dir
))
833 ;; this sets various vars in the meta buffer inside
834 ;; ediff-prepare-meta-buffer
836 ;; tell what to do if the user clicks on a session record
837 (setq ediff-session-action-function
(quote ,action
))
838 ;; set ediff-dir-difference-list
839 (setq ediff-dir-difference-list
840 (cdr (quote ,dir-diff-struct
))))
842 (setq meta-buf
(ediff-prepare-meta-buffer
843 'ediff-filegroup-action
844 (car dir-diff-struct
)
845 "*Ediff Session Group Panel"
846 'ediff-redraw-directory-group-buffer
849 (ediff-show-meta-buffer meta-buf
)
852 ;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
854 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
855 &optional startup-hooks
857 (setq dir1
(if (file-directory-p dir1
) dir1
(file-name-directory dir1
)))
859 (if merge-autostore-dir
860 (or (stringp merge-autostore-dir
)
861 (error "%S: Directory for storing merged files must be a string"
863 (let (file-list meta-buf
)
864 (if (and ediff-autostore-merges
865 (ediff-merge-metajob jobname
)
866 (not merge-autostore-dir
))
867 (setq merge-autostore-dir
868 (read-directory-name "Save merged files in directory: "
869 (if ediff-use-last-dir
870 ediff-last-merge-autostore-dir
871 (ediff-strip-last-dir dir1
))
874 ;; verify merge-autostore-dir != dir1
875 (if (and merge-autostore-dir
877 (string= merge-autostore-dir dir1
))
879 "Directory for saving merged file = directory A. Sure? ")
880 (error "Merge of directory revisions aborted")))
883 (ediff-get-directory-files-under-revision
884 jobname regexp dir1 merge-autostore-dir
))
886 ;; this sets various vars in the meta buffer inside
887 ;; ediff-prepare-meta-buffer
889 ;; tell what to do if the user clicks on a session record
890 (setq ediff-session-action-function
(quote ,action
)))
892 (setq meta-buf
(ediff-prepare-meta-buffer
893 'ediff-filegroup-action
895 "*Ediff Session Group Panel"
896 'ediff-redraw-directory-group-buffer
899 (ediff-show-meta-buffer meta-buf
)
903 ;;; Compare regions and windows
906 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks
)
907 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
908 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
910 If WIND-A is nil, use selected window.
911 If WIND-B is nil, use window next to WIND-A."
913 (ediff-windows dumb-mode wind-A wind-B
914 startup-hooks
'ediff-windows-wordwise
'word-mode
))
917 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks
)
918 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
919 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
921 If WIND-A is nil, use selected window.
922 If WIND-B is nil, use window next to WIND-A."
924 (ediff-windows dumb-mode wind-A wind-B
925 startup-hooks
'ediff-windows-linewise nil
))
927 ;; Compare WIND-A and WIND-B, which are selected by clicking.
928 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
930 ;; If WIND-A is nil, use selected window.
931 ;; If WIND-B is nil, use window next to WIND-A.
932 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode
)
933 (if (or dumb-mode
(not (ediff-window-display-p)))
934 (setq wind-A
(ediff-get-next-window wind-A nil
)
935 wind-B
(ediff-get-next-window wind-B wind-A
))
936 (setq wind-A
(ediff-get-window-by-clicking wind-A nil
1)
937 wind-B
(ediff-get-window-by-clicking wind-B wind-A
2)))
939 (let ((buffer-A (window-buffer wind-A
))
940 (buffer-B (window-buffer wind-B
))
941 beg-A end-A beg-B end-B
)
944 (save-window-excursion
945 (sit-for 0) ; sync before using window-start/end -- a precaution
946 (select-window wind-A
)
947 (setq beg-A
(window-start)
949 (select-window wind-B
)
950 (setq beg-B
(window-start)
951 end-B
(window-end))))
953 (ediff-clone-buffer-for-window-comparison
954 buffer-A wind-A
"-Window.A-")
956 (ediff-clone-buffer-for-window-comparison
957 buffer-B wind-B
"-Window.B-"))
958 (ediff-regions-internal
959 buffer-A beg-A end-A buffer-B beg-B end-B
960 startup-hooks job-name word-mode nil
)))
964 (defun ediff-regions-wordwise (buffer-A buffer-B
&optional startup-hooks
)
965 "Run Ediff on a pair of regions in specified buffers.
966 Regions \(i.e., point and mark\) can be set in advance or marked interactively.
967 This function is effective only for relatively small regions, up to 200
968 lines. For large regions, use `ediff-regions-linewise'."
971 (list (setq bf
(read-buffer "Region's A buffer: "
972 (ediff-other-buffer "") t
))
973 (read-buffer "Region's B buffer: "
975 ;; realign buffers so that two visible bufs will be
977 (save-window-excursion (other-window 1))
978 (ediff-other-buffer bf
))
980 (if (not (ediff-buffer-live-p buffer-A
))
981 (error "Buffer %S doesn't exist" buffer-A
))
982 (if (not (ediff-buffer-live-p buffer-B
))
983 (error "Buffer %S doesn't exist" buffer-B
))
987 (ediff-clone-buffer-for-region-comparison buffer-A
"-Region.A-"))
989 (ediff-clone-buffer-for-region-comparison buffer-B
"-Region.B-"))
990 reg-A-beg reg-A-end reg-B-beg reg-B-end
)
991 (with-current-buffer buffer-A
992 (setq reg-A-beg
(region-beginning)
993 reg-A-end
(region-end))
994 (set-buffer buffer-B
)
995 (setq reg-B-beg
(region-beginning)
996 reg-B-end
(region-end)))
998 (ediff-regions-internal
999 (get-buffer buffer-A
) reg-A-beg reg-A-end
1000 (get-buffer buffer-B
) reg-B-beg reg-B-end
1001 startup-hooks
'ediff-regions-wordwise
'word-mode nil
)))
1004 (defun ediff-regions-linewise (buffer-A buffer-B
&optional startup-hooks
)
1005 "Run Ediff on a pair of regions in specified buffers.
1006 Regions \(i.e., point and mark\) can be set in advance or marked interactively.
1007 Each region is enlarged to contain full lines.
1008 This function is effective for large regions, over 100-200
1009 lines. For small regions, use `ediff-regions-wordwise'."
1012 (list (setq bf
(read-buffer "Region A's buffer: "
1013 (ediff-other-buffer "") t
))
1014 (read-buffer "Region B's buffer: "
1016 ;; realign buffers so that two visible bufs will be
1018 (save-window-excursion (other-window 1))
1019 (ediff-other-buffer bf
))
1021 (if (not (ediff-buffer-live-p buffer-A
))
1022 (error "Buffer %S doesn't exist" buffer-A
))
1023 (if (not (ediff-buffer-live-p buffer-B
))
1024 (error "Buffer %S doesn't exist" buffer-B
))
1027 (ediff-clone-buffer-for-region-comparison buffer-A
"-Region.A-"))
1029 (ediff-clone-buffer-for-region-comparison buffer-B
"-Region.B-"))
1030 reg-A-beg reg-A-end reg-B-beg reg-B-end
)
1031 (with-current-buffer buffer-A
1032 (setq reg-A-beg
(region-beginning)
1033 reg-A-end
(region-end))
1034 ;; enlarge the region to hold full lines
1035 (goto-char reg-A-beg
)
1037 (setq reg-A-beg
(point))
1038 (goto-char reg-A-end
)
1040 (or (eobp) (forward-char)) ; include the newline char
1041 (setq reg-A-end
(point))
1043 (set-buffer buffer-B
)
1044 (setq reg-B-beg
(region-beginning)
1045 reg-B-end
(region-end))
1046 ;; enlarge the region to hold full lines
1047 (goto-char reg-B-beg
)
1049 (setq reg-B-beg
(point))
1050 (goto-char reg-B-end
)
1052 (or (eobp) (forward-char)) ; include the newline char
1053 (setq reg-B-end
(point))
1056 (ediff-regions-internal
1057 (get-buffer buffer-A
) reg-A-beg reg-A-end
1058 (get-buffer buffer-B
) reg-B-beg reg-B-end
1059 startup-hooks
'ediff-regions-linewise nil nil
))) ; no word mode
1061 ;; compare region beg-A to end-A of buffer-A
1062 ;; to regions beg-B -- end-B in buffer-B.
1063 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
1064 startup-hooks job-name word-mode
1066 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer
))
1071 ;; in case beg/end-A/B aren't markers--make them into markers
1072 (ediff-with-current-buffer buffer-A
1073 (setq beg-A
(move-marker (make-marker) beg-A
)
1074 end-A
(move-marker (make-marker) end-A
)))
1075 (ediff-with-current-buffer buffer-B
1076 (setq beg-B
(move-marker (make-marker) beg-B
)
1077 end-B
(move-marker (make-marker) end-B
)))
1081 (ediff-wordify beg-A end-A buffer-A tmp-buffer
)
1082 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer
))
1083 (setq file-A
(ediff-make-temp-file tmp-buffer
"regA"))
1087 (ediff-wordify beg-B end-B buffer-B tmp-buffer
)
1088 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer
))
1089 (setq file-B
(ediff-make-temp-file tmp-buffer
"regB"))
1091 (setq overl-A
(ediff-make-bullet-proof-overlay beg-A end-A buffer-A
))
1092 (setq overl-B
(ediff-make-bullet-proof-overlay beg-B end-B buffer-B
))
1093 (ediff-setup buffer-A file-A
1095 nil nil
; buffer & file C
1097 (delete-file ,file-A
)
1098 (delete-file ,file-B
))
1101 (list (cons 'ediff-word-mode word-mode
)
1102 (cons 'ediff-narrow-bounds
(list overl-A overl-B
))
1103 (cons 'ediff-job-name job-name
))
1105 (if (and (stringp file-A
) (file-exists-p file-A
))
1106 (delete-file file-A
))
1107 (if (and (stringp file-B
) (file-exists-p file-B
))
1108 (delete-file file-B
)))
1112 ;;; Merge files and buffers
1115 (defalias 'ediff-merge
'ediff-merge-files
)
1117 (defsubst ediff-merge-on-startup
()
1119 ;; Can't remember why this is here, but it may cause the automatically merged
1120 ;; buffer to be lost. So, keep the buffer modified.
1121 ;;(ediff-with-current-buffer ediff-buffer-C
1122 ;; (set-buffer-modified-p nil))
1126 (defun ediff-merge-files (file-A file-B
1127 ;; MERGE-BUFFER-FILE is the file to be
1128 ;; associated with the merge buffer
1129 &optional startup-hooks merge-buffer-file
)
1130 "Merge two files without ancestor."
1132 (let ((dir-A (if ediff-use-last-dir
1136 (list (setq f
(ediff-read-file-name
1139 (ediff-get-default-file-name)
1141 (ediff-read-file-name "File B to merge"
1143 (if ediff-use-last-dir
1145 (file-name-directory f
)))
1147 (ediff-add-to-history
1149 (ediff-abbreviate-file-name
1151 (file-name-nondirectory f
)
1153 (ediff-get-default-file-name f
1)))
1155 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1156 (ediff-files-internal file-A
1157 (if (file-directory-p file-B
)
1159 (file-name-nondirectory file-A
) file-B
)
1167 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
1170 ;; MERGE-BUFFER-FILE is the file
1171 ;; to be associated with the
1174 "Merge two files with ancestor."
1176 (let ((dir-A (if ediff-use-last-dir
1179 dir-B dir-ancestor f ff
)
1180 (list (setq f
(ediff-read-file-name
1183 (ediff-get-default-file-name)
1185 (setq ff
(ediff-read-file-name "File B to merge"
1187 (if ediff-use-last-dir
1189 (file-name-directory f
)))
1191 (ediff-add-to-history
1193 (ediff-abbreviate-file-name
1195 (file-name-nondirectory f
)
1197 (ediff-get-default-file-name f
1))))
1198 (ediff-read-file-name "Ancestor file"
1200 (if ediff-use-last-dir
1201 ediff-last-dir-ancestor
1202 (file-name-directory ff
)))
1204 (ediff-add-to-history
1206 (ediff-abbreviate-file-name
1208 (file-name-nondirectory ff
)
1210 (ediff-get-default-file-name ff
2)))
1212 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1213 (ediff-files-internal file-A
1214 (if (file-directory-p file-B
)
1216 (file-name-nondirectory file-A
) file-B
)
1220 'ediff-merge-files-with-ancestor
1224 (defalias 'ediff-merge-with-ancestor
'ediff-merge-files-with-ancestor
)
1227 (defun ediff-merge-buffers (buffer-A buffer-B
1229 ;; MERGE-BUFFER-FILE is the file to be
1230 ;; associated with the merge buffer
1231 startup-hooks job-name merge-buffer-file
)
1232 "Merge buffers without ancestor."
1235 (list (setq bf
(read-buffer "Buffer A to merge: "
1236 (ediff-other-buffer "") t
))
1237 (read-buffer "Buffer B to merge: "
1239 ;; realign buffers so that two visible bufs will be
1241 (save-window-excursion (other-window 1))
1242 (ediff-other-buffer bf
))
1245 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1246 (or job-name
(setq job-name
'ediff-merge-buffers
))
1247 (ediff-buffers-internal
1248 buffer-A buffer-B nil startup-hooks job-name merge-buffer-file
))
1251 (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
1255 ;; MERGE-BUFFER-FILE is the
1256 ;; file to be associated
1257 ;; with the merge buffer
1259 "Merge buffers with ancestor."
1262 (list (setq bf
(read-buffer "Buffer A to merge: "
1263 (ediff-other-buffer "") t
))
1264 (setq bff
(read-buffer "Buffer B to merge: "
1266 ;; realign buffers so that two visible
1267 ;; bufs will be at the top
1268 (save-window-excursion (other-window 1))
1269 (ediff-other-buffer bf
))
1271 (read-buffer "Ancestor buffer: "
1273 ;; realign buffers so that three visible
1274 ;; bufs will be at the top
1275 (save-window-excursion (other-window 1))
1276 (ediff-other-buffer (list bf bff
)))
1280 (setq startup-hooks
(cons 'ediff-merge-on-startup startup-hooks
))
1281 (or job-name
(setq job-name
'ediff-merge-buffers-with-ancestor
))
1282 (ediff-buffers-internal
1283 buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file
))
1287 (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file
)
1288 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
1289 "Run Ediff by merging two revisions of a file.
1290 The file is the optional FILE argument or the file visited by the current
1293 (if (stringp file
) (find-file file
))
1298 "Version 1 to merge (default %s's working version): "
1300 (file-name-nondirectory file
) "current buffer")))
1304 "Version 2 to merge (default %s): "
1306 (file-name-nondirectory file
) "current buffer"))))
1307 (ediff-load-version-control)
1308 ;; ancestor-revision=nil
1310 (intern (format "ediff-%S-merge-internal" ediff-version-control-package
))
1311 rev1 rev2 nil startup-hooks merge-buffer-file
)))
1315 (defun ediff-merge-revisions-with-ancestor (&optional
1317 ;; MERGE-BUFFER-FILE is the file to
1318 ;; be associated with the merge
1321 "Run Ediff by merging two revisions of a file with a common ancestor.
1322 The file is the optional FILE argument or the file visited by the current
1325 (if (stringp file
) (find-file file
))
1326 (let (rev1 rev2 ancestor-rev
)
1330 "Version 1 to merge (default %s's working version): "
1332 (file-name-nondirectory file
) "current buffer")))
1336 "Version 2 to merge (default %s): "
1338 (file-name-nondirectory file
) "current buffer")))
1342 "Ancestor version (default %s's base revision): "
1344 (file-name-nondirectory file
) "current buffer"))))
1345 (ediff-load-version-control)
1347 (intern (format "ediff-%S-merge-internal" ediff-version-control-package
))
1348 rev1 rev2 ancestor-rev startup-hooks merge-buffer-file
)))
1351 (defvar ediff-last-dir-patch
)
1352 (defvar ediff-patch-default-directory
)
1353 (declare-function ediff-get-patch-buffer
"ediff-ptch"
1354 (&optional arg patch-buf
))
1355 (declare-function ediff-dispatch-file-patching-job
"ediff-ptch"
1356 (patch-buf filename
&optional startup-hooks
))
1359 (defun ediff-patch-file (&optional arg patch-buf
)
1360 "Query for a file name, and then run Ediff by patching that file.
1361 If optional PATCH-BUF is given, use the patch in that buffer
1362 and don't ask the user.
1363 If prefix argument, then: if even argument, assume that the patch is in a
1364 buffer. If odd -- assume it is in a file."
1366 (let (source-dir source-file
)
1367 (require 'ediff-ptch
)
1369 (ediff-get-patch-buffer
1370 (if arg
(prefix-numeric-value arg
)) patch-buf
))
1371 (setq source-dir
(cond (ediff-use-last-dir ediff-last-dir-patch
)
1372 ((and (not ediff-patch-default-directory
)
1373 (buffer-file-name patch-buf
))
1374 (file-name-directory
1376 (buffer-file-name patch-buf
))))
1377 (t default-directory
)))
1380 "File to patch (directory, if multifile patch): "
1381 ;; use an explicit initial file
1382 source-dir nil nil
(ediff-get-default-file-name)))
1383 (ediff-dispatch-file-patching-job patch-buf source-file
)))
1385 (declare-function ediff-patch-buffer-internal
"ediff-ptch"
1386 (patch-buf buf-to-patch-name
&optional startup-hooks
))
1389 (defun ediff-patch-buffer (&optional arg patch-buf
)
1390 "Run Ediff by patching the buffer specified at prompt.
1391 Without the optional prefix ARG, asks if the patch is in some buffer and
1392 prompts for the buffer or a file, depending on the answer.
1393 With ARG=1, assumes the patch is in a file and prompts for the file.
1394 With ARG=2, assumes the patch is in a buffer and prompts for the buffer.
1395 PATCH-BUF is an optional argument, which specifies the buffer that contains the
1396 patch. If not given, the user is prompted according to the prefix argument."
1398 (require 'ediff-ptch
)
1400 (ediff-get-patch-buffer
1401 (if arg
(prefix-numeric-value arg
)) patch-buf
))
1402 (ediff-patch-buffer-internal
1405 "Which buffer to patch? "
1406 (ediff-other-buffer patch-buf
))))
1410 (defalias 'epatch
'ediff-patch-file
)
1412 (defalias 'epatch-buffer
'ediff-patch-buffer
)
1417 ;;; Versions Control functions
1420 (defun ediff-revision (&optional file startup-hooks
)
1421 "Run Ediff by comparing versions of a file.
1422 The file is an optional FILE argument or the file entered at the prompt.
1423 Default: the file visited by the current buffer.
1424 Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
1425 ;; if buffer is non-nil, use that buffer instead of the current buffer
1427 (if (not (stringp file
))
1429 (ediff-read-file-name "Compare revisions for file"
1430 (if ediff-use-last-dir
1433 (ediff-get-default-file-name)
1436 (if (and (buffer-modified-p)
1437 (y-or-n-p (format "Buffer %s is modified. Save buffer? "
1439 (save-buffer (current-buffer)))
1443 (format "Revision 1 to compare (default %s's latest revision): "
1444 (file-name-nondirectory file
)))
1447 (format "Revision 2 to compare (default %s's current state): "
1448 (file-name-nondirectory file
))))
1449 (ediff-load-version-control)
1451 (intern (format "ediff-%S-internal" ediff-version-control-package
))
1452 rev1 rev2 startup-hooks
)
1457 (defalias 'erevision
'ediff-revision
)
1460 ;; Test if version control package is loaded and load if not
1461 ;; Is SILENT is non-nil, don't report error if package is not found.
1462 (defun ediff-load-version-control (&optional silent
)
1463 (require 'ediff-vers
)
1464 (or (featurep ediff-version-control-package
)
1465 (if (locate-library (symbol-name ediff-version-control-package
))
1467 (message "") ; kill the message from `locate-library'
1468 (require ediff-version-control-package
))
1470 (error "Version control package %S.el not found. Use vc.el instead"
1471 ediff-version-control-package
)))))
1475 (defun ediff-version ()
1476 "Return string describing the version of Ediff.
1477 When called interactively, displays the version."
1479 (if (if (featurep 'xemacs
)
1481 (called-interactively-p 'interactive
))
1482 (message "%s" (ediff-version))
1483 (format "Ediff %s of %s" ediff-version ediff-date
)))
1485 ;; info is run first, and will autoload info.el.
1486 (declare-function Info-goto-node
"info" (nodename &optional fork strict-case
))
1489 (defun ediff-documentation (&optional node
)
1490 "Display Ediff's manual.
1491 With optional NODE, goes to that node."
1493 (let ((ctl-window ediff-control-window
)
1494 (ctl-buf ediff-control-buffer
))
1496 (ediff-skip-unsuitable-frames)
1499 (pop-to-buffer (get-buffer-create "*info*"))
1500 (info (if (featurep 'xemacs
) "ediff.info" "ediff"))
1502 (Info-goto-node node
)
1503 (message "Type `i' to search for a specific topic"))
1506 (with-output-to-temp-buffer ediff-msg-buffer
1507 (ediff-with-current-buffer standard-output
1509 (princ ediff-BAD-INFO
))
1510 (if (window-live-p ctl-window
)
1512 (select-window ctl-window
)
1513 (set-window-buffer ctl-window ctl-buf
)))))))
1516 (dolist (mess '("^Errors in diff output. Diff output is in "
1517 "^Hmm... I don't see an Ediff command around here...$"
1518 "^Undocumented command! Type `G' in Ediff Control Panel to drop a note to the Ediff maintainer$"
1519 ": This command runs in Ediff Control Buffer only!$"
1520 ": Invalid op in ediff-check-version$"
1521 "^ediff-shrink-window-C can be used only for merging jobs$"
1522 "^Lost difference info on these directories$"
1523 "^This command is inapplicable in the present context$"
1524 "^This session group has no parent$"
1525 "^Can't hide active session, $"
1526 "^Ediff: something wrong--no multiple diffs buffer$"
1527 "^Can't make context diff for Session $"
1528 "^The patch buffer wasn't found$"
1530 "^This Ediff session is not part of a session group$"
1531 "^No active Ediff sessions or corrupted session registry$"
1532 "^No session info in this line$"
1533 "^`.*' is not an ordinary file$"
1534 "^Patch appears to have failed$"
1535 "^Recomputation of differences cancelled$"
1536 "^No fine differences in this mode$"
1537 "^Lost connection to ancestor buffer...sorry$"
1538 "^Not merging with ancestor$"
1539 "^Don't know how to toggle read-only in buffer "
1540 "Emacs is not running as a window application$"
1541 "^This command makes sense only when merging with an ancestor$"
1542 "^At end of the difference list$"
1543 "^At beginning of the difference list$"
1544 "^Nothing saved for diff .* in buffer "
1545 "^Buffer is out of sync for file "
1546 "^Buffer out of sync for file "
1547 "^Output from `diff' not found$"
1548 "^You forgot to specify a region in buffer "
1549 "^All right. Make up your mind and come back...$"
1550 "^Current buffer is not visiting any file$"
1551 "^Failed to retrieve revision: $"
1552 "^Can't determine display width.$"
1553 "^File `.*' does not exist or is not readable$"
1554 "^File `.*' is a directory$"
1555 "^Buffer .* doesn't exist$"
1556 "^Directories . and . are the same: "
1557 "^Directory merge aborted$"
1558 "^Merge of directory revisions aborted$"
1559 "^Buffer .* doesn't exist$"
1560 "^There is no file to merge$"
1561 "^Version control package .*.el not found. Use vc.el instead$"))
1562 (add-to-list 'debug-ignored-errors mess
))
1566 ;;; Command line interface
1569 (defun ediff-files-command ()
1570 (let ((file-a (nth 0 command-line-args-left
))
1571 (file-b (nth 1 command-line-args-left
)))
1572 (setq command-line-args-left
(nthcdr 2 command-line-args-left
))
1573 (ediff file-a file-b
)))
1576 (defun ediff3-files-command ()
1577 (let ((file-a (nth 0 command-line-args-left
))
1578 (file-b (nth 1 command-line-args-left
))
1579 (file-c (nth 2 command-line-args-left
)))
1580 (setq command-line-args-left
(nthcdr 3 command-line-args-left
))
1581 (ediff3 file-a file-b file-c
)))
1584 (defun ediff-merge-command ()
1585 (let ((file-a (nth 0 command-line-args-left
))
1586 (file-b (nth 1 command-line-args-left
)))
1587 (setq command-line-args-left
(nthcdr 2 command-line-args-left
))
1588 (ediff-merge-files file-a file-b
)))
1591 (defun ediff-merge-with-ancestor-command ()
1592 (let ((file-a (nth 0 command-line-args-left
))
1593 (file-b (nth 1 command-line-args-left
))
1594 (ancestor (nth 2 command-line-args-left
)))
1595 (setq command-line-args-left
(nthcdr 3 command-line-args-left
))
1596 (ediff-merge-files-with-ancestor file-a file-b ancestor
)))
1599 (defun ediff-directories-command ()
1600 (let ((file-a (nth 0 command-line-args-left
))
1601 (file-b (nth 1 command-line-args-left
))
1602 (regexp (nth 2 command-line-args-left
)))
1603 (setq command-line-args-left
(nthcdr 3 command-line-args-left
))
1604 (ediff-directories file-a file-b regexp
)))
1607 (defun ediff-directories3-command ()
1608 (let ((file-a (nth 0 command-line-args-left
))
1609 (file-b (nth 1 command-line-args-left
))
1610 (file-c (nth 2 command-line-args-left
))
1611 (regexp (nth 3 command-line-args-left
)))
1612 (setq command-line-args-left
(nthcdr 4 command-line-args-left
))
1613 (ediff-directories3 file-a file-b file-c regexp
)))
1616 (defun ediff-merge-directories-command ()
1617 (let ((file-a (nth 0 command-line-args-left
))
1618 (file-b (nth 1 command-line-args-left
))
1619 (regexp (nth 2 command-line-args-left
)))
1620 (setq command-line-args-left
(nthcdr 3 command-line-args-left
))
1621 (ediff-merge-directories file-a file-b regexp
)))
1624 (defun ediff-merge-directories-with-ancestor-command ()
1625 (let ((file-a (nth 0 command-line-args-left
))
1626 (file-b (nth 1 command-line-args-left
))
1627 (ancestor (nth 2 command-line-args-left
))
1628 (regexp (nth 3 command-line-args-left
)))
1629 (setq command-line-args-left
(nthcdr 4 command-line-args-left
))
1630 (ediff-merge-directories-with-ancestor file-a file-b ancestor regexp
)))
1634 (require 'ediff-util
)
1636 (run-hooks 'ediff-load-hook
)
1640 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1641 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1642 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1645 ;;; ediff.el ends here