This section describes the basic interface for reading from the minibuffer with completion.
This function reads a string in the minibuffer, assisting the user by providing completion. It activates the minibuffer with prompt prompt, which must be a string.
The actual completion is done by passing the completion table
collection and the completion predicate predicate to the
try-completion (see Basic Completion). This
happens in certain commands bound in the local keymaps used for
completion. Some of these commands also call
Thus, if predicate is non-
nil, it should be compatible
with collection and
See Definition of test-completion.
See Programmed Completion, for detailed requirements when collection is a function.
The value of the optional argument require-match determines how the user may exit the minibuffer:
nil, the usual minibuffer exit commands work regardless of the input in the minibuffer.
t, the usual minibuffer exit commands won’t exit unless the input completes to an element of collection.
confirm, the user can exit with any input, but is asked for confirmation if the input is not an element of collection.
confirm-after-completion, the user can exit with any input, but is asked for confirmation if the preceding command was a completion command (i.e., one of the commands in
minibuffer-confirm-exit-commands) and the resulting input is not an element of collection. See Completion Commands.
t, except that the exit commands won’t exit if it performs completion.
However, empty input is always permitted, regardless of the value of
require-match; in that case,
completing-read returns the
first element of default, if it is a list;
nil; or default. The string or strings
in default are also available to the user through the history
minibuffer-local-completion-map as the keymap if
nil, and uses
minibuffer-local-must-match-map if require-match is
nil. See Completion Commands.
The argument history specifies which history list variable to use for
saving the input and for minibuffer history commands. It defaults to
minibuffer-history. See Minibuffer History.
The argument initial is mostly deprecated; we recommend using a
nil value only in conjunction with specifying a cons cell
for history. See Initial Input. For default input, use
If the argument inherit-input-method is non-
nil, then the
minibuffer inherits the current input method (see Input Methods) and the setting of
(see Text Representations) from whichever buffer was current before
entering the minibuffer.
If the variable
nil, completion ignores case when comparing the input
against the possible matches. See Basic Completion. In this mode
of operation, predicate must also ignore case, or you will get
Here’s an example of using
(completing-read "Complete a foo: " '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)) nil t "fo")
;; After evaluation of the preceding expression, ;; the following appears in the minibuffer: ---------- Buffer: Minibuffer ---------- Complete a foo: fo∗ ---------- Buffer: Minibuffer ----------
If the user then types DEL DEL b RET,
completing-read function binds variables to pass
information to the commands that actually do completion.
They are described in the following section.
The value of this variable must be a function, which is called by
completing-read to actually do its work. It should accept the
same arguments as
completing-read. This can be bound to a
different function to completely override the normal behavior of