ediff.el 54.6 KB
Newer Older
1
;;; ediff.el --- a comprehensive visual interface to diff & patch
Erik Naggum's avatar
Erik Naggum committed
2

3
;; Copyright (C) 1994-2012 Free Software Foundation, Inc.
Richard M. Stallman's avatar
Richard M. Stallman committed
4

5
;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
Richard M. Stallman's avatar
Richard M. Stallman committed
6
;; Created: February 2, 1994
7
;; Keywords: comparing, merging, patching, vc, tools, unix
8
;; Version: 2.81.4
Richard M. Stallman's avatar
Richard M. Stallman committed
9

10 11 12 13 14
;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
;; file on 20/3/2008, and the maintainer agreed that when a bug is
;; filed in the Emacs bug reporting system against this file, a copy
;; of the bug report be sent to the maintainer's email address.

15 16
(defconst ediff-version "2.81.4" "The current version of Ediff")
(defconst ediff-date "December 7, 2009" "Date of last update")
Michael Kifer's avatar
Michael Kifer committed
17

18

Richard M. Stallman's avatar
Richard M. Stallman committed
19 20
;; This file is part of GNU Emacs.

21
;; GNU Emacs is free software: you can redistribute it and/or modify
Richard M. Stallman's avatar
Richard M. Stallman committed
22
;; it under the terms of the GNU General Public License as published by
23 24
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Richard M. Stallman's avatar
Richard M. Stallman committed
25 26 27 28 29 30 31

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; 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/>.
Richard M. Stallman's avatar
Richard M. Stallman committed
33 34 35

;;; Commentary:

36
;; Never read that diff output again!
Michael Kifer's avatar
Michael Kifer committed
37
;; Apply patch interactively!
38
;; Merge with ease!
Richard M. Stallman's avatar
Richard M. Stallman committed
39

40
;; This package provides a convenient way of simultaneous browsing through
Karl Heuer's avatar
Karl Heuer committed
41
;; the differences between a pair (or a triple) of files or buffers.  The
42 43 44 45 46
;; files being compared, file-A, file-B, and file-C (if applicable) are
;; shown in separate windows (side by side, one above the another, or in
;; separate frames), and the differences are highlighted as you step
;; through them.  You can also copy difference regions from one buffer to
;; another (and recover old differences if you change your mind).
Richard M. Stallman's avatar
Richard M. Stallman committed
47

48
;; Ediff also supports merging operations on files and buffers, including
Michael Kifer's avatar
Michael Kifer committed
49
;; merging using ancestor versions.  Both comparison and merging operations can
50 51 52
;; be performed on directories, i.e., by pairwise comparison of files in those
;; directories.

Richard M. Stallman's avatar
Richard M. Stallman committed
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,
Richard M. Stallman's avatar
Richard M. Stallman committed
55 56 57 58
;; difference-by-difference.  You can even apply a patch right out of a
;; mail buffer, i.e., patches received by mail don't even have to be saved.
;; Since Ediff lets you copy differences between buffers, you can, in
;; effect, apply patches selectively (i.e., you can copy a difference
59
;; region from file_orig to file, thereby undoing any particular patch that
Richard M. Stallman's avatar
Richard M. Stallman committed
60 61
;; you don't like).

Karl Heuer's avatar
Karl Heuer committed
62
;; Ediff is aware of version control, which lets the user compare
Michael Kifer's avatar
Michael Kifer committed
63 64
;; files with their older versions.  Ediff can also work with remote and
;; compressed files.  Details are given below.
Karl Heuer's avatar
Karl Heuer committed
65

Michael Kifer's avatar
Michael Kifer committed
66
;; Finally, Ediff supports directory-level comparison, merging and patching.
67
;; See the on-line manual for details.
Richard M. Stallman's avatar
Richard M. Stallman committed
68

69
;; This package builds upon the ideas borrowed from emerge.el and several
Michael Kifer's avatar
Michael Kifer committed
70
;; Ediff's functions are adaptations from emerge.el.  Much of the functionality
71 72
;; Ediff provides is also influenced by emerge.el.

Michael Kifer's avatar
Michael Kifer committed
73 74
;; The present version of Ediff supersedes Emerge.  It provides a superior user
;; interface and has numerous major features not found in Emerge.  In
75 76
;; particular, it can do patching, and 2-way and 3-way file comparison,
;; merging, and directory operations.
77

Michael Kifer's avatar
Michael Kifer committed
78 79


Richard M. Stallman's avatar
Richard M. Stallman committed
80 81
;;; Bugs:

Michael Kifer's avatar
Michael Kifer committed
82
;;  1. The undo command doesn't restore deleted regions well.  That is, if
Richard M. Stallman's avatar
Richard M. Stallman committed
83
;;  you delete all characters in a difference region and then invoke
84
;;  `undo', the reinstated text will most likely be inserted outside of
Richard M. Stallman's avatar
Richard M. Stallman committed
85
;;  what Ediff thinks is the current difference region. (This problem
86
;;  doesn't seem to exist with XEmacs.)
Richard M. Stallman's avatar
Richard M. Stallman committed
87 88 89 90
;;
;;  If at any point you feel that difference regions are no longer correct,
;;  you can hit '!' to recompute the differences.

Karl Heuer's avatar
Karl Heuer committed
91
;;  2. On a monochrome display, the repertoire of faces with which to
Michael Kifer's avatar
Michael Kifer committed
92 93
;;  highlight fine differences is limited.  By default, Ediff is using
;;  underlining.  However, if the region is already underlined by some other
Richard M. Stallman's avatar
Richard M. Stallman committed
94
;;  overlays, there is no simple way to temporarily remove that residual
Michael Kifer's avatar
Michael Kifer committed
95 96 97 98
;;  underlining.  This problem occurs when a buffer is highlighted with
;;  hilit19.el or font-lock.el packages.  If this residual highlighting gets
;;  in the way, you can do the following.  Both font-lock.el and hilit19.el
;;  provide commands for unhighlighting buffers.  You can either place these
99
;;  commands in `ediff-prepare-buffer-hook' (which will unhighlight every
Richard M. Stallman's avatar
Richard M. Stallman committed
100 101
;;  buffer used by Ediff) or you can execute them interactively, at any time
;;  and on any buffer.
102

Michael Kifer's avatar
Michael Kifer committed
103

104 105
;;; Acknowledgements:

106 107
;; Ediff was inspired by Dale R. Worley's <drw@math.mit.edu> emerge.el.
;; Ediff would not have been possible without the help and encouragement of
Michael Kifer's avatar
Michael Kifer committed
108 109
;; its many users.  See Ediff on-line Info for the full list of those who
;; helped.  Improved defaults in Ediff file-name reading commands.
110 111 112

;;; Code:

113
(provide 'ediff)
114

Michael Kifer's avatar
Michael Kifer committed
115
;; Compiler pacifier
116 117 118
(eval-and-compile
  (unless (fboundp 'declare-function) (defmacro declare-function (&rest  r))))

119

Michael Kifer's avatar
Michael Kifer committed
120
(eval-when-compile
121
  (require 'dired)
122 123
  (require 'ediff-util)
  (require 'ediff-ptch))
Michael Kifer's avatar
Michael Kifer committed
124 125 126 127 128 129
;; end pacifier

(require 'ediff-init)
(require 'ediff-mult)  ; required because of the registry stuff

(defgroup ediff nil
130
  "Comprehensive visual interface to `diff' and `patch'."
Michael Kifer's avatar
Michael Kifer committed
131
  :tag "Ediff"
Michael Kifer's avatar
Michael Kifer committed
132 133 134 135
  :group 'tools)


(defcustom ediff-use-last-dir nil
Lute Kamstra's avatar
Lute Kamstra committed
136
  "If t, Ediff will use previous directory as default when reading file name."
Michael Kifer's avatar
Michael Kifer committed
137 138
  :type 'boolean
  :group 'ediff)
Michael Kifer's avatar
Michael Kifer committed
139

Michael Kifer's avatar
Michael Kifer committed
140 141 142 143 144 145 146 147 148
;; Last directory used by an Ediff command for file-A.
(defvar ediff-last-dir-A nil)
;; Last directory used by an Ediff command for file-B.
(defvar ediff-last-dir-B nil)
;; Last directory used by an Ediff command for file-C.
(defvar ediff-last-dir-C nil)
;; Last directory used by an Ediff command for the ancestor file.
(defvar ediff-last-dir-ancestor nil)
;; Last directory used by an Ediff command as the output directory for merge.
Michael Kifer's avatar
Michael Kifer committed
149
(defvar ediff-last-merge-autostore-dir nil)
Richard M. Stallman's avatar
Richard M. Stallman committed
150

151

Michael Kifer's avatar
Michael Kifer committed
152
;; Used as a startup hook to set `_orig' patch file read-only.
Karl Heuer's avatar
Karl Heuer committed
153
(defun ediff-set-read-only-in-buf-A ()
Michael Kifer's avatar
Michael Kifer committed
154
  (ediff-with-current-buffer ediff-buffer-A
Karl Heuer's avatar
Karl Heuer committed
155
    (toggle-read-only 1)))
Richard M. Stallman's avatar
Richard M. Stallman committed
156

157
;; Return a plausible default for ediff's first file:
158 159 160 161 162
;; In dired, return the file number FILENO (or 0) in the list
;; (all-selected-files, filename under the cursor), where directories are
;; ignored. Otherwise, return DEFAULT file name, if non-nil. Else,
;; if the buffer is visiting a file, return that file name.
(defun ediff-get-default-file-name (&optional default fileno)
163
  (cond ((eq major-mode 'dired-mode)
164 165 166
	 (let ((current (dired-get-filename nil 'no-error))
	       (marked (condition-case nil
			   (dired-get-marked-files 'no-dir)
167
			 (error nil)))
168 169 170 171 172 173 174 175 176 177 178
	       aux-list choices result)
	   (or (integerp fileno) (setq fileno 0))
	   (if (stringp default)
	       (setq aux-list (cons default aux-list)))
	   (if (and (stringp current) (not (file-directory-p current)))
	       (setq aux-list (cons current aux-list)))
	   (setq choices (nconc  marked aux-list))
	   (setq result (elt choices fileno))
	   (or result
	       default)))
	((stringp default) default)
179 180 181 182
	((buffer-file-name (current-buffer))
	 (file-name-nondirectory (buffer-file-name (current-buffer))))
	))

183
;;; Compare files/buffers
Richard M. Stallman's avatar
Richard M. Stallman committed
184 185 186

;;;###autoload
(defun ediff-files (file-A file-B &optional startup-hooks)
187
  "Run Ediff on a pair of files, FILE-A and FILE-B."
Richard M. Stallman's avatar
Richard M. Stallman committed
188
  (interactive
189 190 191 192
   (let ((dir-A (if ediff-use-last-dir
		    ediff-last-dir-A
		  default-directory))
	 dir-B f)
193
     (list (setq f (ediff-read-file-name
194
		    "File A to compare"
195
		    dir-A
196 197
		    (ediff-get-default-file-name)
		    'no-dirs))
198
	   (ediff-read-file-name "File B to compare"
199 200
				 (setq dir-B
				       (if ediff-use-last-dir
201
					   ediff-last-dir-B
202 203
					 (file-name-directory f)))
				 (progn
204 205 206 207 208 209
				   (ediff-add-to-history
				    'file-name-history
				    (ediff-abbreviate-file-name
				     (expand-file-name
				      (file-name-nondirectory f)
				      dir-B)))
210
				   (ediff-get-default-file-name f 1)))
211
	   )))
212
  (ediff-files-internal file-A
213 214 215 216 217 218 219
			(if (file-directory-p file-B)
			    (expand-file-name
			     (file-name-nondirectory file-A) file-B)
			  file-B)
			nil ; file-C
			startup-hooks
			'ediff-files))
220

221 222 223 224 225 226 227 228
;;;###autoload
(defun ediff-files3 (file-A file-B file-C &optional startup-hooks)
  "Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
  (interactive
   (let ((dir-A (if ediff-use-last-dir
		    ediff-last-dir-A
		  default-directory))
	 dir-B dir-C f ff)
229
     (list (setq f (ediff-read-file-name
230 231 232 233
		    "File A to compare"
		    dir-A
		    (ediff-get-default-file-name)
		    'no-dirs))
234
	   (setq ff (ediff-read-file-name "File B to compare"
235 236 237 238 239
					  (setq dir-B
						(if ediff-use-last-dir
						    ediff-last-dir-B
						  (file-name-directory f)))
					  (progn
240 241 242 243 244 245
					    (ediff-add-to-history
					     'file-name-history
					     (ediff-abbreviate-file-name
					      (expand-file-name
					       (file-name-nondirectory f)
					       dir-B)))
246
					    (ediff-get-default-file-name f 1))))
247
	   (ediff-read-file-name "File C to compare"
248 249 250 251
				 (setq dir-C (if ediff-use-last-dir
						 ediff-last-dir-C
					       (file-name-directory ff)))
				 (progn
252 253 254 255 256 257
				   (ediff-add-to-history
				    'file-name-history
				    (ediff-abbreviate-file-name
				     (expand-file-name
				      (file-name-nondirectory ff)
				      dir-C)))
258
				   (ediff-get-default-file-name ff 2)))
Richard M. Stallman's avatar
Richard M. Stallman committed
259
	   )))
260
  (ediff-files-internal file-A
Richard M. Stallman's avatar
Richard M. Stallman committed
261 262 263 264
			(if (file-directory-p file-B)
			    (expand-file-name
			     (file-name-nondirectory file-A) file-B)
			  file-B)
265 266 267 268 269 270
			(if (file-directory-p file-C)
			    (expand-file-name
			     (file-name-nondirectory file-A) file-C)
			  file-C)
			startup-hooks
			'ediff-files3))
Richard M. Stallman's avatar
Richard M. Stallman committed
271

272 273
;;;###autoload
(defalias 'ediff3 'ediff-files3)
Richard M. Stallman's avatar
Richard M. Stallman committed
274 275


276
(defun ediff-find-file (file-var buffer-name &optional last-dir hooks-var)
277 278 279 280 281 282 283 284 285 286
  "Visit FILE and arrange its buffer to Ediff's liking.
FILE-VAR is actually a variable symbol whose value must contain a true
file name.
BUFFER-NAME is a variable symbol, which will get the buffer object into
which FILE is read.
LAST-DIR is the directory variable symbol where FILE's
directory name should be returned.  HOOKS-VAR is a variable symbol that will
be assigned the hook to be executed after `ediff-startup' is finished.
`ediff-find-file' arranges that the temp files it might create will be
deleted."
287
  (let* ((file (symbol-value file-var))
Michael Kifer's avatar
Michael Kifer committed
288
	 (file-magic (ediff-filename-magic-p file))
289
	 (temp-file-name-prefix (file-name-nondirectory file)))
290 291 292 293
    (cond ((not (file-readable-p file))
	   (error "File `%s' does not exist or is not readable" file))
	  ((file-directory-p file)
	   (error "File `%s' is a directory" file)))
294

Michael Kifer's avatar
Michael Kifer committed
295
    ;; some of the commands, below, require full file name
296
    (setq file (expand-file-name file))
297

298 299 300
    ;; Record the directory of the file
    (if last-dir
	(set last-dir (expand-file-name (file-name-directory file))))
301

302 303
    ;; Setup the buffer
    (set buffer-name (find-file-noselect file))
304

Michael Kifer's avatar
Michael Kifer committed
305
    (ediff-with-current-buffer (symbol-value buffer-name)
306
      (widen) ; Make sure the entire file is seen
Michael Kifer's avatar
Michael Kifer committed
307 308
      (cond (file-magic  ;   file has a handler, such as jka-compr-handler or
	     		 ;;; ange-ftp-hook-function--arrange for temp file
309
	     (ediff-verify-file-buffer 'magic)
310 311 312
	     (setq file
		   (ediff-make-temp-file
		    (current-buffer) temp-file-name-prefix))
Michael Kifer's avatar
Michael Kifer committed
313
	     (set hooks-var (cons `(lambda () (delete-file ,file))
314 315 316 317
				  (symbol-value hooks-var))))
	    ;; file processed via auto-mode-alist, a la uncompress.el
	    ((not (equal (file-truename file)
			 (file-truename (buffer-file-name))))
318 319 320
	     (setq file
		   (ediff-make-temp-file
		    (current-buffer) temp-file-name-prefix))
Michael Kifer's avatar
Michael Kifer committed
321
	     (set hooks-var (cons `(lambda () (delete-file ,file))
322 323 324 325 326
				  (symbol-value hooks-var))))
	    (t ;; plain file---just check that the file matches the buffer
	     (ediff-verify-file-buffer))))
    (set file-var file)))

Michael Kifer's avatar
Michael Kifer committed
327 328 329
;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
(defun ediff-files-internal (file-A file-B file-C startup-hooks job-name
				    &optional merge-buffer-file)
330
  (let (buf-A buf-B buf-C)
331 332 333 334 335
    (if (string= file-A file-B)
	(error "Files A and B are the same"))
    (if (stringp file-C)
	(or (and (string= file-A file-C) (error "Files A and C are the same"))
	    (and (string= file-B file-C) (error "Files B and C are the same"))))
336 337
    (message "Reading file %s ... " file-A)
    ;;(sit-for 0)
338
    (ediff-find-file 'file-A 'buf-A 'ediff-last-dir-A 'startup-hooks)
339 340
    (message "Reading file %s ... " file-B)
    ;;(sit-for 0)
341
    (ediff-find-file 'file-B 'buf-B 'ediff-last-dir-B 'startup-hooks)
342
    (if (stringp file-C)
343
	(progn
344 345
	  (message "Reading file %s ... " file-C)
	  ;;(sit-for 0)
346 347 348 349 350 351 352 353 354
	  (ediff-find-file
	   'file-C 'buf-C
	   (if (eq job-name 'ediff-merge-files-with-ancestor)
	       'ediff-last-dir-ancestor 'ediff-last-dir-C)
	   'startup-hooks)))
    (ediff-setup buf-A file-A
		 buf-B file-B
		 buf-C file-C
		 startup-hooks
Michael Kifer's avatar
Michael Kifer committed
355 356
		 (list (cons 'ediff-job-name job-name))
		 merge-buffer-file)))
357

358
(declare-function diff-latest-backup-file "diff" (fn))
359 360 361

;;;###autoload
(defalias 'ediff 'ediff-files)
Richard M. Stallman's avatar
Richard M. Stallman committed
362

363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
;;;###autoload
(defun ediff-current-file ()
  "Start ediff between current buffer and its file on disk.
This command can be used instead of `revert-buffer'.  If there is
nothing to revert then this command fails."
  (interactive)
  (unless (or revert-buffer-function
              revert-buffer-insert-file-contents-function
              (and buffer-file-number
                   (or (buffer-modified-p)
                       (not (verify-visited-file-modtime
                             (current-buffer))))))
    (error "Nothing to revert"))
  (let* ((auto-save-p (and (recent-auto-save-p)
                           buffer-auto-save-file-name
                           (file-readable-p buffer-auto-save-file-name)
                           (y-or-n-p
                            "Buffer has been auto-saved recently.  Compare with auto-save file? ")))
         (file-name (if auto-save-p
                        buffer-auto-save-file-name
                      buffer-file-name))
         (revert-buf-name (concat "FILE=" file-name))
         (revert-buf (get-buffer revert-buf-name))
         (current-major major-mode))
    (unless file-name
      (error "Buffer does not seem to be associated with any file"))
    (when revert-buf
      (kill-buffer revert-buf)
      (setq revert-buf nil))
    (setq revert-buf (get-buffer-create revert-buf-name))
    (with-current-buffer revert-buf
      (insert-file-contents file-name)
      ;; Assume same modes:
      (funcall current-major))
    (ediff-buffers revert-buf (current-buffer))))


400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
;;;###autoload
(defun ediff-backup (file)
  "Run Ediff on FILE and its backup file.
Uses the latest backup, if there are several numerical backups.
If this file is a backup, `ediff' it with its original."
  (interactive (list (read-file-name "Ediff (file with backup): ")))
  ;; The code is taken from `diff-backup'.
  (require 'diff)
  (let (bak ori)
    (if (backup-file-name-p file)
	(setq bak file
	      ori (file-name-sans-versions file))
      (setq bak (or (diff-latest-backup-file file)
		    (error "No backup found for %s" file))
	    ori file))
    (ediff-files bak ori)))
Richard M. Stallman's avatar
Richard M. Stallman committed
416 417

;;;###autoload
418
(defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name)
Richard M. Stallman's avatar
Richard M. Stallman committed
419
  "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
420
  (interactive
421 422 423 424 425 426 427 428 429 430 431 432
   (let (bf)
     (list (setq bf (read-buffer "Buffer A to compare: "
				 (ediff-other-buffer "") t))
	   (read-buffer "Buffer B to compare: "
			(progn
			  ;; realign buffers so that two visible bufs will be
			  ;; at the top
			  (save-window-excursion (other-window 1))
			  (ediff-other-buffer bf))
			t))))
  (or job-name (setq job-name 'ediff-buffers))
  (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name))
Michael Kifer's avatar
Michael Kifer committed
433 434 435 436

;;;###autoload
(defalias 'ebuffers 'ediff-buffers)

437

438 439 440 441
;;;###autoload
(defun ediff-buffers3 (buffer-A buffer-B buffer-C
				 &optional startup-hooks job-name)
  "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
442
  (interactive
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
   (let (bf bff)
     (list (setq bf (read-buffer "Buffer A to compare: "
				 (ediff-other-buffer "") t))
	   (setq bff (read-buffer "Buffer B to compare: "
				  (progn
				    ;; realign buffers so that two visible
				    ;; bufs will be at the top
				    (save-window-excursion (other-window 1))
				    (ediff-other-buffer bf))
				  t))
	   (read-buffer "Buffer C to compare: "
				  (progn
				    ;; realign buffers so that three visible
				    ;; bufs will be at the top
				    (save-window-excursion (other-window 1))
				    (ediff-other-buffer (list bf bff)))
				  t)
	   )))
  (or job-name (setq job-name 'ediff-buffers3))
  (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name))
Michael Kifer's avatar
Michael Kifer committed
463 464 465

;;;###autoload
(defalias 'ebuffers3 'ediff-buffers3)
466

467 468


Michael Kifer's avatar
Michael Kifer committed
469 470 471
;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
(defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
				     &optional merge-buffer-file)
472 473 474 475 476 477
  (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
	 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
	 (buf-C-is-alive (ediff-buffer-live-p buf-C))
	 (buf-C-file-name (if buf-C-is-alive
			      (buffer-file-name (get-buffer buf-B))))
	 file-A file-B file-C)
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
    (unwind-protect
	(progn
	  (if (not (ediff-buffer-live-p buf-A))
	      (error "Buffer %S doesn't exist" buf-A))
	  (if (not (ediff-buffer-live-p buf-B))
	      (error "Buffer %S doesn't exist" buf-B))
	  (let ((ediff-job-name job-name))
	    (if (and ediff-3way-comparison-job
		     (not buf-C-is-alive))
		(error "Buffer %S doesn't exist" buf-C)))
	  (if (stringp buf-A-file-name)
	      (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
	  (if (stringp buf-B-file-name)
	      (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
	  (if (stringp buf-C-file-name)
	      (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
	  
	  (setq file-A (ediff-make-temp-file buf-A buf-A-file-name)
		file-B (ediff-make-temp-file buf-B buf-B-file-name))
	  (if buf-C-is-alive
	      (setq file-C (ediff-make-temp-file buf-C buf-C-file-name)))
	  
	  (ediff-setup (get-buffer buf-A) file-A
		       (get-buffer buf-B) file-B
		       (if buf-C-is-alive (get-buffer buf-C))
		       file-C
		       (cons `(lambda ()
				(delete-file ,file-A)
				(delete-file ,file-B)
				(if (stringp ,file-C) (delete-file ,file-C)))
			     startup-hooks)
		       (list (cons 'ediff-job-name job-name))
		       merge-buffer-file))
      (if (and (stringp file-A) (file-exists-p file-A))
	  (delete-file file-A))
      (if (and (stringp file-B) (file-exists-p file-B))
	  (delete-file file-B))
      (if (and (stringp file-C) (file-exists-p file-C))
	  (delete-file file-C)))))
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537


;;; Directory and file group operations

;; Get appropriate default name for directory:
;; If ediff-use-last-dir, use ediff-last-dir-A.
;; In dired mode, use the directory that is under the point (if any);
;; otherwise, use default-directory
(defun ediff-get-default-directory-name ()
  (cond (ediff-use-last-dir ediff-last-dir-A)
	((eq major-mode 'dired-mode)
	 (let ((f (dired-get-filename nil 'noerror)))
	   (if (and (stringp f) (file-directory-p f))
	       f
	     default-directory)))
	(t default-directory)))


;;;###autoload
(defun ediff-directories (dir1 dir2 regexp)
  "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
538 539
the same name in both.  The third argument, REGEXP, is nil or a regular
expression; only file names that match the regexp are considered."
540 541
  (interactive
   (let ((dir-A (ediff-get-default-directory-name))
542
	 (default-regexp (eval ediff-default-filtering-regexp))
543
	 f)
544 545 546 547 548 549 550
     (list (setq f (read-directory-name
		    "Directory A to compare:" dir-A nil 'must-match))
	   (read-directory-name "Directory B to compare:"
			   (if ediff-use-last-dir
			       ediff-last-dir-B
			     (ediff-strip-last-dir f))
			   nil 'must-match)
551 552 553 554 555 556 557 558
	   (read-string
	    (if (stringp default-regexp)
		(format "Filter through regular expression (default %s): "
			 default-regexp)
	      "Filter through regular expression: ")
	    nil
	    'ediff-filtering-regexp-history
	    (eval ediff-default-filtering-regexp))
559 560 561 562 563 564 565 566 567 568 569 570 571
	   )))
  (ediff-directories-internal
   dir1 dir2 nil regexp 'ediff-files 'ediff-directories
   ))

;;;###autoload
(defalias 'edirs 'ediff-directories)


;;;###autoload
(defun ediff-directory-revisions (dir1 regexp)
  "Run Ediff on a directory, DIR1, comparing its files with their revisions.
The second argument, REGEXP, is a regular expression that filters the file
Michael Kifer's avatar
Michael Kifer committed
572
names.  Only the files that are under revision control are taken into account."
573
  (interactive
574 575 576
   (let ((dir-A (ediff-get-default-directory-name))
	 (default-regexp (eval ediff-default-filtering-regexp))
	 )
577 578
     (list (read-directory-name
	    "Directory to compare with revision:" dir-A nil 'must-match)
579 580 581 582 583 584 585 586
	   (read-string
	    (if (stringp default-regexp)
		(format "Filter through regular expression (default %s): "
			 default-regexp)
	      "Filter through regular expression: ")
	    nil
	    'ediff-filtering-regexp-history
	    (eval ediff-default-filtering-regexp))
587 588 589 590 591 592 593 594 595 596 597 598
	   )))
  (ediff-directory-revisions-internal
   dir1 regexp 'ediff-revision 'ediff-directory-revisions
   ))

;;;###autoload
(defalias 'edir-revisions 'ediff-directory-revisions)


;;;###autoload
(defun ediff-directories3 (dir1 dir2 dir3 regexp)
  "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
599 600 601
have the same name in all three.  The last argument, REGEXP, is nil or a
regular expression; only file names that match the regexp are considered."

602 603
  (interactive
   (let ((dir-A (ediff-get-default-directory-name))
604
	 (default-regexp (eval ediff-default-filtering-regexp))
605
	 f)
606 607 608 609 610 611 612 613 614 615 616
     (list (setq f (read-directory-name "Directory A to compare:" dir-A nil))
	   (setq f (read-directory-name "Directory B to compare:"
				   (if ediff-use-last-dir
				       ediff-last-dir-B
				     (ediff-strip-last-dir f))
				   nil 'must-match))
	   (read-directory-name "Directory C to compare:"
			   (if ediff-use-last-dir
			       ediff-last-dir-C
			     (ediff-strip-last-dir f))
			   nil 'must-match)
617 618 619 620 621 622 623 624
	   (read-string
	    (if (stringp default-regexp)
		(format "Filter through regular expression (default %s): "
			 default-regexp)
	      "Filter through regular expression: ")
	    nil
	    'ediff-filtering-regexp-history
	    (eval ediff-default-filtering-regexp))
625 626 627 628 629 630 631 632 633
	   )))
  (ediff-directories-internal
   dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3
   ))

;;;###autoload
(defalias 'edirs3 'ediff-directories3)

;;;###autoload
Michael Kifer's avatar
Michael Kifer committed
634
(defun ediff-merge-directories (dir1 dir2 regexp &optional merge-autostore-dir)
635
  "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
636 637
the same name in both.  The third argument, REGEXP, is nil or a regular
expression; only file names that match the regexp are considered."
638 639
  (interactive
   (let ((dir-A (ediff-get-default-directory-name))
640
	 (default-regexp (eval ediff-default-filtering-regexp))
641
	 f)
642 643 644 645 646 647 648
     (list (setq f (read-directory-name "Directory A to merge:"
					dir-A nil 'must-match))
	   (read-directory-name "Directory B to merge:"
			   (if ediff-use-last-dir
			       ediff-last-dir-B
			     (ediff-strip-last-dir f))
			   nil 'must-match)
649 650 651 652 653 654 655 656
	   (read-string
	    (if (stringp default-regexp)
		(format "Filter through regular expression (default %s): "
			 default-regexp)
	      "Filter through regular expression: ")
	    nil
	    'ediff-filtering-regexp-history
	    (eval ediff-default-filtering-regexp))
657 658 659
	   )))
  (ediff-directories-internal
   dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories
Michael Kifer's avatar
Michael Kifer committed
660
   nil merge-autostore-dir
661 662 663 664 665 666
   ))

;;;###autoload
(defalias 'edirs-merge 'ediff-merge-directories)

;;;###autoload
Michael Kifer's avatar
Michael Kifer committed
667 668 669
(defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
						   &optional
						   merge-autostore-dir)
Michael Kifer's avatar
Michael Kifer committed
670
  "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
Michael Kifer's avatar
Michael Kifer committed
671
Ediff merges files that have identical names in DIR1, DIR2.  If a pair of files
Michael Kifer's avatar
Michael Kifer committed
672
in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
673 674
without ancestor.  The fourth argument, REGEXP, is nil or a regular expression;
only file names that match the regexp are considered."
675 676
  (interactive
   (let ((dir-A (ediff-get-default-directory-name))
677
	 (default-regexp (eval ediff-default-filtering-regexp))
678
	 f)
679 680
     (list (setq f (read-directory-name "Directory A to merge:" dir-A nil))
	   (setq f (read-directory-name "Directory B to merge:"
681
				 (if ediff-use-last-dir
682
				     ediff-last-dir-B
683
				   (ediff-strip-last-dir f))
684 685
				 nil 'must-match))
	   (read-directory-name "Ancestor directory:"
686
				 (if ediff-use-last-dir
687
				     ediff-last-dir-C
688
				   (ediff-strip-last-dir f))
689
				 nil 'must-match)
690 691 692 693 694 695 696 697
	   (read-string
	    (if (stringp default-regexp)
		(format "Filter through regular expression (default %s): "
			 default-regexp)
	      "Filter through regular expression: ")
	    nil
	    'ediff-filtering-regexp-history
	    (eval ediff-default-filtering-regexp))
698 699
	   )))
  (ediff-directories-internal
Michael Kifer's avatar
Michael Kifer committed
700
   dir1 dir2 ancestor-dir regexp
701
   'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor
Michael Kifer's avatar
Michael Kifer committed
702
   nil merge-autostore-dir
703 704 705
   ))

;;;###autoload
Michael Kifer's avatar
Michael Kifer committed
706 707
(defun ediff-merge-directory-revisions (dir1 regexp
					     &optional merge-autostore-dir)
708 709
  "Run Ediff on a directory, DIR1, merging its files with their revisions.
The second argument, REGEXP, is a regular expression that filters the file
Michael Kifer's avatar
Michael Kifer committed
710
names.  Only the files that are under revision control are taken into account."
711
  (interactive
712 713 714
   (let ((dir-A (ediff-get-default-directory-name))
	 (default-regexp (eval ediff-default-filtering-regexp))
	 )
715 716
     (list (read-directory-name
	    "Directory to merge with revisions:" dir-A nil 'must-match)
717 718 719 720 721 722 723 724
	   (read-string
	    (if (stringp default-regexp)
		(format "Filter through regular expression (default %s): "
			 default-regexp)
	      "Filter through regular expression: ")
	    nil
	    'ediff-filtering-regexp-history
	    (eval ediff-default-filtering-regexp))
725 726 727
	   )))
  (ediff-directory-revisions-internal
   dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions
Michael Kifer's avatar
Michael Kifer committed
728
   nil merge-autostore-dir
729 730 731 732 733 734
   ))

;;;###autoload
(defalias 'edir-merge-revisions 'ediff-merge-directory-revisions)

;;;###autoload
Michael Kifer's avatar
Michael Kifer committed
735 736 737
(defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
							   &optional
							   merge-autostore-dir)
738 739
  "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
The second argument, REGEXP, is a regular expression that filters the file
Michael Kifer's avatar
Michael Kifer committed
740
names.  Only the files that are under revision control are taken into account."
741
  (interactive
742 743 744
   (let ((dir-A (ediff-get-default-directory-name))
	 (default-regexp (eval ediff-default-filtering-regexp))
	 )
745 746 747
     (list (read-directory-name
	    "Directory to merge with revisions and ancestors:"
	    dir-A nil 'must-match)
748 749 750 751 752 753 754 755
	   (read-string
	    (if (stringp default-regexp)
		(format "Filter through regular expression (default %s): "
			 default-regexp)
	      "Filter through regular expression: ")
	    nil
	    'ediff-filtering-regexp-history
	    (eval ediff-default-filtering-regexp))
756 757 758 759
	   )))
  (ediff-directory-revisions-internal
   dir1 regexp 'ediff-merge-revisions-with-ancestor
   'ediff-merge-directory-revisions-with-ancestor
Michael Kifer's avatar
Michael Kifer committed
760
   nil merge-autostore-dir
761 762 763 764 765
   ))

;;;###autoload
(defalias
  'edir-merge-revisions-with-ancestor
766
  'ediff-merge-directory-revisions-with-ancestor)
767 768 769 770 771 772

;;;###autoload
(defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor)

;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
;; on a pair of directories (three directories, in case of ancestor).
773 774
;; The third argument, REGEXP, is nil or a regular expression;
;; only file names that match the regexp are considered.
775
;; JOBNAME is the symbol indicating the meta-job to be performed.
Michael Kifer's avatar
Michael Kifer committed
776
;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
777
(defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
Michael Kifer's avatar
Michael Kifer committed
778 779
					&optional startup-hooks
					merge-autostore-dir)
780 781 782 783 784 785 786 787 788 789 790 791
  (if (stringp dir3)
      (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))

  (cond ((string= dir1 dir2)
	 (error "Directories A and B are the same: %s" dir1))
	((and (eq jobname 'ediff-directories3)
	      (string= dir1 dir3))
	 (error "Directories A and C are the same: %s" dir1))
	((and (eq jobname 'ediff-directories3)
	      (string= dir2 dir3))
	 (error "Directories B and C are the same: %s" dir1)))

Michael Kifer's avatar
Michael Kifer committed
792 793 794 795
  (if merge-autostore-dir
      (or (stringp merge-autostore-dir)
	  (error "%s: Directory for storing merged files must be a string"
		 jobname)))
796
  (let (;; dir-diff-struct is of the form (common-list diff-list)
Michael Kifer's avatar
Michael Kifer committed
797 798 799 800
	;; It is a structure where ediff-intersect-directories returns
	;; commonalities and differences among directories
	dir-diff-struct
	meta-buf)
Michael Kifer's avatar
Michael Kifer committed
801 802 803
    (if (and ediff-autostore-merges
	     (ediff-merge-metajob jobname)
	     (not merge-autostore-dir))
804
	(setq merge-autostore-dir
805
	      (read-directory-name "Save merged files in directory: "
Michael Kifer's avatar
Michael Kifer committed
806
			      (if ediff-use-last-dir
Michael Kifer's avatar
Michael Kifer committed
807 808
					ediff-last-merge-autostore-dir
				      (ediff-strip-last-dir dir1))
Michael Kifer's avatar
Michael Kifer committed
809 810
			      nil
			      'must-match)))
Michael Kifer's avatar
Michael Kifer committed
811
    ;; verify we are not merging into an orig directory
Michael Kifer's avatar
Michael Kifer committed
812
    (if merge-autostore-dir
Michael Kifer's avatar
Michael Kifer committed
813
	(cond ((and (stringp dir1) (string= merge-autostore-dir dir1))
Michael Kifer's avatar
Michael Kifer committed
814 815
	       (or (y-or-n-p
		    "Directory for saving merged files = Directory A.  Sure? ")
Michael Kifer's avatar
Michael Kifer committed
816 817
		   (error "Directory merge aborted")))
	      ((and (stringp dir2) (string= merge-autostore-dir dir2))
Michael Kifer's avatar
Michael Kifer committed
818 819
	       (or (y-or-n-p
		    "Directory for saving merged files = Directory B.  Sure? ")
Michael Kifer's avatar
Michael Kifer committed
820 821 822
		   (error "Directory merge aborted")))
	      ((and (stringp dir3) (string= merge-autostore-dir dir3))
	       (or (y-or-n-p
Michael Kifer's avatar
Michael Kifer committed
823
		    "Directory for saving merged files = Ancestor Directory.  Sure? ")
Michael Kifer's avatar
Michael Kifer committed
824
		   (error "Directory merge aborted")))))
825 826

    (setq dir-diff-struct (ediff-intersect-directories
Michael Kifer's avatar
Michael Kifer committed
827 828
			   jobname
			   regexp dir1 dir2 dir3 merge-autostore-dir))
829 830 831
    (setq startup-hooks
	  ;; this sets various vars in the meta buffer inside
	  ;; ediff-prepare-meta-buffer
Michael Kifer's avatar
Michael Kifer committed
832 833 834
	  (cons `(lambda ()
		   ;; tell what to do if the user clicks on a session record
		   (setq ediff-session-action-function (quote ,action))
835
		   ;; set ediff-dir-difference-list
Michael Kifer's avatar
Michael Kifer committed
836 837
		   (setq ediff-dir-difference-list
			 (cdr (quote ,dir-diff-struct))))
838
		startup-hooks))
839
    (setq meta-buf (ediff-prepare-meta-buffer
Michael Kifer's avatar
Michael Kifer committed
840
		    'ediff-filegroup-action
Michael Kifer's avatar
Michael Kifer committed
841
		    (car dir-diff-struct)
842 843 844 845 846 847 848
		    "*Ediff Session Group Panel"
		    'ediff-redraw-directory-group-buffer
		    jobname
		    startup-hooks))
    (ediff-show-meta-buffer meta-buf)
    ))

Michael Kifer's avatar
Michael Kifer committed
849 850
;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
;; files
851
(defun ediff-directory-revisions-internal (dir1 regexp action jobname
Michael Kifer's avatar
Michael Kifer committed
852 853
						&optional startup-hooks
						merge-autostore-dir)
854
  (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)))
Michael Kifer's avatar
Michael Kifer committed
855

Michael Kifer's avatar
Michael Kifer committed
856 857 858 859 860
  (if merge-autostore-dir
      (or (stringp merge-autostore-dir)
	  (error "%S: Directory for storing merged files must be a string"
		 jobname)))
  (let (file-list meta-buf)
861
    (if (and ediff-autostore-merges
Michael Kifer's avatar
Michael Kifer committed
862 863
	     (ediff-merge-metajob jobname)
	     (not merge-autostore-dir))
864
	(setq merge-autostore-dir
865
	      (read-directory-name "Save merged files in directory: "
Michael Kifer's avatar
Michael Kifer committed
866 867 868 869 870
			      (if ediff-use-last-dir
				  ediff-last-merge-autostore-dir
				(ediff-strip-last-dir dir1))
			      nil
			      'must-match)))
Michael Kifer's avatar
Michael Kifer committed
871
    ;; verify merge-autostore-dir != dir1
Michael Kifer's avatar
Michael Kifer committed
872
    (if (and merge-autostore-dir
Michael Kifer's avatar
Michael Kifer committed
873 874 875
	     (stringp dir1)
	     (string= merge-autostore-dir dir1))
	(or (y-or-n-p
Michael Kifer's avatar
Michael Kifer committed
876
	     "Directory for saving merged file = directory A.  Sure? ")
Michael Kifer's avatar
Michael Kifer committed
877
	    (error "Merge of directory revisions aborted")))
878

879
    (setq file-list
Michael Kifer's avatar
Michael Kifer committed
880 881
	  (ediff-get-directory-files-under-revision
	   jobname regexp dir1 merge-autostore-dir))
882 883 884
    (setq startup-hooks
	  ;; this sets various vars in the meta buffer inside
	  ;; ediff-prepare-meta-buffer
Michael Kifer's avatar
Michael Kifer committed
885 886 887
	  (cons `(lambda ()
		   ;; tell what to do if the user clicks on a session record
		   (setq ediff-session-action-function (quote ,action)))
888
		startup-hooks))
889
    (setq meta-buf (ediff-prepare-meta-buffer
Michael Kifer's avatar
Michael Kifer committed
890
		    'ediff-filegroup-action
891 892 893 894 895 896 897
		    file-list
		    "*Ediff Session Group Panel"
		    'ediff-redraw-directory-group-buffer
		    jobname
		    startup-hooks))
    (ediff-show-meta-buffer meta-buf)
    ))
898 899 900 901 902


;;; Compare regions and windows

;;;###autoload
Karl Heuer's avatar
Karl Heuer committed
903 904
(defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks)
  "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
905 906 907 908 909
With prefix argument, DUMB-MODE, or on a non-windowing display, works as
follows:
If WIND-A is nil, use selected window.
If WIND-B is nil, use window next to WIND-A."
  (interactive "P")
Karl Heuer's avatar
Karl Heuer committed
910 911
  (ediff-windows dumb-mode wind-A wind-B
		 startup-hooks 'ediff-windows-wordwise 'word-mode))
912

Karl Heuer's avatar
Karl Heuer committed
913 914 915 916 917 918 919 920 921 922
;;;###autoload
(defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks)
  "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
With prefix argument, DUMB-MODE, or on a non-windowing display, works as
follows:
If WIND-A is nil, use selected window.
If WIND-B is nil, use window next to WIND-A."
  (interactive "P")
  (ediff-windows dumb-mode wind-A wind-B
		 startup-hooks 'ediff-windows-linewise nil))
923

Karl Heuer's avatar
Karl Heuer committed
924 925 926 927 928 929 930
;; Compare WIND-A and WIND-B, which are selected by clicking.
;; With prefix argument, DUMB-MODE, or on a non-windowing display,
;; works as follows:
;; If WIND-A is nil, use selected window.
;; If WIND-B is nil, use window next to WIND-A.
(defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode)
  (if (or dumb-mode (not (ediff-window-display-p)))
931 932 933 934
      (setq wind-A (ediff-get-next-window wind-A nil)
	    wind-B (ediff-get-next-window wind-B wind-A))
    (setq wind-A (ediff-get-window-by-clicking wind-A nil 1)
	  wind-B (ediff-get-window-by-clicking wind-B wind-A 2)))
935

936 937 938
  (let ((buffer-A (window-buffer wind-A))
	(buffer-B (window-buffer wind-B))
	beg-A end-A beg-B end-B)
939

940 941
    (save-excursion
      (save-window-excursion
Karl Heuer's avatar
Karl Heuer committed
942
	(sit-for 0) ; sync before using window-start/end -- a precaution
943 944 945 946 947 948
	(select-window wind-A)
	(setq beg-A (window-start)
	      end-A (window-end))
	(select-window wind-B)
	(setq beg-B (window-start)
	      end-B (window-end))))
949 950
    (setq buffer-A
	  (ediff-clone-buffer-for-window-comparison
Michael Kifer's avatar
Michael Kifer committed
951
	   buffer-A wind-A "-Window.A-")
952 953
	  buffer-B
	  (ediff-clone-buffer-for-window-comparison
Michael Kifer's avatar
Michael Kifer committed
954
	   buffer-B wind-B "-Window.B-"))
955 956
    (ediff-regions-internal
     buffer-A beg-A end-A buffer-B beg-B end-B
Michael Kifer's avatar
Michael Kifer committed
957
     startup-hooks job-name word-mode nil)))
958

959

960
;;;###autoload
Karl Heuer's avatar
Karl Heuer committed
961
(defun ediff-regions-wordwise (buffer-A buffer-B &optional startup-hooks)
962
  "Run Ediff on a pair of regions in specified buffers.
963
Regions \(i.e., point and mark\) can be set in advance or marked interactively.
964
This function is effective only for relatively small regions, up to 200
Michael Kifer's avatar
Michael Kifer committed
965
lines.  For large regions, use `ediff-regions-linewise'."
966
  (interactive
967 968 969 970 971 972 973 974 975 976 977 978 979 980
   (let (bf)
     (list (setq bf (read-buffer "Region's A buffer: "
				 (ediff-other-buffer "") t))
	   (read-buffer "Region's B buffer: "
			(progn
			  ;; realign buffers so that two visible bufs will be
			  ;; at the top
			  (save-window-excursion (other-window 1))
			  (ediff-other-buffer bf))
			t))))
  (if (not (ediff-buffer-live-p buffer-A))
      (error "Buffer %S doesn't exist" buffer-A))
  (if (not (ediff-buffer-live-p buffer-B))
      (error "Buffer %S doesn't exist" buffer-B))
981 982


983
  (let ((buffer-A
Michael Kifer's avatar
Michael Kifer committed
984
         (ediff-clone-buffer-for-region-comparison buffer-A "-Region.A-"))
985
	(buffer-B
Michael Kifer's avatar
Michael Kifer committed
986
         (ediff-clone-buffer-for-region-comparison buffer-B