;;; ediff.el --- a comprehensive visual interface to diff & patch;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.;; Author: Michael Kifer <kifer@cs.sunysb.edu>;; Created: February 2, 1994;; Keywords: comparing, merging, patching, version control.(defconstediff-version"2.70.2""The current version of Ediff")(defconstediff-date"May 21, 1998""Date of last update");; This file is part of GNU Emacs.;; GNU Emacs is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 2, or (at your option);; any later version.;; 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;; along with GNU Emacs; see the file COPYING. If not, write to the;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,;; Boston, MA 02111-1307, USA.;;; Commentary:;; Never read that diff output again!;; Apply patch interactively!;; Merge with ease!;; This package provides a convenient way of simultaneous browsing through;; the differences between a pair (or a triple) of files or buffers. The;; 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).;; Ediff also supports merging operations on files and buffers, including;; merging using ancestor versions. Both comparison and merging operations can;; be performed on directories, i.e., by pairwise comparison of files in those;; directories.;; In addition, Ediff can apply a patch to a file and then let you step;; though both files, the patched and the original one, simultaneously,;; 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;; region from file_orig to file, thereby undoing any particular patch that;; you don't like).;; Ediff is aware of version control, which lets the user compare;; files with their older versions. Ediff can also work with remote and;; compressed files. Details are given below.;; Finally, Ediff supports directory-level comparison, merging and patching.;; See the on-line manual for details.;; This package builds upon the ideas borrowed from emerge.el and several;; Ediff's functions are adaptations from emerge.el. Much of the functionality;; Ediff provides is also influenced by emerge.el.;; The present version of Ediff supersedes Emerge. It provides a superior user;; interface and has numerous major features not found in Emerge. In;; particular, it can do patching, and 2-way and 3-way file comparison,;; merging, and directory operations.;;; Bugs:;; 1. The undo command doesn't restore deleted regions well. That is, if;; you delete all characters in a difference region and then invoke;; `undo', the reinstated text will most likely be inserted outside of;; what Ediff thinks is the current difference region. (This problem;; doesn't seem to exist with XEmacs.);;;; If at any point you feel that difference regions are no longer correct,;; you can hit '!' to recompute the differences.;; 2. On a monochrome display, the repertoire of faces with which to;; highlight fine differences is limited. By default, Ediff is using;; underlining. However, if the region is already underlined by some other;; overlays, there is no simple way to temporarily remove that residual;; 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;; commands in `ediff-prepare-buffer-hook' (which will unhighlight every;; buffer used by Ediff) or you can execute them interactively, at any time;; and on any buffer.;;; Acknowledgements:;; 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;; its many users. See Ediff on-line Info for the full list of those who;; helped. Improved defaults in Ediff file-name reading commands.;;; Code:(provide'ediff);; Compiler pacifier(defvarcvs-cookie-handle)(defvarediff-last-dir-patch)(defvarediff-patch-default-directory)(andnoninteractive(eval-when-compile(load-library"dired")(load-library"info")(load"pcl-cvs"'noerror)))(eval-when-compile(let((load-path(cons(expand-file-name".")load-path)))(or(featurep'ediff-init)(load"ediff-init.el"nilnil'nosuffix))(or(featurep'ediff-mult)(load"ediff-mult.el"nilnil'nosuffix))(or(featurep'ediff-ptch)(load"ediff-ptch.el"nilnil'nosuffix))(or(featurep'ediff-vers)(load"ediff-vers.el"nilnil'nosuffix))));; end pacifier(require'ediff-init)(require'ediff-mult); required because of the registry stuff(defgroupediffnil"A comprehensive visual interface to diff & patch":tag"Ediff":group'tools)(defcustomediff-use-last-dirnil"*If t, Ediff will use previous directory as default when reading file name.":type'boolean:group'ediff);; Last directory used by an Ediff command for file-A.(defvarediff-last-dir-Anil);; Last directory used by an Ediff command for file-B.(defvarediff-last-dir-Bnil);; Last directory used by an Ediff command for file-C.(defvarediff-last-dir-Cnil);; Last directory used by an Ediff command for the ancestor file.(defvarediff-last-dir-ancestornil);; Last directory used by an Ediff command as the output directory for merge.(defvarediff-last-merge-autostore-dir);; Used as a startup hook to set `_orig' patch file read-only.(defunediff-set-read-only-in-buf-A()(ediff-with-current-bufferediff-buffer-A(toggle-read-only1)));; Return a plausible default for ediff's first file:;; In dired, return the file name under the point, unless it is a directory;; If the buffer has a file name, return that file name.(defunediff-get-default-file-name()(cond((eqmajor-mode'dired-mode)(let((f(dired-get-filenamenil'no-error)))(if(and(stringpf)(not(file-directory-pf)))f)))((buffer-file-name(current-buffer))(file-name-nondirectory(buffer-file-name(current-buffer))))));;; Compare files/buffers;;;###autoload(defunediff-files(file-Afile-B&optionalstartup-hooks)"Run Ediff on a pair of files, FILE-A and FILE-B."(interactive(let((dir-A(ifediff-use-last-dirediff-last-dir-Adefault-directory))dir-Bf)(list(setqf(ediff-read-file-name"File A to compare"dir-A(ediff-get-default-file-name)))(ediff-read-file-name"File B to compare"(setqdir-B(ifediff-use-last-dirediff-last-dir-B(file-name-directoryf)))(progn(setqfile-name-history(cons(ediff-abbreviate-file-name(expand-file-name(file-name-nondirectoryf)dir-B))file-name-history))f)))))(ediff-files-internalfile-A(if(file-directory-pfile-B)(expand-file-name(file-name-nondirectoryfile-A)file-B)file-B)nil; file-Cstartup-hooks'ediff-files));;;###autoload(defunediff-files3(file-Afile-Bfile-C&optionalstartup-hooks)"Run Ediff on three files, FILE-A, FILE-B, and FILE-C."(interactive(let((dir-A(ifediff-use-last-dirediff-last-dir-Adefault-directory))dir-Bdir-Cfff)(list(setqf(ediff-read-file-name"File A to compare"dir-A(ediff-get-default-file-name)))(setqff(ediff-read-file-name"File B to compare"(setqdir-B(ifediff-use-last-dirediff-last-dir-B(file-name-directoryf)))(progn(setqfile-name-history(cons(ediff-abbreviate-file-name(expand-file-name(file-name-nondirectoryf)dir-B))file-name-history))f)))(ediff-read-file-name"File C to compare"(setqdir-C(ifediff-use-last-dirediff-last-dir-C(file-name-directoryff)))(progn(setqfile-name-history(cons(ediff-abbreviate-file-name(expand-file-name(file-name-nondirectoryff)dir-C))file-name-history))ff)))))(ediff-files-internalfile-A(if(file-directory-pfile-B)(expand-file-name(file-name-nondirectoryfile-A)file-B)file-B)(if(file-directory-pfile-C)(expand-file-name(file-name-nondirectoryfile-A)file-C)file-C)startup-hooks'ediff-files3));;;###autoload(defalias'ediff3'ediff-files3);; Visit FILE and arrange its buffer to Ediff's liking. ;; FILE is actually a variable symbol that 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.(defunediff-find-file(file-varbuffer-name&optionallast-dirhooks-var)(let*((file(symbol-valuefile-var))(file-magic(ediff-filename-magic-pfile))(temp-file-name-prefix(file-name-nondirectoryfile)))(cond((not(file-readable-pfile))(error"File `%s' does not exist or is not readable"file))((file-directory-pfile)(error"File `%s' is a directory"file)));; some of the commands, below, require full file name(setqfile(expand-file-namefile));; Record the directory of the file(iflast-dir(setlast-dir(expand-file-name(file-name-directoryfile))));; Setup the buffer(setbuffer-name(find-file-noselectfile))(ediff-with-current-buffer(symbol-valuebuffer-name)(widen); Make sure the entire file is seen(cond(file-magic; file has a handler, such as jka-compr-handler or;;; ange-ftp-hook-function--arrange for temp file(ediff-verify-file-buffer'magic)(setqfile(ediff-make-temp-file(current-buffer)temp-file-name-prefix))(sethooks-var(cons(`(lambda()(delete-file(,file))))(symbol-valuehooks-var))));; file processed via auto-mode-alist, a la uncompress.el((not(equal(file-truenamefile)(file-truename(buffer-file-name))))(setqfile(ediff-make-temp-file(current-buffer)temp-file-name-prefix))(sethooks-var(cons(`(lambda()(delete-file(,file))))(symbol-valuehooks-var))))(t;; plain file---just check that the file matches the buffer(ediff-verify-file-buffer))))(setfile-varfile)));; MERGE-BUFFER-FILE is the file to be associated with the merge buffer(defunediff-files-internal(file-Afile-Bfile-Cstartup-hooksjob-name&optionalmerge-buffer-file)(let(buf-Abuf-Bbuf-C)(message"Reading file %s ... "file-A);;(sit-for 0)(ediff-find-file'file-A'buf-A'ediff-last-dir-A'startup-hooks)(message"Reading file %s ... "file-B);;(sit-for 0)(ediff-find-file'file-B'buf-B'ediff-last-dir-B'startup-hooks)(if(stringpfile-C)(progn(message"Reading file %s ... "file-C);;(sit-for 0)(ediff-find-file'file-C'buf-C(if(eqjob-name'ediff-merge-files-with-ancestor)'ediff-last-dir-ancestor'ediff-last-dir-C)'startup-hooks)))(ediff-setupbuf-Afile-Abuf-Bfile-Bbuf-Cfile-Cstartup-hooks(list(cons'ediff-job-namejob-name))merge-buffer-file)));;;###autoload(defalias'ediff'ediff-files);;;###autoload(defunediff-buffers(buffer-Abuffer-B&optionalstartup-hooksjob-name)"Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B."(interactive(let(bf)(list(setqbf(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-window1))(ediff-other-bufferbf))t))))(orjob-name(setqjob-name'ediff-buffers))(ediff-buffers-internalbuffer-Abuffer-Bnilstartup-hooksjob-name));;;###autoload(defalias'ebuffers'ediff-buffers);;;###autoload(defunediff-buffers3(buffer-Abuffer-Bbuffer-C&optionalstartup-hooksjob-name)"Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C."(interactive(let(bfbff)(list(setqbf(read-buffer"Buffer A to compare: "(ediff-other-buffer"")t))(setqbff(read-buffer"Buffer B to compare: "(progn;; realign buffers so that two visible;; bufs will be at the top(save-window-excursion(other-window1))(ediff-other-bufferbf))t))(read-buffer"Buffer C to compare: "(progn;; realign buffers so that three visible;; bufs will be at the top(save-window-excursion(other-window1))(ediff-other-buffer(listbfbff)))t))))(orjob-name(setqjob-name'ediff-buffers3))(ediff-buffers-internalbuffer-Abuffer-Bbuffer-Cstartup-hooksjob-name));;;###autoload(defalias'ebuffers3'ediff-buffers3);; MERGE-BUFFER-FILE is the file to be associated with the merge buffer(defunediff-buffers-internal(buf-Abuf-Bbuf-Cstartup-hooksjob-name&optionalmerge-buffer-file)(let*((buf-A-file-name(buffer-file-name(get-bufferbuf-A)))(buf-B-file-name(buffer-file-name(get-bufferbuf-B)))(buf-C-is-alive(ediff-buffer-live-pbuf-C))(buf-C-file-name(ifbuf-C-is-alive(buffer-file-name(get-bufferbuf-B))))file-Afile-Bfile-C)(if(not(ediff-buffer-live-pbuf-A))(error"Buffer %S doesn't exist"buf-A))(if(not(ediff-buffer-live-pbuf-B))(error"Buffer %S doesn't exist"buf-B))(let((ediff-job-namejob-name))(if(andediff-3way-comparison-job(notbuf-C-is-alive))(error"Buffer %S doesn't exist"buf-C)))(if(stringpbuf-A-file-name)(setqbuf-A-file-name(file-name-nondirectorybuf-A-file-name)))(if(stringpbuf-B-file-name)(setqbuf-B-file-name(file-name-nondirectorybuf-B-file-name)))(if(stringpbuf-C-file-name)(setqbuf-C-file-name(file-name-nondirectorybuf-C-file-name)))(setqfile-A(ediff-make-temp-filebuf-Abuf-A-file-name)file-B(ediff-make-temp-filebuf-Bbuf-B-file-name))(ifbuf-C-is-alive(setqfile-C(ediff-make-temp-filebuf-Cbuf-C-file-name)))(ediff-setup(get-bufferbuf-A)file-A(get-bufferbuf-B)file-B(ifbuf-C-is-alive(get-bufferbuf-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-namejob-name))merge-buffer-file)));;; 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(defunediff-get-default-directory-name()(cond(ediff-use-last-dirediff-last-dir-A)((eqmajor-mode'dired-mode)(let((f(dired-get-filenamenil'noerror)))(if(and(stringpf)(file-directory-pf))fdefault-directory)))(tdefault-directory)));;;###autoload(defunediff-directories(dir1dir2regexp)"Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that havethe same name in both. The third argument, REGEXP, is a regular expression thatcan be used to filter out certain file names."(interactive(let((dir-A(ediff-get-default-directory-name))f)(list(setqf(ediff-read-file-name"Directory A to compare:"dir-Anil))(ediff-read-file-name"Directory B to compare:"(ifediff-use-last-dirediff-last-dir-B(ediff-strip-last-dirf))nil)(read-string"Filter through regular expression: "nil'ediff-filtering-regexp-history))))(ediff-directories-internaldir1dir2nilregexp'ediff-files'ediff-directories));;;###autoload(defalias'edirs'ediff-directories);;;###autoload(defunediff-directory-revisions(dir1regexp)"Run Ediff on a directory, DIR1, comparing its files with their revisions.The second argument, REGEXP, is a regular expression that filters the filenames. Only the files that are under revision control are taken into account."(interactive(let((dir-A(ediff-get-default-directory-name)))(list(ediff-read-file-name"Directory to compare with revision:"dir-Anil)(read-string"Filter through regular expression: "nil'ediff-filtering-regexp-history))))(ediff-directory-revisions-internaldir1regexp'ediff-revision'ediff-directory-revisions));;;###autoload(defalias'edir-revisions'ediff-directory-revisions);;;###autoload(defunediff-directories3(dir1dir2dir3regexp)"Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files thathave the same name in all three. The last argument, REGEXP, is a regularexpression that can be used to filter out certain file names."(interactive(let((dir-A(ediff-get-default-directory-name))f)(list(setqf(ediff-read-file-name"Directory A to compare:"dir-Anil))(setqf(ediff-read-file-name"Directory B to compare:"(ifediff-use-last-dirediff-last-dir-B(ediff-strip-last-dirf))nil))(ediff-read-file-name"Directory C to compare:"(ifediff-use-last-dirediff-last-dir-C(ediff-strip-last-dirf))nil)(read-string"Filter through regular expression: "nil'ediff-filtering-regexp-history))))(ediff-directories-internaldir1dir2dir3regexp'ediff-files3'ediff-directories3));;;###autoload(defalias'edirs3'ediff-directories3);;;###autoload(defunediff-merge-directories(dir1dir2regexp)"Run Ediff on a pair of directories, DIR1 and DIR2, merging files that havethe same name in both. The third argument, REGEXP, is a regular expression thatcan be used to filter out certain file names."(interactive(let((dir-A(ediff-get-default-directory-name))f)(list(setqf(ediff-read-file-name"Directory A to merge:"dir-Anil))(ediff-read-file-name"Directory B to merge:"(ifediff-use-last-dirediff-last-dir-B(ediff-strip-last-dirf))nil)(read-string"Filter through regular expression: "nil'ediff-filtering-regexp-history))))(ediff-directories-internaldir1dir2nilregexp'ediff-merge-files'ediff-merge-directories));;;###autoload(defalias'edirs-merge'ediff-merge-directories);;;###autoload(defunediff-merge-directories-with-ancestor(dir1dir2ancestor-dirregexp)"Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors.Ediff merges files that have identical names in DIR1, DIR2. If a pair of filesin DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will mergewithout ancestor. The fourth argument, REGEXP, is a regular expression thatcan be used to filter out certain file names."(interactive(let((dir-A(ediff-get-default-directory-name))f)(list(setqf(ediff-read-file-name"Directory A to merge:"dir-Anil))(setqf(ediff-read-file-name"Directory B to merge:"(ifediff-use-last-dirediff-last-dir-B(ediff-strip-last-dirf))nil))(ediff-read-file-name"Ancestor directory:"(ifediff-use-last-dirediff-last-dir-C(ediff-strip-last-dirf))nil)(read-string"Filter through regular expression: "nil'ediff-filtering-regexp-history))))(ediff-directories-internaldir1dir2ancestor-dirregexp'ediff-merge-files-with-ancestor'ediff-merge-directories-with-ancestor));;;###autoload(defunediff-merge-directory-revisions(dir1regexp)"Run Ediff on a directory, DIR1, merging its files with their revisions.The second argument, REGEXP, is a regular expression that filters the filenames. Only the files that are under revision control are taken into account."(interactive(let((dir-A(ediff-get-default-directory-name)))(list(ediff-read-file-name"Directory to merge with revisions:"dir-Anil)(read-string"Filter through regular expression: "nil'ediff-filtering-regexp-history))))(ediff-directory-revisions-internaldir1regexp'ediff-merge-revisions'ediff-merge-directory-revisions));;;###autoload(defalias'edir-merge-revisions'ediff-merge-directory-revisions);;;###autoload(defunediff-merge-directory-revisions-with-ancestor(dir1regexp)"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 filenames. Only the files that are under revision control are taken into account."(interactive(let((dir-A(ediff-get-default-directory-name)))(list(ediff-read-file-name"Directory to merge with revisions and ancestors:"dir-Anil)(read-string"Filter through regular expression: "nil'ediff-filtering-regexp-history))))(ediff-directory-revisions-internaldir1regexp'ediff-merge-revisions-with-ancestor'ediff-merge-directory-revisions-with-ancestor));;;###autoload(defalias'edir-merge-revisions-with-ancestor'ediff-merge-directory-revisions-with-ancestor);;;###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).;; The third argument, REGEXP, is a regular expression that can be used to;; filter out certain file names.;; JOBNAME is the symbol indicating the meta-job to be performed.;; MERGE-DIR is the directory in which to store merged files.(defunediff-directories-internal(dir1dir2dir3regexpactionjobname&optionalstartup-hooks);; ediff-read-file-name is set to attach a previously entered file name if;; the currently entered file is a directory. This code takes care of that.(setqdir1(if(file-directory-pdir1)dir1(file-name-directorydir1))dir2(if(file-directory-pdir2)dir2(file-name-directorydir2)))(if(stringpdir3)(setqdir3(if(file-directory-pdir3)dir3(file-name-directorydir3))))(cond((string=dir1dir2)(error"Directories A and B are the same: %s"dir1))((and(eqjobname'ediff-directories3)(string=dir1dir3))(error"Directories A and C are the same: %s"dir1))((and(eqjobname'ediff-directories3)(string=dir2dir3))(error"Directories B and C are the same: %s"dir1)))(let(diffs; var where ediff-intersect-directories returns the diff listmerge-autostore-dirfile-listmeta-buf)(if(andediff-autostore-merges(ediff-merge-metajobjobname))(setqmerge-autostore-dir(ediff-read-file-name"Directory to save merged files:"(ifediff-use-last-dirediff-last-merge-autostore-dir(ediff-strip-last-dirdir1))nil)));; verify we are not merging into an orig directory(if(stringpmerge-autostore-dir)(cond((and(stringpdir1)(string=merge-autostore-dirdir1))(or(y-or-n-p"Merge directory same as directory A, sure? ")(error"Directory merge aborted")))((and(stringpdir2)(string=merge-autostore-dirdir2))(or(y-or-n-p"Merge directory same as directory B, sure? ")(error"Directory merge aborted")))((and(stringpdir3)(string=merge-autostore-dirdir3))(or(y-or-n-p"Merge directory same as ancestor directory, sure? ")(error"Directory merge aborted")))))(setqfile-list(ediff-intersect-directoriesjobname'diffsregexpdir1dir2dir3merge-autostore-dir))(setqstartup-hooks;; this sets various vars in the meta buffer inside;; ediff-prepare-meta-buffer(cons(`(lambda();; tell what to do if the user clicks on a session record(setqediff-session-action-function(quote(,action)));; set ediff-dir-difference-list (setqediff-dir-difference-list(quote(,diffs)))))startup-hooks))(setqmeta-buf(ediff-prepare-meta-buffer'ediff-filegroup-actionfile-list"*Ediff Session Group Panel"'ediff-redraw-directory-group-bufferjobnamestartup-hooks))(ediff-show-meta-buffermeta-buf)))(defunediff-directory-revisions-internal(dir1regexpactionjobname&optionalstartup-hooks)(setqdir1(if(file-directory-pdir1)dir1(file-name-directorydir1)))(let(file-listmeta-bufmerge-autostore-dir)(if(andediff-autostore-merges(ediff-merge-metajobjobname))(setqmerge-autostore-dir(ediff-read-file-name"Directory to save merged files:"(ifediff-use-last-dirediff-last-merge-autostore-dir(ediff-strip-last-dirdir1))nil)));; verify merge-autostore-dir != dir1(if(and(stringpmerge-autostore-dir)(stringpdir1)(string=merge-autostore-dirdir1))(or(y-or-n-p"Directory for saving merges is the same as directory A. Sure? ")(error"Merge of directory revisions aborted")))(setqfile-list(ediff-get-directory-files-under-revisionjobnameregexpdir1merge-autostore-dir))(setqstartup-hooks;; this sets various vars in the meta buffer inside;; ediff-prepare-meta-buffer(cons(`(lambda();; tell what to do if the user clicks on a session record(setqediff-session-action-function(quote(,action)))))startup-hooks))(setqmeta-buf(ediff-prepare-meta-buffer'ediff-filegroup-actionfile-list"*Ediff Session Group Panel"'ediff-redraw-directory-group-bufferjobnamestartup-hooks))(ediff-show-meta-buffermeta-buf)));;; Compare regions and windows;;;###autoload(defunediff-windows-wordwise(dumb-mode&optionalwind-Awind-Bstartup-hooks)"Compare WIND-A and WIND-B, which are selected by clicking, wordwise.With prefix argument, DUMB-MODE, or on a non-windowing display, works asfollows:If WIND-A is nil, use selected window.If WIND-B is nil, use window next to WIND-A."(interactive"P")(ediff-windowsdumb-modewind-Awind-Bstartup-hooks'ediff-windows-wordwise'word-mode));;;###autoload(defunediff-windows-linewise(dumb-mode&optionalwind-Awind-Bstartup-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 asfollows:If WIND-A is nil, use selected window.If WIND-B is nil, use window next to WIND-A."(interactive"P")(ediff-windowsdumb-modewind-Awind-Bstartup-hooks'ediff-windows-linewisenil));; 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.(defunediff-windows(dumb-modewind-Awind-Bstartup-hooksjob-nameword-mode)(if(ordumb-mode(not(ediff-window-display-p)))(setqwind-A(ediff-get-next-windowwind-Anil)wind-B(ediff-get-next-windowwind-Bwind-A))(setqwind-A(ediff-get-window-by-clickingwind-Anil1)wind-B(ediff-get-window-by-clickingwind-Bwind-A2)))(let((buffer-A(window-bufferwind-A))(buffer-B(window-bufferwind-B))beg-Aend-Abeg-Bend-B)(save-excursion(save-window-excursion(sit-for0); sync before using window-start/end -- a precaution(select-windowwind-A)(setqbeg-A(window-start)end-A(window-end))(select-windowwind-B)(setqbeg-B(window-start)end-B(window-end))))(ediff-regions-internalbuffer-Abeg-Aend-Abuffer-Bbeg-Bend-Bstartup-hooksjob-nameword-modenil)));;;###autoload(defunediff-regions-wordwise(buffer-Abuffer-B&optionalstartup-hooks)"Run Ediff on a pair of regions in two different buffers.Regions \(i.e., point and mark\) are assumed to be set in advance.This function is effective only for relatively small regions, up to 200lines. For large regions, use `ediff-regions-linewise'."(interactive(let(bf)(list(setqbf(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-window1))(ediff-other-bufferbf))t))))(if(not(ediff-buffer-live-pbuffer-A))(error"Buffer %S doesn't exist"buffer-A))(if(not(ediff-buffer-live-pbuffer-B))(error"Buffer %S doesn't exist"buffer-B))(let(reg-A-begreg-A-endreg-B-begreg-B-end)(save-excursion(set-bufferbuffer-A)(setqreg-A-beg(region-beginning)reg-A-end(region-end))(set-bufferbuffer-B)(setqreg-B-beg(region-beginning)reg-B-end(region-end)))(ediff-regions-internal(get-bufferbuffer-A)reg-A-begreg-A-end(get-bufferbuffer-B)reg-B-begreg-B-endstartup-hooks'ediff-regions-wordwise'word-modenil)));;;###autoload(defunediff-regions-linewise(buffer-Abuffer-B&optionalstartup-hooks)"Run Ediff on a pair of regions in two different buffers.Regions \(i.e., point and mark\) are assumed to be set in advance.Each region is enlarged to contain full lines.This function is effective for large regions, over 100-200lines. For small regions, use `ediff-regions-wordwise'."(interactive(let(bf)(list(setqbf(read-buffer"Region A's buffer: "(ediff-other-buffer"")t))(read-buffer"Region B's buffer: "(progn;; realign buffers so that two visible bufs will be;; at the top(save-window-excursion(other-window1))(ediff-other-bufferbf))t))))(if(not(ediff-buffer-live-pbuffer-A))(error"Buffer %S doesn't exist"buffer-A))(if(not(ediff-buffer-live-pbuffer-B))(error"Buffer %S doesn't exist"buffer-B))(let(reg-A-begreg-A-endreg-B-begreg-B-end)(save-excursion(set-bufferbuffer-A)(setqreg-A-beg(region-beginning)reg-A-end(region-end));; enlarge the region to hold full lines(goto-charreg-A-beg)(beginning-of-line)(setqreg-A-beg(point))(goto-charreg-A-end)(end-of-line)(or(eobp)(forward-char)); include the newline char(setqreg-A-end(point))(set-bufferbuffer-B)(setqreg-B-beg(region-beginning)reg-B-end(region-end));; enlarge the region to hold full lines(goto-charreg-B-beg)(beginning-of-line)(setqreg-B-beg(point))(goto-charreg-B-end)(end-of-line)(or(eobp)(forward-char)); include the newline char(setqreg-B-end(point))); save excursion(ediff-regions-internal(get-bufferbuffer-A)reg-A-begreg-A-end(get-bufferbuffer-B)reg-B-begreg-B-endstartup-hooks'ediff-regions-linewisenilnil))); no word mode;; compare region beg-A to end-A of buffer-A;; to regions beg-B -- end-B in buffer-B. (defunediff-regions-internal(buffer-Abeg-Aend-Abuffer-Bbeg-Bend-Bstartup-hooksjob-nameword-modesetup-parameters)(let((tmp-buffer(get-buffer-createediff-tmp-buffer))overl-Aoverl-Bfile-Afile-B);; in case beg/end-A/B aren't markers--make them into markers(ediff-with-current-bufferbuffer-A(setqbeg-A(move-marker(make-marker)beg-A)end-A(move-marker(make-marker)end-A)))(ediff-with-current-bufferbuffer-B(setqbeg-B(move-marker(make-marker)beg-B)end-B(move-marker(make-marker)end-B)))(if(and(eqbuffer-Abuffer-B)(or(and(<beg-Aend-B)(<=beg-Bbeg-A)); b-B b-A e-B(and(<beg-Bend-A)(<=end-Aend-B)))); b-B e-A e-B(progn(with-output-to-temp-bufferediff-msg-buffer(princ"You have requested to compare overlapping regions of the same buffer.In this case, Ediff's highlighting may be confusing---in the same window,you may see highlighted regions that belong to different regions.Continue anyway? (y/n) "))(if(y-or-n-p"Continue anyway? ")()(error"%S aborted"job-name))));; make file-A(ifword-mode(ediff-wordifybeg-Aend-Abuffer-Atmp-buffer)(ediff-copy-to-bufferbeg-Aend-Abuffer-Atmp-buffer))(setqfile-A(ediff-make-temp-filetmp-buffer"regA"));; make file-B(ifword-mode(ediff-wordifybeg-Bend-Bbuffer-Btmp-buffer)(ediff-copy-to-bufferbeg-Bend-Bbuffer-Btmp-buffer))(setqfile-B(ediff-make-temp-filetmp-buffer"regB"))(setqoverl-A(ediff-make-bullet-proof-overlaybeg-Aend-Abuffer-A))(setqoverl-B(ediff-make-bullet-proof-overlaybeg-Bend-Bbuffer-B))(ediff-setupbuffer-Afile-Abuffer-Bfile-Bnilnil; buffer & file C(cons(`(lambda()(delete-file(,file-A))(delete-file(,file-B))))startup-hooks)(append(list(cons'ediff-word-modeword-mode)(cons'ediff-narrow-bounds(listoverl-Aoverl-B))(cons'ediff-job-namejob-name))setup-parameters))));;; Merge files and buffers;;;###autoload(defalias'ediff-merge'ediff-merge-files)(defsubstediff-merge-on-startup()(ediff-do-merge0)(ediff-with-current-bufferediff-buffer-C(set-buffer-modified-pnil)));;;###autoload(defunediff-merge-files(file-Afile-B;; MERGE-BUFFER-FILE is the file to be;; associated with the merge buffer &optionalstartup-hooksmerge-buffer-file)"Merge two files without ancestor."(interactive(let((dir-A(ifediff-use-last-dirediff-last-dir-Adefault-directory))dir-Bf)(list(setqf(ediff-read-file-name"File A to merge"dir-A(ediff-get-default-file-name)))(ediff-read-file-name"File B to merge"(setqdir-B(ifediff-use-last-dirediff-last-dir-B(file-name-directoryf)))(progn(setqfile-name-history(cons(ediff-abbreviate-file-name(expand-file-name(file-name-nondirectoryf)dir-B))file-name-history))f)))))(setqstartup-hooks(cons'ediff-merge-on-startupstartup-hooks))(ediff-files-internalfile-A(if(file-directory-pfile-B)(expand-file-name(file-name-nondirectoryfile-A)file-B)file-B)nil; file-Cstartup-hooks'ediff-merge-filesmerge-buffer-file));;;###autoload(defunediff-merge-files-with-ancestor(file-Afile-Bfile-ancestor&optionalstartup-hooks;; MERGE-BUFFER-FILE is the file;; to be associated with the;; merge buffermerge-buffer-file)"Merge two files with ancestor."(interactive(let((dir-A(ifediff-use-last-dirediff-last-dir-Adefault-directory))dir-Bdir-ancestorfff)(list(setqf(ediff-read-file-name"File A to merge"dir-A(ediff-get-default-file-name)))(setqff(ediff-read-file-name"File B to merge"(setqdir-B(ifediff-use-last-dirediff-last-dir-B(file-name-directoryf)))(progn(setqfile-name-history(cons(ediff-abbreviate-file-name(expand-file-name(file-name-nondirectoryf)dir-B))file-name-history))f)))(ediff-read-file-name"Ancestor file"(setqdir-ancestor(ifediff-use-last-dirediff-last-dir-ancestor(file-name-directoryff)))(progn(setqfile-name-history(cons(ediff-abbreviate-file-name(expand-file-name(file-name-nondirectoryff)dir-ancestor))file-name-history))ff)))))(setqstartup-hooks(cons'ediff-merge-on-startupstartup-hooks))(ediff-files-internalfile-A(if(file-directory-pfile-B)(expand-file-name(file-name-nondirectoryfile-A)file-B)file-B)file-ancestorstartup-hooks'ediff-merge-files-with-ancestormerge-buffer-file));;;###autoload(defalias'ediff-merge-with-ancestor'ediff-merge-files-with-ancestor);;;###autoload(defunediff-merge-buffers(buffer-Abuffer-B&optional;; MERGE-BUFFER-FILE is the file to be;; associated with the merge bufferstartup-hooksjob-namemerge-buffer-file)"Merge buffers without ancestor."(interactive(let(bf)(list(setqbf(read-buffer"Buffer A to merge: "(ediff-other-buffer"")t))(read-buffer"Buffer B to merge: "(progn;; realign buffers so that two visible bufs will be;; at the top(save-window-excursion(other-window1))(ediff-other-bufferbf))t))))(setqstartup-hooks(cons'ediff-merge-on-startupstartup-hooks))(orjob-name(setqjob-name'ediff-merge-buffers))(ediff-buffers-internalbuffer-Abuffer-Bnilstartup-hooksjob-namemerge-buffer-file));;;###autoload(defunediff-merge-buffers-with-ancestor(buffer-Abuffer-Bbuffer-ancestor&optionalstartup-hooksjob-name;; MERGE-BUFFER-FILE is the;; file to be associated;; with the merge buffermerge-buffer-file)"Merge buffers with ancestor."(interactive(let(bfbff)(list(setqbf(read-buffer"Buffer A to merge: "(ediff-other-buffer"")t))(setqbff(read-buffer"Buffer B to merge: "(progn;; realign buffers so that two visible;; bufs will be at the top(save-window-excursion(other-window1))(ediff-other-bufferbf))t))(read-buffer"Ancestor buffer: "(progn;; realign buffers so that three visible;; bufs will be at the top(save-window-excursion(other-window1))(ediff-other-buffer(listbfbff)))t))))(setqstartup-hooks(cons'ediff-merge-on-startupstartup-hooks))(orjob-name(setqjob-name'ediff-merge-buffers-with-ancestor))(ediff-buffers-internalbuffer-Abuffer-Bbuffer-ancestorstartup-hooksjob-namemerge-buffer-file));;;###autoload(defunediff-merge-revisions(&optionalfilestartup-hooksmerge-buffer-file);; MERGE-BUFFER-FILE is the file to be associated with the merge buffer"Run Ediff by merging two revisions of a file.The file is the optional FILE argument or the file visited by the currentbuffer."(interactive)(if(stringpfile)(find-filefile))(let(rev1rev2)(setqrev1(read-string(format"Version 1 to merge (default: %s's latest version): "(if(stringpfile)(file-name-nondirectoryfile)"current buffer")))rev2(read-string(format"Version 2 to merge (default: %s): "(if(stringpfile)(file-name-nondirectoryfile)"current buffer"))))(ediff-load-version-control);; ancestor-revision=nil(funcall(intern(format"ediff-%S-merge-internal"ediff-version-control-package))rev1rev2nilstartup-hooksmerge-buffer-file)));;;###autoload(defunediff-merge-revisions-with-ancestor(&optionalfilestartup-hooks;; MERGE-BUFFER-FILE is the file to;; be associated with the merge;; buffermerge-buffer-file)"Run Ediff by merging two revisions of a file with a common ancestor.The file is the the optional FILE argument or the file visited by the currentbuffer."(interactive)(if(stringpfile)(find-filefile))(let(rev1rev2ancestor-rev)(setqrev1(read-string(format"Version 1 to merge (default: %s's latest version): "(if(stringpfile)(file-name-nondirectoryfile)"current buffer")))rev2(read-string(format"Version 2 to merge (default: %s): "(if(stringpfile)(file-name-nondirectoryfile)"current buffer")))ancestor-rev(read-string(format"Ancestor version (default: %s): "(if(stringpfile)(file-name-nondirectoryfile)"current buffer"))))(ediff-load-version-control)(funcall(intern(format"ediff-%S-merge-internal"ediff-version-control-package))rev1rev2ancestor-revstartup-hooksmerge-buffer-file)));;;###autoload(defunrun-ediff-from-cvs-buffer(pos)"Run Ediff-merge on appropriate revisions of the selected file.First run after `M-x cvs-update'. Then place the cursor on a line describing afile and then run `run-ediff-from-cvs-buffer'."(interactive"d")(ediff-load-version-control)(let((tin(tin-locatecvs-cookie-handlepos)))(iftin(cvs-run-ediff-on-file-descriptortin)(error"There is no file to merge"))));;; Apply patch;;;###autoload(defunediff-patch-file()"Run Ediff by patching SOURCE-FILENAME.";; This now returns the control buffer(interactive)(let(source-dirsource-filepatch-buf)(require'ediff-ptch)(setqpatch-buf(ediff-get-patch-buffer))(setqsource-dir(cond(ediff-use-last-dirediff-last-dir-patch)((and(notediff-patch-default-directory)(buffer-file-namepatch-buf))(file-name-directory(expand-file-name(buffer-file-namepatch-buf))))(tdefault-directory)))(setqsource-file;; the default is the directory, not the visited file name(ediff-read-file-name"Which file to patch? "source-dir(ediff-get-default-file-name)))(ediff-dispatch-file-patching-jobpatch-bufsource-file)));;;###autoload(defunediff-patch-buffer()"Run Ediff by patching BUFFER-NAME."(interactive)(let(patch-buf)(require'ediff-ptch)(setqpatch-buf(ediff-get-patch-buffer))(ediff-patch-buffer-internalpatch-buf(read-buffer"Which buffer to patch? "(cond((eqpatch-buf(current-buffer))(ediff-other-buffer(current-buffer)))(t(current-buffer)))'must-match))));;;###autoload(defalias'epatch'ediff-patch-file);;;###autoload(defalias'epatch-buffer'ediff-patch-buffer);;; Versions Control functions ;;;###autoload(defunediff-revision(&optionalfilestartup-hooks)"Run Ediff by comparing versions of a file.The file is an optional FILE argument or the file visited by the currentbuffer. Use `vc.el' or `rcs.el' depending on `ediff-version-control-package'.";; if buffer is non-nil, use that buffer instead of the current buffer(interactive"P")(if(stringpfile)(find-filefile))(let(rev1rev2)(setqrev1(read-string(format"Version 1 to compare (default: %s's latest version): "(if(stringpfile)(file-name-nondirectoryfile)"current buffer")))rev2(read-string(format"Version 2 to compare (default: %s): "(if(stringpfile)(file-name-nondirectoryfile)"current buffer"))))(ediff-load-version-control)(funcall(intern(format"ediff-%S-internal"ediff-version-control-package))rev1rev2startup-hooks)));;;###autoload(defalias'erevision'ediff-revision);; Test if version control package is loaded and load if not;; Is SILENT is non-nil, don't report error if package is not found.(defunediff-load-version-control(&optionalsilent)(require'ediff-vers)(or(featurepediff-version-control-package)(if(locate-library(symbol-nameediff-version-control-package))(progn(message""); kill the message from `locate-library'(requireediff-version-control-package))(orsilent(error"Version control package %S.el not found. Use vc.el instead"ediff-version-control-package)))));;;###autoload(defunediff-version()"Return string describing the version of Ediff.When called interactively, displays the version."(interactive)(if(interactive-p)(message(ediff-version))(format"Ediff %s of %s"ediff-versionediff-date)));;;###autoload(defunediff-documentation(&optionalnode)"Display Ediff's manual.With optional NODE, goes to that node."(interactive)(let((ctl-windowediff-control-window)(ctl-bufediff-control-buffer))(ediff-skip-unsuitable-frames)(condition-casenil(progn(pop-to-buffer(get-buffer-create"*info*"))(info(ifediff-xemacs-p"ediff.info""ediff"))(ifnode(Info-goto-nodenode)(message"Type `i' to search for a specific topic"))(raise-frame(selected-frame)))(error(beep1)(with-output-to-temp-bufferediff-msg-buffer(princediff-BAD-INFO))(if(window-live-pctl-window)(progn(select-windowctl-window)(set-window-bufferctl-windowctl-buf)))))));;; Local Variables:;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun);;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1);;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body));;; End:(require'ediff-util);;; ediff.el ends here