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

The write-file command is useful for editing files that you do not have permission to change. Use the find-file command to get the file you want into a buffer, and then use write-file to create your own private version, with a different name or path. This maneuver allows you to copy the file to one that you own and can change. Of course, the original file is not affected.

1.9 Leaving Emacs

To quit Emacs, type C-x C-c or close it like you would any other application. If you have made changes to a buffer, Emacs asks you if you want to save them.[9] If you type y, Emacs writes the file, then exits. If you type n, Emacs asks you to confirm that you want to abandon the changes you made by typing yes or no in full. If you type no, your normal Emacs session continues just as if you never attempted to exit. If you type yes, you exit Emacs and the changes you made during this session do not become permanent. Leaving without saving changes can be useful if you make changes you didn't intend to make.

By the way, Emacs is picky about whether you type y or yes. Sometimes it wants one, sometimes the other. If it asks for a y, you can sometimes get away with typing yes but not vice versa. If it beeps and displays, Please answer yes or no, you didn't enter the whole word and it wants you to.

1.10 Getting Help

Emacs has extensive online help, which is discussed further in Chapter 14. You can enter help through the lifesaver icon on the toolbar or through the Help menu. Either method will show you a help menu, described later in this section. To enter help using the keyboard, press C-h. Pressing C-h ? gives you a list of options. Pressing C-h t starts a tutorial that is an excellent introduction to Emacs.

To get information about the meaning of a keystroke combination, press C-h k for describe-key. For example, if you type C-h k C-x i, Emacs displays a description of the insert-file command, which is bound to C-x i. Pressing C-h f (for describe-function) asks Emacs to describe a function (really just a command name, such as find-file). Essentially, C-h k and C-h f give you the same information; the difference is that with C-h k, you press a key whereas with C-h f, you type a command name.

Assume you want to find out about what C-x i does.

Type: C-h k

Asking for help about a keyboard command.

Type: C-x i

Emacs splits the screen to display help.

A few things to notice: the window is now split into two parts because you're looking at two separate buffers. Each buffer has its own mode line. The lower buffer is the *Help* buffer; it contains the information about the insert-file command. Emacs keeps the cursor in the dickens buffer because there's no good reason for you to edit the *Help* buffer.

You might also notice that in the text describing this command, Emacs calls the cursor point. This term is used throughout Emacs to refer to the cursor; you're bound to encounter it.

To make the *Help* buffer disappear, press C-x 1 (we cover this command in Chapter 4).

1.10.1 The Help Menu

You can also use the Help menu to access help commands quickly, and you can get there either through the menu or through the lifesaver on the toolbar. On this menu, you find options we've discussed here: Emacs Tutorial, Describe → Describe Key, and Describe → Describe Function. It includes a host of interesting options, including access to the Emacs frequently asked questions (FAQ) file, a new search feature, and even an Emacs psychiatrist (you might tell it something like "Emacs is driving me over the edge today"). There's an interface to Info, Emacs's online documentation. Simply choose Read the Emacs Manual to start Info.

In this section, we've given a very brief introduction to a few of the paths you can take in the help system. There are many more help facilities; they are described thoroughly in Chapter 14. The help features we've described here should be enough to get you started; if you want to learn more, jump ahead to Chapter 14.

1.11 Summary

Now you know the basic commands for starting and stopping Emacs and for working with files. Chapter 2 builds on these commands to give you the skills you need for editing with Emacs. Table 1-4 summarizes the commands we covered in this chapter.

Table 1-4. File handling commands

Keystrokes Command name Action
C-x C-f FileOpen File find-file Find file and read it in a new buffer.
C-x C-v find-alternate-file Read an alternate file, replacing the one read with C-x C-f.
C-x iFile → Insert File insert-file Insert file at cursor position.
C-x C-sFile → Save (current buffer) save-buffer Save file.
C-x C-wFile → Save Buffer As write-file Write buffer contents to file.
C-x C-cFile → Exit Emacs save-buffers-kill-emacs Exit Emacs.
C-h help-command Enter the online help system.
C-h fHelp → Describe Function describe-function Gives online help for a given command name.
C-h kHelp → Describe Key describe-key Gives online help for a given keystroke sequence.
C-h tHelp → Emacs Tutorial help-with-tutorial Start the Emacs tutorial.
C-h iHelp → Browse Manuals info-goto-emacs-command-node Start the Info documentation reader.
вернуться

9

One exception to this rule is the *scratch* buffer. It's a scratchpad and Emacs assumes you were doodling, not doing serious artwork, so to speak. If you do any serious work in the *scratch* buffer, you must save it explicitly.