Now you know the basic commands for starting and stopping Emacs and for working with files. Chapter 2builds on these commands to give you the skills you need for editing with Emacs. Table 1-4summarizes the commands we covered in this chapter.
Table 1-4. File handling commands
Keystrokes |
Command name |
Action |
C-x C-f File → Open 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. |
1.11.1 Problems You May Encounter
• Emacs doesn't do what this book says or look like our screenshots. Make sure that you have GNU Emacs 21.3.5 or later running by typing M-x version Enteror selecting Help → About Emacs. Read the section "Making Emacs Work the Way You Want" in Chapter 2. You may need to install a graphical version of Emacs if you are running in a terminal window; see Chapter 13for details.
• The toolbar icons are completely different. The icons changed between Emacs 21.3.1 and Emacs 21.3.5. The older icons do the same thing; the newer ones are substantially better looking and more intuitive. Upgrade Emacs using instructions in Chapter 13.
• You can't access menus using the mouse. Use the text-based menus instead by pressing F10or M-`. Better yet, install a graphical version of Emacs using the instructions in Chapter 13.
• PgUpdoesn't work properly when using text-based menus. PgUpis probably bound to some application-specific function, such as scrolling in the Mac OS X Terminal application. Press Shift-PgUp, F10, or M-`to access the menus.
• You can't see a mode line or minibuffer. Your Emacs window is bigger than your display. See Chapter 10for information on how to get Emacs to start with a reasonable window size. As a temporary workaround, resize the window. (On some Windows systems, maximizing the window ironically makes it smaller, solving the problem.)
Now that you know how to enter and exit Emacs as well as the basics of working with files, it's time to learn how to move around in and edit files. Emacs offers lots of ways to move around in files. At first, you might find it confusing that there are so many ways to do the same thing. Be patient—as you learn, the confusion will lessen, and you'll begin to appreciate the variety of Emacs commands. The more ways you learn, the fewer keystrokes you'll need to get to the part of the file you want to edit.
If you want to practice commands while you're reading—which will help you learn faster—start by typing a page or two from anything you happen to have handy; the newspaper is fine. That will give you some text to work with as you learn the editing skills described in this chapter. Don't worry if you make mistakes; just keep on typing. You can correct any mistakes after you learn the basic editing skills outlined here. Learning any editor is primarily a matter of forming certain finger habits rather than memorizing what the book says. You will learn the right finger habits only if you start typing.
When you are typing and you get to the right side of the display, you have two options. You can press Enterto go to the next line, or you can keep typing. If you type a long line and don't press Enter, Emacs waits until you reach the end of the display. Then it puts a curved arrow at the end of the line and one at the beginning of the next line as a visual indication that the next line is a continuation of the previous line (see Figure 2-1). If Emacs is run in a nongraphical environment, a backslash (\) is used instead.
Figure 2-1. Graphical versions of Emacs use curved arrows to indicate that a line is continued; terminal versions use backslashes
Refill mode is a minor mode that keeps paragraphs neat as you edit them. It is not on by default. Look at the mode line. If the word Refill
appears, you are in refill mode already. If not, you can turn it on for this buffer only by typing M-x refill-mode Enter. If you decide that you don't like refill mode, type M-x refill-mode Enteragain. This command is like a light switch: it toggles refill mode on and off.
You may decide that you want to enter refill mode automatically whenever you edit. We'll describe how to do so at the end of this chapter.
In some contexts, refill mode can be annoying, and it is still a work in progress according to the Emacs manual. You may prefer auto-fill mode. You enter it in the same way; type M-x auto-fill-mode Enter. The word Fill
appears on the mode line.
When you type paragraphs, auto-fill mode formats them. When you edit them, however, auto-fill mode does not automatically reformat them. You do that yourself using the fill-paragraphcommand, M-q.
If you turn on refill mode and then decide to use auto-fill mode, you still have to turn refill mode off explicitly by typing M-x refill-mode Enter. Otherwise, both modes appear on the mode line, and refill mode continues its merry automatic reformatting of paragraphs, ignoring the fact that auto-fill mode has been enabled.
Watch out for one important pitfall when reformatting paragraphs. In text mode, a paragraph is any text that is indented or has a blank line before and after it. If you have a file with no blank lines, Emacs thinks it is all one long paragraph. Typing M-qtakes all the text, ignoring line breaks, and makes it one long paragraph. This command is a particular problem if you have a data file, a program, or if you just prefer to write files with no blank lines. Luckily, pressing C-_or C-x u(both for undo) magically puts things back the way they were. If you regularly create files with no blank lines, here are some suggestions:
• Instead of writing in text mode, use paragraph indent text mode. In this mode, a line that starts with any blank space is a new paragraph. Type M-x paragraph-indent-text-modeto start this mode; you'll see Parindent
on the mode line. See Chapter 6for more details.
Читать дальше