GNU Emacs
Emacs
Dashboard

8.4.3 Completion Exit

When a command reads an argument using the minibuffer with completion, it also controls what happens when you type RET ( minibuffer-complete-and-exit) to submit the argument. There are four types of behavior:

  • Strict completion accepts only exact completion matches. Typing RET exits the minibuffer only if the minibuffer text is an exact match, or completes to one. Otherwise, Emacs refuses to exit the minibuffer; instead it tries to complete, and if no completion can be done it momentarily displays ‘ [No match]’ after the minibuffer text. (You can still leave the minibuffer by typing C-g to cancel the command.)

An example of a command that uses this behavior is M-x, since it is meaningless for it to accept a non-existent command name.

  • Cautious completion is like strict completion, except RET exits only if the text is already an exact match. If the text completes to an exact match, RET performs that completion but does not exit yet; you must type a second RET to exit.

Cautious completion is used for reading file names for files that must already exist, for example.

  • Permissive completion allows any input; the completion candidates are just suggestions. Typing RET does not complete, it just submits the argument as you have entered it.

  • Permissive completion with confirmation is like permissive completion, with an exception: if you typed TAB and this completed the text up to some intermediate state (i.e., one that is not yet an exact completion match), typing RET right afterward does not submit the argument. Instead, Emacs asks for confirmation by momentarily displaying ‘ [Confirm]’ after the text; type RET again to confirm and submit the text. This catches a common mistake, in which one types RET before realizing that TAB did not complete as far as desired.

You can tweak the confirmation behavior by customizing the variable confirm-nonexistent-file-or-buffer. The default value, after-completion, gives the behavior we have just described. If you change it to nil, Emacs does not ask for confirmation, falling back on permissive completion. If you change it to any other non- nil value, Emacs asks for confirmation whether or not the preceding command was TAB.

This behavior is used by most commands that read file names, like C-x C-f, and commands that read buffer names, like C-x b.