Update & fix texi docs to build clean against makeinfo v5.2
[sxemacs] / info / lispref / minibuf.texi
1 @c -*-texinfo-*-
2 @c This is part of the SXEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
4 @c Copyright (C) 2005 Sebastian Freundt <hroptatyr@sxemacs.org>
5 @c See the file lispref.texi for copying conditions.
6 @setfilename ../../info/minibuf.info
7
8 @node Minibuffers, Command Loop, Read and Print, Top
9 @chapter Minibuffers
10 @cindex arguments, reading
11 @cindex complex arguments
12 @cindex minibuffer
13
14   A @dfn{minibuffer} is a special buffer that SXEmacs commands use to read
15 arguments more complicated than the single numeric prefix argument.
16 These arguments include file names, buffer names, and command names (as
17 in @kbd{M-x}).  The minibuffer is displayed on the bottom line of the
18 frame, in the same place as the echo area, but only while it is in
19 use for reading an argument.
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 * Completion::                How to invoke and customize completion.
28 * Yes-or-No Queries::         Asking a question with a simple answer.
29 * Multiple Queries::          Asking a series of similar questions.
30 * Reading a Password::        Reading a password from the terminal.
31 * Minibuffer Misc::           Various customization hooks and variables.
32 @end menu
33
34
35 @node Intro to Minibuffers, Text from Minibuffer, Minibuffers, Minibuffers
36 @section Introduction to Minibuffers
37
38   In most ways, a minibuffer is a normal SXEmacs buffer.  Most operations
39 @emph{within} a buffer, such as editing commands, work normally in a
40 minibuffer.  However, many operations for managing buffers do not apply
41 to minibuffers.  The name of a minibuffer always has the form @w{@samp{
42 *Minibuf-@var{number}}}, and it cannot be changed.  Minibuffers are
43 displayed only in special windows used only for minibuffers; these
44 windows always appear at the bottom of a frame.  (Sometimes frames have
45 no minibuffer window, and sometimes a special kind of frame contains
46 nothing but a minibuffer window; see @ref{Minibuffers and Frames}.)
47
48   The minibuffer's window is normally a single line.  You can resize it
49 temporarily with the window sizing commands; it reverts to its normal
50 size when the minibuffer is exited.  You can resize it permanently by
51 using the window sizing commands in the frame's other window, when the
52 minibuffer is not active.  If the frame contains just a minibuffer, you
53 can change the minibuffer's size by changing the frame's size.
54
55   If a command uses a minibuffer while there is an active minibuffer,
56 this is called a @dfn{recursive minibuffer}.  The first minibuffer is
57 named @w{@samp{ *Minibuf-0*}}.  Recursive minibuffers are named by
58 incrementing the number at the end of the name.  (The names begin with a
59 space so that they won't show up in normal buffer lists.)  Of several
60 recursive minibuffers, the innermost (or most recently entered) is the
61 active minibuffer.  We usually call this ``the'' minibuffer.  You can
62 permit or forbid recursive minibuffers by setting the variable
63 @code{enable-recursive-minibuffers}.
64
65   Like other buffers, a minibuffer may use any of several local keymaps
66 (@pxref{Keymaps}); these contain various exit commands and in some cases
67 completion commands (@pxref{Completion}).
68
69 @itemize @bullet
70 @item
71 @code{minibuffer-local-map} is for ordinary input (no completion).
72
73 @item
74 @code{minibuffer-local-completion-map} is for permissive completion.
75
76 @item
77 @code{minibuffer-local-must-match-map} is for strict completion and
78 for cautious completion.
79 @end itemize
80
81
82 @node Text from Minibuffer, Object from Minibuffer, Intro to Minibuffers, Minibuffers
83 @section Reading Text Strings with the Minibuffer
84
85   Most often, the minibuffer is used to read text as a string.  It can
86 also be used to read a Lisp object in textual form.  The most basic
87 primitive for minibuffer input is @code{read-from-minibuffer}; it can do
88 either one.
89
90   In most cases, you should not call minibuffer input functions in the
91 middle of a Lisp function.  Instead, do all minibuffer input as part of
92 reading the arguments for a command, in the @code{interactive} spec.
93 @xref{Defining Commands}.
94
95 @defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist abbrev-table default
96 This function is the most general way to get input through the
97 minibuffer.  By default, it accepts arbitrary text and returns it as a
98 string; however, if @var{read} is non-@code{nil}, then it uses
99 @code{read} to convert the text into a Lisp object (@pxref{Input
100 Functions}).
101
102 The first thing this function does is to activate a minibuffer and
103 display it with @var{prompt-string} as the prompt.  This value must be a
104 string.
105
106 Then, if @var{initial-contents} is a string, @code{read-from-minibuffer}
107 inserts it into the minibuffer, leaving point at the end.  The
108 minibuffer appears with this text as its contents.
109
110 @c Emacs 19 feature
111 The value of @var{initial-contents} may also be a cons cell of the form
112 @code{(@var{string} . @var{position})}.  This means to insert
113 @var{string} in the minibuffer but put point @var{position} characters
114 from the beginning, rather than at the end.
115
116 When the user types a command to exit the minibuffer,
117 @code{read-from-minibuffer} constructs the return value from the text in
118 the minibuffer.  Normally it returns a string containing that text.
119 However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer}
120 reads the text and returns the resulting Lisp object, unevaluated.
121 (@xref{Input Functions}, for information about reading.)
122
123 The argument @var{default} specifies a default value to make available
124 through the history commands.  It should be a string, or @code{nil}.
125
126 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to
127 use in the minibuffer.  If @var{keymap} is omitted or @code{nil}, the
128 value of @code{minibuffer-local-map} is used as the keymap.  Specifying
129 a keymap is the most important way to customize the minibuffer for
130 various applications such as completion.
131
132 The argument @var{abbrev-table} specifies @code{local-abbrev-table} in
133 the minibuffer (@pxref{Standard Abbrev Tables}).
134
135 The argument @var{hist} specifies which history list variable to use
136 for saving the input and for history commands used in the minibuffer.
137 It defaults to @code{minibuffer-history}.  @xref{Minibuffer History}.
138
139 When the user types a command to exit the minibuffer,
140 @code{read-from-minibuffer} uses the text in the minibuffer to produce
141 its return value.  Normally it simply makes a string containing that
142 text.  However, if @var{read} is non-@code{nil},
143 @code{read-from-minibuffer} reads the text and returns the resulting
144 Lisp object, unevaluated.  (@xref{Input Functions}, for information
145 about reading.)
146
147 @strong{Usage note:} The @var{initial-contents} argument and the
148 @var{default} argument are two alternative features for more or less the
149 same job.  It does not make sense to use both features in a single call
150 to @code{read-from-minibuffer}.  In general, we recommend using
151 @var{default}, since this permits the user to insert the default value
152 when it is wanted, but does not burden the user with deleting it from
153 the minibuffer on other occasions.  However, if user is supposed to edit
154 default value, @var{initial-contents} may be preferred.
155 @end defun
156
157 @defun read-string prompt &optional initial history default-value
158 This function reads a string from the minibuffer and returns it.  The
159 arguments @var{prompt} and @var{initial} are used as in
160 @code{read-from-minibuffer}.  The keymap used is
161 @code{minibuffer-local-map}.
162
163 The optional argument @var{history}, if non-@code{nil}, specifies a history
164 list and optionally the initial position in the list.  The optional
165 argument @var{default-value} specifies a default value to return if the user
166 enters null input; it should be a string.
167
168 This function is a simplified interface to the
169 @code{read-from-minibuffer} function:
170
171 @smallexample
172 @group
173 (read-string @var{prompt} @var{initial} @var{history} @var{default})
174 @equiv{}
175 (read-from-minibuffer @var{prompt} @var{initial} nil nil
176                       @var{history} nil @var{default})))
177 @end group
178 @end smallexample
179 @end defun
180
181 @defvar minibuffer-local-map
182 This is the default local keymap for reading from the minibuffer.  By
183 default, it makes the following bindings:
184
185 @table @asis
186 @item @kbd{C-j}
187 @code{exit-minibuffer}
188
189 @item @key{RET}
190 @code{exit-minibuffer}
191
192 @item @kbd{C-g}
193 @code{abort-recursive-edit}
194
195 @item @kbd{M-n}
196 @code{next-history-element}
197
198 @item @kbd{M-p}
199 @code{previous-history-element}
200
201 @item @kbd{M-r}
202 @code{next-matching-history-element}
203
204 @item @kbd{M-s}
205 @code{previous-matching-history-element}
206 @end table
207 @end defvar
208
209
210 @node Object from Minibuffer, Minibuffer History, Text from Minibuffer, Minibuffers
211 @section Reading Lisp Objects with the Minibuffer
212
213   This section describes functions for reading Lisp objects with the
214 minibuffer.
215
216 @defun read-expression prompt &optional initial history default-value
217 This function reads a Lisp object using the minibuffer, and returns it
218 without evaluating it.  The arguments @var{prompt} and @var{initial} are
219 used as in @code{read-from-minibuffer}.
220
221 The optional argument @var{history}, if non-@code{nil}, specifies a history
222 list and optionally the initial position in the list.  The optional
223 argument @var{default-value} specifies a default value to return if the
224 user enters null input; it should be a string.
225
226 This is a simplified interface to the
227 @code{read-from-minibuffer} function:
228
229 @smallexample
230 @group
231 (read-expression @var{prompt} @var{initial} @var{history} @var{default-value})
232 @equiv{}
233 (read-from-minibuffer @var{prompt} @var{initial} nil t
234                       @var{history} nil @var{default-value})
235 @end group
236 @end smallexample
237
238 Here is an example in which we supply the string @code{"(testing)"} as
239 initial input:
240
241 @smallexample
242 @group
243 (read-expression
244  "Enter an expression: " (format "%s" '(testing)))
245
246 ;; @r{Here is how the minibuffer is displayed:}
247 @end group
248
249 @group
250 ---------- Buffer: Minibuffer ----------
251 Enter an expression: (testing)@point{}
252 ---------- Buffer: Minibuffer ----------
253 @end group
254 @end smallexample
255
256 @noindent
257 The user can type @key{RET} immediately to use the initial input as a
258 default, or can edit the input.
259 @end defun
260
261 @defun read-minibuffer prompt &optional initial history default-value
262
263 This is a FSF Emacs compatible function.  Use @code{read-expression}
264 instead.
265 @end defun
266
267 @defun eval-minibuffer prompt &optional initial history default-value
268 This function reads a Lisp expression using the minibuffer, evaluates
269 it, then returns the result.  The arguments @var{prompt} and
270 @var{initial} are used as in @code{read-from-minibuffer}.
271
272 The optional argument @var{history}, if non-@code{nil}, specifies a history
273 list and optionally the initial position in the list.  The optional
274 argument @var{default-value} specifies a default value to return if the
275 user enters null input; it should be a string.
276
277 This function simply evaluates the result of a call to
278 @code{read-expression}:
279
280 @smallexample
281 @group
282 (eval-minibuffer @var{prompt} @var{initial})
283 @equiv{}
284 (eval (read-expression @var{prompt} @var{initial}))
285 @end group
286 @end smallexample
287 @end defun
288
289 @defun edit-and-eval-command prompt form &optional history
290 This function reads a Lisp expression in the minibuffer, and then
291 evaluates it.  The difference between this command and
292 @code{eval-minibuffer} is that here the initial @var{form} is not
293 optional and it is treated as a Lisp object to be converted to printed
294 representation rather than as a string of text.  It is printed with
295 @code{prin1}, so if it is a string, double-quote characters (@samp{"})
296 appear in the initial text.  @xref{Output Functions}.
297
298 The first thing @code{edit-and-eval-command} does is to activate the
299 minibuffer with @var{prompt} as the prompt.  Then it inserts the printed
300 representation of @var{form} in the minibuffer, and lets the user edit it.
301 When the user exits the minibuffer, the edited text is read with
302 @code{read} and then evaluated.  The resulting value becomes the value
303 of @code{edit-and-eval-command}.
304
305 In the following example, we offer the user an expression with initial
306 text which is a valid form already:
307
308 @smallexample
309 @group
310 (edit-and-eval-command "Please edit: " '(forward-word 1))
311
312 ;; @r{After evaluation of the preceding expression,}
313 ;;   @r{the following appears in the minibuffer:}
314 @end group
315
316 @group
317 ---------- Buffer: Minibuffer ----------
318 Please edit: (forward-word 1)@point{}
319 ---------- Buffer: Minibuffer ----------
320 @end group
321 @end smallexample
322
323 @noindent
324 Typing @key{RET} right away would exit the minibuffer and evaluate the
325 expression, thus moving point forward one word.
326 @code{edit-and-eval-command} returns @code{t} in this example.
327 @end defun
328
329
330 @node Minibuffer History, Completion, Object from Minibuffer, Minibuffers
331 @section Minibuffer History
332 @cindex minibuffer history
333 @cindex history list
334
335 A @dfn{minibuffer history list} records previous minibuffer inputs so
336 the user can reuse them conveniently.  A history list is actually a
337 symbol, not a list; it is a variable whose value is a list of strings
338 (previous inputs), most recent first.
339
340 There are many separate history lists, used for different kinds of
341 inputs.  It's the Lisp programmer's job to specify the right history
342 list for each use of the minibuffer.
343
344 The basic minibuffer input functions @code{read-from-minibuffer} and
345 @code{completing-read} both accept an optional argument named @var{hist}
346 which is how you specify the history list.  Here are the possible
347 values:
348
349 @table @asis
350 @item @var{variable}
351 Use @var{variable} (a symbol) as the history list.
352
353 @item (@var{variable} . @var{startpos})
354 Use @var{variable} (a symbol) as the history list, and assume that the
355 initial history position is @var{startpos} (an integer, counting from
356 zero which specifies the most recent element of the history).
357
358 If you specify @var{startpos}, then you should also specify that element
359 of the history as the initial minibuffer contents, for consistency.
360 @end table
361
362 If you don't specify @var{hist}, then the default history list
363 @code{minibuffer-history} is used.  For other standard history lists,
364 see below.  You can also create your own history list variable; just
365 initialize it to @code{nil} before the first use.
366
367 Both @code{read-from-minibuffer} and @code{completing-read} add new
368 elements to the history list automatically, and provide commands to
369 allow the user to reuse items on the list.  The only thing your program
370 needs to do to use a history list is to initialize it and to pass its
371 name to the input functions when you wish.  But it is safe to modify the
372 list by hand when the minibuffer input functions are not using it.
373
374   Here are some of the standard minibuffer history list variables:
375
376 @defvar minibuffer-history
377 The default history list for minibuffer history input.
378 @end defvar
379
380 @defvar query-replace-history
381 A history list for arguments to @code{query-replace} (and similar
382 arguments to other commands).
383 @end defvar
384
385 @defvar file-name-history
386 A history list for file name arguments.
387 @end defvar
388
389 @defvar regexp-history
390 A history list for regular expression arguments.
391 @end defvar
392
393 @defvar extended-command-history
394 A history list for arguments that are names of extended commands.
395 @end defvar
396
397 @defvar shell-command-history
398 A history list for arguments that are shell commands.
399 @end defvar
400
401 @defvar read-expression-history
402 A history list for arguments that are Lisp expressions to evaluate.
403 @end defvar
404
405 @defvar Info-minibuffer-history
406 A history list for Info mode's minibuffer.
407 @end defvar
408
409 @defvar Manual-page-minibuffer-history
410 A history list for @code{manual-entry}.
411 @end defvar
412
413   There are many other minibuffer history lists, defined by various
414 libraries.  An @kbd{M-x apropos} search for @samp{history} should prove
415 fruitful in discovering them.
416
417
418 @node Completion, Yes-or-No Queries, Minibuffer History, Minibuffers
419 @section Completion
420 @cindex completion
421
422   @dfn{Completion} is a feature that fills in the rest of a name
423 starting from an abbreviation for it.  Completion works by comparing the
424 user's input against a list of valid names and determining how much of
425 the name is determined uniquely by what the user has typed.  For
426 example, when you type @kbd{C-x b} (@code{switch-to-buffer}) and then
427 type the first few letters of the name of the buffer to which you wish
428 to switch, and then type @key{TAB} (@code{minibuffer-complete}), SXEmacs
429 extends the name as far as it can.
430
431   Standard SXEmacs commands offer completion for names of symbols, files,
432 buffers, and processes; with the functions in this section, you can
433 implement completion for other kinds of names.
434
435   The @code{try-completion} function is the basic primitive for
436 completion: it returns the longest determined completion of a given
437 initial string, with a given set of strings to match against.
438
439   The function @code{completing-read} provides a higher-level interface
440 for completion.  A call to @code{completing-read} specifies how to
441 determine the list of valid names.  The function then activates the
442 minibuffer with a local keymap that binds a few keys to commands useful
443 for completion.  Other functions provide convenient simple interfaces
444 for reading certain kinds of names with completion.
445
446 @menu
447 * Basic Completion::       Low-level functions for completing strings.
448                              (These are too low level to use the minibuffer.)
449 * Minibuffer Completion::  Invoking the minibuffer with completion.
450 * Completion Commands::    Minibuffer commands that do completion.
451 * High-Level Completion::  Convenient special cases of completion
452                              (reading buffer name, file name, etc.)
453 * Reading File Names::     Using completion to read file names.
454 * Programmed Completion::  Finding the completions for a given file name.
455 @end menu
456
457
458 @node Basic Completion, Minibuffer Completion, Completion, Completion
459 @subsection Basic Completion Functions
460
461   The two functions @code{try-completion} and @code{all-completions}
462 have nothing in themselves to do with minibuffers.  We describe them in
463 this chapter so as to keep them near the higher-level completion
464 features that do use the minibuffer.
465
466 @defun try-completion string collection &optional predicate
467 This function returns the longest common prefix of all possible
468 completions of @var{string} in @var{collection}.  The value of
469 @var{collection} must be an alist, an obarray, or a function that
470 implements a virtual set of strings (see below).
471
472 Completion compares @var{string} against each of the permissible
473 completions specified by @var{collection}; if the beginning of the
474 permissible completion equals @var{string}, it matches.  If no permissible
475 completions match, @code{try-completion} returns @code{nil}.  If only
476 one permissible completion matches, and the match is exact, then
477 @code{try-completion} returns @code{t}.  Otherwise, the value is the
478 longest initial sequence common to all the permissible completions that
479 match.
480
481 If @var{collection} is an alist (@pxref{Association Lists}), the
482 @sc{car}s of the alist elements form the set of permissible completions.
483
484 @cindex obarray in completion
485 If @var{collection} is an obarray (@pxref{Creating Symbols}), the names
486 of all symbols in the obarray form the set of permissible completions.  The
487 global variable @code{obarray} holds an obarray containing the names of
488 all interned Lisp symbols.
489
490 Note that the only valid way to make a new obarray is to create it
491 empty and then add symbols to it one by one using @code{intern}.
492 Also, you cannot intern a given symbol in more than one obarray.
493
494 If the argument @var{predicate} is non-@code{nil}, then it must be a
495 function of one argument.  It is used to test each possible match, and
496 the match is accepted only if @var{predicate} returns non-@code{nil}.
497 The argument given to @var{predicate} is either a cons cell from the alist
498 (the @sc{car} of which is a string) or else it is a symbol (@emph{not} a
499 symbol name) from the obarray.
500
501 You can also use a symbol that is a function as @var{collection}.  Then
502 the function is solely responsible for performing completion;
503 @code{try-completion} returns whatever this function returns.  The
504 function is called with three arguments: @var{string}, @var{predicate}
505 and @code{nil}.  (The reason for the third argument is so that the same
506 function can be used in @code{all-completions} and do the appropriate
507 thing in either case.)  @xref{Programmed Completion}.
508
509 In the first of the following examples, the string @samp{foo} is
510 matched by three of the alist @sc{car}s.  All of the matches begin with
511 the characters @samp{fooba}, so that is the result.  In the second
512 example, there is only one possible match, and it is exact, so the value
513 is @code{t}.
514
515 @smallexample
516 @group
517 (try-completion
518  "foo"
519  '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
520      @result{} "fooba"
521 @end group
522
523 @group
524 (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
525      @result{} t
526 @end group
527 @end smallexample
528
529 In the following example, numerous symbols begin with the characters
530 @samp{forw}, and all of them begin with the word @samp{forward}.  In
531 most of the symbols, this is followed with a @samp{-}, but not in all,
532 so no more than @samp{forward} can be completed.
533
534 @smallexample
535 @group
536 (try-completion "forw" obarray)
537      @result{} "forward"
538 @end group
539 @end smallexample
540
541 Finally, in the following example, only two of the three possible
542 matches pass the predicate @code{test} (the string @samp{foobaz} is
543 too short).  Both of those begin with the string @samp{foobar}.
544
545 @smallexample
546 @group
547 (defun test (s)
548   (> (length (car s)) 6))
549      @result{} test
550 @end group
551 @group
552 (try-completion
553  "foo"
554  '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
555  'test)
556      @result{} "foobar"
557 @end group
558 @end smallexample
559 @end defun
560
561 @defun all-completions string collection &optional predicate
562 This function returns a list of all possible completions of @var{string}.
563 The arguments to this function are the same as those of @code{try-completion}.
564
565 If @var{collection} is a function, it is called with three arguments:
566 @var{string}, @var{predicate} and @code{t}; then @code{all-completions}
567 returns whatever the function returns.  @xref{Programmed Completion}.
568
569 Here is an example, using the function @code{test} shown in the
570 example for @code{try-completion}:
571
572 @smallexample
573 @group
574 (defun test (s)
575   (> (length (car s)) 6))
576      @result{} test
577 @end group
578
579 @group
580 (all-completions
581  "foo"
582  '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
583  'test)
584      @result{} ("foobar1" "foobar2")
585 @end group
586 @end smallexample
587 @end defun
588
589 @defvar completion-ignore-case
590 If the value of this variable is
591 non-@code{nil}, SXEmacs does not consider case significant in completion.
592 @end defvar
593
594
595 @node Minibuffer Completion, Completion Commands, Basic Completion, Completion
596 @subsection Completion and the Minibuffer
597
598   This section describes the basic interface for reading from the
599 minibuffer with completion.
600
601 @defun completing-read prompt collection &optional predicate require-match initial hist default
602 This function reads a string in the minibuffer, assisting the user by
603 providing completion.  It activates the minibuffer with prompt
604 @var{prompt}, which must be a string.  If @var{initial} is
605 non-@code{nil}, @code{completing-read} inserts it into the minibuffer as
606 part of the input.  Then it allows the user to edit the input, providing
607 several commands to attempt completion.
608
609 The actual completion is done by passing @var{collection} and
610 @var{predicate} to the function @code{try-completion}.  This happens in
611 certain commands bound in the local keymaps used for completion.
612
613 If @var{require-match} is @code{t}, the usual minibuffer exit commands
614 won't exit unless the input completes to an element of @var{collection}.
615 If @var{require-match} is neither @code{nil} nor @code{t}, then the exit
616 commands won't exit unless the input typed is itself an element of
617 @var{collection}.  If @var{require-match} is @code{nil}, the exit
618 commands work regardless of the input in the minibuffer.
619
620 However, empty input is always permitted, regardless of the value of
621 @var{require-match}; in that case, @code{completing-read} returns
622 @var{default}.  The value of @var{default} (if non-@code{nil}) is also
623 available to the user through the history commands.
624
625 The user can exit with null input by typing @key{RET} with an empty
626 minibuffer.  Then @code{completing-read} returns @code{""}.  This is how
627 the user requests whatever default the command uses for the value being
628 read.  The user can return using @key{RET} in this way regardless of the
629 value of @var{require-match}, and regardless of whether the empty string
630 is included in @var{collection}.
631
632 The function @code{completing-read} works by calling
633 @code{read-expression}.  It uses @code{minibuffer-local-completion-map}
634 as the keymap if @var{require-match} is @code{nil}, and uses
635 @code{minibuffer-local-must-match-map} if @var{require-match} is
636 non-@code{nil}.  @xref{Completion Commands}.
637
638 The argument @var{hist} specifies which history list variable to use for
639 saving the input and for minibuffer history commands.  It defaults to
640 @code{minibuffer-history}.  @xref{Minibuffer History}.
641
642 Completion ignores case when comparing the input against the possible
643 matches, if the built-in variable @code{completion-ignore-case} is
644 non-@code{nil}.  @xref{Basic Completion}.
645
646 Here's an example of using @code{completing-read}:
647
648 @smallexample
649 @group
650 (completing-read
651  "Complete a foo: "
652  '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
653  nil t "fo")
654 @end group
655
656 @group
657 ;; @r{After evaluation of the preceding expression,}
658 ;;   @r{the following appears in the minibuffer:}
659
660 ---------- Buffer: Minibuffer ----------
661 Complete a foo: fo@point{}
662 ---------- Buffer: Minibuffer ----------
663 @end group
664 @end smallexample
665
666 @noindent
667 If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}},
668 @code{completing-read} returns @code{barfoo}.
669
670 The @code{completing-read} function binds three variables to pass
671 information to the commands that actually do completion.  These
672 variables are @code{minibuffer-completion-table},
673 @code{minibuffer-completion-predicate} and
674 @code{minibuffer-completion-confirm}.  For more information about them,
675 see @ref{Completion Commands}.
676 @end defun
677
678
679 @node Completion Commands, High-Level Completion, Minibuffer Completion, Completion
680 @subsection Minibuffer Commands That Do Completion
681
682   This section describes the keymaps, commands and user options used in
683 the minibuffer to do completion.
684
685 @defvar minibuffer-local-completion-map
686 @code{completing-read} uses this value as the local keymap when an
687 exact match of one of the completions is not required.  By default, this
688 keymap makes the following bindings:
689
690 @table @asis
691 @item @kbd{?}
692 @code{minibuffer-completion-help}
693
694 @item @key{SPC}
695 @code{minibuffer-complete-word}
696
697 @item @key{TAB}
698 @code{minibuffer-complete}
699 @end table
700
701 @noindent
702 with other characters bound as in @code{minibuffer-local-map}
703 (@pxref{Text from Minibuffer}).
704 @end defvar
705
706 @defvar minibuffer-local-must-match-map
707 @code{completing-read} uses this value as the local keymap when an
708 exact match of one of the completions is required.  Therefore, no keys
709 are bound to @code{exit-minibuffer}, the command that exits the
710 minibuffer unconditionally.  By default, this keymap makes the following
711 bindings:
712
713 @table @asis
714 @item @kbd{?}
715 @code{minibuffer-completion-help}
716
717 @item @key{SPC}
718 @code{minibuffer-complete-word}
719
720 @item @key{TAB}
721 @code{minibuffer-complete}
722
723 @item @kbd{C-j}
724 @code{minibuffer-complete-and-exit}
725
726 @item @key{RET}
727 @code{minibuffer-complete-and-exit}
728 @end table
729
730 @noindent
731 with other characters bound as in @code{minibuffer-local-map}.
732 @end defvar
733
734 @defvar minibuffer-completion-table
735 The value of this variable is the alist or obarray used for completion
736 in the minibuffer.  This is the global variable that contains what
737 @code{completing-read} passes to @code{try-completion}.  It is used by
738 minibuffer completion commands such as @code{minibuffer-complete-word}.
739 @end defvar
740
741 @defvar minibuffer-completion-predicate
742 This variable's value is the predicate that @code{completing-read}
743 passes to @code{try-completion}.  The variable is also used by the other
744 minibuffer completion functions.
745 @end defvar
746
747 @deffn Command minibuffer-complete-word
748 This function completes the minibuffer contents by at most a single
749 word.  Even if the minibuffer contents have only one completion,
750 @code{minibuffer-complete-word} does not add any characters beyond the
751 first character that is not a word constituent.  @xref{Syntax Tables}.
752 @end deffn
753
754 @deffn Command minibuffer-complete
755 This function completes the minibuffer contents as far as possible.
756 @end deffn
757
758 @deffn Command minibuffer-complete-and-exit
759 This function completes the minibuffer contents, and exits if
760 confirmation is not required, i.e., if
761 @code{minibuffer-completion-confirm} is @code{nil}.  If confirmation
762 @emph{is} required, it is given by repeating this command
763 immediately---the command is programmed to work without confirmation
764 when run twice in succession.
765 @end deffn
766
767 @defvar minibuffer-completion-confirm
768 When the value of this variable is non-@code{nil}, SXEmacs asks for
769 confirmation of a completion before exiting the minibuffer.  The
770 function @code{minibuffer-complete-and-exit} checks the value of this
771 variable before it exits.
772 @end defvar
773
774 @deffn Command minibuffer-completion-help
775 This function creates a list of the possible completions of the
776 current minibuffer contents.  It works by calling @code{all-completions}
777 using the value of the variable @code{minibuffer-completion-table} as
778 the @var{collection} argument, and the value of
779 @code{minibuffer-completion-predicate} as the @var{predicate} argument.
780 The list of completions is displayed as text in a buffer named
781 @samp{*Completions*}.
782 @end deffn
783
784 @defun display-completion-list completions &rest cl-keys
785 This function displays @var{completions} to the stream in
786 @code{standard-output}, usually a buffer.  (@xref{Read and Print}, for more
787 information about streams.)  The argument @var{completions} is normally
788 a list of completions just returned by @code{all-completions}, but it
789 does not have to be.  Each element may be a symbol or a string, either
790 of which is simply printed, or a list of two strings, which is printed
791 as if the strings were concatenated.
792
793 This function is called by @code{minibuffer-completion-help}.  The
794 most common way to use it is together with
795 @code{with-output-to-temp-buffer}, like this:
796
797 @example
798 (with-output-to-temp-buffer "*Completions*"
799   (display-completion-list
800     (all-completions (buffer-string) my-alist)))
801 @end example
802 @end defun
803
804 @defopt completion-auto-help
805 If this variable is non-@code{nil}, the completion commands
806 automatically display a list of possible completions whenever nothing
807 can be completed because the next character is not uniquely determined.
808 @end defopt
809
810
811 @node High-Level Completion, Reading File Names, Completion Commands, Completion
812 @subsection High-Level Completion  Functions
813
814   This section describes the higher-level convenient functions for
815 reading certain sorts of names with completion.
816
817   In most cases, you should not call these functions in the middle of a
818 Lisp function.  When possible, do all minibuffer input as part of
819 reading the arguments for a command, in the @code{interactive} spec.
820 @xref{Defining Commands}.
821
822 @defun read-buffer prompt &optional default existing
823 This function reads the name of a buffer and returns it as a string.
824 The argument @var{default} is the default name to use, the value to
825 return if the user exits with an empty minibuffer.  If non-@code{nil},
826 it should be a string or a buffer.  It is mentioned in the prompt, but
827 is not inserted in the minibuffer as initial input.
828
829 If @var{existing} is non-@code{nil}, then the name specified must be
830 that of an existing buffer.  The usual commands to exit the minibuffer
831 do not exit if the text is not valid, and @key{RET} does completion to
832 attempt to find a valid name.  (However, @var{default} is not checked
833 for validity; it is returned, whatever it is, if the user exits with the
834 minibuffer empty.)
835
836 In the following example, the user enters @samp{minibuffer.t}, and
837 then types @key{RET}.  The argument @var{existing} is @code{t}, and the
838 only buffer name starting with the given input is
839 @samp{minibuffer.texi}, so that name is the value.
840
841 @example
842 (read-buffer "Buffer name? " "foo" t)
843 @group
844 ;; @r{After evaluation of the preceding expression,}
845 ;;   @r{the following prompt appears,}
846 ;;   @r{with an empty minibuffer:}
847 @end group
848
849 @group
850 ---------- Buffer: Minibuffer ----------
851 Buffer name? (default foo) @point{}
852 ---------- Buffer: Minibuffer ----------
853 @end group
854
855 @group
856 ;; @r{The user types @kbd{minibuffer.t @key{RET}}.}
857      @result{} "minibuffer.texi"
858 @end group
859 @end example
860 @end defun
861
862 @defun read-command prompt &optional default-value
863 This function reads the name of a command and returns it as a Lisp
864 symbol.  The argument @var{prompt} is used as in
865 @code{read-from-minibuffer}.  Recall that a command is anything for
866 which @code{commandp} returns @code{t}, and a command name is a symbol
867 for which @code{commandp} returns @code{t}.  @xref{Interactive Call}.
868
869 The argument @var{default-value} specifies what to return if the user
870 enters null input.  It can be a symbol or a string; if it is a string,
871 @code{read-command} interns it before returning it.  If @var{default} is
872 @code{nil}, that means no default has been specified; then if the user
873 enters null input, the return value is @code{nil}.
874
875 @example
876 (read-command "Command name? ")
877
878 @group
879 ;; @r{After evaluation of the preceding expression,}
880 ;;   @r{the following prompt appears with an empty minibuffer:}
881 @end group
882
883 @group
884 ---------- Buffer: Minibuffer ----------
885 Command name?
886 ---------- Buffer: Minibuffer ----------
887 @end group
888 @end example
889
890 @noindent
891 If the user types @kbd{forward-c @key{RET}}, then this function returns
892 @code{forward-char}.
893
894 The @code{read-command} function is a simplified interface to the
895 function @code{completing-read}.  It uses the variable @code{obarray} so
896 as to complete in the set of extant Lisp symbols, and it uses the
897 @code{commandp} predicate so as to accept only command names:
898
899 @cindex @code{commandp} example
900 @example
901 @group
902 (read-command @var{prompt})
903 @equiv{}
904 (intern (completing-read @var{prompt} obarray
905                          'commandp t nil))
906 @end group
907 @end example
908 @end defun
909
910 @defun read-variable prompt &optional default-value
911 This function reads the name of a user variable and returns it as a
912 symbol.
913
914 The argument @var{default-value} specifies what to return if the user
915 enters null input.  It can be a symbol or a string; if it is a string,
916 @code{read-variable} interns it before returning it.  If @var{default-value}
917 is @code{nil}, that means no default has been specified; then if the
918 user enters null input, the return value is @code{nil}.
919
920 @example
921 @group
922 (read-variable "Variable name? ")
923
924 ;; @r{After evaluation of the preceding expression,}
925 ;;   @r{the following prompt appears,}
926 ;;   @r{with an empty minibuffer:}
927 @end group
928
929 @group
930 ---------- Buffer: Minibuffer ----------
931 Variable name? @point{}
932 ---------- Buffer: Minibuffer ----------
933 @end group
934 @end example
935
936 @noindent
937 If the user then types @kbd{fill-p @key{RET}}, @code{read-variable}
938 returns @code{fill-prefix}.
939
940 This function is similar to @code{read-command}, but uses the
941 predicate @code{user-variable-p} instead of @code{commandp}:
942
943 @cindex @code{user-variable-p} example
944 @example
945 @group
946 (read-variable @var{prompt})
947 @equiv{}
948 (intern
949  (completing-read @var{prompt} obarray
950                   'user-variable-p t nil))
951 @end group
952 @end example
953 @end defun
954
955
956 @node Reading File Names, Programmed Completion, High-Level Completion, Completion
957 @subsection Reading File Names
958
959   Here is another high-level completion function, designed for reading a
960 file name.  It provides special features including automatic insertion
961 of the default directory.
962
963 @defun read-file-name prompt &optional directory default existing initial history
964 This function reads a file name in the minibuffer, prompting with
965 @var{prompt} and providing completion.  If @var{default} is
966 non-@code{nil}, then the function returns @var{default} if the user just
967 types @key{RET}.  @var{default} is not checked for validity; it is
968 returned, whatever it is, if the user exits with the minibuffer empty.
969
970 If @var{existing} is non-@code{nil}, then the user must specify the name
971 of an existing file; @key{RET} performs completion to make the name
972 valid if possible, and then refuses to exit if it is not valid.  If the
973 value of @var{existing} is neither @code{nil} nor @code{t}, then
974 @key{RET} also requires confirmation after completion.  If
975 @var{existing} is @code{nil}, then the name of a nonexistent file is
976 acceptable.
977
978 The argument @var{directory} specifies the directory to use for
979 completion of relative file names.  If @code{insert-default-directory}
980 is non-@code{nil}, @var{directory} is also inserted in the minibuffer as
981 initial input.  It defaults to the current buffer's value of
982 @code{default-directory}.
983
984 @c Emacs 19 feature
985 If you specify @var{initial}, that is an initial file name to insert in
986 the buffer (after @var{directory}, if that is inserted).  In this
987 case, point goes at the beginning of @var{initial}.  The default for
988 @var{initial} is @code{nil}---don't insert any file name.  To see what
989 @var{initial} does, try the command @kbd{C-x C-v}.
990
991 Here is an example:
992
993 @example
994 @group
995 (read-file-name "The file is ")
996
997 ;; @r{After evaluation of the preceding expression,}
998 ;;   @r{the following appears in the minibuffer:}
999 @end group
1000
1001 @group
1002 ---------- Buffer: Minibuffer ----------
1003 The file is /gp/gnu/elisp/@point{}
1004 ---------- Buffer: Minibuffer ----------
1005 @end group
1006 @end example
1007
1008 @noindent
1009 Typing @kbd{manual @key{TAB}} results in the following:
1010
1011 @example
1012 @group
1013 ---------- Buffer: Minibuffer ----------
1014 The file is /gp/gnu/elisp/manual.texi@point{}
1015 ---------- Buffer: Minibuffer ----------
1016 @end group
1017 @end example
1018
1019 @c Wordy to avoid overfull hbox in smallbook mode.
1020 @noindent
1021 If the user types @key{RET}, @code{read-file-name} returns the file name
1022 as the string @code{"/gp/gnu/elisp/manual.texi"}.
1023 @end defun
1024
1025 @defopt insert-default-directory
1026 This variable is used by @code{read-file-name}.  Its value controls
1027 whether @code{read-file-name} starts by placing the name of the default
1028 directory in the minibuffer, plus the initial file name if any.  If the
1029 value of this variable is @code{nil}, then @code{read-file-name} does
1030 not place any initial input in the minibuffer (unless you specify
1031 initial input with the @var{initial} argument).  In that case, the
1032 default directory is still used for completion of relative file names,
1033 but is not displayed.
1034
1035 For example:
1036
1037 @example
1038 @group
1039 ;; @r{Here the minibuffer starts out with the default directory.}
1040 (let ((insert-default-directory t))
1041   (read-file-name "The file is "))
1042 @end group
1043
1044 @group
1045 ---------- Buffer: Minibuffer ----------
1046 The file is ~lewis/manual/@point{}
1047 ---------- Buffer: Minibuffer ----------
1048 @end group
1049
1050 @group
1051 ;; @r{Here the minibuffer is empty and only the prompt}
1052 ;;   @r{appears on its line.}
1053 (let ((insert-default-directory nil))
1054   (read-file-name "The file is "))
1055 @end group
1056
1057 @group
1058 ---------- Buffer: Minibuffer ----------
1059 The file is @point{}
1060 ---------- Buffer: Minibuffer ----------
1061 @end group
1062 @end example
1063 @end defopt
1064
1065
1066 @node Programmed Completion,  , Reading File Names, Completion
1067 @subsection Programmed Completion
1068 @cindex programmed completion
1069
1070   Sometimes it is not possible to create an alist or an obarray
1071 containing all the intended possible completions.  In such a case, you
1072 can supply your own function to compute the completion of a given string.
1073 This is called @dfn{programmed completion}.
1074
1075   To use this feature, pass a symbol with a function definition as the
1076 @var{collection} argument to @code{completing-read}.  The function
1077 @code{completing-read} arranges to pass your completion function along
1078 to @code{try-completion} and @code{all-completions}, which will then let
1079 your function do all the work.
1080
1081   The completion function should accept three arguments:
1082
1083 @itemize @bullet
1084 @item
1085 The string to be completed.
1086
1087 @item
1088 The predicate function to filter possible matches, or @code{nil} if
1089 none.  Your function should call the predicate for each possible match,
1090 and ignore the possible match if the predicate returns @code{nil}.
1091
1092 @item
1093 A flag specifying the type of operation.
1094 @end itemize
1095
1096   There are three flag values for three operations:
1097
1098 @itemize @bullet
1099 @item
1100 @code{nil} specifies @code{try-completion}.  The completion function
1101 should return the completion of the specified string, or @code{t} if the
1102 string is a unique and exact match already, or @code{nil} if the string
1103 matches no possibility.
1104
1105 If the string is an exact match for one possibility, but also matches
1106 other longer possibilities, the function should return the string, not
1107 @code{t}.
1108
1109 @item
1110 @code{t} specifies @code{all-completions}.  The completion function
1111 should return a list of all possible completions of the specified
1112 string.
1113
1114 @item
1115 @code{lambda} specifies a test for an exact match.  The completion
1116 function should return @code{t} if the specified string is an exact
1117 match for some possibility; @code{nil} otherwise.
1118 @end itemize
1119
1120   It would be consistent and clean for completion functions to allow
1121 lambda expressions (lists that are functions) as well as function
1122 symbols as @var{collection}, but this is impossible.  Lists as
1123 completion tables are already assigned another meaning---as alists.  It
1124 would be unreliable to fail to handle an alist normally because it is
1125 also a possible function.  So you must arrange for any function you wish
1126 to use for completion to be encapsulated in a symbol.
1127
1128   SXEmacs uses programmed completion when completing file names.
1129 @xref{File Name Completion}.
1130
1131
1132 @node Yes-or-No Queries, Multiple Queries, Completion, Minibuffers
1133 @section Yes-or-No Queries
1134 @cindex asking the user questions
1135 @cindex querying the user
1136 @cindex yes-or-no questions
1137
1138   This section describes functions used to ask the user a yes-or-no
1139 question.  The function @code{y-or-n-p} can be answered with a single
1140 character; it is useful for questions where an inadvertent wrong answer
1141 will not have serious consequences.  @code{yes-or-no-p} is suitable for
1142 more momentous questions, since it requires three or four characters to
1143 answer.  Variations of these functions can be used to ask a yes-or-no
1144 question using a dialog box, or optionally using one.
1145
1146    If either of these functions is called in a command that was invoked
1147 using the mouse, then it uses a dialog box or pop-up menu to ask the
1148 question.  Otherwise, it uses keyboard input.
1149
1150   Strictly speaking, @code{yes-or-no-p} uses the minibuffer and
1151 @code{y-or-n-p} does not; but it seems best to describe them together.
1152
1153 @defun y-or-n-p prompt
1154 This function asks the user a question, expecting input in the echo
1155 area.  It returns @code{t} if the user types @kbd{y}, @code{nil} if the
1156 user types @kbd{n}.  This function also accepts @key{SPC} to mean yes
1157 and @key{DEL} to mean no.  It accepts @kbd{C-]} to mean ``quit'', like
1158 @kbd{C-g}, because the question might look like a minibuffer and for
1159 that reason the user might try to use @kbd{C-]} to get out.  The answer
1160 is a single character, with no @key{RET} needed to terminate it.  Upper
1161 and lower case are equivalent.
1162
1163 ``Asking the question'' means printing @var{prompt} in the echo area,
1164 followed by the string @w{@samp{(y or n) }}.  If the input is not one of
1165 the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}},
1166 @kbd{@key{DEL}}, or something that quits), the function responds
1167 @samp{Please answer y or n.}, and repeats the request.
1168
1169 This function does not actually use the minibuffer, since it does not
1170 allow editing of the answer.  It actually uses the echo area (@pxref{The
1171 Echo Area}), which uses the same screen space as the minibuffer.  The
1172 cursor moves to the echo area while the question is being asked.
1173
1174 The answers and their meanings, even @samp{y} and @samp{n}, are not
1175 hardwired.  The keymap @code{query-replace-map} specifies them.
1176 @xref{Search and Replace}.
1177
1178 In the following example, the user first types @kbd{q}, which is
1179 invalid.  At the next prompt the user types @kbd{y}.
1180
1181 @smallexample
1182 @group
1183 (y-or-n-p "Do you need a lift? ")
1184
1185 ;; @r{After evaluation of the preceding expression,}
1186 ;;   @r{the following prompt appears in the echo area:}
1187 @end group
1188
1189 @group
1190 ---------- Echo area ----------
1191 Do you need a lift? (y or n)
1192 ---------- Echo area ----------
1193 @end group
1194
1195 ;; @r{If the user then types @kbd{q}, the following appears:}
1196
1197 @group
1198 ---------- Echo area ----------
1199 Please answer y or n.  Do you need a lift? (y or n)
1200 ---------- Echo area ----------
1201 @end group
1202
1203 ;; @r{When the user types a valid answer,}
1204 ;;   @r{it is displayed after the question:}
1205
1206 @group
1207 ---------- Echo area ----------
1208 Do you need a lift? (y or n) y
1209 ---------- Echo area ----------
1210 @end group
1211 @end smallexample
1212
1213 @noindent
1214 We show successive lines of echo area messages, but only one actually
1215 appears on the screen at a time.
1216 @end defun
1217
1218 @defun yes-or-no-p prompt
1219 This function asks the user a question, expecting input in the
1220 minibuffer.  It returns @code{t} if the user enters @samp{yes},
1221 @code{nil} if the user types @samp{no}.  The user must type @key{RET} to
1222 finalize the response.  Upper and lower case are equivalent.
1223
1224 @code{yes-or-no-p} starts by displaying @var{prompt} in the echo area,
1225 followed by @w{@samp{(yes or no) }}.  The user must type one of the
1226 expected responses; otherwise, the function responds @samp{Please answer
1227 yes or no.}, waits about two seconds and repeats the request.
1228
1229 @code{yes-or-no-p} requires more work from the user than
1230 @code{y-or-n-p} and is appropriate for more crucial decisions.
1231
1232 Here is an example:
1233
1234 @smallexample
1235 @group
1236 (yes-or-no-p "Do you really want to remove everything? ")
1237
1238 ;; @r{After evaluation of the preceding expression,}
1239 ;;   @r{the following prompt appears,}
1240 ;;   @r{with an empty minibuffer:}
1241 @end group
1242
1243 @group
1244 ---------- Buffer: minibuffer ----------
1245 Do you really want to remove everything? (yes or no)
1246 ---------- Buffer: minibuffer ----------
1247 @end group
1248 @end smallexample
1249
1250 @noindent
1251 If the user first types @kbd{y @key{RET}}, which is invalid because this
1252 function demands the entire word @samp{yes}, it responds by displaying
1253 these prompts, with a brief pause between them:
1254
1255 @smallexample
1256 @group
1257 ---------- Buffer: minibuffer ----------
1258 Please answer yes or no.
1259 Do you really want to remove everything? (yes or no)
1260 ---------- Buffer: minibuffer ----------
1261 @end group
1262 @end smallexample
1263 @end defun
1264
1265 @c The rest is SXEmacs stuff
1266 @defun yes-or-no-p-dialog-box prompt
1267 This function asks the user a ``y or n'' question with a popup dialog
1268 box.  It returns @code{t} if the answer is ``yes''.  @var{prompt} is the
1269 string to display to ask the question.
1270 @end defun
1271
1272 The following functions ask a question either in the minibuffer or a
1273 dialog box, depending on whether the last user event (which presumably
1274 invoked this command) was a keyboard or mouse event.  When SXEmacs is
1275 running on a window system, the functions @code{y-or-n-p} and
1276 @code{yes-or-no-p} are replaced with the following functions, so that
1277 menu items bring up dialog boxes instead of minibuffer questions.
1278
1279 @defun y-or-n-p-maybe-dialog-box prompt
1280 This function asks user a ``y or n'' question, using either a dialog box
1281 or the minibuffer, as appropriate.
1282 @end defun
1283
1284 @defun yes-or-no-p-maybe-dialog-box prompt
1285 This function asks user a ``yes or no'' question, using either a dialog
1286 box or the minibuffer, as appropriate.
1287 @end defun
1288
1289
1290 @node Multiple Queries, Reading a Password, Yes-or-No Queries, Minibuffers
1291 @section Asking Multiple Y-or-N Questions
1292
1293   When you have a series of similar questions to ask, such as ``Do you
1294 want to save this buffer'' for each buffer in turn, you should use
1295 @code{map-y-or-n-p} to ask the collection of questions, rather than
1296 asking each question individually.  This gives the user certain
1297 convenient facilities such as the ability to answer the whole series at
1298 once.
1299
1300 @defun map-y-or-n-p prompter actor list &optional help action-alist
1301 This function, new in Emacs 19, asks the user a series of questions,
1302 reading a single-character answer in the echo area for each one.
1303
1304 The value of @var{list} specifies the objects to ask questions about.
1305 It should be either a list of objects or a generator function.  If it is
1306 a function, it should expect no arguments, and should return either the
1307 next object to ask about, or @code{nil} meaning stop asking questions.
1308
1309 The argument @var{prompter} specifies how to ask each question.  If
1310 @var{prompter} is a string, the question text is computed like this:
1311
1312 @example
1313 (format @var{prompter} @var{object})
1314 @end example
1315
1316 @noindent
1317 where @var{object} is the next object to ask about (as obtained from
1318 @var{list}).
1319
1320 If not a string, @var{prompter} should be a function of one argument
1321 (the next object to ask about) and should return the question text.  If
1322 the value is a string, that is the question to ask the user.  The
1323 function can also return @code{t} meaning do act on this object (and
1324 don't ask the user), or @code{nil} meaning ignore this object (and don't
1325 ask the user).
1326
1327 The argument @var{actor} says how to act on the answers that the user
1328 gives.  It should be a function of one argument, and it is called with
1329 each object that the user says yes for.  Its argument is always an
1330 object obtained from @var{list}.
1331
1332 If the argument @var{help} is given, it should be a list of this form:
1333
1334 @example
1335 (@var{singular} @var{plural} @var{action})
1336 @end example
1337
1338 @noindent
1339 where @var{singular} is a string containing a singular noun that
1340 describes the objects conceptually being acted on, @var{plural} is the
1341 corresponding plural noun, and @var{action} is a transitive verb
1342 describing what @var{actor} does.
1343
1344 If you don't specify @var{help}, the default is @code{("object"
1345 "objects" "act on")}.
1346
1347 Each time a question is asked, the user may enter @kbd{y}, @kbd{Y}, or
1348 @key{SPC} to act on that object; @kbd{n}, @kbd{N}, or @key{DEL} to skip
1349 that object; @kbd{!} to act on all following objects; @key{ESC} or
1350 @kbd{q} to exit (skip all following objects); @kbd{.} (period) to act on
1351 the current object and then exit; or @kbd{C-h} to get help.  These are
1352 the same answers that @code{query-replace} accepts.  The keymap
1353 @code{query-replace-map} defines their meaning for @code{map-y-or-n-p}
1354 as well as for @code{query-replace}; see @ref{Search and Replace}.
1355
1356 You can use @var{action-alist} to specify additional possible answers
1357 and what they mean.  It is an alist of elements of the form
1358 @code{(@var{char} @var{function} @var{help})}, each of which defines one
1359 additional answer.  In this element, @var{char} is a character (the
1360 answer); @var{function} is a function of one argument (an object from
1361 @var{list}); @var{help} is a string.
1362
1363 When the user responds with @var{char}, @code{map-y-or-n-p} calls
1364 @var{function}.  If it returns non-@code{nil}, the object is considered
1365 ``acted upon'', and @code{map-y-or-n-p} advances to the next object in
1366 @var{list}.  If it returns @code{nil}, the prompt is repeated for the
1367 same object.
1368
1369 If @code{map-y-or-n-p} is called in a command that was invoked using the
1370 mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command
1371 Loop Info}) is either @code{nil} or a list---then it uses a dialog box
1372 or pop-up menu to ask the question.  In this case, it does not use
1373 keyboard input or the echo area.  You can force use of the mouse or use
1374 of keyboard input by binding @code{last-nonmenu-event} to a suitable
1375 value around the call.
1376
1377 The return value of @code{map-y-or-n-p} is the number of objects acted on.
1378 @end defun
1379
1380
1381 @node Reading a Password, Minibuffer Misc, Multiple Queries, Minibuffers
1382 @section Reading a Password
1383 @cindex passwords, reading
1384
1385   To read a password to pass to another program, you can use the
1386 function @code{read-passwd}.
1387
1388 @defun read-passwd prompt &optional confirm default
1389 This function reads a password, prompting with @var{prompt}.  It does
1390 not echo the password as the user types it; instead, it echoes @samp{.}
1391 for each character in the password.
1392
1393 The optional argument @var{confirm}, if non-@code{nil}, says to read the
1394 password twice and insist it must be the same both times.  If it isn't
1395 the same, the user has to type it over and over until the last two
1396 times match.
1397
1398 The optional argument @var{default} specifies the default password to
1399 return if the user enters empty input.  It is translated to @samp{.}
1400 and inserted in the minibuffer. If @var{default} is @code{nil}, then
1401 @code{read-passwd} returns the null string in that case.
1402 @end defun
1403
1404 @defopt passwd-invert-frame-when-keyboard-grabbed
1405 If non-@code{nil}, swap the foreground and background colors of all faces while
1406 reading a password.  Default values is @code{t}, unless feature
1407 @code{infodock} is provided.
1408 @end defopt
1409
1410 @defopt passwd-echo
1411 This specifies the character echoed when typing a password.  When @code{nil},
1412 nothing is echoed.
1413 @end defopt
1414
1415
1416 @node Minibuffer Misc,  , Reading a Password, Minibuffers
1417 @section Minibuffer Miscellany
1418
1419   This section describes some basic functions and variables related to
1420 minibuffers.
1421
1422 @deffn Command exit-minibuffer
1423 This command exits the active minibuffer.  It is normally bound to
1424 keys in minibuffer local keymaps.
1425 @end deffn
1426
1427 @deffn Command self-insert-and-exit
1428 This command exits the active minibuffer after inserting the last
1429 character typed on the keyboard (found in @code{last-command-char};
1430 @pxref{Command Loop Info}).
1431 @end deffn
1432
1433 @deffn Command previous-history-element n
1434 This command replaces the minibuffer contents with the value of the
1435 @var{n}th previous (older) history element.
1436 @end deffn
1437
1438 @deffn Command next-history-element n
1439 This command replaces the minibuffer contents with the value of the
1440 @var{n}th more recent history element.
1441 @end deffn
1442
1443 @deffn Command previous-matching-history-element pattern
1444 This command replaces the minibuffer contents with the value of the
1445 previous (older) history element that matches @var{pattern} (a regular
1446 expression).
1447 @end deffn
1448
1449 @deffn Command next-matching-history-element pattern
1450 This command replaces the minibuffer contents with the value of the next
1451 (newer) history element that matches @var{pattern} (a regular
1452 expression).
1453 @end deffn
1454
1455 @defun minibuffer-prompt
1456 This function returns the prompt string of the currently active
1457 minibuffer.  If no minibuffer is active, it returns @code{nil}.
1458 @end defun
1459
1460 @defun minibuffer-prompt-width
1461 This function returns the display width of the prompt string of the
1462 currently active minibuffer.  If no minibuffer is active, it returns 0.
1463 @end defun
1464
1465 @defvar minibuffer-setup-hook
1466 This is a normal hook that is run whenever the minibuffer is entered.
1467 @xref{Hooks}.
1468 @end defvar
1469
1470 @defvar minibuffer-exit-hook
1471 This is a normal hook that is run whenever the minibuffer is exited.
1472 @xref{Hooks}.
1473 @end defvar
1474
1475 @defvar minibuffer-help-form
1476 The current value of this variable is used to rebind @code{help-form}
1477 locally inside the minibuffer (@pxref{Help Functions}).
1478 @end defvar
1479
1480 @defun active-minibuffer-window
1481 This function returns the currently active minibuffer window, or
1482 @code{nil} if none is currently active.
1483 @end defun
1484
1485 @defun minibuffer-window &optional frame
1486 This function returns the minibuffer window used for frame @var{frame}.
1487 If @var{frame} is @code{nil}, that stands for the current frame.  Note
1488 that the minibuffer window used by a frame need not be part of that
1489 frame---a frame that has no minibuffer of its own necessarily uses some
1490 other frame's minibuffer window.
1491 @end defun
1492
1493 @c Emacs 19 feature
1494 @defun window-minibuffer-p &optional window
1495 This function returns non-@code{nil} if @var{window} is a minibuffer window.
1496 @end defun
1497
1498 It is not correct to determine whether a given window is a minibuffer by
1499 comparing it with the result of @code{(minibuffer-window)}, because
1500 there can be more than one minibuffer window if there is more than one
1501 frame.
1502
1503 @defun minibuffer-window-active-p window
1504 This function returns non-@code{nil} if @var{window}, assumed to be
1505 a minibuffer window, is currently active.
1506 @end defun
1507
1508 @defvar minibuffer-scroll-window
1509 If the value of this variable is non-@code{nil}, it should be a window
1510 object.  When the function @code{scroll-other-window} is called in the
1511 minibuffer, it scrolls this window.
1512 @end defvar
1513
1514 Finally, some functions and variables deal with recursive minibuffers
1515 (@pxref{Recursive Editing}):
1516
1517 @defun minibuffer-depth
1518 This function returns the current depth of activations of the
1519 minibuffer, a nonnegative integer.  If no minibuffers are active, it
1520 returns zero.
1521 @end defun
1522
1523 @defopt enable-recursive-minibuffers
1524 If this variable is non-@code{nil}, you can invoke commands (such as
1525 @code{find-file}) that use minibuffers even while the minibuffer window
1526 is active.  Such invocation produces a recursive editing level for a new
1527 minibuffer.  The outer-level minibuffer is invisible while you are
1528 editing the inner one.
1529
1530 This variable only affects invoking the minibuffer while the
1531 minibuffer window is selected.   If you switch windows while in the
1532 minibuffer, you can always invoke minibuffer commands while some other
1533 window is selected.
1534 @end defopt
1535
1536 @c Emacs 19 feature
1537 In FSF Emacs 19, if a command name has a property
1538 @code{enable-recursive-minibuffers} that is non-@code{nil}, then the
1539 command can use the minibuffer to read arguments even if it is invoked
1540 from the minibuffer.  The minibuffer command
1541 @code{next-matching-history-element} (normally @kbd{M-s} in the
1542 minibuffer) uses this feature.
1543
1544 This is not implemented in SXEmacs because it is a kludge.  If you
1545 want to explicitly set the value of @code{enable-recursive-minibuffers}
1546 in this fashion, just use an evaluated interactive spec and bind
1547 @code{enable-recursive-minibuffers} while reading from the minibuffer.
1548 See the definition of @code{next-matching-history-element} in
1549 @file{lisp/minibuf.el}.