Выбрать главу

Type: novel Enter

Emacs creates the directory and displays it on the screen (Windows).

Now let's move the ch files we marked into the new directory. We'll use the rename command, R. This command, like the Unix mv command, is used for renaming files and for moving them. Because we have marked more than one file with an asterisk, when we type R, Emacs assumes we mean to move the marked files.

Type: R

Emacs asks where you want to move the marked files to (Windows).

Type: novel Enter

Emacs moves the files (Windows).

Now you can see that the files have moved. Marking files by regular expression allows you to work with a select group of files quickly.

One of the more interesting things you can do with a group of files is perform a query-replace on all of them with a single command. On large projects, a last-minute change often forces arduous searching and replacing of certain text in each file. First, select the files you want to include in the query-replace, then press Q (for dired-do-query-replace). Put in the search string, then the replacement string (the strings can be plain text or a regular expression) and Emacs starts a query-replace that moves you through each file sequentially. Here's the only hitch: if you interrupt the query-replace with a recursive edit, you can't restart it without going back to the Dired buffer.

Another interesting command is searching across files for a given regular expression. To do this, mark the files, then press A. Emacs stops at the first match; press M-, to move to the next match.

5.2.7 Navigating Directories

Often when you are cleaning up directories, you're moving files between them, organizing subdirectories, and the like. This naturally involves a lot of moving among directories.

To move to the parent directory of the one you're in, press ^. To move to the next directory in the buffer, press >; pressing <, not surprisingly, moves you to the previous directory in the buffer.

Sometimes it's more convenient to edit a directory and its subdirectories in the same buffer. To insert a subdirectory in the current Dired buffer, move to it and press i. Emacs inserts the subdirectory at the end of the buffer. If you insert more subdirectories in this fashion, they will appear in alphabetical order at the end of the buffer.

As you can see, much of your file maintenance and cleanup can be done easily from within Dired. Table 5-2 summarizes Dired commands, some of which we haven't fully discussed. There's more to learn about Dired,[29] but now that you know the basics, you can experiment on your own.

Table 5-2. Dired commands

вернуться

29

And if all the Dired features aren't enough, there's Dired-x, an add-in module that includes other features such as omitting unimportant files from the listing, finding files mentioned in any buffer, and additional variables and means of marking files. For more details, see the Info text on this subject (type C-h i to get to the Info menu).

Keystrokes Command name Action
C-x d FileOpen Directory dired Start Dired.
A OperateSearch Files dired-do-search Do a regular expression search on marked files; stops at first match; M-, finds next match.
B OperateByte-compile dired-do-byte-compile Byte-compile file.
C OperateCopy to dired-do-copy Copy file.
d MarkFlag dired-flag-file-deletion Flag for deletion.
D OperateDelete dired-do-delete Query for immediate deletion.
e ImmediateFind This File dired-find-file Edit file.
f dired-advertised-find-file Find (so you can edit).
g ImmediateRefresh revert-buffer Reread the directory from disk.
G OperateChange Group dired-do-chgrp Change group permissions.
h describe-mode Display descriptive help text for Dired.
H OperateHardlink to ... dired-do-hardlink Create a hard link to this file; Emacs asks you to name the hard link (not all OSes support hard links).
i SubdirInsert This Subdir ... dired-maybe-insert-subdir Add a listing of this subdirectory to the current dired buffer; if it's already there, just move to it.
k dired-do-kill-lines Remove line from display (don't delete file).
L OperateLoad dired-do-load Load file.