Chapter 14. The Help System

Emacs has the most comprehensive help facility of any text editor—and one of the best such facilities of any program at all. In fact, the Emacs help facilities probably cut down the time it took for us to write this book by an order of magnitude, and they can help you immeasurably in your ongoing quest to learn more about Emacs.

In this chapter, we describe Emacs help in the following areas:

• The tutorial.

• The help key (C-h) and Help menu, which allow you to get help on a wide variety of topics.

• The help facilities of complex commands like query-replace and dired.

• Navigating Emacs manuals and using the info documentation reader.

Completion, in which Emacs helps you finish typing names of functions, variables, filenames, and more. Completion not only saves you time and helps you complete names of functions you know about but can help you discover new commands and variables.

14.1 Using the Tutorial

If you are just starting out with Emacs, check out the tutorial by typing C-h t (for help-with-tutorial), which deletes all extra windows (leaving just one) and starts up a learn-by-doing tutorial. Actually, it displays a file called TUTORIAL in the window. The tutorial is currently available in 21 languages. The tutorial provides an introduction to the following Emacs features:

• Basic cursor motion

• Delete and yank

• Visiting and saving files

• Buffers

• Text and auto-fill modes

• Incremental search

• Basic help commands

You might want to use the tutorial along with Chapter 1 and Chapter 2. The tutorial is helpful, but of necessity it covers only the most basic information.

14.2 Help Commands

Emacs has many help commands, which are available as standard Emacs commands or as options to the C-h help key. They can be used to find information about commands, keystrokes, variables, modes, and various things about Emacs in general. The most basic help command is C-h C-h (help-for-help). C-h ? also invokes help-for-help. This command causes Emacs to open a

*Help*
buffer in a window with descriptions of all the help commands. You can type any one of these help keys, or, if you press Space, the
*Help*
window scrolls down as if you pressed C-v. Any other key aborts the whole process. If you scroll to the bottom of the help documentation, you can type a help key or any other key to abort.

The keys listed in the

*Help*
are those that, when appended to your help key, run Emacs help commands at any time. Help commands fall into two general categories: those that provide answers to specific questions and those that give general information about Emacs.

You will find the help commands in the former category to be invaluable after you have become comfortable with Emacs. Because it is so large and functionally rich, there will be times when you need to look up a detail such as a keystroke or command name or when you need to do something with Emacs that you don't know exactly how to do. As we've repeated again and again throughout this book, Emacs probably does what you want; you just need to figure out how. The help commands let you find these things out immediately, without leaving Emacs and without being a slave to your reference manual (or even this book).

14.2.1 Detail Information

Let's start with the help commands that are useful when you need to look up a specific detail. You'll probably use the commands listed in Table 14-1 most often.


Table 14-1. Detail information help commands

Keystrokes Command name Question answered
C-h c describe-key-briefly What command does this keystroke sequence run?
C-h k HelpDescribeDescribe Key describe-key What command does this keystroke sequence run, and what does it do?
C-h f HelpDescribeDescribe Function describe-function What does this function do?
C-h v HelpDescribeDescribe Variable describe-variable What does this variable mean, and what is its value?
C-h m HelpDescribeDescribe Buffer Modes describe-mode Tell me about the modes the current buffer is in.
C-h b HelpDescribeList Key Bindings describe-bindings What are all the key bindings for this buffer?
C-h w where-is What is the key binding for this command?
C-h s describe-syntax What is the syntax table for this buffer?
C-h l view-lossage What are the last 100 characters I typed?
C-h e view-echo-area-messages What messages have appeared in the minibuffer during this session?

What if you press the wrong key, and something happens to your buffer—but you're not sure what? Usually, the safest thing to do is to press C-_ or C-x u (undo). But sometimes this command won't help, for example, a runaway replace-string. If you remember what you typed, you can use C-h c (for describe-key-briefly) to see what command was run; just retype the offending keystroke(s) at the prompt, and Emacs responds with the name of the command bound to the key(s) in the minibuffer. If the command name alone doesn't help, C-h k (for describe-key) pops up a

*Help*
window with a description of the command as well as its name and key binding. (C-h k and C-h c also help you find out what command a toolbar icon or menu item runs.)

However, if you don't know what keys you pressed, you can type C-h l (for view-lossage). This pops up a

*Help*
window showing the last 100 keystrokes you typed; the offending ones are likely near the end, and you can use C-h c or C-h k with those keystrokes.

Now suppose you want information on a command that isn't bound to keystrokes. Type C-h f (for describe-function) and enter the name of the command at the prompt; Emacs responds with a

*Help*
window containing the documentation for that command. If you remember the name of a command but forget its binding, type C-h w (for where-is). This is the "opposite" of C-h c; it shows the key binding for a given command in the minibuffer, or the message
command-name is not on any keys
if the command has no binding.

You may forget a detail that involves the value of a variable. For example, will Emacs respect or ignore case during a search (the variable case-fold-search)? How often are my buffers being auto-saved (the variable auto-save-interval)? If you type C-h v (for describe-variable) followed by the name of the variable, Emacs puts its value as well as its documentation in a

*Help*
window. C-h f, C-h w, and C-h v all allow you to use completion when typing command or variable names. C-h f and C-h v are also especially useful to Emacs Lisp programmers; note that C-h f gives you information on all functions, not just those bound to keystrokes as commands.

Another common help situation arises when you use a special mode, such as shell mode or a mode for a programming language or text processor, and you forget a command specific to that mode or some other characteristic such as indentation conventions. If you type C-h m (for describe-mode) in a buffer running the mode, Emacs pops up a

*Help*
window showing the mode's documentation. Documentation for a mode usually includes all of its local key bindings (for example, all the commands special to the mode and their associated keystrokes), customization variables, and other interesting characteristics.

What if you want to find out all the keyboard commands available in a given mode? C-h b (for describe-bindings) gives you a

*Help*
window showing all key bindings active in the current buffer, including local (buffer-specific) as well as global ones. It also lists all bindings for mouse actions, menu options, and function keys.

C-h b produces quite a lot of output. If you want to limit this output to only those key bindings with a particular prefix, type that prefix followed by C-h. For example, typing C-x C-h produces a

*Help*
window listing all key bindings that begin with C-x.

C-h s (for describe-syntax) is a more specialized command, designed for Lisp programmers. It produces a

*Help*
window with a description of the syntax table (see Chapter 9) active in the current buffer.

14.2.2 Apropos Commands

Another type of help command applies when you want Emacs to do something, but you're not sure exactly what command to use or what variable to set. These are apropos commands, which resemble a rudimentary information retrieval system of the type found at many libraries. The apropos command has several forms, shown in Table 14-2.


Table 14-2. Apropos commands

Keystrokes Command name Question answered
C-h a HelpSearch DocumentationFind Commands by Name apropos-command What commands include this word?
(none) HelpSearch DocumentationFind Options by Name apropos-variable What variables include this regular expression?
(none) HelpSearch DocumentationFind Options by Value apropos-value What variables are set to this regular expression?
(none) HelpSearch DocumentationSearch Documentation Strings apropos-documentation Where is this regular expression mentioned in the documentation?
(none) HelpSearch DocumentationFind Any Object by Name apropos What functions and variables involve this regular expression?

All apropos commands prompt for regular expressions (an ordinary text string will work, but you can create more powerful searches using regular expressions; see Chapter 11 for details). When you type C-h a followed by a regular expression, Emacs finds all the commands that match it; it displays their key bindings (if any) and the first lines of their documentation in an

*Apropos*
window that is in Apropos mode. This mode displays hyperlinked help. If you click on a bolded item using your middle mouse button or move the cursor there and press Enter, Emacs displays more information.

As always, if you are leery of using regular expressions, use regular search strings as long as you stick to nonspecial characters. For example, if you want to know what replace commands Emacs supports, press C-h a and then type replace; Emacs displays a list of information on the following commands:

dired-do-query-replace

ebrowse-tags-query-replace

ethio-replace-space

map-query-replace-regexp

query-replace

query-replace-regexp

query-replace-regexp-eval

replace-buffer-in-windows

replace-rectangle

replace-regexp

replace-string

tags-query-replace

If you have ever used an information retrieval system, you already know that some skill is needed to use such a system effectively. You need to choose your concepts (search strings) carefully, so that they aren't too general (too much output to wade through) or too specific (too little output, making it less likely that you get the information you want). This problem is compounded when you use the apropos command, which is the same as apropos-command except that it reports on all functions (including internal Emacs functions) and variables as well as commands.

If you type in a search string that is too general, Emacs produces an enormous buffer of help information. For example, invoking apropos-command with the argument "buffer" results in output listing well over two hundred Emacs commands. In general, you may have to invoke the apropos commands a few times to get the information you want (in terms of size as well as relevance).

The apropos command itself is usually overkill, unless you are a Lisp programmer who needs information on noncommand functions (see Chapter 11 for details on this use of apropos). Use a more specific command when possible. For example, to get information on variables, use apropos-variable. To find out about variables related to auto-saving, type M-x apropos-variable Enter auto-save Enter. Emacs responds with information about the variables auto-save-default, auto-save-file-format, auto-save-file-name-transforms, auto-save-interval, auto-save-list-file-prefix, auto-save-timeout, auto-save-visited-file-name, and delete-auto-save-files. To find the value and full description of one of these variables, move to the

*Apropos*
window and either click with the middle mouse button or move to the desired variable and press Enter.

14.3 Help with Complex Emacs Commands

Many of the more complicated Emacs commands include their own sets of help keystrokes. These commands often have their own help functionality, but help is invoked with ? rather than the standard help key. Here is a summary of some popular complex commands and what ? does within each of them:

dired (C-x d)

You see a list of the most frequently used commands in the minibuffer. This list is far from complete. Type C-h m (for describe-mode) for more comprehensive documentation and C-h b (for describe-bindings) for all the key bindings available to you.


query-replace (M-%)

You see a

*Help*
window listing the available commands. Typing C-h does the same thing. This also works with query-replace-regexp. save-some-buffers (C-x s)

Behavior is similar to query-replace just described.


list-buffers (C-x C-b)

You see a

*Help*
window giving information on buffer menu mode. This command has the same effect as typing C-h m (for describe-mode).


Completion

When you are responding to a minibuffer prompt with the name of something on which Emacs can do completion, typing ? at any time gives you a

*Completions*
window with the choices available at that point. Completion is explained in detail later in this chapter.

14.4 Navigating Emacs Documentation

Once upon a time, to get access to Emacs documentation, you ordered manuals from FSF. You can still do so if you like printed documentation (as we do) and would like to support the FSF, but most of the documentation you will ever want or need is at your fingertips right in Emacs.

14.4.1 Using Info to Read Manuals

Most GNU documentation (including Emacs documentation) is in texinfo format and designed to be read in the Info documentation reader. Typing C-h i (for info) puts you at the top-level of the Info tree. You'll see that Emacs is just one choice of many. In Info, documentation is organized as trees of information called nodes. If you want information on a topic, you can select its tree; the nodes of the tree contain information on subtopics, subsubtopics, etc., organized hierarchically.

When you type C-h i, you see a read-only buffer containing the directory node of the Info system in a window in Info mode. If you press h while in Info, you get a tutorial on Info analogous to the one described earlier for basic Emacs commands.

You're probably better off typing C-h r, which sends you directly to the Emacs manual.


Type: C-h r

Emacs displays the table of contents for the Emacs manual.


Note that the icons are almost completely different in Info mode. Later in this section, Table 14-3 lists them, along with the keystrokes needed for navigating in this mode.

Info is relatively simple, yet complex enough to have its own tutorial. Typing h sends you through a tutorial to acquaint you with the main commands.

To select a menu option (you see a * next to these), move to that option. Obviously, moving with the mouse is one method; you then select the option using the middle mouse button. Alternatively, move to the option by pressing Tab, and then press Enter.


Move to Minibuffer (you'll need to scroll down), and then press Enter.

The Minibuffer topic appears.


If you want to read through the whole topic, you can press Space to scroll down. Space is helpful for continuous reading because after you complete a topic, it moves you to the next node at this level. If you read all of this topic, you'll learn more about the minibuffer than you ever thought possible.

If you press u twice (to move up a level), you'll move back to the Emacs table of contents. The up arrow icon on the toolbar does the same thing. To accomplish this with a single keystroke, type t (for Info-top-node) or click on the house toolbar icon. That command takes you to the top level in one move, no matter how far down the Info tree you've traveled.

To search for a particular topic, type i or click on the toolbar icon that shows a finger pointing at a piece of paper.


Type: i

Emacs prompts for an index topic.


Type: macro Enter

Emacs brings up the first topic related to macros.


Type a comma: ,

Emacs moves to the next macro-related topic in the index.


As you step through index entries in this way, it's helpful to look at the top of the screen to see what topic you're in. You might want to move up a node (or to the previous or next node) to get a better view of the topic at hand rather than navigating to the next index entry by typing another comma.

Navigating through Info can take some practice. For example, one might think that the command p (for Info-prev)[97] would behave rather like a web browser back button (especially given that the toolbar icon for this command looks like one). Previous in this case means relative to the Info documentation tree, not to your session (though it may appear that way sometimes). It means that you want to move to the previous item at this level. To move back to the previous screen in your session, use l (for Info-last), shown on the toolbar with a curved arrow icon (like the icon for undo in other modes). This command behaves like a web browser back button.

The commands C-h F (for Info-goto-emacs-command-node) and C-h K (for Info-goto-emacs-key-command-node) let you use Info in a more focused way. They are essentially the Info equivalents of C-h f (for describe-function) and C-h k (for describe-key), respectively: they start up the Info system and go directly to the documentation for the command (for C-h F) or the keystroke(s) (for C-h K) you give as an argument.


Table 14-3. Info commands

Keystrokes Toolbar icon Command name Action

Tab


Info-next-reference

Move to the next menu item or cross-reference.


Space


Info-scroll-up

Scroll the screen; move to the next topic at this level when finished.


Del or PgUp


Info-scroll-down

Scroll backward.


p

Info-prev

Move to the previous topic at this level (not like a browser back button). If there is no previous topic, move up a level.


u

Info-up

Move up a level.


n

Info-next

Move to the next topic at this level.


i

Info-index

Search the index for a topic.


,


Info-index-next

Go to the next topic in the index.


m


Info-menu

Select a menu item through the keyboard.


q

Info-exit

Quit info.


s

Info-search

Search for a regular expression.


g

Info-goto-node

Go to a specified node.


t

Info-top-node

Go to the top node.


l

Info-last

Go to the last node you visited (like a browser back button).


h


Info-help

Start the info tutorial.

14.4.2 FAQ, News, and Antinews

To display the Frequently Asked Questions (FAQ) file, type C-h f. This file is in Info format.

Perhaps the most important of the remaining Emacs help commands for hard-core users and customizers is C-h n (for view-emacs-news), which visits the NEWS file that comes with Emacs. This file contains a history of changes made to Emacs since the last major version; for example, all changes in Version 20.1 and following up to the latest minor version (which in our case is Version 21.3.5, though the file says 21.4). This can be a very long file if there have been several minor releases since the last major version—in our case, the file is 12,886 lines long. If you want to look through it for changes to a specific aspect of Emacs, use an appropriate search command. But if you just want to skim it, note that this file was intended for use with outline mode: topics are introduced on lines beginning with *, and subtopics are introduced on lines beginning with **. Use outline mode commands to skim the file; see Chapter 7 for information. The outline mode command hide-body displays the main topics and hides the text; show-all redisplays all the text as well.

An entertaining approach to learning about the latest release is Antinews. This file takes the viewpoint that Emacs has been downgraded, in our case from 21.4 to 21.3. It takes you through all the features that have been ripped from Emacs 21.4 to create Emacs 21.3. Antinews is a menu item on the first page of the Emacs manual you reach via C-h r.

Table 14-4 summarizes commands relating to reading documentation, getting general information about Emacs, and language encoding issues.


Table 14-4. Documentation, general information, and encoding options

Keystrokes Command name Action
C-h t HelpEmacs Tutorial help-with-tutorial Run the Emacs tutorial.
C-h i info Start the Info documentation reader. If prefaced with C-u, reads an Info file of your choice.
C-h r HelpRead the Emacs Manual info-emacs-manual Opens the Emacs manual.
C-h F HelpMore ManualsFind Command in Manual Info-goto-emacs-command-node Start Info documentation reader at the node that discusses this command.
C-h K HelpMore ManualsFind Key in Manual Info-goto-emacs-key-command-node Start Info documentation reader at the node that discusses this key sequence.
C-h n or C-h C-n HelpEmacs News view-emacs-news View news about recent changes in Emacs.
C-h C-f HelpEmacs FAQ view-emacs-FAQ View a file of frequently asked questions and their answers about Emacs.
(none) HelpSearch DocumentationEmacs Terminology search-emacs-glossary Open a glossary of Emacs terms.
(none) HelpSearch DocumentationLook Up Subject in User Manual emacs-index-search Search the index of the Emacs user manual.
(none) HelpSearch DocumentationLook Up Subject in ELisp Manual elisp-index-search Search the index of the Emacs Lisp manual.
C-h Enter HelpMore ManualsOrdering Manuals view-order-manuals Displays information about ordering print manuals.
C-h p finder-by-keyword Invoke a menu that lets you get information about Emacs Lisp packages available on your system.
C-h C-c HelpCopying Conditions describe-copying View the General Public License (GPL).
C-h C-d HelpGetting New Versions describe-distribution View information on ordering Emacs from FSF.
C-h C-p describe-project View information on the GNU project. (See the Preface.)
C-h C-w Help(Non)Warranty describe-no-warranty View the (non-)warranty for Emacs. Emacs doesn't provide a warranty, hence the name here.
C-h C-t view-todo If you're a programmer looking to contribute to the Emacs code base, use this command to view a list of what needs to be done.
C-h C-e HelpEmacs Known Problems view-emacs-problems Displays the PROBLEMS file, which includes a list of known problems.
C-h h view-hello-file View the HELLO file, which displays the word "hello" in numerous languages.
C-h L HelpDescribeDescribe Language Environment describe-language-environment Prompts for either default (current environment) or lists possible completions. Menu option shows these choices.
C-h I or C-h C-\ HelpDescribeDescribe Input Method describe-input-method Shows current input method (the default) or, with completion, a list of possible input methods.
C-h C HelpDescribeDescribe Coding System describe-coding-system Shows current coding system (the default) or, with completion, lists all available coding systems.

14.5 Completion

We saw an example of Emacs's completion facility in Chapter 1. Completion is more than just a feature: it is a general principle in the design of Emacs. It can be articulated as follows:

If you have to type in the name of something, and that name is one of a finite number of possibilities, Emacs should figure out what you mean after the smallest possible number of keystrokes.

In other words, you can type in the shortest unambiguous prefix and tell Emacs to figure out the rest of the name. By "shortest unambiguous prefix," we mean "enough of the name, starting from the beginning, to distinguish it from the other possibilities." Several important things in Emacs have names that are chosen from a finite number of possibilities, including the following:

• Commands

• Files in a given directory

• Buffers

• Emacs variables

Most of the time, completion is available when you are prompted for a name of something in the minibuffer. While you are typing in the name, you can use three keys to tell Emacs to help complete it for you: Tab, Space, and question mark (?). Their functions are shown in Table 14-5.


Table 14-5. Completion keys

Keystroke Action
Tab Completes the name as far as possible.
Space Completes the name out to the next punctuation character.
? Lists the choices at this point in a
*Completions*
window.

You will probably find Tab to be the most useful.

As a running example, assume you have typed C-x C-f to visit a file, and the file you want to visit is a C program called program.c. Let's say you type pro and press Tab; Emacs responds by completing the name to the full program.c. If you press Space, Emacs completes only as far as program. After Emacs completes the name, you can press Enter to visit the file.

How much of the name do you need to type in before you can use completion? That depends on the other possible choices in the given situation. If program.c were the only file in your directory, you could just type p and press Tab.[98] If there were other files in your directory and none of them has a name beginning with p, you could do the same thing. But if you had a file called problem.c, you would have to type prog before you pressed Tab; in this case, prog is the shortest unambiguous prefix. If you just type in pro and press Tab, Emacs responds with a

*Completions*
window containing a list of the completion choices, in this case program.c and problem.c, and returns your cursor to the minibuffer so that you can finish typing the filename. The same thing happens if you typed a question mark instead of Tab. At this point, you can type g and press Tab again; Emacs completes the name to program.c.

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.

Загрузка...