subrp fix
[bpt/emacs.git] / doc / lispref / minibuf.texi
CommitLineData
b8d4c8d0
GM
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
ba318903 3@c Copyright (C) 1990-1995, 1998-1999, 2001-2014 Free Software
ab422c4d 4@c Foundation, Inc.
b8d4c8d0 5@c See the file elisp.texi for copying conditions.
ecc6530d 6@node Minibuffers
b8d4c8d0
GM
7@chapter Minibuffers
8@cindex arguments, reading
9@cindex complex arguments
10@cindex minibuffer
11
12 A @dfn{minibuffer} is a special buffer that Emacs commands use to
13read arguments more complicated than the single numeric prefix
14argument. These arguments include file names, buffer names, and
15command names (as in @kbd{M-x}). The minibuffer is displayed on the
16bottom line of the frame, in the same place as the echo area
17(@pxref{The Echo Area}), but only while it is in use for reading an
18argument.
19
20@menu
21* Intro to Minibuffers:: Basic information about minibuffers.
22* Text from Minibuffer:: How to read a straight text string.
23* Object from Minibuffer:: How to read a Lisp object or expression.
d24880de
GM
24* Minibuffer History:: Recording previous minibuffer inputs
25 so the user can reuse them.
b8d4c8d0
GM
26* Initial Input:: Specifying initial contents for the minibuffer.
27* Completion:: How to invoke and customize completion.
28* Yes-or-No Queries:: Asking a question with a simple answer.
d24880de
GM
29* Multiple Queries:: Asking a series of similar questions.
30* Reading a Password:: Reading a password from the terminal.
b8d4c8d0 31* Minibuffer Commands:: Commands used as key bindings in minibuffers.
b8d4c8d0 32* Minibuffer Windows:: Operating on the special minibuffer windows.
c0ea08d2 33* Minibuffer Contents:: How such commands access the minibuffer text.
b8d4c8d0
GM
34* Recursive Mini:: Whether recursive entry to minibuffer is allowed.
35* Minibuffer Misc:: Various customization hooks and variables.
36@end menu
37
38@node Intro to Minibuffers
39@section Introduction to Minibuffers
40
41 In most ways, a minibuffer is a normal Emacs buffer. Most operations
42@emph{within} a buffer, such as editing commands, work normally in a
43minibuffer. However, many operations for managing buffers do not apply
44to minibuffers. The name of a minibuffer always has the form @w{@samp{
45*Minibuf-@var{number}*}}, and it cannot be changed. Minibuffers are
46displayed only in special windows used only for minibuffers; these
47windows always appear at the bottom of a frame. (Sometimes frames have
48no minibuffer window, and sometimes a special kind of frame contains
49nothing but a minibuffer window; see @ref{Minibuffers and Frames}.)
50
51 The text in the minibuffer always starts with the @dfn{prompt string},
52the text that was specified by the program that is using the minibuffer
53to tell the user what sort of input to type. This text is marked
54read-only so you won't accidentally delete or change it. It is also
55marked as a field (@pxref{Fields}), so that certain motion functions,
56including @code{beginning-of-line}, @code{forward-word},
57@code{forward-sentence}, and @code{forward-paragraph}, stop at the
a560da7e 58boundary between the prompt and the actual text.
b8d4c8d0 59
9c51bbaa 60@c See http://debbugs.gnu.org/11276
b8d4c8d0 61 The minibuffer's window is normally a single line; it grows
9c51bbaa
GM
62automatically if the contents require more space. Whilst it is
63active, you can explicitly resize it temporarily with the window
64sizing commands; it reverts to its normal size when the minibuffer is
65exited. When the minibuffer is not active, you can resize it
a560da7e 66permanently by using the window sizing commands in the frame's other
9c51bbaa
GM
67window, or dragging the mode line with the mouse. (Due to details of
68the current implementation, for this to work @code{resize-mini-windows}
69must be @code{nil}.) If the frame contains just a minibuffer, you can
70change the minibuffer's size by changing the frame's size.
b8d4c8d0
GM
71
72 Use of the minibuffer reads input events, and that alters the values
73of variables such as @code{this-command} and @code{last-command}
74(@pxref{Command Loop Info}). Your program should bind them around the
75code that uses the minibuffer, if you do not want that to change them.
76
a560da7e 77 Under some circumstances, a command can use a minibuffer even if
9d2754f5 78there is an active minibuffer; such a minibuffer is called a
a560da7e 79@dfn{recursive minibuffer}. The first minibuffer is named
9d2754f5 80@w{@samp{ *Minibuf-1*}}. Recursive minibuffers are named by
a560da7e
CY
81incrementing the number at the end of the name. (The names begin with
82a space so that they won't show up in normal buffer lists.) Of
83several recursive minibuffers, the innermost (or most recently
84entered) is the active minibuffer. We usually call this ``the''
85minibuffer. You can permit or forbid recursive minibuffers by setting
86the variable @code{enable-recursive-minibuffers}, or by putting
11625308 87properties of that name on command symbols (@xref{Recursive Mini}.)
b8d4c8d0
GM
88
89 Like other buffers, a minibuffer uses a local keymap
90(@pxref{Keymaps}) to specify special key bindings. The function that
91invokes the minibuffer also sets up its local map according to the job
92to be done. @xref{Text from Minibuffer}, for the non-completion
93minibuffer local maps. @xref{Completion Commands}, for the minibuffer
94local maps for completion.
95
9d2754f5 96@cindex inactive minibuffer
78c1f490 97 When a minibuffer is inactive, its major mode is
9d2754f5
GM
98@code{minibuffer-inactive-mode}, with keymap
99@code{minibuffer-inactive-mode-map}. This is only really useful if
100the minibuffer is in a separate frame. @xref{Minibuffers and Frames}.
101
b8d4c8d0
GM
102 When Emacs is running in batch mode, any request to read from the
103minibuffer actually reads a line from the standard input descriptor that
64c35331
GM
104was supplied when Emacs was started. This supports only basic input:
105none of the special minibuffer features (history, completion,
106password hiding, etc.) are available in batch mode.
b8d4c8d0
GM
107
108@node Text from Minibuffer
109@section Reading Text Strings with the Minibuffer
110
a560da7e
CY
111 The most basic primitive for minibuffer input is
112@code{read-from-minibuffer}, which can be used to read either a string
113or a Lisp object in textual form. The function @code{read-regexp} is
114used for reading regular expressions (@pxref{Regular Expressions}),
115which are a special kind of string. There are also specialized
116functions for reading commands, variables, file names, etc.@:
117(@pxref{Completion}).
b8d4c8d0
GM
118
119 In most cases, you should not call minibuffer input functions in the
120middle of a Lisp function. Instead, do all minibuffer input as part of
121reading the arguments for a command, in the @code{interactive}
122specification. @xref{Defining Commands}.
123
9d2754f5 124@defun read-from-minibuffer prompt &optional initial keymap read history default inherit-input-method
a560da7e 125This function is the most general way to get input from the
b8d4c8d0
GM
126minibuffer. By default, it accepts arbitrary text and returns it as a
127string; however, if @var{read} is non-@code{nil}, then it uses
128@code{read} to convert the text into a Lisp object (@pxref{Input
129Functions}).
130
131The first thing this function does is to activate a minibuffer and
9d2754f5
GM
132display it with @var{prompt} (which must be a string) as the
133prompt. Then the user can edit text in the minibuffer.
b8d4c8d0
GM
134
135When the user types a command to exit the minibuffer,
136@code{read-from-minibuffer} constructs the return value from the text in
137the minibuffer. Normally it returns a string containing that text.
138However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer}
139reads the text and returns the resulting Lisp object, unevaluated.
140(@xref{Input Functions}, for information about reading.)
141
c1d2409c
RS
142The argument @var{default} specifies default values to make available
143through the history commands. It should be a string, a list of
144strings, or @code{nil}. The string or strings become the minibuffer's
9d2754f5 145``future history'', available to the user with @kbd{M-n}.
c1d2409c 146
63b4387f
JL
147If @var{read} is non-@code{nil}, then @var{default} is also used
148as the input to @code{read}, if the user enters empty input.
149If @var{default} is a list of strings, the first string is used as the input.
150If @var{default} is @code{nil}, empty input results in an @code{end-of-file} error.
151However, in the usual case (where @var{read} is @code{nil}),
152@code{read-from-minibuffer} ignores @var{default} when the user enters
153empty input and returns an empty string, @code{""}. In this respect,
154it differs from all the other minibuffer input functions in this chapter.
b8d4c8d0
GM
155
156If @var{keymap} is non-@code{nil}, that keymap is the local keymap to
157use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the
158value of @code{minibuffer-local-map} is used as the keymap. Specifying
159a keymap is the most important way to customize the minibuffer for
160various applications such as completion.
161
9d2754f5 162The argument @var{history} specifies a history list variable to use
b8d4c8d0 163for saving the input and for history commands used in the minibuffer.
9d2754f5
GM
164It defaults to @code{minibuffer-history}. You can optionally specify
165a starting position in the history list as well. @xref{Minibuffer History}.
b8d4c8d0
GM
166
167If the variable @code{minibuffer-allow-text-properties} is
9d2754f5 168non-@code{nil}, then the string that is returned includes whatever text
b8d4c8d0
GM
169properties were present in the minibuffer. Otherwise all the text
170properties are stripped when the value is returned.
171
172If the argument @var{inherit-input-method} is non-@code{nil}, then the
173minibuffer inherits the current input method (@pxref{Input Methods}) and
174the setting of @code{enable-multibyte-characters} (@pxref{Text
175Representations}) from whichever buffer was current before entering the
176minibuffer.
177
9d2754f5 178Use of @var{initial} is mostly deprecated; we recommend using
b8d4c8d0 179a non-@code{nil} value only in conjunction with specifying a cons cell
9d2754f5 180for @var{history}. @xref{Initial Input}.
b8d4c8d0
GM
181@end defun
182
183@defun read-string prompt &optional initial history default inherit-input-method
184This function reads a string from the minibuffer and returns it. The
185arguments @var{prompt}, @var{initial}, @var{history} and
186@var{inherit-input-method} are used as in @code{read-from-minibuffer}.
187The keymap used is @code{minibuffer-local-map}.
188
189The optional argument @var{default} is used as in
190@code{read-from-minibuffer}, except that, if non-@code{nil}, it also
191specifies a default value to return if the user enters null input. As
c1d2409c 192in @code{read-from-minibuffer} it should be a string, a list of
9d2754f5 193strings, or @code{nil}, which is equivalent to an empty string. When
c1d2409c
RS
194@var{default} is a string, that string is the default value. When it
195is a list of strings, the first string is the default value. (All
196these strings are available to the user in the ``future minibuffer
9d2754f5 197history''.)
c1d2409c
RS
198
199This function works by calling the
b8d4c8d0
GM
200@code{read-from-minibuffer} function:
201
202@smallexample
203@group
204(read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit})
205@equiv{}
206(let ((value
207 (read-from-minibuffer @var{prompt} @var{initial} nil nil
208 @var{history} @var{default} @var{inherit})))
209 (if (and (equal value "") @var{default})
c066bafa 210 (if (consp @var{default}) (car @var{default}) @var{default})
b8d4c8d0
GM
211 value))
212@end group
213@end smallexample
214@end defun
215
2836affa 216@defun read-regexp prompt &optional defaults history
6d4913f0 217This function reads a regular expression as a string from the
2836affa
GM
218minibuffer and returns it. If the minibuffer prompt string
219@var{prompt} does not end in @samp{:} (followed by optional
220whitespace), the function adds @samp{: } to the end, preceded by the
221default return value (see below), if that is non-empty.
6d4913f0 222
2836affa
GM
223The optional argument @var{defaults} controls the default value to
224return if the user enters null input, and should be one of: a string;
225@code{nil}, which is equivalent to an empty string; a list of strings;
226or a symbol.
2ee797be 227
2836affa
GM
228If @var{defaults} is a symbol, @code{read-regexp} consults the value
229of the variable @code{read-regexp-defaults-function} (see below), and
230if that is non-@code{nil} uses it in preference to @var{defaults}.
231The value in this case should be either:
232
233@itemize @minus
234@item
235@code{regexp-history-last}, which means to use the first element of
236the appropriate minibuffer history list (see below).
237
238@item
239A function of no arguments, whose return value (which should be
240@code{nil}, a string, or a list of strings) becomes the value of
241@var{defaults}.
242@end itemize
cd996018 243
2836affa
GM
244@code{read-regexp} now ensures that the result of processing
245@var{defaults} is a list (i.e., if the value is @code{nil} or a
246string, it converts it to a list of one element). To this list,
247@code{read-regexp} then appends a few potentially useful candidates for
248input. These are:
6d4913f0
EZ
249
250@itemize @minus
251@item
56b00ec7 252The word or symbol at point.
6d4913f0
EZ
253@item
254The last regexp used in an incremental search.
255@item
256The last string used in an incremental search.
257@item
258The last string or pattern used in query-replace commands.
259@end itemize
260
2836affa
GM
261The function now has a list of regular expressions that it passes to
262@code{read-from-minibuffer} to obtain the user's input. The first
263element of the list is the default result in case of empty input. All
264elements of the list are available to the user as the ``future
265minibuffer history list'' (@pxref{Minibuffer History, future list,,
266emacs, The GNU Emacs Manual}).
267
268The optional argument @var{history}, if non-@code{nil}, is a symbol
269specifying a minibuffer history list to use (@pxref{Minibuffer
270History}). If it is omitted or @code{nil}, the history list defaults
271to @code{regexp-history}.
6d4913f0
EZ
272@end defun
273
2836affa
GM
274@defvar read-regexp-defaults-function
275The function @code{read-regexp} may use the value of this variable to
276determine its list of default regular expressions. If non-@code{nil},
277the value of this variable should be either:
278
279@itemize @minus
280@item
281The symbol @code{regexp-history-last}.
282
283@item
284A function of no arguments that returns either @code{nil}, a string,
285or a list of strings.
286@end itemize
287
288@noindent
289See @code{read-regexp} above for details of how these values are used.
290@end defvar
291
b8d4c8d0 292@defvar minibuffer-allow-text-properties
9d2754f5
GM
293If this variable is @code{nil}, then @code{read-from-minibuffer}
294and @code{read-string} strip all text properties from the minibuffer
295input before returning it. However,
b8d4c8d0
GM
296@code{read-no-blanks-input} (see below), as well as
297@code{read-minibuffer} and related functions (@pxref{Object from
298Minibuffer,, Reading Lisp Objects With the Minibuffer}), and all
299functions that do minibuffer input with completion, discard text
300properties unconditionally, regardless of the value of this variable.
301@end defvar
302
303@defvar minibuffer-local-map
304This
305@anchor{Definition of minibuffer-local-map}
306@c avoid page break at anchor; work around Texinfo deficiency
307is the default local keymap for reading from the minibuffer. By
308default, it makes the following bindings:
309
310@table @asis
311@item @kbd{C-j}
312@code{exit-minibuffer}
313
314@item @key{RET}
315@code{exit-minibuffer}
316
317@item @kbd{C-g}
318@code{abort-recursive-edit}
319
320@item @kbd{M-n}
321@itemx @key{DOWN}
322@code{next-history-element}
323
324@item @kbd{M-p}
325@itemx @key{UP}
326@code{previous-history-element}
327
328@item @kbd{M-s}
329@code{next-matching-history-element}
330
331@item @kbd{M-r}
332@code{previous-matching-history-element}
9d2754f5
GM
333
334@ignore
335@c Does not seem worth/appropriate mentioning.
336@item @kbd{C-@key{TAB}}
337@code{file-cache-minibuffer-complete}
338@end ignore
b8d4c8d0
GM
339@end table
340@end defvar
341
342@c In version 18, initial is required
343@c Emacs 19 feature
344@defun read-no-blanks-input prompt &optional initial inherit-input-method
345This function reads a string from the minibuffer, but does not allow
346whitespace characters as part of the input: instead, those characters
347terminate the input. The arguments @var{prompt}, @var{initial}, and
348@var{inherit-input-method} are used as in @code{read-from-minibuffer}.
349
350This is a simplified interface to the @code{read-from-minibuffer}
351function, and passes the value of the @code{minibuffer-local-ns-map}
352keymap as the @var{keymap} argument for that function. Since the keymap
353@code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is}
354possible to put a space into the string, by quoting it.
355
356This function discards text properties, regardless of the value of
357@code{minibuffer-allow-text-properties}.
358
359@smallexample
360@group
361(read-no-blanks-input @var{prompt} @var{initial})
362@equiv{}
363(let (minibuffer-allow-text-properties)
364 (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map))
365@end group
366@end smallexample
367@end defun
368
9d2754f5
GM
369@c Slightly unfortunate name, suggesting it might be related to the
370@c Nextstep port...
b8d4c8d0
GM
371@defvar minibuffer-local-ns-map
372This built-in variable is the keymap used as the minibuffer local keymap
373in the function @code{read-no-blanks-input}. By default, it makes the
374following bindings, in addition to those of @code{minibuffer-local-map}:
375
376@table @asis
377@item @key{SPC}
378@cindex @key{SPC} in minibuffer
379@code{exit-minibuffer}
380
381@item @key{TAB}
382@cindex @key{TAB} in minibuffer
383@code{exit-minibuffer}
384
385@item @kbd{?}
386@cindex @kbd{?} in minibuffer
387@code{self-insert-and-exit}
388@end table
389@end defvar
390
391@node Object from Minibuffer
392@section Reading Lisp Objects with the Minibuffer
393
394 This section describes functions for reading Lisp objects with the
395minibuffer.
396
397@defun read-minibuffer prompt &optional initial
398This function reads a Lisp object using the minibuffer, and returns it
399without evaluating it. The arguments @var{prompt} and @var{initial} are
400used as in @code{read-from-minibuffer}.
401
402This is a simplified interface to the
403@code{read-from-minibuffer} function:
404
405@smallexample
406@group
407(read-minibuffer @var{prompt} @var{initial})
408@equiv{}
409(let (minibuffer-allow-text-properties)
410 (read-from-minibuffer @var{prompt} @var{initial} nil t))
411@end group
412@end smallexample
413
414Here is an example in which we supply the string @code{"(testing)"} as
415initial input:
416
417@smallexample
418@group
419(read-minibuffer
420 "Enter an expression: " (format "%s" '(testing)))
421
422;; @r{Here is how the minibuffer is displayed:}
423@end group
424
425@group
426---------- Buffer: Minibuffer ----------
427Enter an expression: (testing)@point{}
428---------- Buffer: Minibuffer ----------
429@end group
430@end smallexample
431
432@noindent
433The user can type @key{RET} immediately to use the initial input as a
434default, or can edit the input.
435@end defun
436
437@defun eval-minibuffer prompt &optional initial
438This function reads a Lisp expression using the minibuffer, evaluates
439it, then returns the result. The arguments @var{prompt} and
440@var{initial} are used as in @code{read-from-minibuffer}.
441
442This function simply evaluates the result of a call to
443@code{read-minibuffer}:
444
445@smallexample
446@group
447(eval-minibuffer @var{prompt} @var{initial})
448@equiv{}
449(eval (read-minibuffer @var{prompt} @var{initial}))
450@end group
451@end smallexample
452@end defun
453
454@defun edit-and-eval-command prompt form
c0ea08d2
GM
455This function reads a Lisp expression in the minibuffer, evaluates it,
456then returns the result. The difference between this command and
b8d4c8d0
GM
457@code{eval-minibuffer} is that here the initial @var{form} is not
458optional and it is treated as a Lisp object to be converted to printed
459representation rather than as a string of text. It is printed with
460@code{prin1}, so if it is a string, double-quote characters (@samp{"})
461appear in the initial text. @xref{Output Functions}.
462
b8d4c8d0 463In the following example, we offer the user an expression with initial
c0ea08d2 464text that is already a valid form:
b8d4c8d0
GM
465
466@smallexample
467@group
468(edit-and-eval-command "Please edit: " '(forward-word 1))
469
470;; @r{After evaluation of the preceding expression,}
471;; @r{the following appears in the minibuffer:}
472@end group
473
474@group
475---------- Buffer: Minibuffer ----------
476Please edit: (forward-word 1)@point{}
477---------- Buffer: Minibuffer ----------
478@end group
479@end smallexample
480
481@noindent
482Typing @key{RET} right away would exit the minibuffer and evaluate the
483expression, thus moving point forward one word.
b8d4c8d0
GM
484@end defun
485
486@node Minibuffer History
487@section Minibuffer History
488@cindex minibuffer history
489@cindex history list
490
b923f7a9
CY
491 A @dfn{minibuffer history list} records previous minibuffer inputs
492so the user can reuse them conveniently. It is a variable whose value
493is a list of strings (previous inputs), most recent first.
494
495 There are many separate minibuffer history lists, used for different
496kinds of inputs. It's the Lisp programmer's job to specify the right
497history list for each use of the minibuffer.
498
9d2754f5 499 You specify a minibuffer history list with the optional @var{history}
b923f7a9
CY
500argument to @code{read-from-minibuffer} or @code{completing-read}.
501Here are the possible values for it:
b8d4c8d0
GM
502
503@table @asis
504@item @var{variable}
505Use @var{variable} (a symbol) as the history list.
506
507@item (@var{variable} . @var{startpos})
508Use @var{variable} (a symbol) as the history list, and assume that the
509initial history position is @var{startpos} (a nonnegative integer).
510
511Specifying 0 for @var{startpos} is equivalent to just specifying the
512symbol @var{variable}. @code{previous-history-element} will display
513the most recent element of the history list in the minibuffer. If you
514specify a positive @var{startpos}, the minibuffer history functions
9d2754f5 515behave as if @code{(elt @var{variable} (1- @var{startpos}))} were the
b8d4c8d0
GM
516history element currently shown in the minibuffer.
517
518For consistency, you should also specify that element of the history
519as the initial minibuffer contents, using the @var{initial} argument
520to the minibuffer input function (@pxref{Initial Input}).
521@end table
522
9d2754f5 523 If you don't specify @var{history}, then the default history list
b8d4c8d0
GM
524@code{minibuffer-history} is used. For other standard history lists,
525see below. You can also create your own history list variable; just
526initialize it to @code{nil} before the first use.
527
528 Both @code{read-from-minibuffer} and @code{completing-read} add new
529elements to the history list automatically, and provide commands to
530allow the user to reuse items on the list. The only thing your program
531needs to do to use a history list is to initialize it and to pass its
532name to the input functions when you wish. But it is safe to modify the
533list by hand when the minibuffer input functions are not using it.
534
535 Emacs functions that add a new element to a history list can also
536delete old elements if the list gets too long. The variable
537@code{history-length} specifies the maximum length for most history
538lists. To specify a different maximum length for a particular history
539list, put the length in the @code{history-length} property of the
540history list symbol. The variable @code{history-delete-duplicates}
541specifies whether to delete duplicates in history.
542
543@defun add-to-history history-var newelt &optional maxelt keep-all
544This function adds a new element @var{newelt}, if it isn't the empty
545string, to the history list stored in the variable @var{history-var},
546and returns the updated history list. It limits the list length to
547the value of @var{maxelt} (if non-@code{nil}) or @code{history-length}
548(described below). The possible values of @var{maxelt} have the same
549meaning as the values of @code{history-length}.
550
551Normally, @code{add-to-history} removes duplicate members from the
552history list if @code{history-delete-duplicates} is non-@code{nil}.
553However, if @var{keep-all} is non-@code{nil}, that says not to remove
554duplicates, and to add @var{newelt} to the list even if it is empty.
555@end defun
556
557@defvar history-add-new-input
558If the value of this variable is @code{nil}, standard functions that
559read from the minibuffer don't add new elements to the history list.
560This lets Lisp programs explicitly manage input history by using
e68b393e 561@code{add-to-history}. The default value is @code{t}.
b8d4c8d0
GM
562@end defvar
563
01f17ae2 564@defopt history-length
b8d4c8d0
GM
565The value of this variable specifies the maximum length for all
566history lists that don't specify their own maximum lengths. If the
da0bbbc4 567value is @code{t}, that means there is no maximum (don't delete old
c0ea08d2
GM
568elements). If a history list variable's symbol has a non-@code{nil}
569@code{history-length} property, it overrides this variable for that
b8d4c8d0 570particular history list.
01f17ae2 571@end defopt
b8d4c8d0 572
01f17ae2 573@defopt history-delete-duplicates
b8d4c8d0
GM
574If the value of this variable is @code{t}, that means when adding a
575new history element, all previous identical elements are deleted.
01f17ae2 576@end defopt
b8d4c8d0
GM
577
578 Here are some of the standard minibuffer history list variables:
579
580@defvar minibuffer-history
581The default history list for minibuffer history input.
582@end defvar
583
584@defvar query-replace-history
585A history list for arguments to @code{query-replace} (and similar
586arguments to other commands).
587@end defvar
588
589@defvar file-name-history
590A history list for file-name arguments.
591@end defvar
592
593@defvar buffer-name-history
594A history list for buffer-name arguments.
595@end defvar
596
597@defvar regexp-history
598A history list for regular expression arguments.
599@end defvar
600
601@defvar extended-command-history
602A history list for arguments that are names of extended commands.
603@end defvar
604
605@defvar shell-command-history
606A history list for arguments that are shell commands.
607@end defvar
608
609@defvar read-expression-history
610A history list for arguments that are Lisp expressions to evaluate.
611@end defvar
612
c0ea08d2
GM
613@defvar face-name-history
614A history list for arguments that are faces.
615@end defvar
616
617@c Less common: coding-system-history, input-method-history,
618@c command-history, grep-history, grep-find-history,
619@c read-envvar-name-history, setenv-history, yes-or-no-p-history.
620
b8d4c8d0
GM
621@node Initial Input
622@section Initial Input
623
624Several of the functions for minibuffer input have an argument called
9d2754f5 625@var{initial}. This is a mostly-deprecated
b8d4c8d0
GM
626feature for specifying that the minibuffer should start out with
627certain text, instead of empty as usual.
628
629If @var{initial} is a string, the minibuffer starts out containing the
630text of the string, with point at the end, when the user starts to
631edit the text. If the user simply types @key{RET} to exit the
632minibuffer, it will use the initial input string to determine the
633value to return.
634
635@strong{We discourage use of a non-@code{nil} value for
636@var{initial}}, because initial input is an intrusive interface.
637History lists and default values provide a much more convenient method
638to offer useful default inputs to the user.
639
640There is just one situation where you should specify a string for an
641@var{initial} argument. This is when you specify a cons cell for the
9d2754f5 642@var{history} argument. @xref{Minibuffer History}.
b8d4c8d0
GM
643
644@var{initial} can also be a cons cell of the form @code{(@var{string}
645. @var{position})}. This means to insert @var{string} in the
646minibuffer but put point at @var{position} within the string's text.
647
648As a historical accident, @var{position} was implemented
649inconsistently in different functions. In @code{completing-read},
650@var{position}'s value is interpreted as origin-zero; that is, a value
651of 0 means the beginning of the string, 1 means after the first
652character, etc. In @code{read-minibuffer}, and the other
653non-completion minibuffer input functions that support this argument,
c0ea08d2 6541 means the beginning of the string, 2 means after the first character,
b8d4c8d0
GM
655etc.
656
c0ea08d2 657Use of a cons cell as the value for @var{initial} arguments is deprecated.
b8d4c8d0
GM
658
659@node Completion
660@section Completion
661@cindex completion
662
663 @dfn{Completion} is a feature that fills in the rest of a name
664starting from an abbreviation for it. Completion works by comparing the
665user's input against a list of valid names and determining how much of
666the name is determined uniquely by what the user has typed. For
667example, when you type @kbd{C-x b} (@code{switch-to-buffer}) and then
b58b1df8 668@c "This is the sort of English up with which I will not put."
b8d4c8d0
GM
669type the first few letters of the name of the buffer to which you wish
670to switch, and then type @key{TAB} (@code{minibuffer-complete}), Emacs
671extends the name as far as it can.
672
673 Standard Emacs commands offer completion for names of symbols, files,
674buffers, and processes; with the functions in this section, you can
675implement completion for other kinds of names.
676
677 The @code{try-completion} function is the basic primitive for
678completion: it returns the longest determined completion of a given
679initial string, with a given set of strings to match against.
680
681 The function @code{completing-read} provides a higher-level interface
682for completion. A call to @code{completing-read} specifies how to
683determine the list of valid names. The function then activates the
684minibuffer with a local keymap that binds a few keys to commands useful
685for completion. Other functions provide convenient simple interfaces
686for reading certain kinds of names with completion.
687
688@menu
689* Basic Completion:: Low-level functions for completing strings.
b8d4c8d0
GM
690* Minibuffer Completion:: Invoking the minibuffer with completion.
691* Completion Commands:: Minibuffer commands that do completion.
692* High-Level Completion:: Convenient special cases of completion
b58b1df8 693 (reading buffer names, variable names, etc.).
e4372165
EZ
694* Reading File Names:: Using completion to read file names and
695 shell commands.
321cc491
CY
696* Completion Variables:: Variables controlling completion behavior.
697* Programmed Completion:: Writing your own completion function.
60236b0d 698* Completion in Buffers:: Completing text in ordinary buffers.
b8d4c8d0
GM
699@end menu
700
701@node Basic Completion
702@subsection Basic Completion Functions
703
eb5ed549
CY
704 The following completion functions have nothing in themselves to do
705with minibuffers. We describe them here to keep them near the
706higher-level completion features that do use the minibuffer.
b8d4c8d0
GM
707
708@defun try-completion string collection &optional predicate
709This function returns the longest common substring of all possible
60236b0d
CY
710completions of @var{string} in @var{collection}.
711
712@cindex completion table
379acb95
CY
713@var{collection} is called the @dfn{completion table}. Its value must
714be a list of strings or cons cells, an obarray, a hash table, or a
715completion function.
716
717@code{try-completion} compares @var{string} against each of the
718permissible completions specified by the completion table. If no
719permissible completions match, it returns @code{nil}. If there is
720just one matching completion, and the match is exact, it returns
eb5ed549
CY
721@code{t}. Otherwise, it returns the longest initial sequence common
722to all possible matching completions.
b8d4c8d0 723
379acb95
CY
724If @var{collection} is an list, the permissible completions are
725specified by the elements of the list, each of which should be either
726a string, or a cons cell whose @sc{car} is either a string or a symbol
727(a symbol is converted to a string using @code{symbol-name}). If the
728list contains elements of any other type, those are ignored.
b8d4c8d0
GM
729
730@cindex obarray in completion
731If @var{collection} is an obarray (@pxref{Creating Symbols}), the names
b58b1df8 732of all symbols in the obarray form the set of permissible completions.
b8d4c8d0
GM
733
734If @var{collection} is a hash table, then the keys that are strings
735are the possible completions. Other keys are ignored.
736
60236b0d
CY
737You can also use a function as @var{collection}. Then the function is
738solely responsible for performing completion; @code{try-completion}
739returns whatever this function returns. The function is called with
740three arguments: @var{string}, @var{predicate} and @code{nil} (the
e68b393e 741third argument is so that the same function can be used
60236b0d
CY
742in @code{all-completions} and do the appropriate thing in either
743case). @xref{Programmed Completion}.
b8d4c8d0
GM
744
745If the argument @var{predicate} is non-@code{nil}, then it must be a
746function of one argument, unless @var{collection} is a hash table, in
747which case it should be a function of two arguments. It is used to
748test each possible match, and the match is accepted only if
749@var{predicate} returns non-@code{nil}. The argument given to
750@var{predicate} is either a string or a cons cell (the @sc{car} of
751which is a string) from the alist, or a symbol (@emph{not} a symbol
752name) from the obarray. If @var{collection} is a hash table,
753@var{predicate} is called with two arguments, the string key and the
754associated value.
755
756In addition, to be acceptable, a completion must also match all the
757regular expressions in @code{completion-regexp-list}. (Unless
758@var{collection} is a function, in which case that function has to
759handle @code{completion-regexp-list} itself.)
760
761In the first of the following examples, the string @samp{foo} is
762matched by three of the alist @sc{car}s. All of the matches begin with
763the characters @samp{fooba}, so that is the result. In the second
e68b393e
GM
764example, there is only one possible match, and it is exact, so the
765return value is @code{t}.
b8d4c8d0
GM
766
767@smallexample
768@group
769(try-completion
770 "foo"
771 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
772 @result{} "fooba"
773@end group
774
775@group
776(try-completion "foo" '(("barfoo" 2) ("foo" 3)))
777 @result{} t
778@end group
779@end smallexample
780
781In the following example, numerous symbols begin with the characters
782@samp{forw}, and all of them begin with the word @samp{forward}. In
783most of the symbols, this is followed with a @samp{-}, but not in all,
784so no more than @samp{forward} can be completed.
785
786@smallexample
787@group
788(try-completion "forw" obarray)
789 @result{} "forward"
790@end group
791@end smallexample
792
793Finally, in the following example, only two of the three possible
794matches pass the predicate @code{test} (the string @samp{foobaz} is
795too short). Both of those begin with the string @samp{foobar}.
796
797@smallexample
798@group
799(defun test (s)
800 (> (length (car s)) 6))
801 @result{} test
802@end group
803@group
804(try-completion
805 "foo"
806 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
807 'test)
808 @result{} "foobar"
809@end group
810@end smallexample
811@end defun
812
b58b1df8
GM
813@c Removed obsolete argument nospace.
814@defun all-completions string collection &optional predicate
b8d4c8d0 815This function returns a list of all possible completions of
b58b1df8
GM
816@var{string}. The arguments to this function
817@c (aside from @var{nospace})
1df7defd 818are the same as those of @code{try-completion}, and it
b58b1df8 819uses @code{completion-regexp-list} in the same way that
16d1ff5f
CY
820@code{try-completion} does.
821
b58b1df8 822@ignore
16d1ff5f
CY
823The optional argument @var{nospace} is obsolete. If it is
824non-@code{nil}, completions that start with a space are ignored unless
825@var{string} starts with a space.
b58b1df8 826@end ignore
b8d4c8d0
GM
827
828If @var{collection} is a function, it is called with three arguments:
829@var{string}, @var{predicate} and @code{t}; then @code{all-completions}
830returns whatever the function returns. @xref{Programmed Completion}.
831
832Here is an example, using the function @code{test} shown in the
833example for @code{try-completion}:
834
835@smallexample
836@group
837(defun test (s)
838 (> (length (car s)) 6))
839 @result{} test
840@end group
841
842@group
843(all-completions
844 "foo"
845 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
846 'test)
847 @result{} ("foobar1" "foobar2")
848@end group
849@end smallexample
850@end defun
851
852@defun test-completion string collection &optional predicate
853@anchor{Definition of test-completion}
854This function returns non-@code{nil} if @var{string} is a valid
321cc491 855completion alternative specified by @var{collection} and
b8d4c8d0
GM
856@var{predicate}. The arguments are the same as in
857@code{try-completion}. For instance, if @var{collection} is a list of
858strings, this is true if @var{string} appears in the list and
859@var{predicate} is satisfied.
860
861This function uses @code{completion-regexp-list} in the same
862way that @code{try-completion} does.
863
864If @var{predicate} is non-@code{nil} and if @var{collection} contains
865several strings that are equal to each other, as determined by
866@code{compare-strings} according to @code{completion-ignore-case},
867then @var{predicate} should accept either all or none of them.
868Otherwise, the return value of @code{test-completion} is essentially
869unpredictable.
870
871If @var{collection} is a function, it is called with three arguments,
872the values @var{string}, @var{predicate} and @code{lambda}; whatever
873it returns, @code{test-completion} returns in turn.
7f4b4249 874@end defun
637821cd
SM
875
876@defun completion-boundaries string collection predicate suffix
877This function returns the boundaries of the field on which @var{collection}
878will operate, assuming that @var{string} holds the text before point
879and @var{suffix} holds the text after point.
880
881Normally completion operates on the whole string, so for all normal
882collections, this will always return @code{(0 . (length
883@var{suffix}))}. But more complex completion such as completion on
884files is done one field at a time. For example, completion of
885@code{"/usr/sh"} will include @code{"/usr/share/"} but not
886@code{"/usr/share/doc"} even if @code{"/usr/share/doc"} exists.
887Also @code{all-completions} on @code{"/usr/sh"} will not include
888@code{"/usr/share/"} but only @code{"share/"}. So if @var{string} is
889@code{"/usr/sh"} and @var{suffix} is @code{"e/doc"},
890@code{completion-boundaries} will return @code{(5 . 1)} which tells us
891that the @var{collection} will only return completion information that
892pertains to the area after @code{"/usr/"} and before @code{"/doc"}.
b8d4c8d0
GM
893@end defun
894
eb5ed549 895If you store a completion alist in a variable, you should mark the
b58b1df8 896variable as ``risky'' by giving it a non-@code{nil}
eb5ed549
CY
897@code{risky-local-variable} property. @xref{File Local Variables}.
898
b8d4c8d0 899@defvar completion-ignore-case
049bcbcb
CY
900If the value of this variable is non-@code{nil}, case is not
901considered significant in completion. Within @code{read-file-name},
902this variable is overridden by
903@code{read-file-name-completion-ignore-case} (@pxref{Reading File
904Names}); within @code{read-buffer}, it is overridden by
905@code{read-buffer-completion-ignore-case} (@pxref{High-Level
906Completion}).
b8d4c8d0
GM
907@end defvar
908
909@defvar completion-regexp-list
910This is a list of regular expressions. The completion functions only
911consider a completion acceptable if it matches all regular expressions
912in this list, with @code{case-fold-search} (@pxref{Searching and Case})
913bound to the value of @code{completion-ignore-case}.
914@end defvar
915
916@defmac lazy-completion-table var fun
917This macro provides a way to initialize the variable @var{var} as a
918collection for completion in a lazy way, not computing its actual
919contents until they are first needed. You use this macro to produce a
920value that you store in @var{var}. The actual computation of the
921proper value is done the first time you do completion using @var{var}.
922It is done by calling @var{fun} with no arguments. The
923value @var{fun} returns becomes the permanent value of @var{var}.
924
b58b1df8 925Here is an example:
b8d4c8d0
GM
926
927@smallexample
928(defvar foo (lazy-completion-table foo make-my-alist))
929@end smallexample
930@end defmac
931
a045a167 932@c FIXME? completion-table-with-context?
a045a167
GM
933@findex completion-table-case-fold
934@findex completion-table-in-turn
a333e4d2 935@findex completion-table-merge
a045a167 936@findex completion-table-subvert
7f6705c3 937@findex completion-table-with-quoting
a045a167
GM
938@findex completion-table-with-predicate
939@findex completion-table-with-terminator
e3369c41
GM
940@cindex completion table, modifying
941@cindex completion tables, combining
a045a167
GM
942There are several functions that take an existing completion table and
943return a modified version. @code{completion-table-case-fold} returns
a333e4d2
DG
944a case-insensitive table. @code{completion-table-in-turn} and
945@code{completion-table-merge} combine multiple input tables in
946different ways. @code{completion-table-subvert} alters a table to use
947a different initial prefix. @code{completion-table-with-quoting}
7f6705c3 948returns a table suitable for operating on quoted text.
a045a167 949@code{completion-table-with-predicate} filters a table with a
7f6705c3
GM
950predicate function. @code{completion-table-with-terminator} adds a
951terminating string.
a045a167
GM
952
953
b8d4c8d0
GM
954@node Minibuffer Completion
955@subsection Completion and the Minibuffer
956@cindex minibuffer completion
957@cindex reading from minibuffer with completion
958
959 This section describes the basic interface for reading from the
960minibuffer with completion.
961
9d2754f5 962@defun completing-read prompt collection &optional predicate require-match initial history default inherit-input-method
b8d4c8d0
GM
963This function reads a string in the minibuffer, assisting the user by
964providing completion. It activates the minibuffer with prompt
965@var{prompt}, which must be a string.
966
60236b0d
CY
967The actual completion is done by passing the completion table
968@var{collection} and the completion predicate @var{predicate} to the
969function @code{try-completion} (@pxref{Basic Completion}). This
970happens in certain commands bound in the local keymaps used for
971completion. Some of these commands also call @code{test-completion}.
972Thus, if @var{predicate} is non-@code{nil}, it should be compatible
973with @var{collection} and @code{completion-ignore-case}.
974@xref{Definition of test-completion}.
b8d4c8d0 975
b613b1dc
CY
976The value of the optional argument @var{require-match} determines how
977the user may exit the minibuffer:
978
979@itemize @bullet
980@item
981If @code{nil}, the usual minibuffer exit commands work regardless of
982the input in the minibuffer.
983
984@item
985If @code{t}, the usual minibuffer exit commands won't exit unless the
986input completes to an element of @var{collection}.
987
988@item
989If @code{confirm}, the user can exit with any input, but is asked for
990confirmation if the input is not an element of @var{collection}.
991
992@item
993If @code{confirm-after-completion}, the user can exit with any input,
994but is asked for confirmation if the preceding command was a
995completion command (i.e., one of the commands in
996@code{minibuffer-confirm-exit-commands}) and the resulting input is
997not an element of @var{collection}. @xref{Completion Commands}.
998
999@item
1000Any other value of @var{require-match} behaves like @code{t}, except
1001that the exit commands won't exit if it performs completion.
1002@end itemize
b8d4c8d0
GM
1003
1004However, empty input is always permitted, regardless of the value of
c1d2409c
RS
1005@var{require-match}; in that case, @code{completing-read} returns the
1006first element of @var{default}, if it is a list; @code{""}, if
70ee951b
JL
1007@var{default} is @code{nil}; or @var{default}. The string or strings
1008in @var{default} are also available to the user through the history
c1d2409c 1009commands.
b8d4c8d0
GM
1010
1011The function @code{completing-read} uses
1012@code{minibuffer-local-completion-map} as the keymap if
1013@var{require-match} is @code{nil}, and uses
1014@code{minibuffer-local-must-match-map} if @var{require-match} is
1015non-@code{nil}. @xref{Completion Commands}.
1016
9d2754f5 1017The argument @var{history} specifies which history list variable to use for
b8d4c8d0
GM
1018saving the input and for minibuffer history commands. It defaults to
1019@code{minibuffer-history}. @xref{Minibuffer History}.
1020
1021The argument @var{initial} is mostly deprecated; we recommend using a
1022non-@code{nil} value only in conjunction with specifying a cons cell
9d2754f5 1023for @var{history}. @xref{Initial Input}. For default input, use
b8d4c8d0
GM
1024@var{default} instead.
1025
1026If the argument @var{inherit-input-method} is non-@code{nil}, then the
1027minibuffer inherits the current input method (@pxref{Input
1028Methods}) and the setting of @code{enable-multibyte-characters}
1029(@pxref{Text Representations}) from whichever buffer was current before
1030entering the minibuffer.
1031
b58b1df8 1032If the variable @code{completion-ignore-case} is
b8d4c8d0
GM
1033non-@code{nil}, completion ignores case when comparing the input
1034against the possible matches. @xref{Basic Completion}. In this mode
1035of operation, @var{predicate} must also ignore case, or you will get
1036surprising results.
1037
1038Here's an example of using @code{completing-read}:
1039
1040@smallexample
1041@group
1042(completing-read
1043 "Complete a foo: "
1044 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
1045 nil t "fo")
1046@end group
1047
1048@group
1049;; @r{After evaluation of the preceding expression,}
1050;; @r{the following appears in the minibuffer:}
1051
1052---------- Buffer: Minibuffer ----------
1053Complete a foo: fo@point{}
1054---------- Buffer: Minibuffer ----------
1055@end group
1056@end smallexample
1057
1058@noindent
1059If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}},
1060@code{completing-read} returns @code{barfoo}.
1061
1062The @code{completing-read} function binds variables to pass
1063information to the commands that actually do completion.
1064They are described in the following section.
1065@end defun
1066
245d176b
CY
1067@defvar completing-read-function
1068The value of this variable must be a function, which is called by
1069@code{completing-read} to actually do its work. It should accept the
1070same arguments as @code{completing-read}. This can be bound to a
1071different function to completely override the normal behavior of
1072@code{completing-read}.
1073@end defvar
1074
b8d4c8d0
GM
1075@node Completion Commands
1076@subsection Minibuffer Commands that Do Completion
1077
1078 This section describes the keymaps, commands and user options used
b613b1dc 1079in the minibuffer to do completion.
b8d4c8d0
GM
1080
1081@defvar minibuffer-completion-table
60236b0d
CY
1082The value of this variable is the completion table used for completion
1083in the minibuffer. This is the global variable that contains what
b8d4c8d0 1084@code{completing-read} passes to @code{try-completion}. It is used by
60236b0d
CY
1085minibuffer completion commands such as
1086@code{minibuffer-complete-word}.
b8d4c8d0
GM
1087@end defvar
1088
1089@defvar minibuffer-completion-predicate
1090This variable's value is the predicate that @code{completing-read}
1091passes to @code{try-completion}. The variable is also used by the other
1092minibuffer completion functions.
1093@end defvar
1094
1095@defvar minibuffer-completion-confirm
b613b1dc
CY
1096This variable determines whether Emacs asks for confirmation before
1097exiting the minibuffer; @code{completing-read} binds this variable,
1098and the function @code{minibuffer-complete-and-exit} checks the value
1099before exiting. If the value is @code{nil}, confirmation is not
1100required. If the value is @code{confirm}, the user may exit with an
1101input that is not a valid completion alternative, but Emacs asks for
1102confirmation. If the value is @code{confirm-after-completion}, the
1103user may exit with an input that is not a valid completion
1104alternative, but Emacs asks for confirmation if the user submitted the
1105input right after any of the completion commands in
1106@code{minibuffer-confirm-exit-commands}.
1107@end defvar
1108
1109@defvar minibuffer-confirm-exit-commands
1110This variable holds a list of commands that cause Emacs to ask for
1111confirmation before exiting the minibuffer, if the @var{require-match}
1112argument to @code{completing-read} is @code{confirm-after-completion}.
1113The confirmation is requested if the user attempts to exit the
1114minibuffer immediately after calling any command in this list.
b8d4c8d0
GM
1115@end defvar
1116
1117@deffn Command minibuffer-complete-word
1118This function completes the minibuffer contents by at most a single
1119word. Even if the minibuffer contents have only one completion,
1120@code{minibuffer-complete-word} does not add any characters beyond the
1121first character that is not a word constituent. @xref{Syntax Tables}.
1122@end deffn
1123
1124@deffn Command minibuffer-complete
1125This function completes the minibuffer contents as far as possible.
1126@end deffn
1127
1128@deffn Command minibuffer-complete-and-exit
1129This function completes the minibuffer contents, and exits if
1130confirmation is not required, i.e., if
1131@code{minibuffer-completion-confirm} is @code{nil}. If confirmation
1132@emph{is} required, it is given by repeating this command
1133immediately---the command is programmed to work without confirmation
1134when run twice in succession.
1135@end deffn
1136
1137@deffn Command minibuffer-completion-help
1138This function creates a list of the possible completions of the
1139current minibuffer contents. It works by calling @code{all-completions}
1140using the value of the variable @code{minibuffer-completion-table} as
1141the @var{collection} argument, and the value of
1142@code{minibuffer-completion-predicate} as the @var{predicate} argument.
1143The list of completions is displayed as text in a buffer named
2bb0eca1 1144@file{*Completions*}.
b8d4c8d0
GM
1145@end deffn
1146
6faf982a 1147@defun display-completion-list completions
b8d4c8d0
GM
1148This function displays @var{completions} to the stream in
1149@code{standard-output}, usually a buffer. (@xref{Read and Print}, for more
1150information about streams.) The argument @var{completions} is normally
1151a list of completions just returned by @code{all-completions}, but it
1152does not have to be. Each element may be a symbol or a string, either
1153of which is simply printed. It can also be a list of two strings,
1154which is printed as if the strings were concatenated. The first of
1155the two strings is the actual completion, the second string serves as
1156annotation.
1157
b58b1df8
GM
1158This function is called by @code{minibuffer-completion-help}. A
1159common way to use it is together with
b8d4c8d0
GM
1160@code{with-output-to-temp-buffer}, like this:
1161
1162@example
1163(with-output-to-temp-buffer "*Completions*"
1164 (display-completion-list
6faf982a 1165 (all-completions (buffer-string) my-alist)))
b8d4c8d0
GM
1166@end example
1167@end defun
1168
1169@defopt completion-auto-help
1170If this variable is non-@code{nil}, the completion commands
1171automatically display a list of possible completions whenever nothing
1172can be completed because the next character is not uniquely determined.
1173@end defopt
1174
1175@defvar minibuffer-local-completion-map
1176@code{completing-read} uses this value as the local keymap when an
1177exact match of one of the completions is not required. By default, this
1178keymap makes the following bindings:
1179
1180@table @asis
1181@item @kbd{?}
1182@code{minibuffer-completion-help}
1183
1184@item @key{SPC}
1185@code{minibuffer-complete-word}
1186
1187@item @key{TAB}
1188@code{minibuffer-complete}
1189@end table
1190
1191@noindent
b58b1df8 1192and uses @code{minibuffer-local-map} as its parent keymap
b8d4c8d0
GM
1193(@pxref{Definition of minibuffer-local-map}).
1194@end defvar
1195
1196@defvar minibuffer-local-must-match-map
1197@code{completing-read} uses this value as the local keymap when an
1198exact match of one of the completions is required. Therefore, no keys
1199are bound to @code{exit-minibuffer}, the command that exits the
1200minibuffer unconditionally. By default, this keymap makes the following
1201bindings:
1202
1203@table @asis
b8d4c8d0
GM
1204@item @kbd{C-j}
1205@code{minibuffer-complete-and-exit}
1206
1207@item @key{RET}
1208@code{minibuffer-complete-and-exit}
1209@end table
1210
1211@noindent
b58b1df8 1212and uses @code{minibuffer-local-completion-map} as its parent keymap.
b8d4c8d0
GM
1213@end defvar
1214
1215@defvar minibuffer-local-filename-completion-map
b58b1df8
GM
1216This is a sparse keymap that simply unbinds @key{SPC}; because
1217filenames can contain spaces. The function @code{read-file-name}
1218combines this keymap with either @code{minibuffer-local-completion-map}
1219or @code{minibuffer-local-must-match-map}.
b8d4c8d0
GM
1220@end defvar
1221
b8d4c8d0
GM
1222
1223@node High-Level Completion
e4372165 1224@subsection High-Level Completion Functions
b8d4c8d0 1225
b58b1df8 1226 This section describes the higher-level convenience functions for
b8d4c8d0
GM
1227reading certain sorts of names with completion.
1228
1229 In most cases, you should not call these functions in the middle of a
1230Lisp function. When possible, do all minibuffer input as part of
1231reading the arguments for a command, in the @code{interactive}
1232specification. @xref{Defining Commands}.
1233
b613b1dc 1234@defun read-buffer prompt &optional default require-match
b8d4c8d0
GM
1235This function reads the name of a buffer and returns it as a string.
1236The argument @var{default} is the default name to use, the value to
1237return if the user exits with an empty minibuffer. If non-@code{nil},
c066bafa
JL
1238it should be a string, a list of strings, or a buffer. If it is
1239a list, the default value is the first element of this list. It is
1240mentioned in the prompt, but is not inserted in the minibuffer as
1241initial input.
b8d4c8d0
GM
1242
1243The argument @var{prompt} should be a string ending with a colon and a
1244space. If @var{default} is non-@code{nil}, the function inserts it in
1245@var{prompt} before the colon to follow the convention for reading from
1246the minibuffer with a default value (@pxref{Programming Tips}).
1247
b613b1dc
CY
1248The optional argument @var{require-match} has the same meaning as in
1249@code{completing-read}. @xref{Minibuffer Completion}.
b8d4c8d0
GM
1250
1251In the following example, the user enters @samp{minibuffer.t}, and
b613b1dc
CY
1252then types @key{RET}. The argument @var{require-match} is @code{t},
1253and the only buffer name starting with the given input is
b8d4c8d0
GM
1254@samp{minibuffer.texi}, so that name is the value.
1255
1256@example
1257(read-buffer "Buffer name: " "foo" t)
1258@group
1259;; @r{After evaluation of the preceding expression,}
1260;; @r{the following prompt appears,}
1261;; @r{with an empty minibuffer:}
1262@end group
1263
1264@group
1265---------- Buffer: Minibuffer ----------
1266Buffer name (default foo): @point{}
1267---------- Buffer: Minibuffer ----------
1268@end group
1269
1270@group
1271;; @r{The user types @kbd{minibuffer.t @key{RET}}.}
1272 @result{} "minibuffer.texi"
1273@end group
1274@end example
1275@end defun
1276
01f17ae2 1277@defopt read-buffer-function
05b621a6
CY
1278This variable, if non-@code{nil}, specifies a function for reading
1279buffer names. @code{read-buffer} calls this function instead of doing
1280its usual work, with the same arguments passed to @code{read-buffer}.
01f17ae2 1281@end defopt
b8d4c8d0 1282
01f17ae2 1283@defopt read-buffer-completion-ignore-case
b613b1dc
CY
1284If this variable is non-@code{nil}, @code{read-buffer} ignores case
1285when performing completion.
01f17ae2 1286@end defopt
b613b1dc 1287
b8d4c8d0
GM
1288@defun read-command prompt &optional default
1289This function reads the name of a command and returns it as a Lisp
1290symbol. The argument @var{prompt} is used as in
1291@code{read-from-minibuffer}. Recall that a command is anything for
1292which @code{commandp} returns @code{t}, and a command name is a symbol
1293for which @code{commandp} returns @code{t}. @xref{Interactive Call}.
1294
1295The argument @var{default} specifies what to return if the user enters
c066bafa
JL
1296null input. It can be a symbol, a string or a list of strings. If it
1297is a string, @code{read-command} interns it before returning it.
b58b1df8 1298If it is a list, @code{read-command} interns the first element of this list.
c066bafa
JL
1299If @var{default} is @code{nil}, that means no default has been
1300specified; then if the user enters null input, the return value is
1301@code{(intern "")}, that is, a symbol whose name is an empty string.
b8d4c8d0
GM
1302
1303@example
1304(read-command "Command name? ")
1305
1306@group
1307;; @r{After evaluation of the preceding expression,}
1308;; @r{the following prompt appears with an empty minibuffer:}
1309@end group
1310
1311@group
1312---------- Buffer: Minibuffer ----------
1313Command name?
1314---------- Buffer: Minibuffer ----------
1315@end group
1316@end example
1317
1318@noindent
1319If the user types @kbd{forward-c @key{RET}}, then this function returns
1320@code{forward-char}.
1321
1322The @code{read-command} function is a simplified interface to
1323@code{completing-read}. It uses the variable @code{obarray} so as to
1324complete in the set of extant Lisp symbols, and it uses the
1325@code{commandp} predicate so as to accept only command names:
1326
1327@cindex @code{commandp} example
1328@example
1329@group
1330(read-command @var{prompt})
1331@equiv{}
1332(intern (completing-read @var{prompt} obarray
1333 'commandp t nil))
1334@end group
1335@end example
1336@end defun
1337
1338@defun read-variable prompt &optional default
1339@anchor{Definition of read-variable}
c07a4c0b
CY
1340This function reads the name of a customizable variable and returns it
1341as a symbol. Its arguments have the same form as those of
1342@code{read-command}. It behaves just like @code{read-command}, except
1343that it uses the predicate @code{custom-variable-p} instead of
1344@code{commandp}.
b8d4c8d0
GM
1345@end defun
1346
ef164dbc
EZ
1347@deffn Command read-color &optional prompt convert allow-empty display
1348This function reads a string that is a color specification, either the
1349color's name or an RGB hex value such as @code{#RRRGGGBBB}. It
94bc7984 1350prompts with @var{prompt} (default: @code{"Color (name or #RGB triplet):"})
ef164dbc
EZ
1351and provides completion for color names, but not for hex RGB values.
1352In addition to names of standard colors, completion candidates include
1353the foreground and background colors at point.
1354
1355Valid RGB values are described in @ref{Color Names}.
1356
94bc7984 1357The function's return value is the string typed by the user in the
ef164dbc 1358minibuffer. However, when called interactively or if the optional
94bc7984
GM
1359argument @var{convert} is non-@code{nil}, it converts any input color
1360name into the corresponding RGB value string and instead returns that.
1361This function requires a valid color specification to be input.
b58b1df8 1362Empty color names are allowed when @var{allow-empty} is
ef164dbc
EZ
1363non-@code{nil} and the user enters null input.
1364
62e8099c 1365Interactively, or when @var{display} is non-@code{nil}, the return
ef164dbc
EZ
1366value is also displayed in the echo area.
1367@end deffn
1368
b8d4c8d0
GM
1369 See also the functions @code{read-coding-system} and
1370@code{read-non-nil-coding-system}, in @ref{User-Chosen Coding Systems},
1371and @code{read-input-method-name}, in @ref{Input Methods}.
1372
1373@node Reading File Names
1374@subsection Reading File Names
1375@cindex read file names
1376@cindex prompt for file name
1377
62e8099c
CY
1378 The high-level completion functions @code{read-file-name},
1379@code{read-directory-name}, and @code{read-shell-command} are designed
b58b1df8 1380to read file names, directory names, and shell commands, respectively.
62e8099c
CY
1381They provide special features, including automatic insertion of the
1382default directory.
b8d4c8d0 1383
b613b1dc 1384@defun read-file-name prompt &optional directory default require-match initial predicate
0f063651
CY
1385This function reads a file name, prompting with @var{prompt} and
1386providing completion.
1387
1388As an exception, this function reads a file name using a graphical
b58b1df8
GM
1389file dialog instead of the minibuffer, if all of the following are
1390true:
1391
1392@enumerate
1393@item
1394It is invoked via a mouse command.
1395
1396@item
1397The selected frame is on a graphical display supporting such dialogs.
1398
1399@item
1400The variable @code{use-dialog-box} is non-@code{nil}.
1401@xref{Dialog Boxes,, Dialog Boxes, emacs, The GNU Emacs Manual}.
1402
1403@item
1404The @var{directory} argument, described below, does not specify a
1405remote file. @xref{Remote Files,, Remote Files, emacs, The GNU Emacs Manual}.
1406@end enumerate
1407
1408@noindent
1409The exact behavior when using a graphical file dialog is
1410platform-dependent. Here, we simply document the behavior when using
1411the minibuffer.
b8d4c8d0 1412
b4d52acc
CY
1413@code{read-file-name} does not automatically expand the returned file
1414name. You must call @code{expand-file-name} yourself if an absolute
1415file name is required.
b8d4c8d0 1416
b4d52acc 1417The optional argument @var{require-match} has the same meaning as in
245d176b 1418@code{completing-read}. @xref{Minibuffer Completion}.
b8d4c8d0
GM
1419
1420The argument @var{directory} specifies the directory to use for
b4d52acc 1421completing relative file names. It should be an absolute directory
b58b1df8 1422name. If the variable @code{insert-default-directory} is non-@code{nil},
b8d4c8d0
GM
1423@var{directory} is also inserted in the minibuffer as initial input.
1424It defaults to the current buffer's value of @code{default-directory}.
1425
b8d4c8d0
GM
1426If you specify @var{initial}, that is an initial file name to insert
1427in the buffer (after @var{directory}, if that is inserted). In this
1428case, point goes at the beginning of @var{initial}. The default for
1429@var{initial} is @code{nil}---don't insert any file name. To see what
b58b1df8
GM
1430@var{initial} does, try the command @kbd{C-x C-v} in a buffer visiting
1431a file. @strong{Please note:} we recommend using @var{default} rather
1432than @var{initial} in most cases.
b8d4c8d0
GM
1433
1434If @var{default} is non-@code{nil}, then the function returns
1435@var{default} if the user exits the minibuffer with the same non-empty
1436contents that @code{read-file-name} inserted initially. The initial
1437minibuffer contents are always non-empty if
1438@code{insert-default-directory} is non-@code{nil}, as it is by
1439default. @var{default} is not checked for validity, regardless of the
b613b1dc 1440value of @var{require-match}. However, if @var{require-match} is
b8d4c8d0
GM
1441non-@code{nil}, the initial minibuffer contents should be a valid file
1442(or directory) name. Otherwise @code{read-file-name} attempts
1443completion if the user exits without any editing, and does not return
1444@var{default}. @var{default} is also available through the history
1445commands.
1446
1447If @var{default} is @code{nil}, @code{read-file-name} tries to find a
1448substitute default to use in its place, which it treats in exactly the
1449same way as if it had been specified explicitly. If @var{default} is
1450@code{nil}, but @var{initial} is non-@code{nil}, then the default is
1451the absolute file name obtained from @var{directory} and
1452@var{initial}. If both @var{default} and @var{initial} are @code{nil}
1453and the buffer is visiting a file, @code{read-file-name} uses the
1454absolute file name of that file as default. If the buffer is not
1455visiting a file, then there is no default. In that case, if the user
1456types @key{RET} without any editing, @code{read-file-name} simply
1457returns the pre-inserted contents of the minibuffer.
1458
1459If the user types @key{RET} in an empty minibuffer, this function
b613b1dc
CY
1460returns an empty string, regardless of the value of
1461@var{require-match}. This is, for instance, how the user can make the
0b128ac4 1462current buffer visit no file using @kbd{M-x set-visited-file-name}.
b8d4c8d0
GM
1463
1464If @var{predicate} is non-@code{nil}, it specifies a function of one
1465argument that decides which file names are acceptable completion
321cc491 1466alternatives. A file name is an acceptable value if @var{predicate}
b8d4c8d0
GM
1467returns non-@code{nil} for it.
1468
b4d52acc 1469Here is an example of using @code{read-file-name}:
b8d4c8d0
GM
1470
1471@example
1472@group
1473(read-file-name "The file is ")
1474
1475;; @r{After evaluation of the preceding expression,}
1476;; @r{the following appears in the minibuffer:}
1477@end group
1478
1479@group
1480---------- Buffer: Minibuffer ----------
1481The file is /gp/gnu/elisp/@point{}
1482---------- Buffer: Minibuffer ----------
1483@end group
1484@end example
1485
1486@noindent
1487Typing @kbd{manual @key{TAB}} results in the following:
1488
1489@example
1490@group
1491---------- Buffer: Minibuffer ----------
1492The file is /gp/gnu/elisp/manual.texi@point{}
1493---------- Buffer: Minibuffer ----------
1494@end group
1495@end example
1496
1497@c Wordy to avoid overfull hbox in smallbook mode.
1498@noindent
1499If the user types @key{RET}, @code{read-file-name} returns the file name
1500as the string @code{"/gp/gnu/elisp/manual.texi"}.
1501@end defun
1502
1503@defvar read-file-name-function
1504If non-@code{nil}, this should be a function that accepts the same
1505arguments as @code{read-file-name}. When @code{read-file-name} is
1506called, it calls this function with the supplied arguments instead of
1507doing its usual work.
1508@end defvar
1509
01f17ae2 1510@defopt read-file-name-completion-ignore-case
b8d4c8d0
GM
1511If this variable is non-@code{nil}, @code{read-file-name} ignores case
1512when performing completion.
01f17ae2 1513@end defopt
b8d4c8d0 1514
b613b1dc 1515@defun read-directory-name prompt &optional directory default require-match initial
b8d4c8d0 1516This function is like @code{read-file-name} but allows only directory
321cc491 1517names as completion alternatives.
b8d4c8d0
GM
1518
1519If @var{default} is @code{nil} and @var{initial} is non-@code{nil},
1520@code{read-directory-name} constructs a substitute default by
1521combining @var{directory} (or the current buffer's default directory
1522if @var{directory} is @code{nil}) and @var{initial}. If both
1523@var{default} and @var{initial} are @code{nil}, this function uses
1524@var{directory} as substitute default, or the current buffer's default
1525directory if @var{directory} is @code{nil}.
1526@end defun
1527
1528@defopt insert-default-directory
1529This variable is used by @code{read-file-name}, and thus, indirectly,
1530by most commands reading file names. (This includes all commands that
1531use the code letters @samp{f} or @samp{F} in their interactive form.
1532@xref{Interactive Codes,, Code Characters for interactive}.) Its
1533value controls whether @code{read-file-name} starts by placing the
1534name of the default directory in the minibuffer, plus the initial file
b58b1df8 1535name, if any. If the value of this variable is @code{nil}, then
b8d4c8d0
GM
1536@code{read-file-name} does not place any initial input in the
1537minibuffer (unless you specify initial input with the @var{initial}
1538argument). In that case, the default directory is still used for
1539completion of relative file names, but is not displayed.
1540
1541If this variable is @code{nil} and the initial minibuffer contents are
1542empty, the user may have to explicitly fetch the next history element
1543to access a default value. If the variable is non-@code{nil}, the
1544initial minibuffer contents are always non-empty and the user can
1545always request a default value by immediately typing @key{RET} in an
1546unedited minibuffer. (See above.)
1547
1548For example:
1549
1550@example
1551@group
1552;; @r{Here the minibuffer starts out with the default directory.}
1553(let ((insert-default-directory t))
1554 (read-file-name "The file is "))
1555@end group
1556
1557@group
1558---------- Buffer: Minibuffer ----------
1559The file is ~lewis/manual/@point{}
1560---------- Buffer: Minibuffer ----------
1561@end group
1562
1563@group
1564;; @r{Here the minibuffer is empty and only the prompt}
1565;; @r{appears on its line.}
1566(let ((insert-default-directory nil))
1567 (read-file-name "The file is "))
1568@end group
1569
1570@group
1571---------- Buffer: Minibuffer ----------
1572The file is @point{}
1573---------- Buffer: Minibuffer ----------
1574@end group
1575@end example
1576@end defopt
1577
9d2754f5 1578@defun read-shell-command prompt &optional initial history &rest args
e4372165
EZ
1579This function reads a shell command from the minibuffer, prompting
1580with @var{prompt} and providing intelligent completion. It completes
1581the first word of the command using candidates that are appropriate
d8f0f8a5
EZ
1582for command names, and the rest of the command words as file names.
1583
1584This function uses @code{minibuffer-local-shell-command-map} as the
9d2754f5 1585keymap for minibuffer input. The @var{history} argument specifies the
d8f0f8a5 1586history list to use; if is omitted or @code{nil}, it defaults to
e4372165 1587@code{shell-command-history} (@pxref{Minibuffer History,
9d2754f5 1588shell-command-history}). The optional argument @var{initial}
d8f0f8a5
EZ
1589specifies the initial content of the minibuffer (@pxref{Initial
1590Input}). The rest of @var{args}, if present, are used as the
1591@var{default} and @var{inherit-input-method} arguments in
1592@code{read-from-minibuffer} (@pxref{Text from Minibuffer}).
e4372165
EZ
1593@end defun
1594
1595@defvar minibuffer-local-shell-command-map
1596This keymap is used by @code{read-shell-command} for completing
b58b1df8
GM
1597command and file names that are part of a shell command. It uses
1598@code{minibuffer-local-map} as its parent keymap, and binds @key{TAB}
1599to @code{completion-at-point}.
e4372165
EZ
1600@end defvar
1601
321cc491
CY
1602@node Completion Variables
1603@subsection Completion Variables
dc1ce9aa 1604
b58b1df8 1605 Here are some variables that can be used to alter the default
321cc491 1606completion behavior.
dc1ce9aa 1607
321cc491 1608@cindex completion styles
dc1ce9aa 1609@defopt completion-styles
ea0ff314
CY
1610The value of this variable is a list of completion style (symbols) to
1611use for performing completion. A @dfn{completion style} is a set of
b58b1df8 1612rules for generating completions. Each symbol occurring this list
ea0ff314 1613must have a corresponding entry in @code{completion-styles-alist}.
dc1ce9aa
CY
1614@end defopt
1615
1616@defvar completion-styles-alist
1617This variable stores a list of available completion styles. Each
321cc491
CY
1618element in the list has the form
1619
1620@example
ea0ff314 1621(@var{style} @var{try-completion} @var{all-completions} @var{doc})
321cc491
CY
1622@end example
1623
1624@noindent
ea0ff314
CY
1625Here, @var{style} is the name of the completion style (a symbol),
1626which may be used in the @code{completion-styles} variable to refer to
1627this style; @var{try-completion} is the function that does the
1628completion; @var{all-completions} is the function that lists the
1629completions; and @var{doc} is a string describing the completion
1630style.
321cc491
CY
1631
1632The @var{try-completion} and @var{all-completions} functions should
1633each accept four arguments: @var{string}, @var{collection},
1634@var{predicate}, and @var{point}. The @var{string}, @var{collection},
1635and @var{predicate} arguments have the same meanings as in
1636@code{try-completion} (@pxref{Basic Completion}), and the @var{point}
1637argument is the position of point within @var{string}. Each function
1638should return a non-@code{nil} value if it performed its job, and
1df7defd 1639@code{nil} if it did not (e.g., if there is no way to complete
321cc491
CY
1640@var{string} according to the completion style).
1641
1642When the user calls a completion command like
dc1ce9aa
CY
1643@code{minibuffer-complete} (@pxref{Completion Commands}), Emacs looks
1644for the first style listed in @code{completion-styles} and calls its
1645@var{try-completion} function. If this function returns @code{nil},
321cc491
CY
1646Emacs moves to the next listed completion style and calls its
1647@var{try-completion} function, and so on until one of the
1648@var{try-completion} functions successfully performs completion and
1649returns a non-@code{nil} value. A similar procedure is used for
1650listing completions, via the @var{all-completions} functions.
1651
1652@xref{Completion Styles,,, emacs, The GNU Emacs Manual}, for a
1653description of the available completion styles.
dc1ce9aa
CY
1654@end defvar
1655
ea0ff314
CY
1656@defopt completion-category-overrides
1657This variable specifies special completion styles and other completion
1658behaviors to use when completing certain types of text. Its value
b58b1df8
GM
1659should be an alist with elements of the form @code{(@var{category}
1660. @var{alist})}. @var{category} is a symbol describing what is being
1661completed; currently, the @code{buffer}, @code{file}, and
1662@code{unicode-name} categories are defined, but others can be defined
1663via specialized completion functions (@pxref{Programmed Completion}).
1664@var{alist} is an association list describing how completion should
1665behave for the corresponding category. The following alist keys are
1666supported:
ea0ff314
CY
1667
1668@table @code
1669@item styles
1670The value should be a list of completion styles (symbols).
1671
1672@item cycle
1673The value should be a value for @code{completion-cycle-threshold}
1674(@pxref{Completion Options,,, emacs, The GNU Emacs Manual}) for this
1675category.
1676@end table
1677
1678@noindent
1679Additional alist entries may be defined in the future.
1680@end defopt
1681
321cc491
CY
1682@defvar completion-extra-properties
1683This variable is used to specify extra properties of the current
1684completion command. It is intended to be let-bound by specialized
1685completion commands. Its value should be a list of property and value
1686pairs. The following properties are supported:
1687
1688@table @code
1689@item :annotation-function
1690The value should be a function to add annotations in the completions
1691buffer. This function must accept one argument, a completion, and
1692should either return @code{nil} or a string to be displayed next to
1693the completion.
1694
1695@item :exit-function
1696The value should be a function to run after performing completion.
1697The function should accept two arguments, @var{string} and
1698@var{status}, where @var{string} is the text to which the field was
b58b1df8 1699completed, and @var{status} indicates what kind of operation happened:
321cc491
CY
1700@code{finished} if text is now complete, @code{sole} if the text
1701cannot be further completed but completion is not finished, or
1702@code{exact} if the text is a valid completion but may be further
1703completed.
1704@end table
1705@end defvar
dc1ce9aa 1706
b8d4c8d0
GM
1707@node Programmed Completion
1708@subsection Programmed Completion
1709@cindex programmed completion
1710
fd5a8ae8
SM
1711 Sometimes it is not possible or convenient to create an alist or
1712an obarray containing all the intended possible completions ahead
1713of time. In such a case, you can supply your own function to compute
1714the completion of a given string. This is called @dfn{programmed
1715completion}. Emacs uses programmed completion when completing file
1716names (@pxref{File Name Completion}), among many other cases.
b8d4c8d0 1717
637821cd
SM
1718 To use this feature, pass a function as the @var{collection}
1719argument to @code{completing-read}. The function
b8d4c8d0 1720@code{completing-read} arranges to pass your completion function along
637821cd
SM
1721to @code{try-completion}, @code{all-completions}, and other basic
1722completion functions, which will then let your function do all
1723the work.
b8d4c8d0
GM
1724
1725 The completion function should accept three arguments:
1726
1727@itemize @bullet
1728@item
1729The string to be completed.
1730
1731@item
321cc491
CY
1732A predicate function with which to filter possible matches, or
1733@code{nil} if none. The function should call the predicate for each
1734possible match, and ignore the match if the predicate returns
1735@code{nil}.
b8d4c8d0
GM
1736
1737@item
321cc491 1738A flag specifying the type of completion operation to perform. This
cb6e0bfa 1739flag may be one of the following values.
b8d4c8d0 1740
321cc491
CY
1741@table @code
1742@item nil
1743This specifies a @code{try-completion} operation. The function should
1744return @code{t} if the specified string is a unique and exact match;
1745if there is more than one match, it should return the common substring
1746of all matches (if the string is an exact match for one completion
1747alternative but also matches other longer alternatives, the return
1748value is the string); if there are no matches, it should return
1749@code{nil}.
1750
1751@item t
1752This specifies an @code{all-completions} operation. The function
b8d4c8d0
GM
1753should return a list of all possible completions of the specified
1754string.
1755
321cc491
CY
1756@item lambda
1757This specifies a @code{test-completion} operation. The function
1758should return @code{t} if the specified string is an exact match for
1759some completion alternative; @code{nil} otherwise.
637821cd 1760
321cc491
CY
1761@item (boundaries . @var{suffix})
1762This specifies a @code{completion-boundaries} operation. The function
9d2754f5
GM
1763should return @code{(boundaries @var{start} . @var{end})}, where
1764@var{start} is the position of the beginning boundary in the specified
1765string, and @var{end} is the position of the end boundary in
1766@var{suffix}.
ea0ff314
CY
1767
1768@item metadata
1769This specifies a request for information about the state of the
74ca4d39
LL
1770current completion. The return value should have the form
1771@code{(metadata . @var{alist})}, where @var{alist} is an alist whose
1772elements are described below.
321cc491 1773@end table
ea0ff314
CY
1774
1775@noindent
1776If the flag has any other value, the completion function should return
1777@code{nil}.
b8d4c8d0
GM
1778@end itemize
1779
ea0ff314
CY
1780The following is a list of metadata entries that a completion function
1781may return in response to a @code{metadata} flag argument:
1782
1783@table @code
1784@item category
1785The value should be a symbol describing what kind of text the
1786completion function is trying to complete. If the symbol matches one
1787of the keys in @code{completion-category-overrides}, the usual
1788completion behavior is overridden. @xref{Completion Variables}.
1789
1790@item annotation-function
1791The value should be a function for @dfn{annotating} completions. The
1792function should take one argument, @var{string}, which is a possible
1793completion. It should return a string, which is displayed after the
2bb0eca1 1794completion @var{string} in the @file{*Completions*} buffer.
ea0ff314
CY
1795
1796@item display-sort-function
1797The value should be a function for sorting completions. The function
1798should take one argument, a list of completion strings, and return a
1799sorted list of completion strings. It is allowed to alter the input
1800list destructively.
1801
1802@item cycle-sort-function
1803The value should be a function for sorting completions, when
1804@code{completion-cycle-threshold} is non-@code{nil} and the user is
1805cycling through completion alternatives. @xref{Completion Options,,,
1806emacs, The GNU Emacs Manual}. Its argument list and return value are
1807the same as for @code{display-sort-function}.
1808@end table
1809
25c0d999
SM
1810@defun completion-table-dynamic function
1811This function is a convenient way to write a function that can act as
b58b1df8 1812a programmed completion function. The argument @var{function} should be
b8d4c8d0
GM
1813a function that takes one argument, a string, and returns an alist of
1814possible completions of it. You can think of
25c0d999 1815@code{completion-table-dynamic} as a transducer between that interface
b8d4c8d0 1816and the interface for programmed completion functions.
25c0d999 1817@end defun
b8d4c8d0 1818
ea7826ba
GM
1819@defun completion-table-with-cache function &optional ignore-case
1820This is a wrapper for @code{completion-table-dynamic} that saves the
1821last argument-result pair. This means that multiple lookups with the
1822same argument only need to call @var{function} once. This can be useful
1823when a slow operation is involved, such as calling an external process.
1824@end defun
1825
60236b0d
CY
1826@node Completion in Buffers
1827@subsection Completion in Ordinary Buffers
1828@cindex inline completion
1829
1830@findex completion-at-point
1831 Although completion is usually done in the minibuffer, the
1832completion facility can also be used on the text in ordinary Emacs
1833buffers. In many major modes, in-buffer completion is performed by
1834the @kbd{C-M-i} or @kbd{M-@key{TAB}} command, bound to
1835@code{completion-at-point}. @xref{Symbol Completion,,, emacs, The GNU
1836Emacs Manual}. This command uses the abnormal hook variable
1837@code{completion-at-point-functions}:
1838
1839@defvar completion-at-point-functions
1840The value of this abnormal hook should be a list of functions, which
1841are used to compute a completion table for completing the text at
1842point. It can be used by major modes to provide mode-specific
1843completion tables (@pxref{Major Mode Conventions}).
1844
1845When the command @code{completion-at-point} runs, it calls the
1846functions in the list one by one, without any argument. Each function
1847should return @code{nil} if it is unable to produce a completion table
1848for the text at point. Otherwise it should return a list of the form
1849
1850@example
1851(@var{start} @var{end} @var{collection} . @var{props})
1852@end example
1853
1854@noindent
1855@var{start} and @var{end} delimit the text to complete (which should
1856enclose point). @var{collection} is a completion table for completing
1857that text, in a form suitable for passing as the second argument to
1858@code{try-completion} (@pxref{Basic Completion}); completion
1859alternatives will be generated from this completion table in the usual
1860way, via the completion styles defined in @code{completion-styles}
321cc491 1861(@pxref{Completion Variables}). @var{props} is a property list for
245d176b
CY
1862additional information; any of the properties in
1863@code{completion-extra-properties} are recognized (@pxref{Completion
1864Variables}), as well as the following additional ones:
60236b0d
CY
1865
1866@table @code
1867@item :predicate
1868The value should be a predicate that completion candidates need to
1869satisfy.
1870
1871@item :exclusive
1872If the value is @code{no}, then if the completion table fails to match
b58b1df8 1873the text at point, @code{completion-at-point} moves on to the
60236b0d
CY
1874next function in @code{completion-at-point-functions} instead of
1875reporting a completion failure.
1876@end table
1877
d94c875d
DC
1878Supplying a function for @var{collection} is strongly recommended if
1879generating the list of completions is an expensive operation. Emacs
1880may internally call functions in @code{completion-at-point-functions}
1881many times, but care about the value of @var{collection} for only some
1882of these calls. By supplying a function for @var{collection}, Emacs
1883can defer generating completions until necessary. You can use
1884@var{completion-table-dynamic} to create a wrapper function:
1885
1886@smallexample
1887;; Avoid this pattern.
1888(let ((beg ...) (end ...) (my-completions (my-make-completions)))
1889 (list beg end my-completions))
1890
1891;; Use this instead.
1892(let ((beg ...) (end ...))
1893 (list beg
1894 end
1895 (completion-table-dynamic
1896 (lambda (_)
1897 (my-make-completions)))))
1898@end smallexample
1899
60236b0d 1900A function in @code{completion-at-point-functions} may also return a
d94c875d
DC
1901function instead of a list as described above. In that case, that
1902returned function is called, with no argument, and it is entirely
1903responsible for performing the completion. We discourage this usage;
1904it is intended to help convert old code to using
1905@code{completion-at-point}.
60236b0d
CY
1906
1907The first function in @code{completion-at-point-functions} to return a
1908non-@code{nil} value is used by @code{completion-at-point}. The
1909remaining functions are not called. The exception to this is when
b58b1df8 1910there is an @code{:exclusive} specification, as described above.
60236b0d
CY
1911@end defvar
1912
1913 The following function provides a convenient way to perform
1914completion on an arbitrary stretch of text in an Emacs buffer:
1915
1916@defun completion-in-region start end collection &optional predicate
1917This function completes the text in the current buffer between the
1918positions @var{start} and @var{end}, using @var{collection}. The
1919argument @var{collection} has the same meaning as in
1920@code{try-completion} (@pxref{Basic Completion}).
1921
1922This function inserts the completion text directly into the current
1923buffer. Unlike @code{completing-read} (@pxref{Minibuffer
1924Completion}), it does not activate the minibuffer.
1925
1926For this function to work, point must be somewhere between @var{start}
1927and @var{end}.
1928@end defun
1929
1930
b8d4c8d0
GM
1931@node Yes-or-No Queries
1932@section Yes-or-No Queries
1933@cindex asking the user questions
1934@cindex querying the user
1935@cindex yes-or-no questions
1936
1937 This section describes functions used to ask the user a yes-or-no
1938question. The function @code{y-or-n-p} can be answered with a single
1939character; it is useful for questions where an inadvertent wrong answer
1940will not have serious consequences. @code{yes-or-no-p} is suitable for
1941more momentous questions, since it requires three or four characters to
1942answer.
1943
1944 If either of these functions is called in a command that was invoked
1945using the mouse---more precisely, if @code{last-nonmenu-event}
1946(@pxref{Command Loop Info}) is either @code{nil} or a list---then it
1947uses a dialog box or pop-up menu to ask the question. Otherwise, it
c0ea08d2 1948uses keyboard input. You can force use either of the mouse or of keyboard
b8d4c8d0
GM
1949input by binding @code{last-nonmenu-event} to a suitable value around
1950the call.
1951
1952 Strictly speaking, @code{yes-or-no-p} uses the minibuffer and
1953@code{y-or-n-p} does not; but it seems best to describe them together.
1954
1955@defun y-or-n-p prompt
1956This function asks the user a question, expecting input in the echo
1957area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the
1958user types @kbd{n}. This function also accepts @key{SPC} to mean yes
9d2754f5 1959and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit'', like
b8d4c8d0
GM
1960@kbd{C-g}, because the question might look like a minibuffer and for
1961that reason the user might try to use @kbd{C-]} to get out. The answer
1962is a single character, with no @key{RET} needed to terminate it. Upper
1963and lower case are equivalent.
1964
1965``Asking the question'' means printing @var{prompt} in the echo area,
1966followed by the string @w{@samp{(y or n) }}. If the input is not one of
1967the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}},
1968@kbd{@key{DEL}}, or something that quits), the function responds
1969@samp{Please answer y or n.}, and repeats the request.
1970
1971This function does not actually use the minibuffer, since it does not
1972allow editing of the answer. It actually uses the echo area (@pxref{The
1973Echo Area}), which uses the same screen space as the minibuffer. The
1974cursor moves to the echo area while the question is being asked.
1975
1976The answers and their meanings, even @samp{y} and @samp{n}, are not
011474aa
CY
1977hardwired, and are specified by the keymap @code{query-replace-map}
1978(@pxref{Search and Replace}). In particular, if the user enters the
1979special responses @code{recenter}, @code{scroll-up},
1980@code{scroll-down}, @code{scroll-other-window}, or
1981@code{scroll-other-window-down} (respectively bound to @kbd{C-l},
1982@kbd{C-v}, @kbd{M-v}, @kbd{C-M-v} and @kbd{C-M-S-v} in
1983@code{query-replace-map}), this function performs the specified window
1984recentering or scrolling operation, and poses the question again.
b8d4c8d0
GM
1985
1986@noindent
1987We show successive lines of echo area messages, but only one actually
1988appears on the screen at a time.
1989@end defun
1990
9d2754f5 1991@defun y-or-n-p-with-timeout prompt seconds default
b8d4c8d0
GM
1992Like @code{y-or-n-p}, except that if the user fails to answer within
1993@var{seconds} seconds, this function stops waiting and returns
9d2754f5 1994@var{default}. It works by setting up a timer; see @ref{Timers}.
09b73f08 1995The argument @var{seconds} should be a number.
b8d4c8d0
GM
1996@end defun
1997
1998@defun yes-or-no-p prompt
1999This function asks the user a question, expecting input in the
2000minibuffer. It returns @code{t} if the user enters @samp{yes},
2001@code{nil} if the user types @samp{no}. The user must type @key{RET} to
2002finalize the response. Upper and lower case are equivalent.
2003
2004@code{yes-or-no-p} starts by displaying @var{prompt} in the echo area,
2005followed by @w{@samp{(yes or no) }}. The user must type one of the
2006expected responses; otherwise, the function responds @samp{Please answer
2007yes or no.}, waits about two seconds and repeats the request.
2008
2009@code{yes-or-no-p} requires more work from the user than
2010@code{y-or-n-p} and is appropriate for more crucial decisions.
2011
2012Here is an example:
2013
2014@smallexample
2015@group
2016(yes-or-no-p "Do you really want to remove everything? ")
2017
2018;; @r{After evaluation of the preceding expression,}
2019;; @r{the following prompt appears,}
2020;; @r{with an empty minibuffer:}
2021@end group
2022
2023@group
2024---------- Buffer: minibuffer ----------
2025Do you really want to remove everything? (yes or no)
2026---------- Buffer: minibuffer ----------
2027@end group
2028@end smallexample
2029
2030@noindent
2031If the user first types @kbd{y @key{RET}}, which is invalid because this
2032function demands the entire word @samp{yes}, it responds by displaying
2033these prompts, with a brief pause between them:
2034
2035@smallexample
2036@group
2037---------- Buffer: minibuffer ----------
2038Please answer yes or no.
2039Do you really want to remove everything? (yes or no)
2040---------- Buffer: minibuffer ----------
2041@end group
2042@end smallexample
2043@end defun
2044
2045@node Multiple Queries
2046@section Asking Multiple Y-or-N Questions
2047
2048 When you have a series of similar questions to ask, such as ``Do you
2049want to save this buffer'' for each buffer in turn, you should use
2050@code{map-y-or-n-p} to ask the collection of questions, rather than
2051asking each question individually. This gives the user certain
2052convenient facilities such as the ability to answer the whole series at
2053once.
2054
2055@defun map-y-or-n-p prompter actor list &optional help action-alist no-cursor-in-echo-area
2056This function asks the user a series of questions, reading a
2057single-character answer in the echo area for each one.
2058
2059The value of @var{list} specifies the objects to ask questions about.
2060It should be either a list of objects or a generator function. If it is
2061a function, it should expect no arguments, and should return either the
c0ea08d2 2062next object to ask about, or @code{nil}, meaning to stop asking questions.
b8d4c8d0
GM
2063
2064The argument @var{prompter} specifies how to ask each question. If
2065@var{prompter} is a string, the question text is computed like this:
2066
2067@example
2068(format @var{prompter} @var{object})
2069@end example
2070
2071@noindent
2072where @var{object} is the next object to ask about (as obtained from
2073@var{list}).
2074
2075If not a string, @var{prompter} should be a function of one argument
2076(the next object to ask about) and should return the question text. If
2077the value is a string, that is the question to ask the user. The
c0ea08d2
GM
2078function can also return @code{t}, meaning do act on this object (and
2079don't ask the user), or @code{nil}, meaning ignore this object (and don't
b8d4c8d0
GM
2080ask the user).
2081
2082The argument @var{actor} says how to act on the answers that the user
2083gives. It should be a function of one argument, and it is called with
2084each object that the user says yes for. Its argument is always an
2085object obtained from @var{list}.
2086
2087If the argument @var{help} is given, it should be a list of this form:
2088
2089@example
2090(@var{singular} @var{plural} @var{action})
2091@end example
2092
2093@noindent
2094where @var{singular} is a string containing a singular noun that
2095describes the objects conceptually being acted on, @var{plural} is the
2096corresponding plural noun, and @var{action} is a transitive verb
2097describing what @var{actor} does.
2098
2099If you don't specify @var{help}, the default is @code{("object"
2100"objects" "act on")}.
2101
2102Each time a question is asked, the user may enter @kbd{y}, @kbd{Y}, or
2103@key{SPC} to act on that object; @kbd{n}, @kbd{N}, or @key{DEL} to skip
2104that object; @kbd{!} to act on all following objects; @key{ESC} or
2105@kbd{q} to exit (skip all following objects); @kbd{.} (period) to act on
2106the current object and then exit; or @kbd{C-h} to get help. These are
2107the same answers that @code{query-replace} accepts. The keymap
2108@code{query-replace-map} defines their meaning for @code{map-y-or-n-p}
2109as well as for @code{query-replace}; see @ref{Search and Replace}.
2110
2111You can use @var{action-alist} to specify additional possible answers
2112and what they mean. It is an alist of elements of the form
2113@code{(@var{char} @var{function} @var{help})}, each of which defines one
2114additional answer. In this element, @var{char} is a character (the
2115answer); @var{function} is a function of one argument (an object from
2116@var{list}); @var{help} is a string.
2117
2118When the user responds with @var{char}, @code{map-y-or-n-p} calls
2119@var{function}. If it returns non-@code{nil}, the object is considered
9d2754f5 2120``acted upon'', and @code{map-y-or-n-p} advances to the next object in
b8d4c8d0
GM
2121@var{list}. If it returns @code{nil}, the prompt is repeated for the
2122same object.
2123
2124Normally, @code{map-y-or-n-p} binds @code{cursor-in-echo-area} while
2125prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it
2126does not do that.
2127
2128If @code{map-y-or-n-p} is called in a command that was invoked using the
2129mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command
2130Loop Info}) is either @code{nil} or a list---then it uses a dialog box
2131or pop-up menu to ask the question. In this case, it does not use
c0ea08d2 2132keyboard input or the echo area. You can force use either of the mouse or
b8d4c8d0
GM
2133of keyboard input by binding @code{last-nonmenu-event} to a suitable
2134value around the call.
2135
2136The return value of @code{map-y-or-n-p} is the number of objects acted on.
2137@end defun
c0ea08d2
GM
2138@c FIXME An example of this would be more useful than all the
2139@c preceding examples of simple things.
b8d4c8d0
GM
2140
2141@node Reading a Password
2142@section Reading a Password
2143@cindex passwords, reading
2144
2145 To read a password to pass to another program, you can use the
2146function @code{read-passwd}.
2147
2148@defun read-passwd prompt &optional confirm default
2149This function reads a password, prompting with @var{prompt}. It does
2150not echo the password as the user types it; instead, it echoes @samp{.}
64c35331
GM
2151for each character in the password. (Note that in batch mode, the
2152input is not hidden.)
b8d4c8d0
GM
2153
2154The optional argument @var{confirm}, if non-@code{nil}, says to read the
2155password twice and insist it must be the same both times. If it isn't
2156the same, the user has to type it over and over until the last two
2157times match.
2158
2159The optional argument @var{default} specifies the default password to
2160return if the user enters empty input. If @var{default} is @code{nil},
2161then @code{read-passwd} returns the null string in that case.
2162@end defun
2163
2164@node Minibuffer Commands
2165@section Minibuffer Commands
2166
2167 This section describes some commands meant for use in the
2168minibuffer.
2169
2170@deffn Command exit-minibuffer
2171This command exits the active minibuffer. It is normally bound to
2172keys in minibuffer local keymaps.
2173@end deffn
2174
2175@deffn Command self-insert-and-exit
2176This command exits the active minibuffer after inserting the last
21e96f8f 2177character typed on the keyboard (found in @code{last-command-event};
b8d4c8d0
GM
2178@pxref{Command Loop Info}).
2179@end deffn
2180
2181@deffn Command previous-history-element n
2182This command replaces the minibuffer contents with the value of the
2183@var{n}th previous (older) history element.
2184@end deffn
2185
2186@deffn Command next-history-element n
2187This command replaces the minibuffer contents with the value of the
2188@var{n}th more recent history element.
2189@end deffn
2190
2191@deffn Command previous-matching-history-element pattern n
2192This command replaces the minibuffer contents with the value of the
2193@var{n}th previous (older) history element that matches @var{pattern} (a
2194regular expression).
2195@end deffn
2196
2197@deffn Command next-matching-history-element pattern n
2198This command replaces the minibuffer contents with the value of the
2199@var{n}th next (newer) history element that matches @var{pattern} (a
2200regular expression).
2201@end deffn
2202
c0ea08d2
GM
2203@deffn Command previous-complete-history-element n
2204This command replaces the minibuffer contents with the value of the
2205@var{n}th previous (older) history element that completes the current
2206contents of the minibuffer before the point.
2207@end deffn
2208
2209@deffn Command next-complete-history-element n
2210This command replaces the minibuffer contents with the value of the
2211@var{n}th next (newer) history element that completes the current
2212contents of the minibuffer before the point.
2213@end deffn
2214
2215
b8d4c8d0
GM
2216@node Minibuffer Windows
2217@section Minibuffer Windows
2218@cindex minibuffer windows
2219
2220 These functions access and select minibuffer windows
2221and test whether they are active.
2222
2223@defun active-minibuffer-window
2224This function returns the currently active minibuffer window, or
c0ea08d2 2225@code{nil} if there is none.
b8d4c8d0
GM
2226@end defun
2227
2228@defun minibuffer-window &optional frame
2229@anchor{Definition of minibuffer-window}
2230This function returns the minibuffer window used for frame @var{frame}.
2231If @var{frame} is @code{nil}, that stands for the current frame. Note
2232that the minibuffer window used by a frame need not be part of that
2233frame---a frame that has no minibuffer of its own necessarily uses some
2234other frame's minibuffer window.
2235@end defun
2236
2237@defun set-minibuffer-window window
2238This function specifies @var{window} as the minibuffer window to use.
2239This affects where the minibuffer is displayed if you put text in it
2240without invoking the usual minibuffer commands. It has no effect on
2241the usual minibuffer input functions because they all start by
2242choosing the minibuffer window according to the current frame.
2243@end defun
2244
2245@c Emacs 19 feature
2246@defun window-minibuffer-p &optional window
2247This function returns non-@code{nil} if @var{window} is a minibuffer
2248window.
2249@var{window} defaults to the selected window.
2250@end defun
2251
2252It is not correct to determine whether a given window is a minibuffer by
2253comparing it with the result of @code{(minibuffer-window)}, because
2254there can be more than one minibuffer window if there is more than one
2255frame.
2256
2257@defun minibuffer-window-active-p window
c0ea08d2
GM
2258This function returns non-@code{nil} if @var{window} is the currently
2259active minibuffer window.
b8d4c8d0
GM
2260@end defun
2261
2262@node Minibuffer Contents
2263@section Minibuffer Contents
2264
2265 These functions access the minibuffer prompt and contents.
2266
2267@defun minibuffer-prompt
2268This function returns the prompt string of the currently active
2269minibuffer. If no minibuffer is active, it returns @code{nil}.
2270@end defun
2271
2272@defun minibuffer-prompt-end
2273This function returns the current
2274position of the end of the minibuffer prompt, if a minibuffer is
2275current. Otherwise, it returns the minimum valid buffer position.
2276@end defun
2277
2278@defun minibuffer-prompt-width
2279This function returns the current display-width of the minibuffer
2280prompt, if a minibuffer is current. Otherwise, it returns zero.
2281@end defun
2282
2283@defun minibuffer-contents
2284This function returns the editable
2285contents of the minibuffer (that is, everything except the prompt) as
2286a string, if a minibuffer is current. Otherwise, it returns the
2287entire contents of the current buffer.
2288@end defun
2289
2290@defun minibuffer-contents-no-properties
2291This is like @code{minibuffer-contents}, except that it does not copy text
2292properties, just the characters themselves. @xref{Text Properties}.
2293@end defun
2294
b8d4c8d0
GM
2295@defun delete-minibuffer-contents
2296This function erases the editable contents of the minibuffer (that is,
2297everything except the prompt), if a minibuffer is current. Otherwise,
2298it erases the entire current buffer.
2299@end defun
2300
2301@node Recursive Mini
2302@section Recursive Minibuffers
2303@cindex recursive minibuffers
2304
2305 These functions and variables deal with recursive minibuffers
2306(@pxref{Recursive Editing}):
2307
2308@defun minibuffer-depth
2309This function returns the current depth of activations of the
2310minibuffer, a nonnegative integer. If no minibuffers are active, it
2311returns zero.
2312@end defun
2313
2314@defopt enable-recursive-minibuffers
2315If this variable is non-@code{nil}, you can invoke commands (such as
2316@code{find-file}) that use minibuffers even while the minibuffer window
2317is active. Such invocation produces a recursive editing level for a new
2318minibuffer. The outer-level minibuffer is invisible while you are
2319editing the inner one.
2320
2321If this variable is @code{nil}, you cannot invoke minibuffer
2322commands when the minibuffer window is active, not even if you switch to
2323another window to do it.
2324@end defopt
2325
2326@c Emacs 19 feature
2327If a command name has a property @code{enable-recursive-minibuffers}
2328that is non-@code{nil}, then the command can use the minibuffer to read
2329arguments even if it is invoked from the minibuffer. A command can
2330also achieve this by binding @code{enable-recursive-minibuffers}
2331to @code{t} in the interactive declaration (@pxref{Using Interactive}).
2332The minibuffer command @code{next-matching-history-element} (normally
2333@kbd{M-s} in the minibuffer) does the latter.
2334
2335@node Minibuffer Misc
2336@section Minibuffer Miscellany
2337
2338@defun minibufferp &optional buffer-or-name
2339This function returns non-@code{nil} if @var{buffer-or-name} is a
2340minibuffer. If @var{buffer-or-name} is omitted, it tests the current
2341buffer.
2342@end defun
2343
2344@defvar minibuffer-setup-hook
2345This is a normal hook that is run whenever the minibuffer is entered.
2346@xref{Hooks}.
2347@end defvar
2348
2349@defvar minibuffer-exit-hook
2350This is a normal hook that is run whenever the minibuffer is exited.
2351@xref{Hooks}.
2352@end defvar
2353
2354@defvar minibuffer-help-form
2355@anchor{Definition of minibuffer-help-form}
2356The current value of this variable is used to rebind @code{help-form}
2357locally inside the minibuffer (@pxref{Help Functions}).
2358@end defvar
2359
2360@defvar minibuffer-scroll-window
2361@anchor{Definition of minibuffer-scroll-window}
2362If the value of this variable is non-@code{nil}, it should be a window
2363object. When the function @code{scroll-other-window} is called in the
2364minibuffer, it scrolls this window.
2365@end defvar
2366
2367@defun minibuffer-selected-window
c0ea08d2 2368This function returns the window that was selected when the
b8d4c8d0
GM
2369minibuffer was entered. If selected window is not a minibuffer
2370window, it returns @code{nil}.
2371@end defun
2372
2373@defopt max-mini-window-height
2374This variable specifies the maximum height for resizing minibuffer
2375windows. If a float, it specifies a fraction of the height of the
2376frame. If an integer, it specifies a number of lines.
2377@end defopt
2378
c0ea08d2 2379@vindex minibuffer-message-timeout
106e6894 2380@defun minibuffer-message string &rest args
b8d4c8d0 2381This function displays @var{string} temporarily at the end of the
c0ea08d2
GM
2382minibuffer text, for a few seconds, or until the next input event
2383arrives, whichever comes first. The variable
2384@code{minibuffer-message-timeout} specifies the number of seconds to
2385wait in the absence of input. It defaults to 2. If @var{args} is
2386non-@code{nil}, the actual message is obtained by passing @var{string}
2387and @var{args} through @code{format}. @xref{Formatting Strings}.
b8d4c8d0 2388@end defun
c0ea08d2
GM
2389
2390@deffn Command minibuffer-inactive-mode
2391This is the major mode used in inactive minibuffers. It uses
2392keymap @code{minibuffer-inactive-mode-map}. This can be useful
2393if the minibuffer is in a separate frame. @xref{Minibuffers and Frames}.
2394@end deffn