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
RETexits 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 typingC-gto 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
RETexits only if the text is already an exact match. If the text completes to an exact match,RETperforms that completion but does not exit yet; you must type a secondRETto 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
RETdoes 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
TABand this completed the text up to some intermediate state (i.e., one that is not yet an exact completion match), typingRETright afterward does not submit the argument. Instead, Emacs asks for confirmation by momentarily displaying ‘[Confirm]’ after the text; typeRETagain to confirm and submit the text. This catches a common mistake, in which one typesRETbefore realizing thatTABdid 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 tonil, Emacs does not ask for confirmation, falling back on permissive completion. If you change it to any other non-nilvalue, Emacs asks for confirmation whether or not the preceding command wasTAB.This behavior is used by most commands that read file names, like
C-x C-f, and commands that read buffer names, likeC-x b.