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

As another example, let's say you have documentation for your C program in the file program.txt, and you want to visit it. You press C-x C-f and type prog at the prompt, followed by Tab. Emacs completes out to program.. At this point, you can type t and press Tab again; Emacs completes the entire program.txt. In other words, you can use completion repeatedly when specifying a name.

Finally, let's say you also have a file in your directory called simply program, which is the result of compiling your C file, but you still want to visit the documentation file. You type prog and press Tab; Emacs completes out to program. (including the period). At this point, Tab and Space do different things. If you press Tab again, Emacs responds with the message [Complete, but not unique] in the minibuffer, but if you press Space, Emacs assumes you aren't interested in the file program and attempts to complete further. Because you have the files program.c and program.txt, Emacs only completes out to program., and you have to type t and press Tab again.

Completion works the same way with buffer names, for example, when you type C-x b to switch to another buffer in the current window. It also works with command names when you type M-x—but with one added feature. Notice that when you specify a file or buffer name, it is possible that the file or buffer you want doesn't yet exist (for example, when you want to create a new file). In this case, of course, you must type in the entire file or buffer name and press Enter. But when you type M-x for a command, there is no possibility of the command not existing. Therefore, Emacs automatically attempts to do completion on command names when you press Enter.

For example, if you want to put a buffer for a text file in auto-fill mode (see Chapter 2), you can type M-x auto-f and press Enter instead of typing the entire M-x auto-fill-mode. If you type in a nonunique (ambiguous) prefix of a command name—for example, if you type M-x aut—and press Enter, then Enter acts just like Tab; in this case, it completes out to auto. If you press Enter again, Emacs responds with a *Completions* window listing the choices. To get auto-fill-mode, you have to type f and press Enter again.

Completion on command names with Enter is very convenient. After you have used Emacs for a while, you will become familiar with the shortest unambiguous prefixes for commands you use often, and you can save a considerable amount of typing by using these prefixes instead of the full names.[99]

Emacs can also do completion on the names of Emacs variables. In Chapter 2, and elsewhere, we saw how you can use M-x set-variable to change the values of Emacs variables. The Enter feature just described works on variables as well as commands; therefore, you can use completion, including Enter, when doing M-x set-variable. Actually, commands and variables are both special kinds of Emacs Lisp symbols, and Emacs can do completion with Enter on all kinds of Lisp symbols. Completion on Lisp symbols comes in handy when you are using some of the help commands described earlier in this chapter.

14.5.1 Customizing Completion

If you have read Chapter 10 and are comfortable with setting Emacs variables, you should know that a few variables can customize the way Emacs does completion. The variable completion-auto-help determines whether a *Completions* window automatically appears when you try to use Space or Tab on an ambiguous prefix. Its default is t, meaning that such windows automatically appear. If you set it to nil, instead of a *Completions* window appearing, Emacs just displays the message [Next char not unique] for a couple of seconds in the minibuffer.

If you are a programmer or if you use text formatters like LATEX , you will create files that are not meant for humans to read, such as object files created by compilers and print files created by text formatters. Ideally, you wouldn't want Emacs to bother with these files when you are doing completion; for example, if you have the files program.c and program.o (object-code output from the compiler), you want Emacs to recognize only the former. Emacs does have a feature that deals with this; indeed, you may already have noticed that in this kind of situation, if you type program and press Tab, Emacs ignores program.o and completes out to program.c. The variable completion-ignored-extensions controls this; it is a list of filename suffixes that Emacs ignores during filename completion. By default, the list includes tilde (~) for Emacs backup files, .o for programmers, various suffixes for users, .elc (byte-compiled Emacs Lisp) for Emacs customizers, and others. (Of course, if you really want to look at these files, you can type their names manually.)

You can add your own "ignored" suffix to the list by putting a line of this form in your .emacs file:

(setq completion-ignored-extensions

      (cons "suffix" completion-ignored-extensions))

For example, let's say you are doing text processing with a printer that prints PostScript, and your text processor produces print files with the suffix .ps. If you don't want to look at these files, put the following line in your .emacs file:

(setq completion-ignored-extensions

      (cons ".ps" completion-ignored-extensions))

Finally, you can tell Emacs to ignore case distinctions when doing completion by setting the variable completion-ignore-case to t (or any value other than nil). Its default value is nil, meaning that Emacs respects case distinctions.

Appendix A. Emacs Variables

This appendix lists some Emacs variables. We chose them for their general usefulness and for their applicability to subjects in this book.

The variables below are grouped by category, and their default values are shown (where practical to do so). For more details on specific variables, see the chapters referred to at the beginning of each table. For information on variables used in programming language modes, see Chapter 9.

Table A-1. Backups, auto-save, and versioning

Table A-1. Backups, auto-save, and versioning (Chapter 2, Chapter 12)

Variable Default Description
make-backup-files t If t, create a backup version of the current file before saving it for the first time.
backup-by-copying nil If t, create backup files by copying rather than renaming the file being saved to a backup version. The default is renaming, which is more efficient. Copying can yield different results, especially when you're editing files owned by another user, and in operating systems that allow "hard links" to files (alternate names that are associated with the physical file). There are a raft of variables that can tweak this behavior based on context; check the online help for make-backup-files for the details.
version-control nil If t, create numbered versions of files as backups (with names of the form filename~N~). If nil, only do this for files that have numbered versions already. If 'never (note the leading single quote), never make numbered versions.
kept-new-versions 2 Number of latest versions of a file to keep when a new numbered backup is made.
kept-old-versions 2 Number of oldest versions of a file to keep when a new numbered backup is made.
delete-old-versions nil If t, delete excess versions (not those kept according to the above variables) without asking for confirmation first. If nil, ask for confirmation first. If any other value, don't delete excess versions.
auto-save-default t If t, do auto-saving of every file visited.
auto-save-visited-file-name nil If t, auto-save to the file being visited rather than to a special auto-save file.
auto-save-interval 300 Number of keystrokes between auto-saving; if 0, turn off auto-saving.
auto-save-timeout 30 Length of time of inactivity after which Emacs auto-saves. If nil or 0, turn off this feature.
delete-auto-save-files t Non-nil means delete auto-save files whenever the "real" file is saved.
buffer-offer-save nil Non-nil means offer to save the current buffer when exiting Emacs, even if the buffer is not a file.
vc-handled-backends (RCS CVS SVN SCCS Arch MCVS) Version control systems used with the vc package. The order in which they appear in this list controls the order in which they will be attempted when working with a new file.
vc-display-status t If non-nil, display the version number and the locked state in the mode line.
vc-keep-workfiles t If non-nil, do not delete work files after you register changes with the version control system.
vc-mistrust-permissions nil If non-nil, do not assume that a file's owner ID and permission flags reflect version control system's idea of file's ownership and permission; get this information directly from version control system.
vc-suppress-confirm nil If non-nil, do not ask for confirmation before performing version control actions.
vc-initial-comment nil If non-nil, prompt for an initial comment when registering a file with version control system.
vc-make-backup-files nil If non-nil, make standard Emacs backups of files registered with version control.
diff-switches -c Command-line switches used to control the format of change reports by VC as well as diff.el.
вернуться

99

For example, if you make changes to your .emacs file regularly, you will appreciate that M-x eval-c is an acceptable prefix for M-x eval-current-buffer.