Correcting Mistakes and Emacs Problems

If you type an Emacs command you did not intend, the results are often mysterious. This chapter describes what you can do to cancel your mistakes and recover from such mysterious situations.

Interrupting and Aborting Emacs Commands

Cancel a running or partially-typed command. ^G (interrupt-key)
Abort all recursive editing levels and subsystems that are currently executing. ESC-x top-level

There are two ways of cancelling commands which have not finished executing: interrupting the command with ^G, or aborting all recursive edits with ESC-x top-level.

Interrupting with ^G is used to abort a partially-typed command or a numeric argument that you do not want. It also stops a running command in a safe way, so you can use ^G if you accidentally give a command which takes a long time to execute.

When you are in a position to use ESC-x, you can use ESC-x top-level. This command aborts all active recursive edits and subsystems. ESC-x top-level is like all other commands (apart from ^G) in that it is effective only when Emacs is waiting for keyboard input, whereas ^G can be used at any time.

Dealing with Common Emacs Problems

This section describes various conditions which can cause Emacs to function incorrectly or which can cause it to display strange things, and describes how to correct such conditions.

subsystems and recursive editing levels

Subsystems and recursive editing levels are important and useful features of Emacs, but they can make Emacs appear to behave strangely to the user who does not understand them or has never used them before.

If the mode line starts with a [, or does not look like the standard mode line, you have probably entered a subsystem or a recursive editing level.

In such a situation, first try typing ESC-x exit-emacs. This will exit from any recursive editing level or subsystem. The usual mode line and text display will reappear. If exit-emacs does not seem to work, try typing ^G to abort the current command. This may have the desired effect. Otherwise, use ESC-x top-level.

Undoing Changes to the Buffer

If you mistakenly issue commands that make changes to the buffer, you can often undo the changes without having to know precisely how they came about. This is done by using the ^X-^U command (undo). Type ^X-^U and a change is undone. undo then displays the message Hit <Space> to undo more in the Mini-buffer. For every Space that you press, another change you made to the buffers will be undone. When you press the first non-space character, that character is treated in the usual way and undo exits with the message Finished undoing. If the command is not a Return, its usual action is also executed.

The changes that ^X-^U undoes include all buffer insertions and deletions and any movement of dot in a buffer. Side-effects of MLisp functions, including creation of buffers and setting of variables, are not undone.

For commands that have not affected a buffer, ^X-^U appears to have no effect. So, if you use undo and nothing happens when an undo step is requested, this may well be because a non-buffer-modifying command was executed.

The undo function maintains a database of changes made to buffers. This database has a finite size; if you attempt to undo more than is contained in the database, undo will issue the following message:

I can't undo that. What's done is done.

Note that, when you undo changes, you can redo the changes by using undo again. For example, if you undo too many changes, use ^X-^U again to undo the unwanted undos.