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