Next: , Previous: , Up: Top   [Contents][Index]

27.11 Quitting and Aborting


Quit. Cancel running or partially typed command.


Abort innermost recursive editing level and cancel the command which invoked it (abort-recursive-edit).

M-x top-level

Abort all recursive editing levels that are currently executing.

C-x u

Cancel an already-executed command, usually (undo).

There are two ways of cancelling commands which are not finished executing: quitting with C-g, and aborting with C-] or M-x top-level. Quitting is cancelling a partially typed command or one which is already running. Aborting is getting out of a recursive editing level and cancelling the command that invoked the recursive edit.

Quitting with C-g is used for getting rid of a partially typed command or a numeric argument that you don’t want. It also stops a running command in the middle in a relatively safe way, so you can use it if you accidentally start executing a command that takes a long time. In particular, it is safe to quit out of killing; either your text will all still be there, or it will all be in the kill ring (or maybe both). Quitting an incremental search does special things documented under searching; in general, it may take two successive C-g characters to get out of a search. C-g works by setting the variable quit-flag to t the instant C-g is typed; Emacs Lisp checks this variable frequently and quits if it is non-nil. C-g is only actually executed as a command if it is typed while Emacs is waiting for input.

If you quit twice in a row before the first C-g is recognized, you activate the “emergency escape” feature and return to the shell. See Emergency Escape.

You can use C-] (abort-recursive-edit) to get out of a recursive editing level and cancel the command which invoked it. Quitting with C-g does not do this, and could not do this because it is used to cancel a partially typed command within the recursive editing level. Both operations are useful. For example, if you are in the Emacs debugger (see Lisp Debug) and have typed C-u 8 to enter a numeric argument, you can cancel that argument with C-g and remain in the debugger.

The command M-x top-level is equivalent to “enough” C-] commands to get you out of all the levels of recursive edits that you are in. C-] only gets you out one level at a time, but M-x top-level goes out all levels at once. Both C-] and M-x top-level are like all other commands and unlike C-g in that they are effective only when Emacs is ready for a command. C-] is an ordinary key and has its meaning only because of its binding in the keymap. See Recursive Edit.

C-x u (undo) is not strictly speaking a way of cancelling a command, but you can think of it as cancelling a command already finished executing. See Undo.

Next: , Previous: , Up: Top   [Contents][Index]