Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 14: Finding Differences Between Files |  | Previous HourNext Hour
Sections in this Hour: |  |  |  |

## Using Ediff with Directories of Files

If you have been a good boy or girl and done what I've told you, you will have a directory with all your Lisp configuration. Furthermore if you use Emacs both at home and at work, you will have this directory located on two different machines. You have already learned that you can use Ediff to keep files synchronized, but because you have a whole directory of files to keep synchronized, you need bit extra to ease your work.

Emacs has four functions that let you work on directories of files: ediff-directories, ediff-directories3, ediff-merge-directories, and ediff-merge-directories3. The functions that end in 3 are functions that work with a directory of ancestors. All functions work by creating a buffer such as the one in Figure 14.6, from which you can start individual Ediff or ediff-merge sessions.

Figure 14.6
Ediff window that allows you to start several Ediff sessions on files from two directories.

When you invoke one of the functions listed earlier, Emacs asks you for a regular expression that the filename must match to get in the list.

Pressing the second mouse button or the Enter key over one of the sessions starts an Ediff or ediff-merge with the files listed for the given session. When you quit the given session, Emacs returns to this buffer. You can also return to it by pressing M, as listed in the help text in the top of the buffer.

If the directories contain many files, you might want to remove some of the sessions from the session group. This can be done with a regular expression as described earlier, but this method has one drawback: It is hard to develop a regular expression that excludes some files. For example, it would be hard to write a regular expression that excludes all files ending in .elc. An other solution is to press h ( h for hide) when point is located on top of a session that you do not want to see. This marks the given session for hiding. When you have selected some buffers for hiding, you can press x ( x for e xecute), which does the actual hiding.

If the session contains two subdirectories rather than two files, Emacs brings up a session group for the files of the two subdirectories.

By pressing = in this buffer you tell Emacs to flag all sessions that have files that are not different. This can help you when you are trying to merge two directories coming from different machines. Unfortunately the mark that Emacs put on these files cannot be used to hide the files with x. Fortunately, you have learned about macros in Hour 13, "Macros," so you are capable of developing a macro that can hide all files flagged as different. (See the exercise at the end of the hour.)

Note - If you select at startup a regular expression that lists only files ending in .el, for example, you will not get subdirectories listed. Therefore it is often easier--if you want all files or subdirectories of the given directory listed in the session group, and you want to hide the files that you do want to look at--to use a macro. This macro can search for these files, mark them for hiding, and finally hide them.

Only files located in both directories are shown in the session group buffer, so press D to see which files are not in both directories.

Caution - Hey, did you get that? This is important if you use Ediff to merge a set of files from one machine with a set of files on another machine, take the result with you to the first machine, and overwrite the original files. This way you have a new way of unintentionally deleting files!

Sessions that have been invoked are flagged with a minus sign in the first column.

Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 14: Finding Differences Between Files |  | Previous HourNext Hour
Sections in this Hour: |  |  |  |

© Copyright Macmillan USA. All rights reserved.