* minibuffer.el (completion-table-with-context): Add support for `pred'.
[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.
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, 2002,
57ebf0be 4@c 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
b8d4c8d0 5@c See the file elisp.texi for copying conditions.
6336d8c3 6@setfilename ../../info/minibuf
b8d4c8d0
GM
7@node Minibuffers, Command Loop, Read and Print, Top
8@chapter Minibuffers
9@cindex arguments, reading
10@cindex complex arguments
11@cindex minibuffer
12
13 A @dfn{minibuffer} is a special buffer that Emacs commands use to
14read arguments more complicated than the single numeric prefix
15argument. These arguments include file names, buffer names, and
16command names (as in @kbd{M-x}). The minibuffer is displayed on the
17bottom line of the frame, in the same place as the echo area
18(@pxref{The Echo Area}), but only while it is in use for reading an
19argument.
20
21@menu
22* Intro to Minibuffers:: Basic information about minibuffers.
23* Text from Minibuffer:: How to read a straight text string.
24* Object from Minibuffer:: How to read a Lisp object or expression.
25* Minibuffer History:: Recording previous minibuffer inputs
26 so the user can reuse them.
27* Initial Input:: Specifying initial contents for the minibuffer.
28* Completion:: How to invoke and customize completion.
29* Yes-or-No Queries:: Asking a question with a simple answer.
30* Multiple Queries:: Asking a series of similar questions.
31* Reading a Password:: Reading a password from the terminal.
32* Minibuffer Commands:: Commands used as key bindings in minibuffers.
33* Minibuffer Contents:: How such commands access the minibuffer text.
34* Minibuffer Windows:: Operating on the special minibuffer windows.
35* Recursive Mini:: Whether recursive entry to minibuffer is allowed.
36* Minibuffer Misc:: Various customization hooks and variables.
37@end menu
38
39@node Intro to Minibuffers
40@section Introduction to Minibuffers
41
42 In most ways, a minibuffer is a normal Emacs buffer. Most operations
43@emph{within} a buffer, such as editing commands, work normally in a
44minibuffer. However, many operations for managing buffers do not apply
45to minibuffers. The name of a minibuffer always has the form @w{@samp{
46*Minibuf-@var{number}*}}, and it cannot be changed. Minibuffers are
47displayed only in special windows used only for minibuffers; these
48windows always appear at the bottom of a frame. (Sometimes frames have
49no minibuffer window, and sometimes a special kind of frame contains
50nothing but a minibuffer window; see @ref{Minibuffers and Frames}.)
51
52 The text in the minibuffer always starts with the @dfn{prompt string},
53the text that was specified by the program that is using the minibuffer
54to tell the user what sort of input to type. This text is marked
55read-only so you won't accidentally delete or change it. It is also
56marked as a field (@pxref{Fields}), so that certain motion functions,
57including @code{beginning-of-line}, @code{forward-word},
58@code{forward-sentence}, and @code{forward-paragraph}, stop at the
59boundary between the prompt and the actual text. (In older Emacs
60versions, the prompt was displayed using a special mechanism and was not
61part of the buffer contents.)
62
63 The minibuffer's window is normally a single line; it grows
64automatically if necessary if the contents require more space. You can
65explicitly resize it temporarily with the window sizing commands; it
66reverts to its normal size when the minibuffer is exited. You can
67resize it permanently by using the window sizing commands in the frame's
68other window, when the minibuffer is not active. If the frame contains
69just a minibuffer, you can change the minibuffer's size by changing the
70frame's size.
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
77 If a command uses a minibuffer while there is an active minibuffer,
78this is called a @dfn{recursive minibuffer}. The first minibuffer is
79named @w{@samp{ *Minibuf-0*}}. Recursive minibuffers are named by
80incrementing the number at the end of the name. (The names begin with a
81space so that they won't show up in normal buffer lists.) Of several
82recursive minibuffers, the innermost (or most recently entered) is the
83active minibuffer. We usually call this ``the'' minibuffer. You can
84permit or forbid recursive minibuffers by setting the variable
85@code{enable-recursive-minibuffers} or by putting properties of that
86name on command symbols (@pxref{Recursive Mini}).
87
88 Like other buffers, a minibuffer uses a local keymap
89(@pxref{Keymaps}) to specify special key bindings. The function that
90invokes the minibuffer also sets up its local map according to the job
91to be done. @xref{Text from Minibuffer}, for the non-completion
92minibuffer local maps. @xref{Completion Commands}, for the minibuffer
93local maps for completion.
94
95 When Emacs is running in batch mode, any request to read from the
96minibuffer actually reads a line from the standard input descriptor that
97was supplied when Emacs was started.
98
99@node Text from Minibuffer
100@section Reading Text Strings with the Minibuffer
101
102 Most often, the minibuffer is used to read text as a string. It can
103also be used to read a Lisp object in textual form. The most basic
104primitive for minibuffer input is @code{read-from-minibuffer}; it can do
105either one. There are also specialized commands for reading
106commands, variables, file names, etc. (@pxref{Completion}).
107
108 In most cases, you should not call minibuffer input functions in the
109middle of a Lisp function. Instead, do all minibuffer input as part of
110reading the arguments for a command, in the @code{interactive}
111specification. @xref{Defining Commands}.
112
113@defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist default inherit-input-method
114This function is the most general way to get input through the
115minibuffer. By default, it accepts arbitrary text and returns it as a
116string; however, if @var{read} is non-@code{nil}, then it uses
117@code{read} to convert the text into a Lisp object (@pxref{Input
118Functions}).
119
120The first thing this function does is to activate a minibuffer and
121display it with @var{prompt-string} as the prompt. This value must be a
122string. Then the user can edit text in the minibuffer.
123
124When the user types a command to exit the minibuffer,
125@code{read-from-minibuffer} constructs the return value from the text in
126the minibuffer. Normally it returns a string containing that text.
127However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer}
128reads the text and returns the resulting Lisp object, unevaluated.
129(@xref{Input Functions}, for information about reading.)
130
c1d2409c
RS
131The argument @var{default} specifies default values to make available
132through the history commands. It should be a string, a list of
133strings, or @code{nil}. The string or strings become the minibuffer's
134``future history,'' available to the user with @kbd{M-n}.
135
136If @var{read} is non-@code{nil}, then @var{default} is also used as
137the input to @code{read}, if the user enters empty input. (If
138@var{read} is non-@code{nil} and @var{default} is @code{nil}, empty
b8d4c8d0
GM
139input results in an @code{end-of-file} error.) However, in the usual
140case (where @var{read} is @code{nil}), @code{read-from-minibuffer}
141ignores @var{default} when the user enters empty input and returns an
c1d2409c
RS
142empty string, @code{""}. In this respect, it differs from all the
143other minibuffer input functions in this chapter.
b8d4c8d0
GM
144
145If @var{keymap} is non-@code{nil}, that keymap is the local keymap to
146use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the
147value of @code{minibuffer-local-map} is used as the keymap. Specifying
148a keymap is the most important way to customize the minibuffer for
149various applications such as completion.
150
151The argument @var{hist} specifies which history list variable to use
152for saving the input and for history commands used in the minibuffer.
153It defaults to @code{minibuffer-history}. @xref{Minibuffer History}.
154
155If the variable @code{minibuffer-allow-text-properties} is
156non-@code{nil}, then the string which is returned includes whatever text
157properties were present in the minibuffer. Otherwise all the text
158properties are stripped when the value is returned.
159
160If the argument @var{inherit-input-method} is non-@code{nil}, then the
161minibuffer inherits the current input method (@pxref{Input Methods}) and
162the setting of @code{enable-multibyte-characters} (@pxref{Text
163Representations}) from whichever buffer was current before entering the
164minibuffer.
165
166Use of @var{initial-contents} is mostly deprecated; we recommend using
167a non-@code{nil} value only in conjunction with specifying a cons cell
168for @var{hist}. @xref{Initial Input}.
169@end defun
170
171@defun read-string prompt &optional initial history default inherit-input-method
172This function reads a string from the minibuffer and returns it. The
173arguments @var{prompt}, @var{initial}, @var{history} and
174@var{inherit-input-method} are used as in @code{read-from-minibuffer}.
175The keymap used is @code{minibuffer-local-map}.
176
177The optional argument @var{default} is used as in
178@code{read-from-minibuffer}, except that, if non-@code{nil}, it also
179specifies a default value to return if the user enters null input. As
c1d2409c
RS
180in @code{read-from-minibuffer} it should be a string, a list of
181strings, or @code{nil} which is equivalent to an empty string. When
182@var{default} is a string, that string is the default value. When it
183is a list of strings, the first string is the default value. (All
184these strings are available to the user in the ``future minibuffer
185history.'')
186
187This function works by calling the
b8d4c8d0
GM
188@code{read-from-minibuffer} function:
189
190@smallexample
191@group
192(read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit})
193@equiv{}
194(let ((value
195 (read-from-minibuffer @var{prompt} @var{initial} nil nil
196 @var{history} @var{default} @var{inherit})))
197 (if (and (equal value "") @var{default})
c066bafa 198 (if (consp @var{default}) (car @var{default}) @var{default})
b8d4c8d0
GM
199 value))
200@end group
201@end smallexample
202@end defun
203
204@defvar minibuffer-allow-text-properties
205If this variable is @code{nil}, then @code{read-from-minibuffer} strips
206all text properties from the minibuffer input before returning it.
207This variable also affects @code{read-string}. However,
208@code{read-no-blanks-input} (see below), as well as
209@code{read-minibuffer} and related functions (@pxref{Object from
210Minibuffer,, Reading Lisp Objects With the Minibuffer}), and all
211functions that do minibuffer input with completion, discard text
212properties unconditionally, regardless of the value of this variable.
213@end defvar
214
215@defvar minibuffer-local-map
216This
217@anchor{Definition of minibuffer-local-map}
218@c avoid page break at anchor; work around Texinfo deficiency
219is the default local keymap for reading from the minibuffer. By
220default, it makes the following bindings:
221
222@table @asis
223@item @kbd{C-j}
224@code{exit-minibuffer}
225
226@item @key{RET}
227@code{exit-minibuffer}
228
229@item @kbd{C-g}
230@code{abort-recursive-edit}
231
232@item @kbd{M-n}
233@itemx @key{DOWN}
234@code{next-history-element}
235
236@item @kbd{M-p}
237@itemx @key{UP}
238@code{previous-history-element}
239
240@item @kbd{M-s}
241@code{next-matching-history-element}
242
243@item @kbd{M-r}
244@code{previous-matching-history-element}
245@end table
246@end defvar
247
248@c In version 18, initial is required
249@c Emacs 19 feature
250@defun read-no-blanks-input prompt &optional initial inherit-input-method
251This function reads a string from the minibuffer, but does not allow
252whitespace characters as part of the input: instead, those characters
253terminate the input. The arguments @var{prompt}, @var{initial}, and
254@var{inherit-input-method} are used as in @code{read-from-minibuffer}.
255
256This is a simplified interface to the @code{read-from-minibuffer}
257function, and passes the value of the @code{minibuffer-local-ns-map}
258keymap as the @var{keymap} argument for that function. Since the keymap
259@code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is}
260possible to put a space into the string, by quoting it.
261
262This function discards text properties, regardless of the value of
263@code{minibuffer-allow-text-properties}.
264
265@smallexample
266@group
267(read-no-blanks-input @var{prompt} @var{initial})
268@equiv{}
269(let (minibuffer-allow-text-properties)
270 (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map))
271@end group
272@end smallexample
273@end defun
274
275@defvar minibuffer-local-ns-map
276This built-in variable is the keymap used as the minibuffer local keymap
277in the function @code{read-no-blanks-input}. By default, it makes the
278following bindings, in addition to those of @code{minibuffer-local-map}:
279
280@table @asis
281@item @key{SPC}
282@cindex @key{SPC} in minibuffer
283@code{exit-minibuffer}
284
285@item @key{TAB}
286@cindex @key{TAB} in minibuffer
287@code{exit-minibuffer}
288
289@item @kbd{?}
290@cindex @kbd{?} in minibuffer
291@code{self-insert-and-exit}
292@end table
293@end defvar
294
295@node Object from Minibuffer
296@section Reading Lisp Objects with the Minibuffer
297
298 This section describes functions for reading Lisp objects with the
299minibuffer.
300
301@defun read-minibuffer prompt &optional initial
302This function reads a Lisp object using the minibuffer, and returns it
303without evaluating it. The arguments @var{prompt} and @var{initial} are
304used as in @code{read-from-minibuffer}.
305
306This is a simplified interface to the
307@code{read-from-minibuffer} function:
308
309@smallexample
310@group
311(read-minibuffer @var{prompt} @var{initial})
312@equiv{}
313(let (minibuffer-allow-text-properties)
314 (read-from-minibuffer @var{prompt} @var{initial} nil t))
315@end group
316@end smallexample
317
318Here is an example in which we supply the string @code{"(testing)"} as
319initial input:
320
321@smallexample
322@group
323(read-minibuffer
324 "Enter an expression: " (format "%s" '(testing)))
325
326;; @r{Here is how the minibuffer is displayed:}
327@end group
328
329@group
330---------- Buffer: Minibuffer ----------
331Enter an expression: (testing)@point{}
332---------- Buffer: Minibuffer ----------
333@end group
334@end smallexample
335
336@noindent
337The user can type @key{RET} immediately to use the initial input as a
338default, or can edit the input.
339@end defun
340
341@defun eval-minibuffer prompt &optional initial
342This function reads a Lisp expression using the minibuffer, evaluates
343it, then returns the result. The arguments @var{prompt} and
344@var{initial} are used as in @code{read-from-minibuffer}.
345
346This function simply evaluates the result of a call to
347@code{read-minibuffer}:
348
349@smallexample
350@group
351(eval-minibuffer @var{prompt} @var{initial})
352@equiv{}
353(eval (read-minibuffer @var{prompt} @var{initial}))
354@end group
355@end smallexample
356@end defun
357
358@defun edit-and-eval-command prompt form
359This function reads a Lisp expression in the minibuffer, and then
360evaluates it. The difference between this command and
361@code{eval-minibuffer} is that here the initial @var{form} is not
362optional and it is treated as a Lisp object to be converted to printed
363representation rather than as a string of text. It is printed with
364@code{prin1}, so if it is a string, double-quote characters (@samp{"})
365appear in the initial text. @xref{Output Functions}.
366
367The first thing @code{edit-and-eval-command} does is to activate the
368minibuffer with @var{prompt} as the prompt. Then it inserts the printed
369representation of @var{form} in the minibuffer, and lets the user edit it.
370When the user exits the minibuffer, the edited text is read with
371@code{read} and then evaluated. The resulting value becomes the value
372of @code{edit-and-eval-command}.
373
374In the following example, we offer the user an expression with initial
375text which is a valid form already:
376
377@smallexample
378@group
379(edit-and-eval-command "Please edit: " '(forward-word 1))
380
381;; @r{After evaluation of the preceding expression,}
382;; @r{the following appears in the minibuffer:}
383@end group
384
385@group
386---------- Buffer: Minibuffer ----------
387Please edit: (forward-word 1)@point{}
388---------- Buffer: Minibuffer ----------
389@end group
390@end smallexample
391
392@noindent
393Typing @key{RET} right away would exit the minibuffer and evaluate the
394expression, thus moving point forward one word.
395@code{edit-and-eval-command} returns @code{nil} in this example.
396@end defun
397
398@node Minibuffer History
399@section Minibuffer History
400@cindex minibuffer history
401@cindex history list
402
403 A @dfn{minibuffer history list} records previous minibuffer inputs so
404the user can reuse them conveniently. A history list is actually a
405symbol, not a list; it is a variable whose value is a list of strings
406(previous inputs), most recent first.
407
408 There are many separate history lists, used for different kinds of
409inputs. It's the Lisp programmer's job to specify the right history
410list for each use of the minibuffer.
411
412 You specify the history list with the optional @var{hist} argument
413to either @code{read-from-minibuffer} or @code{completing-read}. Here
414are the possible values for it:
415
416@table @asis
417@item @var{variable}
418Use @var{variable} (a symbol) as the history list.
419
420@item (@var{variable} . @var{startpos})
421Use @var{variable} (a symbol) as the history list, and assume that the
422initial history position is @var{startpos} (a nonnegative integer).
423
424Specifying 0 for @var{startpos} is equivalent to just specifying the
425symbol @var{variable}. @code{previous-history-element} will display
426the most recent element of the history list in the minibuffer. If you
427specify a positive @var{startpos}, the minibuffer history functions
428behave as if @code{(elt @var{variable} (1- @var{STARTPOS}))} were the
429history element currently shown in the minibuffer.
430
431For consistency, you should also specify that element of the history
432as the initial minibuffer contents, using the @var{initial} argument
433to the minibuffer input function (@pxref{Initial Input}).
434@end table
435
436 If you don't specify @var{hist}, then the default history list
437@code{minibuffer-history} is used. For other standard history lists,
438see below. You can also create your own history list variable; just
439initialize it to @code{nil} before the first use.
440
441 Both @code{read-from-minibuffer} and @code{completing-read} add new
442elements to the history list automatically, and provide commands to
443allow the user to reuse items on the list. The only thing your program
444needs to do to use a history list is to initialize it and to pass its
445name to the input functions when you wish. But it is safe to modify the
446list by hand when the minibuffer input functions are not using it.
447
448 Emacs functions that add a new element to a history list can also
449delete old elements if the list gets too long. The variable
450@code{history-length} specifies the maximum length for most history
451lists. To specify a different maximum length for a particular history
452list, put the length in the @code{history-length} property of the
453history list symbol. The variable @code{history-delete-duplicates}
454specifies whether to delete duplicates in history.
455
456@defun add-to-history history-var newelt &optional maxelt keep-all
457This function adds a new element @var{newelt}, if it isn't the empty
458string, to the history list stored in the variable @var{history-var},
459and returns the updated history list. It limits the list length to
460the value of @var{maxelt} (if non-@code{nil}) or @code{history-length}
461(described below). The possible values of @var{maxelt} have the same
462meaning as the values of @code{history-length}.
463
464Normally, @code{add-to-history} removes duplicate members from the
465history list if @code{history-delete-duplicates} is non-@code{nil}.
466However, if @var{keep-all} is non-@code{nil}, that says not to remove
467duplicates, and to add @var{newelt} to the list even if it is empty.
468@end defun
469
470@defvar history-add-new-input
471If the value of this variable is @code{nil}, standard functions that
472read from the minibuffer don't add new elements to the history list.
473This lets Lisp programs explicitly manage input history by using
474@code{add-to-history}. By default, @code{history-add-new-input} is
475set to a non-@code{nil} value.
476@end defvar
477
478@defvar history-length
479The value of this variable specifies the maximum length for all
480history lists that don't specify their own maximum lengths. If the
481value is @code{t}, that means there no maximum (don't delete old
482elements). The value of @code{history-length} property of the history
483list variable's symbol, if set, overrides this variable for that
484particular history list.
485@end defvar
486
487@defvar history-delete-duplicates
488If the value of this variable is @code{t}, that means when adding a
489new history element, all previous identical elements are deleted.
490@end defvar
491
492 Here are some of the standard minibuffer history list variables:
493
494@defvar minibuffer-history
495The default history list for minibuffer history input.
496@end defvar
497
498@defvar query-replace-history
499A history list for arguments to @code{query-replace} (and similar
500arguments to other commands).
501@end defvar
502
503@defvar file-name-history
504A history list for file-name arguments.
505@end defvar
506
507@defvar buffer-name-history
508A history list for buffer-name arguments.
509@end defvar
510
511@defvar regexp-history
512A history list for regular expression arguments.
513@end defvar
514
515@defvar extended-command-history
516A history list for arguments that are names of extended commands.
517@end defvar
518
519@defvar shell-command-history
520A history list for arguments that are shell commands.
521@end defvar
522
523@defvar read-expression-history
524A history list for arguments that are Lisp expressions to evaluate.
525@end defvar
526
527@node Initial Input
528@section Initial Input
529
530Several of the functions for minibuffer input have an argument called
531@var{initial} or @var{initial-contents}. This is a mostly-deprecated
532feature for specifying that the minibuffer should start out with
533certain text, instead of empty as usual.
534
535If @var{initial} is a string, the minibuffer starts out containing the
536text of the string, with point at the end, when the user starts to
537edit the text. If the user simply types @key{RET} to exit the
538minibuffer, it will use the initial input string to determine the
539value to return.
540
541@strong{We discourage use of a non-@code{nil} value for
542@var{initial}}, because initial input is an intrusive interface.
543History lists and default values provide a much more convenient method
544to offer useful default inputs to the user.
545
546There is just one situation where you should specify a string for an
547@var{initial} argument. This is when you specify a cons cell for the
548@var{hist} or @var{history} argument. @xref{Minibuffer History}.
549
550@var{initial} can also be a cons cell of the form @code{(@var{string}
551. @var{position})}. This means to insert @var{string} in the
552minibuffer but put point at @var{position} within the string's text.
553
554As a historical accident, @var{position} was implemented
555inconsistently in different functions. In @code{completing-read},
556@var{position}'s value is interpreted as origin-zero; that is, a value
557of 0 means the beginning of the string, 1 means after the first
558character, etc. In @code{read-minibuffer}, and the other
559non-completion minibuffer input functions that support this argument,
5601 means the beginning of the string 2 means after the first character,
561etc.
562
563Use of a cons cell as the value for @var{initial} arguments is
564deprecated in user code.
565
566@node Completion
567@section Completion
568@cindex completion
569
570 @dfn{Completion} is a feature that fills in the rest of a name
571starting from an abbreviation for it. Completion works by comparing the
572user's input against a list of valid names and determining how much of
573the name is determined uniquely by what the user has typed. For
574example, when you type @kbd{C-x b} (@code{switch-to-buffer}) and then
575type the first few letters of the name of the buffer to which you wish
576to switch, and then type @key{TAB} (@code{minibuffer-complete}), Emacs
577extends the name as far as it can.
578
579 Standard Emacs commands offer completion for names of symbols, files,
580buffers, and processes; with the functions in this section, you can
581implement completion for other kinds of names.
582
583 The @code{try-completion} function is the basic primitive for
584completion: it returns the longest determined completion of a given
585initial string, with a given set of strings to match against.
586
587 The function @code{completing-read} provides a higher-level interface
588for completion. A call to @code{completing-read} specifies how to
589determine the list of valid names. The function then activates the
590minibuffer with a local keymap that binds a few keys to commands useful
591for completion. Other functions provide convenient simple interfaces
592for reading certain kinds of names with completion.
593
594@menu
595* Basic Completion:: Low-level functions for completing strings.
596 (These are too low level to use the minibuffer.)
597* Minibuffer Completion:: Invoking the minibuffer with completion.
598* Completion Commands:: Minibuffer commands that do completion.
599* High-Level Completion:: Convenient special cases of completion
600 (reading buffer name, file name, etc.)
601* Reading File Names:: Using completion to read file names.
602* Programmed Completion:: Writing your own completion-function.
603@end menu
604
605@node Basic Completion
606@subsection Basic Completion Functions
607
608 The completion functions @code{try-completion},
609@code{all-completions} and @code{test-completion} have nothing in
610themselves to do with minibuffers. We describe them in this chapter
611so as to keep them near the higher-level completion features that do
612use the minibuffer.
613
614 If you store a completion alist in a variable, you should mark the
615variable as ``risky'' with a non-@code{nil}
616@code{risky-local-variable} property.
617
618@defun try-completion string collection &optional predicate
619This function returns the longest common substring of all possible
620completions of @var{string} in @var{collection}. The value of
621@var{collection} must be a list of strings or symbols, an alist, an
622obarray, a hash table, or a function that implements a virtual set of
623strings (see below).
624
625Completion compares @var{string} against each of the permissible
626completions specified by @var{collection}; if the beginning of the
627permissible completion equals @var{string}, it matches. If no permissible
628completions match, @code{try-completion} returns @code{nil}. If only
629one permissible completion matches, and the match is exact, then
630@code{try-completion} returns @code{t}. Otherwise, the value is the
631longest initial sequence common to all the permissible completions that
632match.
633
634If @var{collection} is an alist (@pxref{Association Lists}), the
635permissible completions are the elements of the alist that are either
636strings, symbols, or conses whose @sc{car} is a string or symbol.
637Symbols are converted to strings using @code{symbol-name}. Other
638elements of the alist are ignored. (Remember that in Emacs Lisp, the
639elements of alists do not @emph{have} to be conses.) In particular, a
640list of strings or symbols is allowed, even though we usually do not
641think of such lists as alists.
642
643@cindex obarray in completion
644If @var{collection} is an obarray (@pxref{Creating Symbols}), the names
645of all symbols in the obarray form the set of permissible completions. The
646global variable @code{obarray} holds an obarray containing the names of
647all interned Lisp symbols.
648
649Note that the only valid way to make a new obarray is to create it
650empty and then add symbols to it one by one using @code{intern}.
651Also, you cannot intern a given symbol in more than one obarray.
652
653If @var{collection} is a hash table, then the keys that are strings
654are the possible completions. Other keys are ignored.
655
656You can also use a symbol that is a function as @var{collection}. Then
657the function is solely responsible for performing completion;
658@code{try-completion} returns whatever this function returns. The
659function is called with three arguments: @var{string}, @var{predicate}
660and @code{nil}. (The reason for the third argument is so that the same
661function can be used in @code{all-completions} and do the appropriate
662thing in either case.) @xref{Programmed Completion}.
663
664If the argument @var{predicate} is non-@code{nil}, then it must be a
665function of one argument, unless @var{collection} is a hash table, in
666which case it should be a function of two arguments. It is used to
667test each possible match, and the match is accepted only if
668@var{predicate} returns non-@code{nil}. The argument given to
669@var{predicate} is either a string or a cons cell (the @sc{car} of
670which is a string) from the alist, or a symbol (@emph{not} a symbol
671name) from the obarray. If @var{collection} is a hash table,
672@var{predicate} is called with two arguments, the string key and the
673associated value.
674
675In addition, to be acceptable, a completion must also match all the
676regular expressions in @code{completion-regexp-list}. (Unless
677@var{collection} is a function, in which case that function has to
678handle @code{completion-regexp-list} itself.)
679
680In the first of the following examples, the string @samp{foo} is
681matched by three of the alist @sc{car}s. All of the matches begin with
682the characters @samp{fooba}, so that is the result. In the second
683example, there is only one possible match, and it is exact, so the value
684is @code{t}.
685
686@smallexample
687@group
688(try-completion
689 "foo"
690 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
691 @result{} "fooba"
692@end group
693
694@group
695(try-completion "foo" '(("barfoo" 2) ("foo" 3)))
696 @result{} t
697@end group
698@end smallexample
699
700In the following example, numerous symbols begin with the characters
701@samp{forw}, and all of them begin with the word @samp{forward}. In
702most of the symbols, this is followed with a @samp{-}, but not in all,
703so no more than @samp{forward} can be completed.
704
705@smallexample
706@group
707(try-completion "forw" obarray)
708 @result{} "forward"
709@end group
710@end smallexample
711
712Finally, in the following example, only two of the three possible
713matches pass the predicate @code{test} (the string @samp{foobaz} is
714too short). Both of those begin with the string @samp{foobar}.
715
716@smallexample
717@group
718(defun test (s)
719 (> (length (car s)) 6))
720 @result{} test
721@end group
722@group
723(try-completion
724 "foo"
725 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
726 'test)
727 @result{} "foobar"
728@end group
729@end smallexample
730@end defun
731
732@defun all-completions string collection &optional predicate nospace
733This function returns a list of all possible completions of
734@var{string}. The arguments to this function (aside from
735@var{nospace}) are the same as those of @code{try-completion}. Also,
736this function uses @code{completion-regexp-list} in the same way that
737@code{try-completion} does. The optional argument @var{nospace} only
738matters if @var{string} is the empty string. In that case, if
739@var{nospace} is non-@code{nil}, completions that start with a space
740are ignored.
741
742If @var{collection} is a function, it is called with three arguments:
743@var{string}, @var{predicate} and @code{t}; then @code{all-completions}
744returns whatever the function returns. @xref{Programmed Completion}.
745
746Here is an example, using the function @code{test} shown in the
747example for @code{try-completion}:
748
749@smallexample
750@group
751(defun test (s)
752 (> (length (car s)) 6))
753 @result{} test
754@end group
755
756@group
757(all-completions
758 "foo"
759 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
760 'test)
761 @result{} ("foobar1" "foobar2")
762@end group
763@end smallexample
764@end defun
765
766@defun test-completion string collection &optional predicate
767@anchor{Definition of test-completion}
768This function returns non-@code{nil} if @var{string} is a valid
769completion possibility specified by @var{collection} and
770@var{predicate}. The arguments are the same as in
771@code{try-completion}. For instance, if @var{collection} is a list of
772strings, this is true if @var{string} appears in the list and
773@var{predicate} is satisfied.
774
775This function uses @code{completion-regexp-list} in the same
776way that @code{try-completion} does.
777
778If @var{predicate} is non-@code{nil} and if @var{collection} contains
779several strings that are equal to each other, as determined by
780@code{compare-strings} according to @code{completion-ignore-case},
781then @var{predicate} should accept either all or none of them.
782Otherwise, the return value of @code{test-completion} is essentially
783unpredictable.
784
785If @var{collection} is a function, it is called with three arguments,
786the values @var{string}, @var{predicate} and @code{lambda}; whatever
787it returns, @code{test-completion} returns in turn.
788@end defun
789
790@defvar completion-ignore-case
791If the value of this variable is non-@code{nil}, Emacs does not
792consider case significant in completion.
793@end defvar
794
795@defvar completion-regexp-list
796This is a list of regular expressions. The completion functions only
797consider a completion acceptable if it matches all regular expressions
798in this list, with @code{case-fold-search} (@pxref{Searching and Case})
799bound to the value of @code{completion-ignore-case}.
800@end defvar
801
802@defmac lazy-completion-table var fun
803This macro provides a way to initialize the variable @var{var} as a
804collection for completion in a lazy way, not computing its actual
805contents until they are first needed. You use this macro to produce a
806value that you store in @var{var}. The actual computation of the
807proper value is done the first time you do completion using @var{var}.
808It is done by calling @var{fun} with no arguments. The
809value @var{fun} returns becomes the permanent value of @var{var}.
810
811Here is an example of use:
812
813@smallexample
814(defvar foo (lazy-completion-table foo make-my-alist))
815@end smallexample
816@end defmac
817
818@node Minibuffer Completion
819@subsection Completion and the Minibuffer
820@cindex minibuffer completion
821@cindex reading from minibuffer with completion
822
823 This section describes the basic interface for reading from the
824minibuffer with completion.
825
826@defun completing-read prompt collection &optional predicate require-match initial hist default inherit-input-method
827This function reads a string in the minibuffer, assisting the user by
828providing completion. It activates the minibuffer with prompt
829@var{prompt}, which must be a string.
830
831The actual completion is done by passing @var{collection} and
832@var{predicate} to the function @code{try-completion}. This happens
833in certain commands bound in the local keymaps used for completion.
834Some of these commands also call @code{test-completion}. Thus, if
835@var{predicate} is non-@code{nil}, it should be compatible with
836@var{collection} and @code{completion-ignore-case}. @xref{Definition
837of test-completion}.
838
839If @var{require-match} is @code{nil}, the exit commands work regardless
840of the input in the minibuffer. If @var{require-match} is @code{t}, the
841usual minibuffer exit commands won't exit unless the input completes to
842an element of @var{collection}. If @var{require-match} is neither
843@code{nil} nor @code{t}, then the exit commands won't exit unless the
844input already in the buffer matches an element of @var{collection}.
845
846However, empty input is always permitted, regardless of the value of
c1d2409c
RS
847@var{require-match}; in that case, @code{completing-read} returns the
848first element of @var{default}, if it is a list; @code{""}, if
70ee951b
JL
849@var{default} is @code{nil}; or @var{default}. The string or strings
850in @var{default} are also available to the user through the history
c1d2409c 851commands.
b8d4c8d0
GM
852
853The function @code{completing-read} uses
854@code{minibuffer-local-completion-map} as the keymap if
855@var{require-match} is @code{nil}, and uses
856@code{minibuffer-local-must-match-map} if @var{require-match} is
857non-@code{nil}. @xref{Completion Commands}.
858
859The argument @var{hist} specifies which history list variable to use for
860saving the input and for minibuffer history commands. It defaults to
861@code{minibuffer-history}. @xref{Minibuffer History}.
862
863The argument @var{initial} is mostly deprecated; we recommend using a
864non-@code{nil} value only in conjunction with specifying a cons cell
865for @var{hist}. @xref{Initial Input}. For default input, use
866@var{default} instead.
867
868If the argument @var{inherit-input-method} is non-@code{nil}, then the
869minibuffer inherits the current input method (@pxref{Input
870Methods}) and the setting of @code{enable-multibyte-characters}
871(@pxref{Text Representations}) from whichever buffer was current before
872entering the minibuffer.
873
874If the built-in variable @code{completion-ignore-case} is
875non-@code{nil}, completion ignores case when comparing the input
876against the possible matches. @xref{Basic Completion}. In this mode
877of operation, @var{predicate} must also ignore case, or you will get
878surprising results.
879
880Here's an example of using @code{completing-read}:
881
882@smallexample
883@group
884(completing-read
885 "Complete a foo: "
886 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
887 nil t "fo")
888@end group
889
890@group
891;; @r{After evaluation of the preceding expression,}
892;; @r{the following appears in the minibuffer:}
893
894---------- Buffer: Minibuffer ----------
895Complete a foo: fo@point{}
896---------- Buffer: Minibuffer ----------
897@end group
898@end smallexample
899
900@noindent
901If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}},
902@code{completing-read} returns @code{barfoo}.
903
904The @code{completing-read} function binds variables to pass
905information to the commands that actually do completion.
906They are described in the following section.
907@end defun
908
909@node Completion Commands
910@subsection Minibuffer Commands that Do Completion
911
912 This section describes the keymaps, commands and user options used
913in the minibuffer to do completion. The description refers to the
914situation when Partial Completion mode is disabled (as it is by
915default). When enabled, this minor mode uses its own alternatives to
916some of the commands described below. @xref{Completion Options,,,
917emacs, The GNU Emacs Manual}, for a short description of Partial
918Completion mode.
919
920@defvar minibuffer-completion-table
921The value of this variable is the collection used for completion in
922the minibuffer. This is the global variable that contains what
923@code{completing-read} passes to @code{try-completion}. It is used by
924minibuffer completion commands such as @code{minibuffer-complete-word}.
925@end defvar
926
927@defvar minibuffer-completion-predicate
928This variable's value is the predicate that @code{completing-read}
929passes to @code{try-completion}. The variable is also used by the other
930minibuffer completion functions.
931@end defvar
932
933@defvar minibuffer-completion-confirm
934When the value of this variable is non-@code{nil}, Emacs asks for
935confirmation of a completion before exiting the minibuffer.
936@code{completing-read} binds this variable, and the function
937@code{minibuffer-complete-and-exit} checks the value before exiting.
938@end defvar
939
940@deffn Command minibuffer-complete-word
941This function completes the minibuffer contents by at most a single
942word. Even if the minibuffer contents have only one completion,
943@code{minibuffer-complete-word} does not add any characters beyond the
944first character that is not a word constituent. @xref{Syntax Tables}.
945@end deffn
946
947@deffn Command minibuffer-complete
948This function completes the minibuffer contents as far as possible.
949@end deffn
950
951@deffn Command minibuffer-complete-and-exit
952This function completes the minibuffer contents, and exits if
953confirmation is not required, i.e., if
954@code{minibuffer-completion-confirm} is @code{nil}. If confirmation
955@emph{is} required, it is given by repeating this command
956immediately---the command is programmed to work without confirmation
957when run twice in succession.
958@end deffn
959
960@deffn Command minibuffer-completion-help
961This function creates a list of the possible completions of the
962current minibuffer contents. It works by calling @code{all-completions}
963using the value of the variable @code{minibuffer-completion-table} as
964the @var{collection} argument, and the value of
965@code{minibuffer-completion-predicate} as the @var{predicate} argument.
966The list of completions is displayed as text in a buffer named
967@samp{*Completions*}.
968@end deffn
969
970@defun display-completion-list completions &optional common-substring
971This function displays @var{completions} to the stream in
972@code{standard-output}, usually a buffer. (@xref{Read and Print}, for more
973information about streams.) The argument @var{completions} is normally
974a list of completions just returned by @code{all-completions}, but it
975does not have to be. Each element may be a symbol or a string, either
976of which is simply printed. It can also be a list of two strings,
977which is printed as if the strings were concatenated. The first of
978the two strings is the actual completion, the second string serves as
979annotation.
980
981The argument @var{common-substring} is the prefix that is common to
982all the completions. With normal Emacs completion, it is usually the
983same as the string that was completed. @code{display-completion-list}
984uses this to highlight text in the completion list for better visual
985feedback. This is not needed in the minibuffer; for minibuffer
986completion, you can pass @code{nil}.
987
988This function is called by @code{minibuffer-completion-help}. The
989most common way to use it is together with
990@code{with-output-to-temp-buffer}, like this:
991
992@example
993(with-output-to-temp-buffer "*Completions*"
994 (display-completion-list
995 (all-completions (buffer-string) my-alist)
996 (buffer-string)))
997@end example
998@end defun
999
1000@defopt completion-auto-help
1001If this variable is non-@code{nil}, the completion commands
1002automatically display a list of possible completions whenever nothing
1003can be completed because the next character is not uniquely determined.
1004@end defopt
1005
1006@defvar minibuffer-local-completion-map
1007@code{completing-read} uses this value as the local keymap when an
1008exact match of one of the completions is not required. By default, this
1009keymap makes the following bindings:
1010
1011@table @asis
1012@item @kbd{?}
1013@code{minibuffer-completion-help}
1014
1015@item @key{SPC}
1016@code{minibuffer-complete-word}
1017
1018@item @key{TAB}
1019@code{minibuffer-complete}
1020@end table
1021
1022@noindent
1023with other characters bound as in @code{minibuffer-local-map}
1024(@pxref{Definition of minibuffer-local-map}).
1025@end defvar
1026
1027@defvar minibuffer-local-must-match-map
1028@code{completing-read} uses this value as the local keymap when an
1029exact match of one of the completions is required. Therefore, no keys
1030are bound to @code{exit-minibuffer}, the command that exits the
1031minibuffer unconditionally. By default, this keymap makes the following
1032bindings:
1033
1034@table @asis
1035@item @kbd{?}
1036@code{minibuffer-completion-help}
1037
1038@item @key{SPC}
1039@code{minibuffer-complete-word}
1040
1041@item @key{TAB}
1042@code{minibuffer-complete}
1043
1044@item @kbd{C-j}
1045@code{minibuffer-complete-and-exit}
1046
1047@item @key{RET}
1048@code{minibuffer-complete-and-exit}
1049@end table
1050
1051@noindent
1052with other characters bound as in @code{minibuffer-local-map}.
1053@end defvar
1054
1055@defvar minibuffer-local-filename-completion-map
1056This is like @code{minibuffer-local-completion-map}
1057except that it does not bind @key{SPC}. This keymap is used by the
1058function @code{read-file-name}.
1059@end defvar
1060
1061@defvar minibuffer-local-must-match-filename-map
1062This is like @code{minibuffer-local-must-match-map}
1063except that it does not bind @key{SPC}. This keymap is used by the
1064function @code{read-file-name}.
1065@end defvar
1066
1067@node High-Level Completion
1068@subsection High-Level Completion Functions
1069
1070 This section describes the higher-level convenient functions for
1071reading certain sorts of names with completion.
1072
1073 In most cases, you should not call these functions in the middle of a
1074Lisp function. When possible, do all minibuffer input as part of
1075reading the arguments for a command, in the @code{interactive}
1076specification. @xref{Defining Commands}.
1077
1078@defun read-buffer prompt &optional default existing
1079This function reads the name of a buffer and returns it as a string.
1080The argument @var{default} is the default name to use, the value to
1081return if the user exits with an empty minibuffer. If non-@code{nil},
c066bafa
JL
1082it should be a string, a list of strings, or a buffer. If it is
1083a list, the default value is the first element of this list. It is
1084mentioned in the prompt, but is not inserted in the minibuffer as
1085initial input.
b8d4c8d0
GM
1086
1087The argument @var{prompt} should be a string ending with a colon and a
1088space. If @var{default} is non-@code{nil}, the function inserts it in
1089@var{prompt} before the colon to follow the convention for reading from
1090the minibuffer with a default value (@pxref{Programming Tips}).
1091
1092If @var{existing} is non-@code{nil}, then the name specified must be
1093that of an existing buffer. The usual commands to exit the minibuffer
1094do not exit if the text is not valid, and @key{RET} does completion to
1095attempt to find a valid name. If @var{existing} is neither @code{nil}
1096nor @code{t}, confirmation is required after completion. (However,
1097@var{default} is not checked for validity; it is returned, whatever it
1098is, if the user exits with the minibuffer empty.)
1099
1100In the following example, the user enters @samp{minibuffer.t}, and
1101then types @key{RET}. The argument @var{existing} is @code{t}, and the
1102only buffer name starting with the given input is
1103@samp{minibuffer.texi}, so that name is the value.
1104
1105@example
1106(read-buffer "Buffer name: " "foo" t)
1107@group
1108;; @r{After evaluation of the preceding expression,}
1109;; @r{the following prompt appears,}
1110;; @r{with an empty minibuffer:}
1111@end group
1112
1113@group
1114---------- Buffer: Minibuffer ----------
1115Buffer name (default foo): @point{}
1116---------- Buffer: Minibuffer ----------
1117@end group
1118
1119@group
1120;; @r{The user types @kbd{minibuffer.t @key{RET}}.}
1121 @result{} "minibuffer.texi"
1122@end group
1123@end example
1124@end defun
1125
1126@defvar read-buffer-function
1127This variable specifies how to read buffer names. For example, if you
1128set this variable to @code{iswitchb-read-buffer}, all Emacs commands
1129that call @code{read-buffer} to read a buffer name will actually use the
1130@code{iswitchb} package to read it.
1131@end defvar
1132
1133@defun read-command prompt &optional default
1134This function reads the name of a command and returns it as a Lisp
1135symbol. The argument @var{prompt} is used as in
1136@code{read-from-minibuffer}. Recall that a command is anything for
1137which @code{commandp} returns @code{t}, and a command name is a symbol
1138for which @code{commandp} returns @code{t}. @xref{Interactive Call}.
1139
1140The argument @var{default} specifies what to return if the user enters
c066bafa
JL
1141null input. It can be a symbol, a string or a list of strings. If it
1142is a string, @code{read-command} interns it before returning it.
1143If it is a list, @code{read-command} returns the first element of this list.
1144If @var{default} is @code{nil}, that means no default has been
1145specified; then if the user enters null input, the return value is
1146@code{(intern "")}, that is, a symbol whose name is an empty string.
b8d4c8d0
GM
1147
1148@example
1149(read-command "Command name? ")
1150
1151@group
1152;; @r{After evaluation of the preceding expression,}
1153;; @r{the following prompt appears with an empty minibuffer:}
1154@end group
1155
1156@group
1157---------- Buffer: Minibuffer ----------
1158Command name?
1159---------- Buffer: Minibuffer ----------
1160@end group
1161@end example
1162
1163@noindent
1164If the user types @kbd{forward-c @key{RET}}, then this function returns
1165@code{forward-char}.
1166
1167The @code{read-command} function is a simplified interface to
1168@code{completing-read}. It uses the variable @code{obarray} so as to
1169complete in the set of extant Lisp symbols, and it uses the
1170@code{commandp} predicate so as to accept only command names:
1171
1172@cindex @code{commandp} example
1173@example
1174@group
1175(read-command @var{prompt})
1176@equiv{}
1177(intern (completing-read @var{prompt} obarray
1178 'commandp t nil))
1179@end group
1180@end example
1181@end defun
1182
1183@defun read-variable prompt &optional default
1184@anchor{Definition of read-variable}
1185This function reads the name of a user variable and returns it as a
1186symbol.
1187
c1d2409c
RS
1188The argument @var{default} specifies the default value to return if
1189the user enters null input. It can be a symbol, a string, or a list
1190of strings. If it is a string, @code{read-variable} interns it to
70ee951b 1191make the default value. If it is a list, @code{read-variable} interns
c1d2409c
RS
1192the first element. If @var{default} is @code{nil}, that means no
1193default has been specified; then if the user enters null input, the
1194return value is @code{(intern "")}.
b8d4c8d0
GM
1195
1196@example
1197@group
1198(read-variable "Variable name? ")
1199
1200;; @r{After evaluation of the preceding expression,}
1201;; @r{the following prompt appears,}
1202;; @r{with an empty minibuffer:}
1203@end group
1204
1205@group
1206---------- Buffer: Minibuffer ----------
1207Variable name? @point{}
1208---------- Buffer: Minibuffer ----------
1209@end group
1210@end example
1211
1212@noindent
1213If the user then types @kbd{fill-p @key{RET}}, @code{read-variable}
1214returns @code{fill-prefix}.
1215
1216In general, @code{read-variable} is similar to @code{read-command},
1217but uses the predicate @code{user-variable-p} instead of
1218@code{commandp}:
1219
1220@cindex @code{user-variable-p} example
1221@example
1222@group
1223(read-variable @var{prompt})
1224@equiv{}
1225(intern
1226 (completing-read @var{prompt} obarray
1227 'user-variable-p t nil))
1228@end group
1229@end example
1230@end defun
1231
1232 See also the functions @code{read-coding-system} and
1233@code{read-non-nil-coding-system}, in @ref{User-Chosen Coding Systems},
1234and @code{read-input-method-name}, in @ref{Input Methods}.
1235
1236@node Reading File Names
1237@subsection Reading File Names
1238@cindex read file names
1239@cindex prompt for file name
1240
1241 Here is another high-level completion function, designed for reading a
1242file name. It provides special features including automatic insertion
1243of the default directory.
1244
1245@defun read-file-name prompt &optional directory default existing initial predicate
1246This function reads a file name in the minibuffer, prompting with
1247@var{prompt} and providing completion.
1248
1249If @var{existing} is non-@code{nil}, then the user must specify the name
1250of an existing file; @key{RET} performs completion to make the name
1251valid if possible, and then refuses to exit if it is not valid. If the
1252value of @var{existing} is neither @code{nil} nor @code{t}, then
1253@key{RET} also requires confirmation after completion. If
1254@var{existing} is @code{nil}, then the name of a nonexistent file is
1255acceptable.
1256
1257@code{read-file-name} uses
1258@code{minibuffer-local-filename-completion-map} as the keymap if
1259@var{existing} is @code{nil}, and uses
1260@code{minibuffer-local-must-match-filename-map} if @var{existing} is
1261non-@code{nil}. @xref{Completion Commands}.
1262
1263The argument @var{directory} specifies the directory to use for
1264completion of relative file names. It should be an absolute directory
1265name. If @code{insert-default-directory} is non-@code{nil},
1266@var{directory} is also inserted in the minibuffer as initial input.
1267It defaults to the current buffer's value of @code{default-directory}.
1268
1269@c Emacs 19 feature
1270If you specify @var{initial}, that is an initial file name to insert
1271in the buffer (after @var{directory}, if that is inserted). In this
1272case, point goes at the beginning of @var{initial}. The default for
1273@var{initial} is @code{nil}---don't insert any file name. To see what
1274@var{initial} does, try the command @kbd{C-x C-v}. @strong{Please
1275note:} we recommend using @var{default} rather than @var{initial} in
1276most cases.
1277
1278If @var{default} is non-@code{nil}, then the function returns
1279@var{default} if the user exits the minibuffer with the same non-empty
1280contents that @code{read-file-name} inserted initially. The initial
1281minibuffer contents are always non-empty if
1282@code{insert-default-directory} is non-@code{nil}, as it is by
1283default. @var{default} is not checked for validity, regardless of the
1284value of @var{existing}. However, if @var{existing} is
1285non-@code{nil}, the initial minibuffer contents should be a valid file
1286(or directory) name. Otherwise @code{read-file-name} attempts
1287completion if the user exits without any editing, and does not return
1288@var{default}. @var{default} is also available through the history
1289commands.
1290
1291If @var{default} is @code{nil}, @code{read-file-name} tries to find a
1292substitute default to use in its place, which it treats in exactly the
1293same way as if it had been specified explicitly. If @var{default} is
1294@code{nil}, but @var{initial} is non-@code{nil}, then the default is
1295the absolute file name obtained from @var{directory} and
1296@var{initial}. If both @var{default} and @var{initial} are @code{nil}
1297and the buffer is visiting a file, @code{read-file-name} uses the
1298absolute file name of that file as default. If the buffer is not
1299visiting a file, then there is no default. In that case, if the user
1300types @key{RET} without any editing, @code{read-file-name} simply
1301returns the pre-inserted contents of the minibuffer.
1302
1303If the user types @key{RET} in an empty minibuffer, this function
1304returns an empty string, regardless of the value of @var{existing}.
1305This is, for instance, how the user can make the current buffer visit
1306no file using @code{M-x set-visited-file-name}.
1307
1308If @var{predicate} is non-@code{nil}, it specifies a function of one
1309argument that decides which file names are acceptable completion
1310possibilities. A file name is an acceptable value if @var{predicate}
1311returns non-@code{nil} for it.
1312
1313@code{read-file-name} does not automatically expand file names. You
1314must call @code{expand-file-name} yourself if an absolute file name is
1315required.
1316
1317Here is an example:
1318
1319@example
1320@group
1321(read-file-name "The file is ")
1322
1323;; @r{After evaluation of the preceding expression,}
1324;; @r{the following appears in the minibuffer:}
1325@end group
1326
1327@group
1328---------- Buffer: Minibuffer ----------
1329The file is /gp/gnu/elisp/@point{}
1330---------- Buffer: Minibuffer ----------
1331@end group
1332@end example
1333
1334@noindent
1335Typing @kbd{manual @key{TAB}} results in the following:
1336
1337@example
1338@group
1339---------- Buffer: Minibuffer ----------
1340The file is /gp/gnu/elisp/manual.texi@point{}
1341---------- Buffer: Minibuffer ----------
1342@end group
1343@end example
1344
1345@c Wordy to avoid overfull hbox in smallbook mode.
1346@noindent
1347If the user types @key{RET}, @code{read-file-name} returns the file name
1348as the string @code{"/gp/gnu/elisp/manual.texi"}.
1349@end defun
1350
1351@defvar read-file-name-function
1352If non-@code{nil}, this should be a function that accepts the same
1353arguments as @code{read-file-name}. When @code{read-file-name} is
1354called, it calls this function with the supplied arguments instead of
1355doing its usual work.
1356@end defvar
1357
1358@defvar read-file-name-completion-ignore-case
1359If this variable is non-@code{nil}, @code{read-file-name} ignores case
1360when performing completion.
1361@end defvar
1362
1363@defun read-directory-name prompt &optional directory default existing initial
1364This function is like @code{read-file-name} but allows only directory
1365names as completion possibilities.
1366
1367If @var{default} is @code{nil} and @var{initial} is non-@code{nil},
1368@code{read-directory-name} constructs a substitute default by
1369combining @var{directory} (or the current buffer's default directory
1370if @var{directory} is @code{nil}) and @var{initial}. If both
1371@var{default} and @var{initial} are @code{nil}, this function uses
1372@var{directory} as substitute default, or the current buffer's default
1373directory if @var{directory} is @code{nil}.
1374@end defun
1375
1376@defopt insert-default-directory
1377This variable is used by @code{read-file-name}, and thus, indirectly,
1378by most commands reading file names. (This includes all commands that
1379use the code letters @samp{f} or @samp{F} in their interactive form.
1380@xref{Interactive Codes,, Code Characters for interactive}.) Its
1381value controls whether @code{read-file-name} starts by placing the
1382name of the default directory in the minibuffer, plus the initial file
1383name if any. If the value of this variable is @code{nil}, then
1384@code{read-file-name} does not place any initial input in the
1385minibuffer (unless you specify initial input with the @var{initial}
1386argument). In that case, the default directory is still used for
1387completion of relative file names, but is not displayed.
1388
1389If this variable is @code{nil} and the initial minibuffer contents are
1390empty, the user may have to explicitly fetch the next history element
1391to access a default value. If the variable is non-@code{nil}, the
1392initial minibuffer contents are always non-empty and the user can
1393always request a default value by immediately typing @key{RET} in an
1394unedited minibuffer. (See above.)
1395
1396For example:
1397
1398@example
1399@group
1400;; @r{Here the minibuffer starts out with the default directory.}
1401(let ((insert-default-directory t))
1402 (read-file-name "The file is "))
1403@end group
1404
1405@group
1406---------- Buffer: Minibuffer ----------
1407The file is ~lewis/manual/@point{}
1408---------- Buffer: Minibuffer ----------
1409@end group
1410
1411@group
1412;; @r{Here the minibuffer is empty and only the prompt}
1413;; @r{appears on its line.}
1414(let ((insert-default-directory nil))
1415 (read-file-name "The file is "))
1416@end group
1417
1418@group
1419---------- Buffer: Minibuffer ----------
1420The file is @point{}
1421---------- Buffer: Minibuffer ----------
1422@end group
1423@end example
1424@end defopt
1425
1426@node Programmed Completion
1427@subsection Programmed Completion
1428@cindex programmed completion
1429
1430 Sometimes it is not possible to create an alist or an obarray
1431containing all the intended possible completions. In such a case, you
1432can supply your own function to compute the completion of a given string.
1433This is called @dfn{programmed completion}.
1434
1435 To use this feature, pass a symbol with a function definition as the
1436@var{collection} argument to @code{completing-read}. The function
1437@code{completing-read} arranges to pass your completion function along
1438to @code{try-completion} and @code{all-completions}, which will then let
1439your function do all the work.
1440
1441 The completion function should accept three arguments:
1442
1443@itemize @bullet
1444@item
1445The string to be completed.
1446
1447@item
1448The predicate function to filter possible matches, or @code{nil} if
1449none. Your function should call the predicate for each possible match,
1450and ignore the possible match if the predicate returns @code{nil}.
1451
1452@item
1453A flag specifying the type of operation.
1454@end itemize
1455
1456 There are three flag values for three operations:
1457
1458@itemize @bullet
1459@item
1460@code{nil} specifies @code{try-completion}. The completion function
1461should return the completion of the specified string, or @code{t} if the
1462string is a unique and exact match already, or @code{nil} if the string
1463matches no possibility.
1464
1465If the string is an exact match for one possibility, but also matches
1466other longer possibilities, the function should return the string, not
1467@code{t}.
1468
1469@item
1470@code{t} specifies @code{all-completions}. The completion function
1471should return a list of all possible completions of the specified
1472string.
1473
1474@item
1475@code{lambda} specifies @code{test-completion}. The completion
1476function should return @code{t} if the specified string is an exact
1477match for some possibility; @code{nil} otherwise.
1478@end itemize
1479
1480 It would be consistent and clean for completion functions to allow
1481lambda expressions (lists that are functions) as well as function
1482symbols as @var{collection}, but this is impossible. Lists as
1483completion tables already have other meanings, and it would be
1484unreliable to treat one differently just because it is also a possible
1485function. So you must arrange for any function you wish to use for
1486completion to be encapsulated in a symbol.
1487
1488 Emacs uses programmed completion when completing file names.
1489@xref{File Name Completion}.
1490
25c0d999
SM
1491@defun completion-table-dynamic function
1492This function is a convenient way to write a function that can act as
b8d4c8d0
GM
1493programmed completion function. The argument @var{function} should be
1494a function that takes one argument, a string, and returns an alist of
1495possible completions of it. You can think of
25c0d999 1496@code{completion-table-dynamic} as a transducer between that interface
b8d4c8d0 1497and the interface for programmed completion functions.
25c0d999 1498@end defun
b8d4c8d0
GM
1499
1500@node Yes-or-No Queries
1501@section Yes-or-No Queries
1502@cindex asking the user questions
1503@cindex querying the user
1504@cindex yes-or-no questions
1505
1506 This section describes functions used to ask the user a yes-or-no
1507question. The function @code{y-or-n-p} can be answered with a single
1508character; it is useful for questions where an inadvertent wrong answer
1509will not have serious consequences. @code{yes-or-no-p} is suitable for
1510more momentous questions, since it requires three or four characters to
1511answer.
1512
1513 If either of these functions is called in a command that was invoked
1514using the mouse---more precisely, if @code{last-nonmenu-event}
1515(@pxref{Command Loop Info}) is either @code{nil} or a list---then it
1516uses a dialog box or pop-up menu to ask the question. Otherwise, it
1517uses keyboard input. You can force use of the mouse or use of keyboard
1518input by binding @code{last-nonmenu-event} to a suitable value around
1519the call.
1520
1521 Strictly speaking, @code{yes-or-no-p} uses the minibuffer and
1522@code{y-or-n-p} does not; but it seems best to describe them together.
1523
1524@defun y-or-n-p prompt
1525This function asks the user a question, expecting input in the echo
1526area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the
1527user types @kbd{n}. This function also accepts @key{SPC} to mean yes
1528and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit,'' like
1529@kbd{C-g}, because the question might look like a minibuffer and for
1530that reason the user might try to use @kbd{C-]} to get out. The answer
1531is a single character, with no @key{RET} needed to terminate it. Upper
1532and lower case are equivalent.
1533
1534``Asking the question'' means printing @var{prompt} in the echo area,
1535followed by the string @w{@samp{(y or n) }}. If the input is not one of
1536the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}},
1537@kbd{@key{DEL}}, or something that quits), the function responds
1538@samp{Please answer y or n.}, and repeats the request.
1539
1540This function does not actually use the minibuffer, since it does not
1541allow editing of the answer. It actually uses the echo area (@pxref{The
1542Echo Area}), which uses the same screen space as the minibuffer. The
1543cursor moves to the echo area while the question is being asked.
1544
1545The answers and their meanings, even @samp{y} and @samp{n}, are not
1546hardwired. The keymap @code{query-replace-map} specifies them.
1547@xref{Search and Replace}.
1548
1549In the following example, the user first types @kbd{q}, which is
1550invalid. At the next prompt the user types @kbd{y}.
1551
1552@smallexample
1553@group
1554(y-or-n-p "Do you need a lift? ")
1555
1556;; @r{After evaluation of the preceding expression,}
1557;; @r{the following prompt appears in the echo area:}
1558@end group
1559
1560@group
1561---------- Echo area ----------
1562Do you need a lift? (y or n)
1563---------- Echo area ----------
1564@end group
1565
1566;; @r{If the user then types @kbd{q}, the following appears:}
1567
1568@group
1569---------- Echo area ----------
1570Please answer y or n. Do you need a lift? (y or n)
1571---------- Echo area ----------
1572@end group
1573
1574;; @r{When the user types a valid answer,}
1575;; @r{it is displayed after the question:}
1576
1577@group
1578---------- Echo area ----------
1579Do you need a lift? (y or n) y
1580---------- Echo area ----------
1581@end group
1582@end smallexample
1583
1584@noindent
1585We show successive lines of echo area messages, but only one actually
1586appears on the screen at a time.
1587@end defun
1588
1589@defun y-or-n-p-with-timeout prompt seconds default-value
1590Like @code{y-or-n-p}, except that if the user fails to answer within
1591@var{seconds} seconds, this function stops waiting and returns
1592@var{default-value}. It works by setting up a timer; see @ref{Timers}.
1593The argument @var{seconds} may be an integer or a floating point number.
1594@end defun
1595
1596@defun yes-or-no-p prompt
1597This function asks the user a question, expecting input in the
1598minibuffer. It returns @code{t} if the user enters @samp{yes},
1599@code{nil} if the user types @samp{no}. The user must type @key{RET} to
1600finalize the response. Upper and lower case are equivalent.
1601
1602@code{yes-or-no-p} starts by displaying @var{prompt} in the echo area,
1603followed by @w{@samp{(yes or no) }}. The user must type one of the
1604expected responses; otherwise, the function responds @samp{Please answer
1605yes or no.}, waits about two seconds and repeats the request.
1606
1607@code{yes-or-no-p} requires more work from the user than
1608@code{y-or-n-p} and is appropriate for more crucial decisions.
1609
1610Here is an example:
1611
1612@smallexample
1613@group
1614(yes-or-no-p "Do you really want to remove everything? ")
1615
1616;; @r{After evaluation of the preceding expression,}
1617;; @r{the following prompt appears,}
1618;; @r{with an empty minibuffer:}
1619@end group
1620
1621@group
1622---------- Buffer: minibuffer ----------
1623Do you really want to remove everything? (yes or no)
1624---------- Buffer: minibuffer ----------
1625@end group
1626@end smallexample
1627
1628@noindent
1629If the user first types @kbd{y @key{RET}}, which is invalid because this
1630function demands the entire word @samp{yes}, it responds by displaying
1631these prompts, with a brief pause between them:
1632
1633@smallexample
1634@group
1635---------- Buffer: minibuffer ----------
1636Please answer yes or no.
1637Do you really want to remove everything? (yes or no)
1638---------- Buffer: minibuffer ----------
1639@end group
1640@end smallexample
1641@end defun
1642
1643@node Multiple Queries
1644@section Asking Multiple Y-or-N Questions
1645
1646 When you have a series of similar questions to ask, such as ``Do you
1647want to save this buffer'' for each buffer in turn, you should use
1648@code{map-y-or-n-p} to ask the collection of questions, rather than
1649asking each question individually. This gives the user certain
1650convenient facilities such as the ability to answer the whole series at
1651once.
1652
1653@defun map-y-or-n-p prompter actor list &optional help action-alist no-cursor-in-echo-area
1654This function asks the user a series of questions, reading a
1655single-character answer in the echo area for each one.
1656
1657The value of @var{list} specifies the objects to ask questions about.
1658It should be either a list of objects or a generator function. If it is
1659a function, it should expect no arguments, and should return either the
1660next object to ask about, or @code{nil} meaning stop asking questions.
1661
1662The argument @var{prompter} specifies how to ask each question. If
1663@var{prompter} is a string, the question text is computed like this:
1664
1665@example
1666(format @var{prompter} @var{object})
1667@end example
1668
1669@noindent
1670where @var{object} is the next object to ask about (as obtained from
1671@var{list}).
1672
1673If not a string, @var{prompter} should be a function of one argument
1674(the next object to ask about) and should return the question text. If
1675the value is a string, that is the question to ask the user. The
1676function can also return @code{t} meaning do act on this object (and
1677don't ask the user), or @code{nil} meaning ignore this object (and don't
1678ask the user).
1679
1680The argument @var{actor} says how to act on the answers that the user
1681gives. It should be a function of one argument, and it is called with
1682each object that the user says yes for. Its argument is always an
1683object obtained from @var{list}.
1684
1685If the argument @var{help} is given, it should be a list of this form:
1686
1687@example
1688(@var{singular} @var{plural} @var{action})
1689@end example
1690
1691@noindent
1692where @var{singular} is a string containing a singular noun that
1693describes the objects conceptually being acted on, @var{plural} is the
1694corresponding plural noun, and @var{action} is a transitive verb
1695describing what @var{actor} does.
1696
1697If you don't specify @var{help}, the default is @code{("object"
1698"objects" "act on")}.
1699
1700Each time a question is asked, the user may enter @kbd{y}, @kbd{Y}, or
1701@key{SPC} to act on that object; @kbd{n}, @kbd{N}, or @key{DEL} to skip
1702that object; @kbd{!} to act on all following objects; @key{ESC} or
1703@kbd{q} to exit (skip all following objects); @kbd{.} (period) to act on
1704the current object and then exit; or @kbd{C-h} to get help. These are
1705the same answers that @code{query-replace} accepts. The keymap
1706@code{query-replace-map} defines their meaning for @code{map-y-or-n-p}
1707as well as for @code{query-replace}; see @ref{Search and Replace}.
1708
1709You can use @var{action-alist} to specify additional possible answers
1710and what they mean. It is an alist of elements of the form
1711@code{(@var{char} @var{function} @var{help})}, each of which defines one
1712additional answer. In this element, @var{char} is a character (the
1713answer); @var{function} is a function of one argument (an object from
1714@var{list}); @var{help} is a string.
1715
1716When the user responds with @var{char}, @code{map-y-or-n-p} calls
1717@var{function}. If it returns non-@code{nil}, the object is considered
1718``acted upon,'' and @code{map-y-or-n-p} advances to the next object in
1719@var{list}. If it returns @code{nil}, the prompt is repeated for the
1720same object.
1721
1722Normally, @code{map-y-or-n-p} binds @code{cursor-in-echo-area} while
1723prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it
1724does not do that.
1725
1726If @code{map-y-or-n-p} is called in a command that was invoked using the
1727mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command
1728Loop Info}) is either @code{nil} or a list---then it uses a dialog box
1729or pop-up menu to ask the question. In this case, it does not use
1730keyboard input or the echo area. You can force use of the mouse or use
1731of keyboard input by binding @code{last-nonmenu-event} to a suitable
1732value around the call.
1733
1734The return value of @code{map-y-or-n-p} is the number of objects acted on.
1735@end defun
1736
1737@node Reading a Password
1738@section Reading a Password
1739@cindex passwords, reading
1740
1741 To read a password to pass to another program, you can use the
1742function @code{read-passwd}.
1743
1744@defun read-passwd prompt &optional confirm default
1745This function reads a password, prompting with @var{prompt}. It does
1746not echo the password as the user types it; instead, it echoes @samp{.}
1747for each character in the password.
1748
1749The optional argument @var{confirm}, if non-@code{nil}, says to read the
1750password twice and insist it must be the same both times. If it isn't
1751the same, the user has to type it over and over until the last two
1752times match.
1753
1754The optional argument @var{default} specifies the default password to
1755return if the user enters empty input. If @var{default} is @code{nil},
1756then @code{read-passwd} returns the null string in that case.
1757@end defun
1758
1759@node Minibuffer Commands
1760@section Minibuffer Commands
1761
1762 This section describes some commands meant for use in the
1763minibuffer.
1764
1765@deffn Command exit-minibuffer
1766This command exits the active minibuffer. It is normally bound to
1767keys in minibuffer local keymaps.
1768@end deffn
1769
1770@deffn Command self-insert-and-exit
1771This command exits the active minibuffer after inserting the last
1772character typed on the keyboard (found in @code{last-command-char};
1773@pxref{Command Loop Info}).
1774@end deffn
1775
1776@deffn Command previous-history-element n
1777This command replaces the minibuffer contents with the value of the
1778@var{n}th previous (older) history element.
1779@end deffn
1780
1781@deffn Command next-history-element n
1782This command replaces the minibuffer contents with the value of the
1783@var{n}th more recent history element.
1784@end deffn
1785
1786@deffn Command previous-matching-history-element pattern n
1787This command replaces the minibuffer contents with the value of the
1788@var{n}th previous (older) history element that matches @var{pattern} (a
1789regular expression).
1790@end deffn
1791
1792@deffn Command next-matching-history-element pattern n
1793This command replaces the minibuffer contents with the value of the
1794@var{n}th next (newer) history element that matches @var{pattern} (a
1795regular expression).
1796@end deffn
1797
1798@node Minibuffer Windows
1799@section Minibuffer Windows
1800@cindex minibuffer windows
1801
1802 These functions access and select minibuffer windows
1803and test whether they are active.
1804
1805@defun active-minibuffer-window
1806This function returns the currently active minibuffer window, or
1807@code{nil} if none is currently active.
1808@end defun
1809
1810@defun minibuffer-window &optional frame
1811@anchor{Definition of minibuffer-window}
1812This function returns the minibuffer window used for frame @var{frame}.
1813If @var{frame} is @code{nil}, that stands for the current frame. Note
1814that the minibuffer window used by a frame need not be part of that
1815frame---a frame that has no minibuffer of its own necessarily uses some
1816other frame's minibuffer window.
1817@end defun
1818
1819@defun set-minibuffer-window window
1820This function specifies @var{window} as the minibuffer window to use.
1821This affects where the minibuffer is displayed if you put text in it
1822without invoking the usual minibuffer commands. It has no effect on
1823the usual minibuffer input functions because they all start by
1824choosing the minibuffer window according to the current frame.
1825@end defun
1826
1827@c Emacs 19 feature
1828@defun window-minibuffer-p &optional window
1829This function returns non-@code{nil} if @var{window} is a minibuffer
1830window.
1831@var{window} defaults to the selected window.
1832@end defun
1833
1834It is not correct to determine whether a given window is a minibuffer by
1835comparing it with the result of @code{(minibuffer-window)}, because
1836there can be more than one minibuffer window if there is more than one
1837frame.
1838
1839@defun minibuffer-window-active-p window
1840This function returns non-@code{nil} if @var{window}, assumed to be
1841a minibuffer window, is currently active.
1842@end defun
1843
1844@node Minibuffer Contents
1845@section Minibuffer Contents
1846
1847 These functions access the minibuffer prompt and contents.
1848
1849@defun minibuffer-prompt
1850This function returns the prompt string of the currently active
1851minibuffer. If no minibuffer is active, it returns @code{nil}.
1852@end defun
1853
1854@defun minibuffer-prompt-end
1855This function returns the current
1856position of the end of the minibuffer prompt, if a minibuffer is
1857current. Otherwise, it returns the minimum valid buffer position.
1858@end defun
1859
1860@defun minibuffer-prompt-width
1861This function returns the current display-width of the minibuffer
1862prompt, if a minibuffer is current. Otherwise, it returns zero.
1863@end defun
1864
1865@defun minibuffer-contents
1866This function returns the editable
1867contents of the minibuffer (that is, everything except the prompt) as
1868a string, if a minibuffer is current. Otherwise, it returns the
1869entire contents of the current buffer.
1870@end defun
1871
1872@defun minibuffer-contents-no-properties
1873This is like @code{minibuffer-contents}, except that it does not copy text
1874properties, just the characters themselves. @xref{Text Properties}.
1875@end defun
1876
1877@defun minibuffer-completion-contents
1878This is like @code{minibuffer-contents}, except that it returns only
1879the contents before point. That is the part that completion commands
1880operate on. @xref{Minibuffer Completion}.
1881@end defun
1882
1883@defun delete-minibuffer-contents
1884This function erases the editable contents of the minibuffer (that is,
1885everything except the prompt), if a minibuffer is current. Otherwise,
1886it erases the entire current buffer.
1887@end defun
1888
1889@node Recursive Mini
1890@section Recursive Minibuffers
1891@cindex recursive minibuffers
1892
1893 These functions and variables deal with recursive minibuffers
1894(@pxref{Recursive Editing}):
1895
1896@defun minibuffer-depth
1897This function returns the current depth of activations of the
1898minibuffer, a nonnegative integer. If no minibuffers are active, it
1899returns zero.
1900@end defun
1901
1902@defopt enable-recursive-minibuffers
1903If this variable is non-@code{nil}, you can invoke commands (such as
1904@code{find-file}) that use minibuffers even while the minibuffer window
1905is active. Such invocation produces a recursive editing level for a new
1906minibuffer. The outer-level minibuffer is invisible while you are
1907editing the inner one.
1908
1909If this variable is @code{nil}, you cannot invoke minibuffer
1910commands when the minibuffer window is active, not even if you switch to
1911another window to do it.
1912@end defopt
1913
1914@c Emacs 19 feature
1915If a command name has a property @code{enable-recursive-minibuffers}
1916that is non-@code{nil}, then the command can use the minibuffer to read
1917arguments even if it is invoked from the minibuffer. A command can
1918also achieve this by binding @code{enable-recursive-minibuffers}
1919to @code{t} in the interactive declaration (@pxref{Using Interactive}).
1920The minibuffer command @code{next-matching-history-element} (normally
1921@kbd{M-s} in the minibuffer) does the latter.
1922
1923@node Minibuffer Misc
1924@section Minibuffer Miscellany
1925
1926@defun minibufferp &optional buffer-or-name
1927This function returns non-@code{nil} if @var{buffer-or-name} is a
1928minibuffer. If @var{buffer-or-name} is omitted, it tests the current
1929buffer.
1930@end defun
1931
1932@defvar minibuffer-setup-hook
1933This is a normal hook that is run whenever the minibuffer is entered.
1934@xref{Hooks}.
1935@end defvar
1936
1937@defvar minibuffer-exit-hook
1938This is a normal hook that is run whenever the minibuffer is exited.
1939@xref{Hooks}.
1940@end defvar
1941
1942@defvar minibuffer-help-form
1943@anchor{Definition of minibuffer-help-form}
1944The current value of this variable is used to rebind @code{help-form}
1945locally inside the minibuffer (@pxref{Help Functions}).
1946@end defvar
1947
1948@defvar minibuffer-scroll-window
1949@anchor{Definition of minibuffer-scroll-window}
1950If the value of this variable is non-@code{nil}, it should be a window
1951object. When the function @code{scroll-other-window} is called in the
1952minibuffer, it scrolls this window.
1953@end defvar
1954
1955@defun minibuffer-selected-window
1956This function returns the window which was selected when the
1957minibuffer was entered. If selected window is not a minibuffer
1958window, it returns @code{nil}.
1959@end defun
1960
1961@defopt max-mini-window-height
1962This variable specifies the maximum height for resizing minibuffer
1963windows. If a float, it specifies a fraction of the height of the
1964frame. If an integer, it specifies a number of lines.
1965@end defopt
1966
1967@defun minibuffer-message string
1968This function displays @var{string} temporarily at the end of the
1969minibuffer text, for two seconds, or until the next input event
1970arrives, whichever comes first.
1971@end defun
1972
1973@ignore
1974 arch-tag: bba7f945-9078-477f-a2ce-18818a6e1218
1975@end ignore