GNU Emacs Lisp Reference Manual
This section describes the higher-level convenient functions for reading certain sorts of names with completion.
In most cases, you should not call these functions in the middle of a Lisp function. When possible, do all minibuffer input as part of reading the arguments for a command, in the interactive spec. See Defining Commands.
nil, it should be a string or a buffer. It is mentioned in the prompt, but is not inserted in the minibuffer as initial input. If existing is non-nil, then the name specified must be that of an existing buffer. The usual commands to exit the minibuffer do not exit if the text is not valid, and RET does completion to attempt to find a valid name. (However, default is not checked for validity; it is returned, whatever it is, if the user exits with the minibuffer empty.)
In the following example, the user enters `minibuffer.t', and then types RET. The argument existing is t, and the only buffer name starting with the given input is `minibuffer.texi', so that name is the value.
(read-buffer "Buffer name? " "foo" t)
;; After evaluation of the preceding expression,
;; the following prompt appears,
;; with an empty minibuffer:
---------- Buffer: Minibuffer ----------
Buffer name? (default foo) -!-
---------- Buffer: Minibuffer ----------
;; The user types minibuffer.t RET.
=> "minibuffer.texi"
read-from-minibuffer. Recall that a command is anything for which commandp returns t, and a command name is a symbol for which commandp returns t. See Interactive Call. (read-command "Command name? ") ;; After evaluation of the preceding expression, ;; the following prompt appears with an empty minibuffer: ---------- Buffer: Minibuffer ---------- Command name? ---------- Buffer: Minibuffer ----------
If the user types forward-c RET, then this function returns forward-char.
The read-command function is a simplified interface to the function completing-read. It uses the variable obarray so as to complete in the set of extant Lisp symbols, and it uses the commandp predicate so as to accept only command names:
(read-command prompt)
==
(intern (completing-read prompt obarray
'commandp t nil))
(read-variable "Variable name? ") ;; After evaluation of the preceding expression, ;; the following prompt appears, ;; with an empty minibuffer: ---------- Buffer: Minibuffer ---------- Variable name? -!- ---------- Buffer: Minibuffer ----------
If the user then types fill-p RET, read-variable returns fill-prefix.
This function is similar to read-command, but uses the predicate user-variable-p instead of commandp:
(read-variable prompt)
==
(intern
(completing-read prompt obarray
'user-variable-p t nil))