(syms_of_ntterm) <w32-use-full-screen-buffer>: Doc fix - default value changed.
[emacs.git] / lisp / ediff.el
blob3e0be86b18b612b8b289b5be1624a50f472422df
1 ;;; ediff.el --- a comprehensive visual interface to diff & patch
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
7 ;; Created: February 2, 1994
8 ;; Keywords: comparing, merging, patching, tools, unix
10 (defconst ediff-version "2.81" "The current version of Ediff")
11 (defconst ediff-date "February 18, 2006" "Date of last update")
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 ;; Boston, MA 02110-1301, USA.
31 ;;; Commentary:
33 ;; Never read that diff output again!
34 ;; Apply patch interactively!
35 ;; Merge with ease!
37 ;; This package provides a convenient way of simultaneous browsing through
38 ;; the differences between a pair (or a triple) of files or buffers. The
39 ;; files being compared, file-A, file-B, and file-C (if applicable) are
40 ;; shown in separate windows (side by side, one above the another, or in
41 ;; separate frames), and the differences are highlighted as you step
42 ;; through them. You can also copy difference regions from one buffer to
43 ;; another (and recover old differences if you change your mind).
45 ;; Ediff also supports merging operations on files and buffers, including
46 ;; merging using ancestor versions. Both comparison and merging operations can
47 ;; be performed on directories, i.e., by pairwise comparison of files in those
48 ;; directories.
50 ;; In addition, Ediff can apply a patch to a file and then let you step
51 ;; though both files, the patched and the original one, simultaneously,
52 ;; difference-by-difference. You can even apply a patch right out of a
53 ;; mail buffer, i.e., patches received by mail don't even have to be saved.
54 ;; Since Ediff lets you copy differences between buffers, you can, in
55 ;; effect, apply patches selectively (i.e., you can copy a difference
56 ;; region from file_orig to file, thereby undoing any particular patch that
57 ;; you don't like).
59 ;; Ediff is aware of version control, which lets the user compare
60 ;; files with their older versions. Ediff can also work with remote and
61 ;; compressed files. Details are given below.
63 ;; Finally, Ediff supports directory-level comparison, merging and patching.
64 ;; See the on-line manual for details.
66 ;; This package builds upon the ideas borrowed from emerge.el and several
67 ;; Ediff's functions are adaptations from emerge.el. Much of the functionality
68 ;; Ediff provides is also influenced by emerge.el.
70 ;; The present version of Ediff supersedes Emerge. It provides a superior user
71 ;; interface and has numerous major features not found in Emerge. In
72 ;; particular, it can do patching, and 2-way and 3-way file comparison,
73 ;; merging, and directory operations.
77 ;;; Bugs:
79 ;; 1. The undo command doesn't restore deleted regions well. That is, if
80 ;; you delete all characters in a difference region and then invoke
81 ;; `undo', the reinstated text will most likely be inserted outside of
82 ;; what Ediff thinks is the current difference region. (This problem
83 ;; doesn't seem to exist with XEmacs.)
85 ;; If at any point you feel that difference regions are no longer correct,
86 ;; you can hit '!' to recompute the differences.
88 ;; 2. On a monochrome display, the repertoire of faces with which to
89 ;; highlight fine differences is limited. By default, Ediff is using
90 ;; underlining. However, if the region is already underlined by some other
91 ;; overlays, there is no simple way to temporarily remove that residual
92 ;; underlining. This problem occurs when a buffer is highlighted with
93 ;; hilit19.el or font-lock.el packages. If this residual highlighting gets
94 ;; in the way, you can do the following. Both font-lock.el and hilit19.el
95 ;; provide commands for unhighlighting buffers. You can either place these
96 ;; commands in `ediff-prepare-buffer-hook' (which will unhighlight every
97 ;; buffer used by Ediff) or you can execute them interactively, at any time
98 ;; and on any buffer.
101 ;;; Acknowledgements:
103 ;; Ediff was inspired by Dale R. Worley's <drw@math.mit.edu> emerge.el.
104 ;; Ediff would not have been possible without the help and encouragement of
105 ;; its many users. See Ediff on-line Info for the full list of those who
106 ;; helped. Improved defaults in Ediff file-name reading commands.
108 ;;; Code:
111 ;; Compiler pacifier
112 (defvar cvs-cookie-handle)
113 (defvar ediff-last-dir-patch)
114 (defvar ediff-patch-default-directory)
116 (and noninteractive
117 (eval-when-compile
118 (load-library "dired")
119 (load-library "info")
120 (load "pcl-cvs" 'noerror)))
121 (eval-when-compile
122 (let ((load-path (cons (expand-file-name ".") load-path)))
123 (provide 'ediff) ; to break recursive load cycle
124 (or (featurep 'ediff-init)
125 (load "ediff-init.el" nil nil 'nosuffix))
126 (or (featurep 'ediff-mult)
127 (load "ediff-mult.el" nil nil 'nosuffix))
128 (or (featurep 'ediff-ptch)
129 (load "ediff-ptch.el" nil nil 'nosuffix))
130 (or (featurep 'ediff-vers)
131 (load "ediff-vers.el" nil nil 'nosuffix))
133 ;; end pacifier
135 (require 'ediff-init)
136 (require 'ediff-mult) ; required because of the registry stuff
138 (defgroup ediff nil
139 "A comprehensive visual interface to diff & patch."
140 :tag "Ediff"
141 :group 'tools)
144 (defcustom ediff-use-last-dir nil
145 "*If t, Ediff will use previous directory as default when reading file name."
146 :type 'boolean
147 :group 'ediff)
149 ;; Last directory used by an Ediff command for file-A.
150 (defvar ediff-last-dir-A nil)
151 ;; Last directory used by an Ediff command for file-B.
152 (defvar ediff-last-dir-B nil)
153 ;; Last directory used by an Ediff command for file-C.
154 (defvar ediff-last-dir-C nil)
155 ;; Last directory used by an Ediff command for the ancestor file.
156 (defvar ediff-last-dir-ancestor nil)
157 ;; Last directory used by an Ediff command as the output directory for merge.
158 (defvar ediff-last-merge-autostore-dir nil)
161 ;; Used as a startup hook to set `_orig' patch file read-only.
162 (defun ediff-set-read-only-in-buf-A ()
163 (ediff-with-current-buffer ediff-buffer-A
164 (toggle-read-only 1)))
166 ;; Return a plausible default for ediff's first file:
167 ;; In dired, return the file number FILENO (or 0) in the list
168 ;; (all-selected-files, filename under the cursor), where directories are
169 ;; ignored. Otherwise, return DEFAULT file name, if non-nil. Else,
170 ;; if the buffer is visiting a file, return that file name.
171 (defun ediff-get-default-file-name (&optional default fileno)
172 (cond ((eq major-mode 'dired-mode)
173 (let ((current (dired-get-filename nil 'no-error))
174 (marked (condition-case nil
175 (dired-get-marked-files 'no-dir)
176 (error nil)))
177 aux-list choices result)
178 (or (integerp fileno) (setq fileno 0))
179 (if (stringp default)
180 (setq aux-list (cons default aux-list)))
181 (if (and (stringp current) (not (file-directory-p current)))
182 (setq aux-list (cons current aux-list)))
183 (setq choices (nconc marked aux-list))
184 (setq result (elt choices fileno))
185 (or result
186 default)))
187 ((stringp default) default)
188 ((buffer-file-name (current-buffer))
189 (file-name-nondirectory (buffer-file-name (current-buffer))))
192 ;;; Compare files/buffers
194 ;;;###autoload
195 (defun ediff-files (file-A file-B &optional startup-hooks)
196 "Run Ediff on a pair of files, FILE-A and FILE-B."
197 (interactive
198 (let ((dir-A (if ediff-use-last-dir
199 ediff-last-dir-A
200 default-directory))
201 dir-B f)
202 (list (setq f (ediff-read-file-name
203 "File A to compare"
204 dir-A
205 (ediff-get-default-file-name)
206 'no-dirs))
207 (ediff-read-file-name "File B to compare"
208 (setq dir-B
209 (if ediff-use-last-dir
210 ediff-last-dir-B
211 (file-name-directory f)))
212 (progn
213 (add-to-history 'file-name-history
214 (ediff-abbreviate-file-name
215 (expand-file-name
216 (file-name-nondirectory f)
217 dir-B)))
218 (ediff-get-default-file-name f 1)))
220 (ediff-files-internal file-A
221 (if (file-directory-p file-B)
222 (expand-file-name
223 (file-name-nondirectory file-A) file-B)
224 file-B)
225 nil ; file-C
226 startup-hooks
227 'ediff-files))
229 ;;;###autoload
230 (defun ediff-files3 (file-A file-B file-C &optional startup-hooks)
231 "Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
232 (interactive
233 (let ((dir-A (if ediff-use-last-dir
234 ediff-last-dir-A
235 default-directory))
236 dir-B dir-C f ff)
237 (list (setq f (ediff-read-file-name
238 "File A to compare"
239 dir-A
240 (ediff-get-default-file-name)
241 'no-dirs))
242 (setq ff (ediff-read-file-name "File B to compare"
243 (setq dir-B
244 (if ediff-use-last-dir
245 ediff-last-dir-B
246 (file-name-directory f)))
247 (progn
248 (add-to-history 'file-name-history
249 (ediff-abbreviate-file-name
250 (expand-file-name
251 (file-name-nondirectory f)
252 dir-B)))
253 (ediff-get-default-file-name f 1))))
254 (ediff-read-file-name "File C to compare"
255 (setq dir-C (if ediff-use-last-dir
256 ediff-last-dir-C
257 (file-name-directory ff)))
258 (progn
259 (add-to-history 'file-name-history
260 (ediff-abbreviate-file-name
261 (expand-file-name
262 (file-name-nondirectory ff)
263 dir-C)))
264 (ediff-get-default-file-name ff 2)))
266 (ediff-files-internal file-A
267 (if (file-directory-p file-B)
268 (expand-file-name
269 (file-name-nondirectory file-A) file-B)
270 file-B)
271 (if (file-directory-p file-C)
272 (expand-file-name
273 (file-name-nondirectory file-A) file-C)
274 file-C)
275 startup-hooks
276 'ediff-files3))
278 ;;;###autoload
279 (defalias 'ediff3 'ediff-files3)
282 ;; Visit FILE and arrange its buffer to Ediff's liking.
283 ;; FILE is actually a variable symbol that must contain a true file name.
284 ;; BUFFER-NAME is a variable symbol, which will get the buffer object into
285 ;; which FILE is read.
286 ;; LAST-DIR is the directory variable symbol where FILE's
287 ;; directory name should be returned. HOOKS-VAR is a variable symbol that will
288 ;; be assigned the hook to be executed after `ediff-startup' is finished.
289 ;; `ediff-find-file' arranges that the temp files it might create will be
290 ;; deleted.
291 (defun ediff-find-file (file-var buffer-name &optional last-dir hooks-var)
292 (let* ((file (symbol-value file-var))
293 (file-magic (ediff-filename-magic-p file))
294 (temp-file-name-prefix (file-name-nondirectory file)))
295 (cond ((not (file-readable-p file))
296 (error "File `%s' does not exist or is not readable" file))
297 ((file-directory-p file)
298 (error "File `%s' is a directory" file)))
300 ;; some of the commands, below, require full file name
301 (setq file (expand-file-name file))
303 ;; Record the directory of the file
304 (if last-dir
305 (set last-dir (expand-file-name (file-name-directory file))))
307 ;; Setup the buffer
308 (set buffer-name (find-file-noselect file))
310 (ediff-with-current-buffer (symbol-value buffer-name)
311 (widen) ; Make sure the entire file is seen
312 (cond (file-magic ; file has a handler, such as jka-compr-handler or
313 ;;; ange-ftp-hook-function--arrange for temp file
314 (ediff-verify-file-buffer 'magic)
315 (setq file
316 (ediff-make-temp-file
317 (current-buffer) temp-file-name-prefix))
318 (set hooks-var (cons `(lambda () (delete-file ,file))
319 (symbol-value hooks-var))))
320 ;; file processed via auto-mode-alist, a la uncompress.el
321 ((not (equal (file-truename file)
322 (file-truename (buffer-file-name))))
323 (setq file
324 (ediff-make-temp-file
325 (current-buffer) temp-file-name-prefix))
326 (set hooks-var (cons `(lambda () (delete-file ,file))
327 (symbol-value hooks-var))))
328 (t ;; plain file---just check that the file matches the buffer
329 (ediff-verify-file-buffer))))
330 (set file-var file)))
332 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
333 (defun ediff-files-internal (file-A file-B file-C startup-hooks job-name
334 &optional merge-buffer-file)
335 (let (buf-A buf-B buf-C)
336 (if (string= file-A file-B)
337 (error "Files A and B are the same"))
338 (if (stringp file-C)
339 (or (and (string= file-A file-C) (error "Files A and C are the same"))
340 (and (string= file-B file-C) (error "Files B and C are the same"))))
341 (message "Reading file %s ... " file-A)
342 ;;(sit-for 0)
343 (ediff-find-file 'file-A 'buf-A 'ediff-last-dir-A 'startup-hooks)
344 (message "Reading file %s ... " file-B)
345 ;;(sit-for 0)
346 (ediff-find-file 'file-B 'buf-B 'ediff-last-dir-B 'startup-hooks)
347 (if (stringp file-C)
348 (progn
349 (message "Reading file %s ... " file-C)
350 ;;(sit-for 0)
351 (ediff-find-file
352 'file-C 'buf-C
353 (if (eq job-name 'ediff-merge-files-with-ancestor)
354 'ediff-last-dir-ancestor 'ediff-last-dir-C)
355 'startup-hooks)))
356 (ediff-setup buf-A file-A
357 buf-B file-B
358 buf-C file-C
359 startup-hooks
360 (list (cons 'ediff-job-name job-name))
361 merge-buffer-file)))
364 ;;;###autoload
365 (defalias 'ediff 'ediff-files)
367 ;;;###autoload
368 (defun ediff-backup (file)
369 "Run Ediff on FILE and its backup file.
370 Uses the latest backup, if there are several numerical backups.
371 If this file is a backup, `ediff' it with its original."
372 (interactive (list (read-file-name "Ediff (file with backup): ")))
373 ;; The code is taken from `diff-backup'.
374 (require 'diff)
375 (let (bak ori)
376 (if (backup-file-name-p file)
377 (setq bak file
378 ori (file-name-sans-versions file))
379 (setq bak (or (diff-latest-backup-file file)
380 (error "No backup found for %s" file))
381 ori file))
382 (ediff-files bak ori)))
384 ;;;###autoload
385 (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name)
386 "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."
387 (interactive
388 (let (bf)
389 (list (setq bf (read-buffer "Buffer A to compare: "
390 (ediff-other-buffer "") t))
391 (read-buffer "Buffer B to compare: "
392 (progn
393 ;; realign buffers so that two visible bufs will be
394 ;; at the top
395 (save-window-excursion (other-window 1))
396 (ediff-other-buffer bf))
397 t))))
398 (or job-name (setq job-name 'ediff-buffers))
399 (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name))
401 ;;;###autoload
402 (defalias 'ebuffers 'ediff-buffers)
405 ;;;###autoload
406 (defun ediff-buffers3 (buffer-A buffer-B buffer-C
407 &optional startup-hooks job-name)
408 "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."
409 (interactive
410 (let (bf bff)
411 (list (setq bf (read-buffer "Buffer A to compare: "
412 (ediff-other-buffer "") t))
413 (setq bff (read-buffer "Buffer B to compare: "
414 (progn
415 ;; realign buffers so that two visible
416 ;; bufs will be at the top
417 (save-window-excursion (other-window 1))
418 (ediff-other-buffer bf))
420 (read-buffer "Buffer C to compare: "
421 (progn
422 ;; realign buffers so that three visible
423 ;; bufs will be at the top
424 (save-window-excursion (other-window 1))
425 (ediff-other-buffer (list bf bff)))
428 (or job-name (setq job-name 'ediff-buffers3))
429 (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name))
431 ;;;###autoload
432 (defalias 'ebuffers3 'ediff-buffers3)
436 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
437 (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
438 &optional merge-buffer-file)
439 (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
440 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
441 (buf-C-is-alive (ediff-buffer-live-p buf-C))
442 (buf-C-file-name (if buf-C-is-alive
443 (buffer-file-name (get-buffer buf-B))))
444 file-A file-B file-C)
445 (if (not (ediff-buffer-live-p buf-A))
446 (error "Buffer %S doesn't exist" buf-A))
447 (if (not (ediff-buffer-live-p buf-B))
448 (error "Buffer %S doesn't exist" buf-B))
449 (let ((ediff-job-name job-name))
450 (if (and ediff-3way-comparison-job
451 (not buf-C-is-alive))
452 (error "Buffer %S doesn't exist" buf-C)))
453 (if (stringp buf-A-file-name)
454 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
455 (if (stringp buf-B-file-name)
456 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
457 (if (stringp buf-C-file-name)
458 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
460 (setq file-A (ediff-make-temp-file buf-A buf-A-file-name)
461 file-B (ediff-make-temp-file buf-B buf-B-file-name))
462 (if buf-C-is-alive
463 (setq file-C (ediff-make-temp-file buf-C buf-C-file-name)))
465 (ediff-setup (get-buffer buf-A) file-A
466 (get-buffer buf-B) file-B
467 (if buf-C-is-alive (get-buffer buf-C))
468 file-C
469 (cons `(lambda ()
470 (delete-file ,file-A)
471 (delete-file ,file-B)
472 (if (stringp ,file-C) (delete-file ,file-C)))
473 startup-hooks)
474 (list (cons 'ediff-job-name job-name))
475 merge-buffer-file)))
478 ;;; Directory and file group operations
480 ;; Get appropriate default name for directory:
481 ;; If ediff-use-last-dir, use ediff-last-dir-A.
482 ;; In dired mode, use the directory that is under the point (if any);
483 ;; otherwise, use default-directory
484 (defun ediff-get-default-directory-name ()
485 (cond (ediff-use-last-dir ediff-last-dir-A)
486 ((eq major-mode 'dired-mode)
487 (let ((f (dired-get-filename nil 'noerror)))
488 (if (and (stringp f) (file-directory-p f))
490 default-directory)))
491 (t default-directory)))
494 ;;;###autoload
495 (defun ediff-directories (dir1 dir2 regexp)
496 "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have
497 the same name in both. The third argument, REGEXP, is nil or a regular
498 expression; only file names that match the regexp are considered."
499 (interactive
500 (let ((dir-A (ediff-get-default-directory-name))
501 (default-regexp (eval ediff-default-filtering-regexp))
503 (list (setq f (read-directory-name
504 "Directory A to compare:" dir-A nil 'must-match))
505 (read-directory-name "Directory B to compare:"
506 (if ediff-use-last-dir
507 ediff-last-dir-B
508 (ediff-strip-last-dir f))
509 nil 'must-match)
510 (read-string
511 (if (stringp default-regexp)
512 (format "Filter through regular expression (default %s): "
513 default-regexp)
514 "Filter through regular expression: ")
516 'ediff-filtering-regexp-history
517 (eval ediff-default-filtering-regexp))
519 (ediff-directories-internal
520 dir1 dir2 nil regexp 'ediff-files 'ediff-directories
523 ;;;###autoload
524 (defalias 'edirs 'ediff-directories)
527 ;;;###autoload
528 (defun ediff-directory-revisions (dir1 regexp)
529 "Run Ediff on a directory, DIR1, comparing its files with their revisions.
530 The second argument, REGEXP, is a regular expression that filters the file
531 names. Only the files that are under revision control are taken into account."
532 (interactive
533 (let ((dir-A (ediff-get-default-directory-name))
534 (default-regexp (eval ediff-default-filtering-regexp))
536 (list (read-directory-name
537 "Directory to compare with revision:" dir-A nil 'must-match)
538 (read-string
539 (if (stringp default-regexp)
540 (format "Filter through regular expression (default %s): "
541 default-regexp)
542 "Filter through regular expression: ")
544 'ediff-filtering-regexp-history
545 (eval ediff-default-filtering-regexp))
547 (ediff-directory-revisions-internal
548 dir1 regexp 'ediff-revision 'ediff-directory-revisions
551 ;;;###autoload
552 (defalias 'edir-revisions 'ediff-directory-revisions)
555 ;;;###autoload
556 (defun ediff-directories3 (dir1 dir2 dir3 regexp)
557 "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that
558 have the same name in all three. The last argument, REGEXP, is nil or a
559 regular expression; only file names that match the regexp are considered."
561 (interactive
562 (let ((dir-A (ediff-get-default-directory-name))
563 (default-regexp (eval ediff-default-filtering-regexp))
565 (list (setq f (read-directory-name "Directory A to compare:" dir-A nil))
566 (setq f (read-directory-name "Directory B to compare:"
567 (if ediff-use-last-dir
568 ediff-last-dir-B
569 (ediff-strip-last-dir f))
570 nil 'must-match))
571 (read-directory-name "Directory C to compare:"
572 (if ediff-use-last-dir
573 ediff-last-dir-C
574 (ediff-strip-last-dir f))
575 nil 'must-match)
576 (read-string
577 (if (stringp default-regexp)
578 (format "Filter through regular expression (default %s): "
579 default-regexp)
580 "Filter through regular expression: ")
582 'ediff-filtering-regexp-history
583 (eval ediff-default-filtering-regexp))
585 (ediff-directories-internal
586 dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3
589 ;;;###autoload
590 (defalias 'edirs3 'ediff-directories3)
592 ;;;###autoload
593 (defun ediff-merge-directories (dir1 dir2 regexp &optional merge-autostore-dir)
594 "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have
595 the same name in both. The third argument, REGEXP, is nil or a regular
596 expression; only file names that match the regexp are considered."
597 (interactive
598 (let ((dir-A (ediff-get-default-directory-name))
599 (default-regexp (eval ediff-default-filtering-regexp))
601 (list (setq f (read-directory-name "Directory A to merge:"
602 dir-A nil 'must-match))
603 (read-directory-name "Directory B to merge:"
604 (if ediff-use-last-dir
605 ediff-last-dir-B
606 (ediff-strip-last-dir f))
607 nil 'must-match)
608 (read-string
609 (if (stringp default-regexp)
610 (format "Filter through regular expression (default %s): "
611 default-regexp)
612 "Filter through regular expression: ")
614 'ediff-filtering-regexp-history
615 (eval ediff-default-filtering-regexp))
617 (ediff-directories-internal
618 dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories
619 nil merge-autostore-dir
622 ;;;###autoload
623 (defalias 'edirs-merge 'ediff-merge-directories)
625 ;;;###autoload
626 (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp
627 &optional
628 merge-autostore-dir)
629 "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.
630 Ediff merges files that have identical names in DIR1, DIR2. If a pair of files
631 in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge
632 without ancestor. The fourth argument, REGEXP, is nil or a regular expression;
633 only file names that match the regexp are considered."
634 (interactive
635 (let ((dir-A (ediff-get-default-directory-name))
636 (default-regexp (eval ediff-default-filtering-regexp))
638 (list (setq f (read-directory-name "Directory A to merge:" dir-A nil))
639 (setq f (read-directory-name "Directory B to merge:"
640 (if ediff-use-last-dir
641 ediff-last-dir-B
642 (ediff-strip-last-dir f))
643 nil 'must-match))
644 (read-directory-name "Ancestor directory:"
645 (if ediff-use-last-dir
646 ediff-last-dir-C
647 (ediff-strip-last-dir f))
648 nil 'must-match)
649 (read-string
650 (if (stringp default-regexp)
651 (format "Filter through regular expression (default %s): "
652 default-regexp)
653 "Filter through regular expression: ")
655 'ediff-filtering-regexp-history
656 (eval ediff-default-filtering-regexp))
658 (ediff-directories-internal
659 dir1 dir2 ancestor-dir regexp
660 'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor
661 nil merge-autostore-dir
664 ;;;###autoload
665 (defun ediff-merge-directory-revisions (dir1 regexp
666 &optional merge-autostore-dir)
667 "Run Ediff on a directory, DIR1, merging its files with their revisions.
668 The second argument, REGEXP, is a regular expression that filters the file
669 names. Only the files that are under revision control are taken into account."
670 (interactive
671 (let ((dir-A (ediff-get-default-directory-name))
672 (default-regexp (eval ediff-default-filtering-regexp))
674 (list (read-directory-name
675 "Directory to merge with revisions:" dir-A nil 'must-match)
676 (read-string
677 (if (stringp default-regexp)
678 (format "Filter through regular expression (default %s): "
679 default-regexp)
680 "Filter through regular expression: ")
682 'ediff-filtering-regexp-history
683 (eval ediff-default-filtering-regexp))
685 (ediff-directory-revisions-internal
686 dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions
687 nil merge-autostore-dir
690 ;;;###autoload
691 (defalias 'edir-merge-revisions 'ediff-merge-directory-revisions)
693 ;;;###autoload
694 (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp
695 &optional
696 merge-autostore-dir)
697 "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors.
698 The second argument, REGEXP, is a regular expression that filters the file
699 names. Only the files that are under revision control are taken into account."
700 (interactive
701 (let ((dir-A (ediff-get-default-directory-name))
702 (default-regexp (eval ediff-default-filtering-regexp))
704 (list (read-directory-name
705 "Directory to merge with revisions and ancestors:"
706 dir-A nil 'must-match)
707 (read-string
708 (if (stringp default-regexp)
709 (format "Filter through regular expression (default %s): "
710 default-regexp)
711 "Filter through regular expression: ")
713 'ediff-filtering-regexp-history
714 (eval ediff-default-filtering-regexp))
716 (ediff-directory-revisions-internal
717 dir1 regexp 'ediff-merge-revisions-with-ancestor
718 'ediff-merge-directory-revisions-with-ancestor
719 nil merge-autostore-dir
722 ;;;###autoload
723 (defalias
724 'edir-merge-revisions-with-ancestor
725 'ediff-merge-directory-revisions-with-ancestor)
727 ;;;###autoload
728 (defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor)
730 ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors)
731 ;; on a pair of directories (three directories, in case of ancestor).
732 ;; The third argument, REGEXP, is nil or a regular expression;
733 ;; only file names that match the regexp are considered.
734 ;; JOBNAME is the symbol indicating the meta-job to be performed.
735 ;; MERGE-AUTOSTORE-DIR is the directory in which to store merged files.
736 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
737 &optional startup-hooks
738 merge-autostore-dir)
739 (if (stringp dir3)
740 (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))
742 (cond ((string= dir1 dir2)
743 (error "Directories A and B are the same: %s" dir1))
744 ((and (eq jobname 'ediff-directories3)
745 (string= dir1 dir3))
746 (error "Directories A and C are the same: %s" dir1))
747 ((and (eq jobname 'ediff-directories3)
748 (string= dir2 dir3))
749 (error "Directories B and C are the same: %s" dir1)))
751 (if merge-autostore-dir
752 (or (stringp merge-autostore-dir)
753 (error "%s: Directory for storing merged files must be a string"
754 jobname)))
755 (let (;; dir-diff-struct is of the form (common-list diff-list)
756 ;; It is a structure where ediff-intersect-directories returns
757 ;; commonalities and differences among directories
758 dir-diff-struct
759 meta-buf)
760 (if (and ediff-autostore-merges
761 (ediff-merge-metajob jobname)
762 (not merge-autostore-dir))
763 (setq merge-autostore-dir
764 (read-directory-name "Save merged files in directory: "
765 (if ediff-use-last-dir
766 ediff-last-merge-autostore-dir
767 (ediff-strip-last-dir dir1))
769 'must-match)))
770 ;; verify we are not merging into an orig directory
771 (if merge-autostore-dir
772 (cond ((and (stringp dir1) (string= merge-autostore-dir dir1))
773 (or (y-or-n-p
774 "Directory for saving merged files = Directory A. Sure? ")
775 (error "Directory merge aborted")))
776 ((and (stringp dir2) (string= merge-autostore-dir dir2))
777 (or (y-or-n-p
778 "Directory for saving merged files = Directory B. Sure? ")
779 (error "Directory merge aborted")))
780 ((and (stringp dir3) (string= merge-autostore-dir dir3))
781 (or (y-or-n-p
782 "Directory for saving merged files = Ancestor Directory. Sure? ")
783 (error "Directory merge aborted")))))
785 (setq dir-diff-struct (ediff-intersect-directories
786 jobname
787 regexp dir1 dir2 dir3 merge-autostore-dir))
788 (setq startup-hooks
789 ;; this sets various vars in the meta buffer inside
790 ;; ediff-prepare-meta-buffer
791 (cons `(lambda ()
792 ;; tell what to do if the user clicks on a session record
793 (setq ediff-session-action-function (quote ,action))
794 ;; set ediff-dir-difference-list
795 (setq ediff-dir-difference-list
796 (cdr (quote ,dir-diff-struct))))
797 startup-hooks))
798 (setq meta-buf (ediff-prepare-meta-buffer
799 'ediff-filegroup-action
800 (car dir-diff-struct)
801 "*Ediff Session Group Panel"
802 'ediff-redraw-directory-group-buffer
803 jobname
804 startup-hooks))
805 (ediff-show-meta-buffer meta-buf)
808 ;; MERGE-AUTOSTORE-DIR can be given to tell ediff where to store the merged
809 ;; files
810 (defun ediff-directory-revisions-internal (dir1 regexp action jobname
811 &optional startup-hooks
812 merge-autostore-dir)
813 (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)))
815 (if merge-autostore-dir
816 (or (stringp merge-autostore-dir)
817 (error "%S: Directory for storing merged files must be a string"
818 jobname)))
819 (let (file-list meta-buf)
820 (if (and ediff-autostore-merges
821 (ediff-merge-metajob jobname)
822 (not merge-autostore-dir))
823 (setq merge-autostore-dir
824 (read-directory-name "Save merged files in directory: "
825 (if ediff-use-last-dir
826 ediff-last-merge-autostore-dir
827 (ediff-strip-last-dir dir1))
829 'must-match)))
830 ;; verify merge-autostore-dir != dir1
831 (if (and merge-autostore-dir
832 (stringp dir1)
833 (string= merge-autostore-dir dir1))
834 (or (y-or-n-p
835 "Directory for saving merged file = directory A. Sure? ")
836 (error "Merge of directory revisions aborted")))
838 (setq file-list
839 (ediff-get-directory-files-under-revision
840 jobname regexp dir1 merge-autostore-dir))
841 (setq startup-hooks
842 ;; this sets various vars in the meta buffer inside
843 ;; ediff-prepare-meta-buffer
844 (cons `(lambda ()
845 ;; tell what to do if the user clicks on a session record
846 (setq ediff-session-action-function (quote ,action)))
847 startup-hooks))
848 (setq meta-buf (ediff-prepare-meta-buffer
849 'ediff-filegroup-action
850 file-list
851 "*Ediff Session Group Panel"
852 'ediff-redraw-directory-group-buffer
853 jobname
854 startup-hooks))
855 (ediff-show-meta-buffer meta-buf)
859 ;;; Compare regions and windows
861 ;;;###autoload
862 (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks)
863 "Compare WIND-A and WIND-B, which are selected by clicking, wordwise.
864 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
865 follows:
866 If WIND-A is nil, use selected window.
867 If WIND-B is nil, use window next to WIND-A."
868 (interactive "P")
869 (ediff-windows dumb-mode wind-A wind-B
870 startup-hooks 'ediff-windows-wordwise 'word-mode))
872 ;;;###autoload
873 (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks)
874 "Compare WIND-A and WIND-B, which are selected by clicking, linewise.
875 With prefix argument, DUMB-MODE, or on a non-windowing display, works as
876 follows:
877 If WIND-A is nil, use selected window.
878 If WIND-B is nil, use window next to WIND-A."
879 (interactive "P")
880 (ediff-windows dumb-mode wind-A wind-B
881 startup-hooks 'ediff-windows-linewise nil))
883 ;; Compare WIND-A and WIND-B, which are selected by clicking.
884 ;; With prefix argument, DUMB-MODE, or on a non-windowing display,
885 ;; works as follows:
886 ;; If WIND-A is nil, use selected window.
887 ;; If WIND-B is nil, use window next to WIND-A.
888 (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode)
889 (if (or dumb-mode (not (ediff-window-display-p)))
890 (setq wind-A (ediff-get-next-window wind-A nil)
891 wind-B (ediff-get-next-window wind-B wind-A))
892 (setq wind-A (ediff-get-window-by-clicking wind-A nil 1)
893 wind-B (ediff-get-window-by-clicking wind-B wind-A 2)))
895 (let ((buffer-A (window-buffer wind-A))
896 (buffer-B (window-buffer wind-B))
897 beg-A end-A beg-B end-B)
899 (save-excursion
900 (save-window-excursion
901 (sit-for 0) ; sync before using window-start/end -- a precaution
902 (select-window wind-A)
903 (setq beg-A (window-start)
904 end-A (window-end))
905 (select-window wind-B)
906 (setq beg-B (window-start)
907 end-B (window-end))))
908 (setq buffer-A
909 (ediff-clone-buffer-for-window-comparison
910 buffer-A wind-A "-Window.A-")
911 buffer-B
912 (ediff-clone-buffer-for-window-comparison
913 buffer-B wind-B "-Window.B-"))
914 (ediff-regions-internal
915 buffer-A beg-A end-A buffer-B beg-B end-B
916 startup-hooks job-name word-mode nil)))
919 ;;;###autoload
920 (defun ediff-regions-wordwise (buffer-A buffer-B &optional startup-hooks)
921 "Run Ediff on a pair of regions in specified buffers.
922 Regions \(i.e., point and mark\) are assumed to be set in advance except
923 for the second region in the case both regions are from the same buffer.
924 In such a case the user is asked to interactively establish the second
925 region.
926 This function is effective only for relatively small regions, up to 200
927 lines. For large regions, use `ediff-regions-linewise'."
928 (interactive
929 (let (bf)
930 (list (setq bf (read-buffer "Region's A buffer: "
931 (ediff-other-buffer "") t))
932 (read-buffer "Region's B buffer: "
933 (progn
934 ;; realign buffers so that two visible bufs will be
935 ;; at the top
936 (save-window-excursion (other-window 1))
937 (ediff-other-buffer bf))
938 t))))
939 (if (not (ediff-buffer-live-p buffer-A))
940 (error "Buffer %S doesn't exist" buffer-A))
941 (if (not (ediff-buffer-live-p buffer-B))
942 (error "Buffer %S doesn't exist" buffer-B))
945 (let ((buffer-A
946 (ediff-clone-buffer-for-region-comparison buffer-A "-Region.A-"))
947 (buffer-B
948 (ediff-clone-buffer-for-region-comparison buffer-B "-Region.B-"))
949 reg-A-beg reg-A-end reg-B-beg reg-B-end)
950 (save-excursion
951 (set-buffer buffer-A)
952 (setq reg-A-beg (region-beginning)
953 reg-A-end (region-end))
954 (set-buffer buffer-B)
955 (setq reg-B-beg (region-beginning)
956 reg-B-end (region-end)))
958 (ediff-regions-internal
959 (get-buffer buffer-A) reg-A-beg reg-A-end
960 (get-buffer buffer-B) reg-B-beg reg-B-end
961 startup-hooks 'ediff-regions-wordwise 'word-mode nil)))
963 ;;;###autoload
964 (defun ediff-regions-linewise (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\) are assumed to be set in advance except
967 for the second region in the case both regions are from the same buffer.
968 In such a case the user is asked to interactively establish the second
969 region.
970 Each region is enlarged to contain full lines.
971 This function is effective for large regions, over 100-200
972 lines. For small regions, use `ediff-regions-wordwise'."
973 (interactive
974 (let (bf)
975 (list (setq bf (read-buffer "Region A's buffer: "
976 (ediff-other-buffer "") t))
977 (read-buffer "Region B's buffer: "
978 (progn
979 ;; realign buffers so that two visible bufs will be
980 ;; at the top
981 (save-window-excursion (other-window 1))
982 (ediff-other-buffer bf))
983 t))))
984 (if (not (ediff-buffer-live-p buffer-A))
985 (error "Buffer %S doesn't exist" buffer-A))
986 (if (not (ediff-buffer-live-p buffer-B))
987 (error "Buffer %S doesn't exist" buffer-B))
989 (let ((buffer-A
990 (ediff-clone-buffer-for-region-comparison buffer-A "-Region.A-"))
991 (buffer-B
992 (ediff-clone-buffer-for-region-comparison buffer-B "-Region.B-"))
993 reg-A-beg reg-A-end reg-B-beg reg-B-end)
994 (save-excursion
995 (set-buffer buffer-A)
996 (setq reg-A-beg (region-beginning)
997 reg-A-end (region-end))
998 ;; enlarge the region to hold full lines
999 (goto-char reg-A-beg)
1000 (beginning-of-line)
1001 (setq reg-A-beg (point))
1002 (goto-char reg-A-end)
1003 (end-of-line)
1004 (or (eobp) (forward-char)) ; include the newline char
1005 (setq reg-A-end (point))
1007 (set-buffer buffer-B)
1008 (setq reg-B-beg (region-beginning)
1009 reg-B-end (region-end))
1010 ;; enlarge the region to hold full lines
1011 (goto-char reg-B-beg)
1012 (beginning-of-line)
1013 (setq reg-B-beg (point))
1014 (goto-char reg-B-end)
1015 (end-of-line)
1016 (or (eobp) (forward-char)) ; include the newline char
1017 (setq reg-B-end (point))
1018 ) ; save excursion
1020 (ediff-regions-internal
1021 (get-buffer buffer-A) reg-A-beg reg-A-end
1022 (get-buffer buffer-B) reg-B-beg reg-B-end
1023 startup-hooks 'ediff-regions-linewise nil nil))) ; no word mode
1025 ;; compare region beg-A to end-A of buffer-A
1026 ;; to regions beg-B -- end-B in buffer-B.
1027 (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B
1028 startup-hooks job-name word-mode
1029 setup-parameters)
1030 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
1031 overl-A overl-B
1032 file-A file-B)
1034 ;; in case beg/end-A/B aren't markers--make them into markers
1035 (ediff-with-current-buffer buffer-A
1036 (setq beg-A (move-marker (make-marker) beg-A)
1037 end-A (move-marker (make-marker) end-A)))
1038 (ediff-with-current-buffer buffer-B
1039 (setq beg-B (move-marker (make-marker) beg-B)
1040 end-B (move-marker (make-marker) end-B)))
1042 ;; make file-A
1043 (if word-mode
1044 (ediff-wordify beg-A end-A buffer-A tmp-buffer)
1045 (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer))
1046 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
1048 ;; make file-B
1049 (if word-mode
1050 (ediff-wordify beg-B end-B buffer-B tmp-buffer)
1051 (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer))
1052 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
1054 (setq overl-A (ediff-make-bullet-proof-overlay beg-A end-A buffer-A))
1055 (setq overl-B (ediff-make-bullet-proof-overlay beg-B end-B buffer-B))
1056 (ediff-setup buffer-A file-A
1057 buffer-B file-B
1058 nil nil ; buffer & file C
1059 (cons `(lambda ()
1060 (delete-file ,file-A)
1061 (delete-file ,file-B))
1062 startup-hooks)
1063 (append
1064 (list (cons 'ediff-word-mode word-mode)
1065 (cons 'ediff-narrow-bounds (list overl-A overl-B))
1066 (cons 'ediff-job-name job-name))
1067 setup-parameters))
1071 ;;; Merge files and buffers
1073 ;;;###autoload
1074 (defalias 'ediff-merge 'ediff-merge-files)
1076 (defsubst ediff-merge-on-startup ()
1077 (ediff-do-merge 0)
1078 ;; Can't remember why this is here, but it may cause the automatically merged
1079 ;; buffer to be lost. So, keep the buffer modified.
1080 ;;(ediff-with-current-buffer ediff-buffer-C
1081 ;; (set-buffer-modified-p nil))
1084 ;;;###autoload
1085 (defun ediff-merge-files (file-A file-B
1086 ;; MERGE-BUFFER-FILE is the file to be
1087 ;; associated with the merge buffer
1088 &optional startup-hooks merge-buffer-file)
1089 "Merge two files without ancestor."
1090 (interactive
1091 (let ((dir-A (if ediff-use-last-dir
1092 ediff-last-dir-A
1093 default-directory))
1094 dir-B f)
1095 (list (setq f (ediff-read-file-name
1096 "File A to merge"
1097 dir-A
1098 (ediff-get-default-file-name)
1099 'no-dirs))
1100 (ediff-read-file-name "File B to merge"
1101 (setq dir-B
1102 (if ediff-use-last-dir
1103 ediff-last-dir-B
1104 (file-name-directory f)))
1105 (progn
1106 (add-to-history 'file-name-history
1107 (ediff-abbreviate-file-name
1108 (expand-file-name
1109 (file-name-nondirectory f)
1110 dir-B)))
1111 (ediff-get-default-file-name f 1)))
1113 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1114 (ediff-files-internal file-A
1115 (if (file-directory-p file-B)
1116 (expand-file-name
1117 (file-name-nondirectory file-A) file-B)
1118 file-B)
1119 nil ; file-C
1120 startup-hooks
1121 'ediff-merge-files
1122 merge-buffer-file))
1124 ;;;###autoload
1125 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
1126 &optional
1127 startup-hooks
1128 ;; MERGE-BUFFER-FILE is the file
1129 ;; to be associated with the
1130 ;; merge buffer
1131 merge-buffer-file)
1132 "Merge two files with ancestor."
1133 (interactive
1134 (let ((dir-A (if ediff-use-last-dir
1135 ediff-last-dir-A
1136 default-directory))
1137 dir-B dir-ancestor f ff)
1138 (list (setq f (ediff-read-file-name
1139 "File A to merge"
1140 dir-A
1141 (ediff-get-default-file-name)
1142 'no-dirs))
1143 (setq ff (ediff-read-file-name "File B to merge"
1144 (setq dir-B
1145 (if ediff-use-last-dir
1146 ediff-last-dir-B
1147 (file-name-directory f)))
1148 (progn
1149 (add-to-history 'file-name-history
1150 (ediff-abbreviate-file-name
1151 (expand-file-name
1152 (file-name-nondirectory f)
1153 dir-B)))
1154 (ediff-get-default-file-name f 1))))
1155 (ediff-read-file-name "Ancestor file"
1156 (setq dir-ancestor
1157 (if ediff-use-last-dir
1158 ediff-last-dir-ancestor
1159 (file-name-directory ff)))
1160 (progn
1161 (add-to-history 'file-name-history
1162 (ediff-abbreviate-file-name
1163 (expand-file-name
1164 (file-name-nondirectory ff)
1165 dir-ancestor)))
1166 (ediff-get-default-file-name ff 2)))
1168 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1169 (ediff-files-internal file-A
1170 (if (file-directory-p file-B)
1171 (expand-file-name
1172 (file-name-nondirectory file-A) file-B)
1173 file-B)
1174 file-ancestor
1175 startup-hooks
1176 'ediff-merge-files-with-ancestor
1177 merge-buffer-file))
1179 ;;;###autoload
1180 (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor)
1182 ;;;###autoload
1183 (defun ediff-merge-buffers (buffer-A buffer-B
1184 &optional
1185 ;; MERGE-BUFFER-FILE is the file to be
1186 ;; associated with the merge buffer
1187 startup-hooks job-name merge-buffer-file)
1188 "Merge buffers without ancestor."
1189 (interactive
1190 (let (bf)
1191 (list (setq bf (read-buffer "Buffer A to merge: "
1192 (ediff-other-buffer "") t))
1193 (read-buffer "Buffer B to merge: "
1194 (progn
1195 ;; realign buffers so that two visible bufs will be
1196 ;; at the top
1197 (save-window-excursion (other-window 1))
1198 (ediff-other-buffer bf))
1199 t))))
1201 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1202 (or job-name (setq job-name 'ediff-merge-buffers))
1203 (ediff-buffers-internal
1204 buffer-A buffer-B nil startup-hooks job-name merge-buffer-file))
1206 ;;;###autoload
1207 (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
1208 &optional
1209 startup-hooks
1210 job-name
1211 ;; MERGE-BUFFER-FILE is the
1212 ;; file to be associated
1213 ;; with the merge buffer
1214 merge-buffer-file)
1215 "Merge buffers with ancestor."
1216 (interactive
1217 (let (bf bff)
1218 (list (setq bf (read-buffer "Buffer A to merge: "
1219 (ediff-other-buffer "") t))
1220 (setq bff (read-buffer "Buffer B to merge: "
1221 (progn
1222 ;; realign buffers so that two visible
1223 ;; bufs will be at the top
1224 (save-window-excursion (other-window 1))
1225 (ediff-other-buffer bf))
1227 (read-buffer "Ancestor buffer: "
1228 (progn
1229 ;; realign buffers so that three visible
1230 ;; bufs will be at the top
1231 (save-window-excursion (other-window 1))
1232 (ediff-other-buffer (list bf bff)))
1236 (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
1237 (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor))
1238 (ediff-buffers-internal
1239 buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file))
1242 ;;;###autoload
1243 (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file)
1244 ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
1245 "Run Ediff by merging two revisions of a file.
1246 The file is the optional FILE argument or the file visited by the current
1247 buffer."
1248 (interactive)
1249 (if (stringp file) (find-file file))
1250 (let (rev1 rev2)
1251 (setq rev1
1252 (read-string
1253 (format
1254 "Version 1 to merge (default %s's working version): "
1255 (if (stringp file)
1256 (file-name-nondirectory file) "current buffer")))
1257 rev2
1258 (read-string
1259 (format
1260 "Version 2 to merge (default %s): "
1261 (if (stringp file)
1262 (file-name-nondirectory file) "current buffer"))))
1263 (ediff-load-version-control)
1264 ;; ancestor-revision=nil
1265 (funcall
1266 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1267 rev1 rev2 nil startup-hooks merge-buffer-file)))
1270 ;;;###autoload
1271 (defun ediff-merge-revisions-with-ancestor (&optional
1272 file startup-hooks
1273 ;; MERGE-BUFFER-FILE is the file to
1274 ;; be associated with the merge
1275 ;; buffer
1276 merge-buffer-file)
1277 "Run Ediff by merging two revisions of a file with a common ancestor.
1278 The file is the optional FILE argument or the file visited by the current
1279 buffer."
1280 (interactive)
1281 (if (stringp file) (find-file file))
1282 (let (rev1 rev2 ancestor-rev)
1283 (setq rev1
1284 (read-string
1285 (format
1286 "Version 1 to merge (default %s's working version): "
1287 (if (stringp file)
1288 (file-name-nondirectory file) "current buffer")))
1289 rev2
1290 (read-string
1291 (format
1292 "Version 2 to merge (default %s): "
1293 (if (stringp file)
1294 (file-name-nondirectory file) "current buffer")))
1295 ancestor-rev
1296 (read-string
1297 (format
1298 "Ancestor version (default %s's base revision): "
1299 (if (stringp file)
1300 (file-name-nondirectory file) "current buffer"))))
1301 (ediff-load-version-control)
1302 (funcall
1303 (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
1304 rev1 rev2 ancestor-rev startup-hooks merge-buffer-file)))
1306 ;; MK: Check. This function doesn't seem to be used any more by pcvs or pcl-cvs
1307 ;;;###autoload
1308 (defun run-ediff-from-cvs-buffer (pos)
1309 "Run Ediff-merge on appropriate revisions of the selected file.
1310 First run after `M-x cvs-update'. Then place the cursor on a line describing a
1311 file and then run `run-ediff-from-cvs-buffer'."
1312 (interactive "d")
1313 (ediff-load-version-control)
1314 (let ((tin (tin-locate cvs-cookie-handle pos)))
1315 (if tin
1316 (cvs-run-ediff-on-file-descriptor tin)
1317 (error "There is no file to merge"))))
1320 ;;; Apply patch
1322 ;;;###autoload
1323 (defun ediff-patch-file (&optional arg patch-buf)
1324 "Run Ediff by patching SOURCE-FILENAME.
1325 If optional PATCH-BUF is given, use the patch in that buffer
1326 and don't ask the user.
1327 If prefix argument, then: if even argument, assume that the patch is in a
1328 buffer. If odd -- assume it is in a file."
1329 (interactive "P")
1330 (let (source-dir source-file)
1331 (require 'ediff-ptch)
1332 (setq patch-buf
1333 (ediff-get-patch-buffer
1334 (if arg (prefix-numeric-value arg)) patch-buf))
1335 (setq source-dir (cond (ediff-use-last-dir ediff-last-dir-patch)
1336 ((and (not ediff-patch-default-directory)
1337 (buffer-file-name patch-buf))
1338 (file-name-directory
1339 (expand-file-name
1340 (buffer-file-name patch-buf))))
1341 (t default-directory)))
1342 (setq source-file
1343 (read-file-name
1344 "File to patch (directory, if multifile patch): "
1345 ;; use an explicit initial file
1346 source-dir nil nil (ediff-get-default-file-name)))
1347 (ediff-dispatch-file-patching-job patch-buf source-file)))
1349 ;;;###autoload
1350 (defun ediff-patch-buffer (&optional arg patch-buf)
1351 "Run Ediff by patching the buffer specified at prompt.
1352 Without the optional prefix ARG, asks if the patch is in some buffer and
1353 prompts for the buffer or a file, depending on the answer.
1354 With ARG=1, assumes the patch is in a file and prompts for the file.
1355 With ARG=2, assumes the patch is in a buffer and prompts for the buffer.
1356 PATCH-BUF is an optional argument, which specifies the buffer that contains the
1357 patch. If not given, the user is prompted according to the prefix argument."
1358 (interactive "P")
1359 (require 'ediff-ptch)
1360 (setq patch-buf
1361 (ediff-get-patch-buffer
1362 (if arg (prefix-numeric-value arg)) patch-buf))
1363 (ediff-patch-buffer-internal
1364 patch-buf
1365 (read-buffer
1366 "Which buffer to patch? "
1367 (ediff-other-buffer patch-buf))))
1370 ;;;###autoload
1371 (defalias 'epatch 'ediff-patch-file)
1372 ;;;###autoload
1373 (defalias 'epatch-buffer 'ediff-patch-buffer)
1378 ;;; Versions Control functions
1380 ;;;###autoload
1381 (defun ediff-revision (&optional file startup-hooks)
1382 "Run Ediff by comparing versions of a file.
1383 The file is an optional FILE argument or the file entered at the prompt.
1384 Default: the file visited by the current buffer.
1385 Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
1386 ;; if buffer is non-nil, use that buffer instead of the current buffer
1387 (interactive "P")
1388 (if (not (stringp file))
1389 (setq file
1390 (ediff-read-file-name "Compare revisions for file"
1391 (if ediff-use-last-dir
1392 ediff-last-dir-A
1393 default-directory)
1394 (ediff-get-default-file-name)
1395 'no-dirs)))
1396 (find-file file)
1397 (if (and (buffer-modified-p)
1398 (y-or-n-p (message "Buffer %s is modified. Save buffer? "
1399 (buffer-name))))
1400 (save-buffer (current-buffer)))
1401 (let (rev1 rev2)
1402 (setq rev1
1403 (read-string
1404 (format "Revision 1 to compare (default %s's latest revision): "
1405 (file-name-nondirectory file)))
1406 rev2
1407 (read-string
1408 (format "Revision 2 to compare (default %s's current state): "
1409 (file-name-nondirectory file))))
1410 (ediff-load-version-control)
1411 (funcall
1412 (intern (format "ediff-%S-internal" ediff-version-control-package))
1413 rev1 rev2 startup-hooks)
1417 ;;;###autoload
1418 (defalias 'erevision 'ediff-revision)
1421 ;; Test if version control package is loaded and load if not
1422 ;; Is SILENT is non-nil, don't report error if package is not found.
1423 (defun ediff-load-version-control (&optional silent)
1424 (require 'ediff-vers)
1425 (or (featurep ediff-version-control-package)
1426 (if (locate-library (symbol-name ediff-version-control-package))
1427 (progn
1428 (message "") ; kill the message from `locate-library'
1429 (require ediff-version-control-package))
1430 (or silent
1431 (error "Version control package %S.el not found. Use vc.el instead"
1432 ediff-version-control-package)))))
1435 ;;;###autoload
1436 (defun ediff-version ()
1437 "Return string describing the version of Ediff.
1438 When called interactively, displays the version."
1439 (interactive)
1440 (if (interactive-p)
1441 (message (ediff-version))
1442 (format "Ediff %s of %s" ediff-version ediff-date)))
1445 ;;;###autoload
1446 (defun ediff-documentation (&optional node)
1447 "Display Ediff's manual.
1448 With optional NODE, goes to that node."
1449 (interactive)
1450 (let ((ctl-window ediff-control-window)
1451 (ctl-buf ediff-control-buffer))
1453 (ediff-skip-unsuitable-frames)
1454 (condition-case nil
1455 (progn
1456 (pop-to-buffer (get-buffer-create "*info*"))
1457 (info (if ediff-xemacs-p "ediff.info" "ediff"))
1458 (if node
1459 (Info-goto-node node)
1460 (message "Type `i' to search for a specific topic"))
1461 (raise-frame (selected-frame)))
1462 (error (beep 1)
1463 (with-output-to-temp-buffer ediff-msg-buffer
1464 (ediff-with-current-buffer standard-output
1465 (fundamental-mode))
1466 (princ ediff-BAD-INFO))
1467 (if (window-live-p ctl-window)
1468 (progn
1469 (select-window ctl-window)
1470 (set-window-buffer ctl-window ctl-buf)))))))
1473 (dolist (mess '("^Errors in diff output. Diff output is in "
1474 "^Hmm... I don't see an Ediff command around here...$"
1475 "^Undocumented command! Type `G' in Ediff Control Panel to drop a note to the Ediff maintainer$"
1476 ": This command runs in Ediff Control Buffer only!$"
1477 ": Invalid op in ediff-check-version$"
1478 "^ediff-shrink-window-C can be used only for merging jobs$"
1479 "^Lost difference info on these directories$"
1480 "^This command is inapplicable in the present context$"
1481 "^This session group has no parent$"
1482 "^Can't hide active session, $"
1483 "^Ediff: something wrong--no multiple diffs buffer$"
1484 "^Can't make context diff for Session $"
1485 "^The patch buffer wasn't found$"
1486 "^Aborted$"
1487 "^This Ediff session is not part of a session group$"
1488 "^No active Ediff sessions or corrupted session registry$"
1489 "^No session info in this line$"
1490 "^`.*' is not an ordinary file$"
1491 "^Patch appears to have failed$"
1492 "^Recomputation of differences cancelled$"
1493 "^No fine differences in this mode$"
1494 "^Lost connection to ancestor buffer...sorry$"
1495 "^Not merging with ancestor$"
1496 "^Don't know how to toggle read-only in buffer "
1497 "Emacs is not running as a window application$"
1498 "^This command makes sense only when merging with an ancestor$"
1499 "^At end of the difference list$"
1500 "^At beginning of the difference list$"
1501 "^Nothing saved for diff .* in buffer "
1502 "^Buffer is out of sync for file "
1503 "^Buffer out of sync for file "
1504 "^Output from `diff' not found$"
1505 "^You forgot to specify a region in buffer "
1506 "^All right. Make up your mind and come back...$"
1507 "^Current buffer is not visiting any file$"
1508 "^Failed to retrieve revision: $"
1509 "^Can't determine display width.$"
1510 "^File `.*' does not exist or is not readable$"
1511 "^File `.*' is a directory$"
1512 "^Buffer .* doesn't exist$"
1513 "^Directories . and . are the same: "
1514 "^Directory merge aborted$"
1515 "^Merge of directory revisions aborted$"
1516 "^Buffer .* doesn't exist$"
1517 "^There is no file to merge$"
1518 "^Version control package .*.el not found. Use vc.el instead$"))
1519 (add-to-list 'debug-ignored-errors mess))
1522 (require 'ediff-util)
1524 (run-hooks 'ediff-load-hook)
1526 (provide 'ediff)
1529 ;;; Local Variables:
1530 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1531 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1532 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1533 ;;; End:
1535 ;;; arch-tag: 97c71396-db02-4f41-8b48-6a51c3348fcc
1536 ;;; ediff.el ends here