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

Table 2-10 summarizes the capitalization commands.

Table 2-10. Capitalization commands

Keystrokes Command name Action
M-c capitalize-word Capitalize first letter of word.
M-u upcase-word Uppercase word.
M-l downcase-word Lowercase word.
Meta - M-c negative-argument; capitalize-word Capitalize previous word.
Meta - M-u negative-argument; upcase-word Uppercase previous word.
Meta - M-l negative-argument; downcase-word Lowercase previous word.

2.5.3 Overwrite Mode

You may be used to typing over old text rather than having to delete it. There is a certain satisfaction in destroying some really bad text in this way. You can do this in Emacs, too, by entering a minor mode called overwrite mode. When you're in overwrite mode, any new text you type wipes out the text that's underneath. When you're not in overwrite mode (i.e., in normal Emacs), any new text you type is inserted at the cursor position and any subsequent text is pushed to the right. (Other software may refer to this as insert mode; because it is the way GNU Emacs normally behaves, it doesn't have a name here.)

To enter overwrite mode, press the Insert key.[15] Ovwrt should appear on the mode line. If this doesn't work (or if you don't have an Insert key), type M-x overwrite-mode Enter. You can turn off overwrite mode by typing M-x overwrite-mode Enter again. Using Emacs's command completion, simply type M-x ov and press Enter. This is enough of a unique string to tell Emacs you want to toggle overwrite mode. Completion, one of the best shortcuts in Emacs, is discussed further in Chapter 14.

2.6 Canceling Commands and Undoing Changes

Sometimes you start a command by accident or change your mind about it. Don't worry: with Emacs, you can quit in the middle or undo it.

2.6.1 Canceling Commands

When you want to cancel any command that's in progress, press C-g. The word Quit appears in the command area. This command is helpful when you are stuck in the minibuffer and didn't really mean to go there. Depending on what you were doing, you may have to press C-g a few times.

2.6.2 Undoing Changes

What happens if you make a mistake while you're editing? You can undo your changes by pressing C-_ or C-x u (for undo; conveniently, the toolbar also has an undo icon, a curved left arrow). By typing undo repeatedly, you can gradually work your way back to a point before your mistake.[16] Although the undo command is very powerful, saving your file frequently, if not compulsively, is nevertheless a good idea. We usually save a file whenever we stop typing—even if only for a few seconds. Train your fingers to press C-x C-s whenever you pause; it's a good habit to form.

If you're used to typing C-z to undo, you can easily change Emacs's behavior to match your habits. See "Making Emacs Work the Way You Want" at the end of this chapter for information on CUA mode.

What if you'd like to redo a command after you type undo? There is no formal redo command, but you can use undo in the following way. Just move the cursor in any direction, and type C-_ or C-x u again. Emacs redoes the last command you undid. You can repeat it to redo previous undos.

Although undo is an important command, it can be slow if you want to undo a large number of changes. Table 2-11 summarizes three methods for undoing changes and circumstances in which you might want to use them.

Table 2-11. Methods for undoing changes

If you: Use this command:
Don't like the recent changes you've made and want to undo them one by one C-_ or C-x u (undo)
Want to undo all changes made since you last saved the file M-x revert-buffer Enter
Want to go back to an earlier version of the file (the file as it was when you started this editing session) C-x C-f filename~ Enter C-x C-w filename Enter

We've already talked about undoing changes with undo; next we describe how to revert a buffer from a file and how to go back to an earlier version.

2.6.3 Reverting a Buffer from a File

If the undo command isn't useful, there's another way to restore a file to an earlier state. If you want to get the file back to the state that is stored on disk, type M-x revert-buffer Enter. Emacs asks the following question:

Revert buffer from file filename? (yes or no)

The filename is the name of your original file. Type yes if you want to restore the file, or no if you've changed your mind. Emacs copies the file stored on disk into the buffer, conveniently forgetting everything that happened since the last time you saved the file. Although this command is called revert-buffer, note that it can revert only buffers associated with files.

вернуться

15

On a Mac keyboard, we found that the Help key, to the left of Home, toggles overwrite mode.

вернуться

16

If you find that you repeat the undo command frequently, it's worth getting fluent with C-_. It's true that this requires holding down Ctrl and Shift at the same time, but once you've got that down, pressing _ repeatedly is much easier than typing C-x u again and again.