aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-04-30 07:00:37 +0000
committerRichard M. Stallman1994-04-30 07:00:37 +0000
commit793da230a15d1b1293a667e569e02480408dd2c7 (patch)
tree8e8a07157ae931414478bc94da752d227cfe1536
parente333e8646bf92525dadc074d466901111e169a91 (diff)
downloademacs-793da230a15d1b1293a667e569e02480408dd2c7.tar.gz
emacs-793da230a15d1b1293a667e569e02480408dd2c7.zip
*** empty log message ***
-rw-r--r--lispref/minibuf.texi226
1 files changed, 125 insertions, 101 deletions
diff --git a/lispref/minibuf.texi b/lispref/minibuf.texi
index 51fd3ec4dce..ab7590ed705 100644
--- a/lispref/minibuf.texi
+++ b/lispref/minibuf.texi
@@ -41,7 +41,7 @@ windows always appear at the bottom of a frame. (Sometime frames have
41no minibuffer window, and sometimes a special kind of frame contains 41no minibuffer window, and sometimes a special kind of frame contains
42nothing but a minibuffer window; see @ref{Minibuffers and Frames}.) 42nothing but a minibuffer window; see @ref{Minibuffers and Frames}.)
43 43
44 The minibuffers window is normally a single line. You can resize it 44 The minibuffer's window is normally a single line. You can resize it
45temporarily with the window sizing commands; it reverts to its normal 45temporarily with the window sizing commands; it reverts to its normal
46size when the minibuffer is exited. You can resize it permanently by 46size when the minibuffer is exited. You can resize it permanently by
47using the window sizing commands in the frame's other window, when the 47using the window sizing commands in the frame's other window, when the
@@ -82,10 +82,10 @@ for cautious completion.
82@node Text from Minibuffer 82@node Text from Minibuffer
83@section Reading Text Strings with the Minibuffer 83@section Reading Text Strings with the Minibuffer
84 84
85 Most often, the minibuffer is used to read text which is returned as a 85 Most often, the minibuffer is used to read text as a string. It can
86string. It can also be used to read a Lisp object in textual form. The 86also be used to read a Lisp object in textual form. The most basic
87most basic primitive for minibuffer input is 87primitive for minibuffer input is @code{read-from-minibuffer}; it can do
88@code{read-from-minibuffer}; it can do either one. 88either one.
89 89
90@defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist 90@defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist
91This function is the most general way to get input through the 91This function is the most general way to get input through the
@@ -140,7 +140,7 @@ This is a simplified interface to the
140@group 140@group
141(read-string @var{prompt} @var{initial}) 141(read-string @var{prompt} @var{initial})
142@equiv{} 142@equiv{}
143(read-from-minibuffer @var{prompt} @var{initial} nil nil) 143(read-from-minibuffer @var{prompt} @var{initial} nil nil nil)
144@end group 144@end group
145@end smallexample 145@end smallexample
146@end defun 146@end defun
@@ -223,8 +223,11 @@ following bindings:
223@cindex @kbd{?} in minibuffer 223@cindex @kbd{?} in minibuffer
224@code{self-insert-and-exit} 224@code{self-insert-and-exit}
225 225
226@item @kbd{M-n} and @kbd{M-p} 226@item @kbd{M-n}
227@code{next-history-element} and @code{previous-history-element} 227@code{next-history-element}
228
229@item @kbd{M-p}
230@code{previous-history-element}
228 231
229@item @kbd{M-r} 232@item @kbd{M-r}
230@code{next-matching-history-element} 233@code{next-matching-history-element}
@@ -241,12 +244,11 @@ following bindings:
241minibuffer. 244minibuffer.
242 245
243@defun read-minibuffer prompt &optional initial 246@defun read-minibuffer prompt &optional initial
244 This function reads a Lisp object in the minibuffer and returns it, 247This function reads a Lisp object in the minibuffer and returns it,
245without evaluating it. The arguments @var{prompt} and @var{initial} are 248without evaluating it. The arguments @var{prompt} and @var{initial} are
246used as in @code{read-from-minibuffer}; in particular, @var{initial} 249used as in @code{read-from-minibuffer}.
247must be a string or @code{nil}.
248 250
249 This is a simplified interface to the 251This is a simplified interface to the
250@code{read-from-minibuffer} function: 252@code{read-from-minibuffer} function:
251 253
252@smallexample 254@smallexample
@@ -281,11 +283,11 @@ default, or can edit the input.
281@end defun 283@end defun
282 284
283@defun eval-minibuffer prompt &optional initial 285@defun eval-minibuffer prompt &optional initial
284 This function reads a Lisp expression in the minibuffer, evaluates it, 286This function reads a Lisp expression in the minibuffer, evaluates it,
285then returns the result. The arguments @var{prompt} and @var{initial} 287then returns the result. The arguments @var{prompt} and @var{initial}
286are used as in @code{read-from-minibuffer}. 288are used as in @code{read-from-minibuffer}.
287 289
288 This function simply evaluates the result of a call to 290This function simply evaluates the result of a call to
289@code{read-minibuffer}: 291@code{read-minibuffer}:
290 292
291@smallexample 293@smallexample
@@ -298,7 +300,7 @@ are used as in @code{read-from-minibuffer}.
298@end defun 300@end defun
299 301
300@defun edit-and-eval-command prompt form 302@defun edit-and-eval-command prompt form
301 This function reads a Lisp expression in the minibuffer, and then 303This function reads a Lisp expression in the minibuffer, and then
302evaluates it. The difference between this command and 304evaluates it. The difference between this command and
303@code{eval-minibuffer} is that here the initial @var{form} is not 305@code{eval-minibuffer} is that here the initial @var{form} is not
304optional and it is treated as a Lisp object to be converted to printed 306optional and it is treated as a Lisp object to be converted to printed
@@ -306,21 +308,21 @@ representation rather than as a string of text. It is printed with
306@code{prin1}, so if it is a string, double-quote characters (@samp{"}) 308@code{prin1}, so if it is a string, double-quote characters (@samp{"})
307appear in the initial text. @xref{Output Functions}. 309appear in the initial text. @xref{Output Functions}.
308 310
309 The first thing @code{edit-and-eval-command} does is to activate the 311The first thing @code{edit-and-eval-command} does is to activate the
310minibuffer with @var{prompt} as the prompt. Then it inserts the printed 312minibuffer with @var{prompt} as the prompt. Then it inserts the printed
311representation of @var{form} in the minibuffer, and lets the user edit. 313representation of @var{form} in the minibuffer, and lets the user edit.
312When the user exits the minibuffer, the edited text is read with 314When the user exits the minibuffer, the edited text is read with
313@code{read} and then evaluated. The resulting value becomes the value 315@code{read} and then evaluated. The resulting value becomes the value
314of @code{edit-and-eval-command}. 316of @code{edit-and-eval-command}.
315 317
316 In the following example, we offer the user an expression with initial 318In the following example, we offer the user an expression with initial
317text which is a valid form already: 319text which is a valid form already:
318 320
319@smallexample 321@smallexample
320@group 322@group
321(edit-and-eval-command "Please edit: " '(forward-word 1)) 323(edit-and-eval-command "Please edit: " '(forward-word 1))
322 324
323;; @r{After evaluating the preceding expression,} 325;; @r{After evaluation of the preceding expression,}
324;; @r{the following appears in the minibuffer:} 326;; @r{the following appears in the minibuffer:}
325@end group 327@end group
326 328
@@ -343,9 +345,9 @@ expression, thus moving point forward one word.
343@cindex history list 345@cindex history list
344 346
345A @dfn{minibuffer history list} records previous minibuffer inputs so 347A @dfn{minibuffer history list} records previous minibuffer inputs so
346the user can reuse them conveniently. A history list is a symbol, a 348the user can reuse them conveniently. A history list is actually a
347variable whose value is a list of strings (previous inputs), most recent 349symbol, not a list; it is a variable whose value is a list of strings
348first. 350(previous inputs), most recent first.
349 351
350There are many separate history lists, used for different kinds of 352There are many separate history lists, used for different kinds of
351inputs. It's the Lisp programmer's job to specify the right history 353inputs. It's the Lisp programmer's job to specify the right history
@@ -452,10 +454,15 @@ for reading certain kinds of names with completion.
452@node Basic Completion 454@node Basic Completion
453@subsection Basic Completion Functions 455@subsection Basic Completion Functions
454 456
457 The two functions @code{try-completion} and @code{all-completions}
458have nothing in themselves to do with minibuffers. We describe them in
459this chapter so as to keep them near the higher-level completion
460features that do use the minibuffer.
461
455@defun try-completion string collection &optional predicate 462@defun try-completion string collection &optional predicate
456This function returns the longest common substring of all possible 463This function returns the longest common substring of all possible
457completions of @var{string} in @var{collection}. The value of 464completions of @var{string} in @var{collection}. The value of
458@var{collection} must be an alist, an obarray, or a function which 465@var{collection} must be an alist, an obarray, or a function that
459implements a virtual set of strings (see below). 466implements a virtual set of strings (see below).
460 467
461Completion compares @var{string} against each of the permissible 468Completion compares @var{string} against each of the permissible
@@ -487,8 +494,8 @@ The argument given to @var{predicate} is either a cons cell from the alist
487(the @sc{car} of which is a string) or else it is a symbol (@emph{not} a 494(the @sc{car} of which is a string) or else it is a symbol (@emph{not} a
488symbol name) from the obarray. 495symbol name) from the obarray.
489 496
490You can also use a function symbol as @var{collection}. Then the 497You can also use a symbol that is a function as @var{collection}. Then
491function is solely responsible for performing completion; 498the function is solely responsible for performing completion;
492@code{try-completion} returns whatever this function returns. The 499@code{try-completion} returns whatever this function returns. The
493function is called with three arguments: @var{string}, @var{predicate} 500function is called with three arguments: @var{string}, @var{predicate}
494and @code{nil}. (The reason for the third argument is so that the same 501and @code{nil}. (The reason for the third argument is so that the same
@@ -541,7 +548,7 @@ too short). Both of those begin with the string @samp{foobar}.
541(try-completion 548(try-completion
542 "foo" 549 "foo"
543 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)) 550 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
544 'test) 551 'test)
545 @result{} "foobar" 552 @result{} "foobar"
546@end group 553@end group
547@end smallexample 554@end smallexample
@@ -570,7 +577,7 @@ example for @code{try-completion}:
570(all-completions 577(all-completions
571 "foo" 578 "foo"
572 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)) 579 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
573 (function test)) 580 'test)
574 @result{} ("foobar1" "foobar2") 581 @result{} ("foobar1" "foobar2")
575@end group 582@end group
576@end smallexample 583@end smallexample
@@ -581,11 +588,6 @@ If the value of this variable is
581non-@code{nil}, Emacs does not consider case significant in completion. 588non-@code{nil}, Emacs does not consider case significant in completion.
582@end defvar 589@end defvar
583 590
584 The two functions @code{try-completion} and @code{all-completions}
585have nothing in themselves to do with minibuffers. We describe them in
586this chapter so as to keep them near the higher-level completion
587features that do use the minibuffer.
588
589@node Minibuffer Completion 591@node Minibuffer Completion
590@subsection Completion and the Minibuffer 592@subsection Completion and the Minibuffer
591 593
@@ -608,13 +610,14 @@ If @var{require-match} is @code{t}, the usual minibuffer exit commands
608won't exit unless the input completes to an element of @var{collection}. 610won't exit unless the input completes to an element of @var{collection}.
609If @var{require-match} is neither @code{nil} nor @code{t}, then the exit 611If @var{require-match} is neither @code{nil} nor @code{t}, then the exit
610commands won't exit unless the input typed is itself an element of 612commands won't exit unless the input typed is itself an element of
611@var{collection}. 613@var{collection}. If @var{require-match} is @code{nil}, the exit
614commands work regardless of the input in the minibuffer.
612 615
613The function @code{completing-read} works by calling 616The function @code{completing-read} works by calling
614@code{read-minibuffer}. It uses @code{minibuffer-local-completion-map} 617@code{read-minibuffer}. It uses @code{minibuffer-local-completion-map}
615as the keymap if @var{require-match} is @code{nil}, and uses 618as the keymap if @var{require-match} is @code{nil}, and uses
616@code{minibuffer-local-must-match-map} if @var{require-match} is 619@code{minibuffer-local-must-match-map} if @var{require-match} is
617non-@code{nil}. 620non-@code{nil}. @xref{Completion Commands}.
618 621
619The argument @var{hist} specifies which history list variable to use for 622The argument @var{hist} specifies which history list variable to use for
620saving the input and for minibuffer history commands. It defaults to 623saving the input and for minibuffer history commands. It defaults to
@@ -635,7 +638,7 @@ Here's an example of using @code{completing-read}:
635@end group 638@end group
636 639
637@group 640@group
638;; @r{After evaluating the preceding expression,} 641;; @r{After evaluation of the preceding expression,}
639;; @r{the following appears in the minibuffer:} 642;; @r{the following appears in the minibuffer:}
640 643
641---------- Buffer: Minibuffer ---------- 644---------- Buffer: Minibuffer ----------
@@ -649,22 +652,11 @@ If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}},
649@code{completing-read} returns @code{barfoo}. 652@code{completing-read} returns @code{barfoo}.
650 653
651The @code{completing-read} function binds three variables to pass 654The @code{completing-read} function binds three variables to pass
652information to the commands which actually do completion. Here they 655information to the commands that actually do completion. These
653are: 656variables are @code{minibuffer-completion-table},
654 657@code{minibuffer-completion-predicate} and
655@table @code 658@code{minibuffer-completion-confirm}. For more information about them,
656@item minibuffer-completion-table 659see @ref{Completion Commands}.
657This variable is bound to the @var{collection} argument. It is passed
658to the @code{try-completion} function.
659
660@item minibuffer-completion-predicate
661This variable is bound to the @var{predicate} argument. It is passed to
662the @code{try-completion} function.
663
664@item minibuffer-completion-confirm
665This variable is bound to the @var{require-match} argument. It is used
666in the @code{minibuffer-complete-and-exit} function.
667@end table
668@end defun 660@end defun
669 661
670@node Completion Commands 662@node Completion Commands
@@ -674,7 +666,7 @@ in the @code{minibuffer-complete-and-exit} function.
674the minibuffer to do completion. 666the minibuffer to do completion.
675 667
676@defvar minibuffer-local-completion-map 668@defvar minibuffer-local-completion-map
677 @code{completing-read} uses this value as the local keymap when an 669@code{completing-read} uses this value as the local keymap when an
678exact match of one of the completions is not required. By default, this 670exact match of one of the completions is not required. By default, this
679keymap makes the following bindings: 671keymap makes the following bindings:
680 672
@@ -690,13 +682,14 @@ keymap makes the following bindings:
690@end table 682@end table
691 683
692@noindent 684@noindent
693with other characters bound as in @code{minibuffer-local-map}. 685with other characters bound as in @code{minibuffer-local-map}
686(@pxref{Text from Minibuffer}).
694@end defvar 687@end defvar
695 688
696@defvar minibuffer-local-must-match-map 689@defvar minibuffer-local-must-match-map
697@code{completing-read} uses this value as the local keymap when an 690@code{completing-read} uses this value as the local keymap when an
698exact match of one of the completions is required. Therefore, no keys 691exact match of one of the completions is required. Therefore, no keys
699are bound to @code{exit-minibuffer}, the command which exits the 692are bound to @code{exit-minibuffer}, the command that exits the
700minibuffer unconditionally. By default, this keymap makes the following 693minibuffer unconditionally. By default, this keymap makes the following
701bindings: 694bindings:
702 695
@@ -749,7 +742,9 @@ This function completes the minibuffer contents as far as possible.
749This function completes the minibuffer contents, and exits if 742This function completes the minibuffer contents, and exits if
750confirmation is not required, i.e., if 743confirmation is not required, i.e., if
751@code{minibuffer-completion-confirm} is non-@code{nil}. If confirmation 744@code{minibuffer-completion-confirm} is non-@code{nil}. If confirmation
752@emph{is} required, it is given by repeating this command immediately. 745@emph{is} required, it is given by repeating this command
746immediately---the command is programmed to work without confirmation
747when run twice in succession.
753@end deffn 748@end deffn
754 749
755@defvar minibuffer-completion-confirm 750@defvar minibuffer-completion-confirm
@@ -809,11 +804,11 @@ it should be a string or a buffer. It is mentioned in the prompt, but
809is not inserted in the minibuffer as initial input. 804is not inserted in the minibuffer as initial input.
810 805
811If @var{existing} is non-@code{nil}, then the name specified must be 806If @var{existing} is non-@code{nil}, then the name specified must be
812that of an existing buffer. The usual commands to exit the 807that of an existing buffer. The usual commands to exit the minibuffer
813minibuffer do not exit if the text is not valid, and @key{RET} does 808do not exit if the text is not valid, and @key{RET} does completion to
814completion to attempt to find a valid name. (However, @var{default} is 809attempt to find a valid name. (However, @var{default} is not checked
815not checked for this; it is returned, whatever it is, if the user exits 810for validity; it is returned, whatever it is, if the user exits with the
816with the minibuffer empty.) 811minibuffer empty.)
817 812
818In the following example, the user enters @samp{minibuffer.t}, and 813In the following example, the user enters @samp{minibuffer.t}, and
819then types @key{RET}. The argument @var{existing} is @code{t}, and the 814then types @key{RET}. The argument @var{existing} is @code{t}, and the
@@ -823,7 +818,7 @@ only buffer name starting with the given input is
823@example 818@example
824(read-buffer "Buffer name? " "foo" t) 819(read-buffer "Buffer name? " "foo" t)
825@group 820@group
826;; @r{After evaluating the preceding expression,} 821;; @r{After evaluation of the preceding expression,}
827;; @r{the following prompt appears,} 822;; @r{the following prompt appears,}
828;; @r{with an empty minibuffer:} 823;; @r{with an empty minibuffer:}
829@end group 824@end group
@@ -852,7 +847,7 @@ for which @code{commandp} returns @code{t}. @xref{Interactive Call}.
852(read-command "Command name? ") 847(read-command "Command name? ")
853 848
854@group 849@group
855;; @r{After evaluating the preceding expression,} 850;; @r{After evaluation of the preceding expression,}
856;; @r{the following prompt appears with an empty minibuffer:} 851;; @r{the following prompt appears with an empty minibuffer:}
857@end group 852@end group
858 853
@@ -891,7 +886,7 @@ symbol.
891@group 886@group
892(read-variable "Variable name? ") 887(read-variable "Variable name? ")
893 888
894;; @r{After evaluating the preceding expression,} 889;; @r{After evaluation of the preceding expression,}
895;; @r{the following prompt appears,} 890;; @r{the following prompt appears,}
896;; @r{with an empty minibuffer:} 891;; @r{with an empty minibuffer:}
897@end group 892@end group
@@ -933,25 +928,29 @@ of the default directory.
933This function reads a file name in the minibuffer, prompting with 928This function reads a file name in the minibuffer, prompting with
934@var{prompt} and providing completion. If @var{default} is 929@var{prompt} and providing completion. If @var{default} is
935non-@code{nil}, then the function returns @var{default} if the user just 930non-@code{nil}, then the function returns @var{default} if the user just
936types @key{RET}. 931types @key{RET}. @var{default} is not checked for validity; it is
932returned, whatever it is, if the user exits with the minibuffer empty.
937 933
938If @var{existing} is non-@code{nil}, then the name must refer to an 934If @var{existing} is non-@code{nil}, then the user must specify the name
939existing file; then @key{RET} performs completion to make the name valid 935of an existing file; @key{RET} performs completion to make the name
940if possible, and then refuses to exit if it is not valid. If the value 936valid if possible, and then refuses to exit if it is not valid. If the
941of @var{existing} is neither @code{nil} nor @code{t}, then @key{RET} 937value of @var{existing} is neither @code{nil} nor @code{t}, then
942also requires confirmation after completion. 938@key{RET} also requires confirmation after completion. If
939@var{existing} is @code{nil}, then the name of a nonexistent file is
940acceptable.
943 941
944The argument @var{directory} specifies the directory to use for 942The argument @var{directory} specifies the directory to use for
945completion of relative file names. Usually it is inserted in the 943completion of relative file names. If @code{insert-default-directory}
946minibuffer as initial input as well. It defaults to the current 944is non-@code{nil}, @var{directory} is also inserted in the minibuffer as
947buffer's value of @code{default-directory}. 945initial input. It defaults to the current buffer's value of
946@code{default-directory}.
948 947
949@c Emacs 19 feature 948@c Emacs 19 feature
950If you specify @var{initial}, that is an initial file name to insert in 949If you specify @var{initial}, that is an initial file name to insert in
951the buffer along with @var{directory}. In this case, point goes after 950the buffer (after with @var{directory}, if that is inserted). In this
952@var{directory}, before @var{initial}. The default for @var{initial} is 951case, point goes at the beginning of @var{initial}. The default for
953@code{nil}---don't insert any file name. To see what @var{initial} 952@var{initial} is @code{nil}---don't insert any file name. To see what
954does, try the command @kbd{C-x C-v}. 953@var{initial} does, try the command @kbd{C-x C-v}.
955 954
956Here is an example: 955Here is an example:
957 956
@@ -959,7 +958,7 @@ Here is an example:
959@group 958@group
960(read-file-name "The file is ") 959(read-file-name "The file is ")
961 960
962;; @r{After evaluating the preceding expression,} 961;; @r{After evaluation of the preceding expression,}
963;; @r{the following appears in the minibuffer:} 962;; @r{the following appears in the minibuffer:}
964@end group 963@end group
965 964
@@ -1036,10 +1035,10 @@ can supply your own function to compute the completion of a given string.
1036This is called @dfn{programmed completion}. 1035This is called @dfn{programmed completion}.
1037 1036
1038 To use this feature, pass a symbol with a function definition as the 1037 To use this feature, pass a symbol with a function definition as the
1039@var{collection} argument to @code{completing-read}. This function 1038@var{collection} argument to @code{completing-read}. The function
1040arranges to pass your completion function along to @code{try-completion} 1039@code{completing-read} arranges to pass your completion function along
1041and @code{all-completions}, which will then let your function do all the 1040to @code{try-completion} and @code{all-completions}, which will then let
1042work. 1041your function do all the work.
1043 1042
1044 The completion function should accept three arguments: 1043 The completion function should accept three arguments:
1045 1044
@@ -1077,7 +1076,7 @@ match for some possibility; @code{nil} otherwise.
1077@end itemize 1076@end itemize
1078 1077
1079 It would be consistent and clean for completion functions to allow 1078 It would be consistent and clean for completion functions to allow
1080lambda expressions (lists which are functions) as well as function 1079lambda expressions (lists tha are functions) as well as function
1081symbols as @var{collection}, but this is impossible. Lists as 1080symbols as @var{collection}, but this is impossible. Lists as
1082completion tables are already assigned another meaning---as alists. It 1081completion tables are already assigned another meaning---as alists. It
1083would be unreliable to fail to handle an alist normally because it is 1082would be unreliable to fail to handle an alist normally because it is
@@ -1104,7 +1103,7 @@ answer.
1104@code{y-or-n-p} does not; but it seems best to describe them together. 1103@code{y-or-n-p} does not; but it seems best to describe them together.
1105 1104
1106@defun y-or-n-p prompt 1105@defun y-or-n-p prompt
1107 This function asks the user a question, expecting input in the echo 1106This function asks the user a question, expecting input in the echo
1108area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the 1107area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the
1109user types @kbd{n}. This function also accepts @key{SPC} to mean yes 1108user types @kbd{n}. This function also accepts @key{SPC} to mean yes
1110and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit'', like 1109and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit'', like
@@ -1113,35 +1112,35 @@ that reason the user might try to use @kbd{C-]} to get out. The answer
1113is a single character, with no @key{RET} needed to terminate it. Upper 1112is a single character, with no @key{RET} needed to terminate it. Upper
1114and lower case are equivalent. 1113and lower case are equivalent.
1115 1114
1116 ``Asking the question'' means printing @var{prompt} in the echo area, 1115``Asking the question'' means printing @var{prompt} in the echo area,
1117followed by the string @w{@samp{(y or n) }}. If the input is not one of 1116followed by the string @w{@samp{(y or n) }}. If the input is not one of
1118the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}}, 1117the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}},
1119@kbd{@key{DEL}}, or something that quits), the function responds 1118@kbd{@key{DEL}}, or something that quits), the function responds
1120@samp{Please answer y or n.}, and repeats the request. 1119@samp{Please answer y or n.}, and repeats the request.
1121 1120
1122 This function does not actually use the minibuffer, since it does not 1121This function does not actually use the minibuffer, since it does not
1123allow editing of the answer. It actually uses the echo area (@pxref{The 1122allow editing of the answer. It actually uses the echo area (@pxref{The
1124Echo Area}), which uses the same screen space as the minibuffer. The 1123Echo Area}), which uses the same screen space as the minibuffer. The
1125cursor moves to the echo area while the question is being asked. 1124cursor moves to the echo area while the question is being asked.
1126 1125
1127 The answers and their meanings, even @samp{y} and @samp{n}, are not 1126The answers and their meanings, even @samp{y} and @samp{n}, are not
1128hardwired. The keymap @code{query-replace-map} specifies them. 1127hardwired. The keymap @code{query-replace-map} specifies them.
1129@xref{Search and Replace}. 1128@xref{Search and Replace}.
1130 1129
1131 If @code{y-or-n-p} is called in a command that was invoked using the 1130If @code{y-or-n-p} is called in a command that was invoked using the
1132mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command 1131mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command
1133Loop Info}) is either @code{nil} or a mouse event---then it uses a 1132Loop Info}) is either @code{nil} or a mouse event---then it uses a
1134dialog box or pop-up menu to ask the question. In this case, it does 1133dialog box or pop-up menu to ask the question. In this case, it does
1135not use keyboard input or the echo area. 1134not use keyboard input or the echo area.
1136 1135
1137 In the following example, the user first types @kbd{q}, which is 1136In the following example, the user first types @kbd{q}, which is
1138invalid. At the next prompt the user types @kbd{y}. 1137invalid. At the next prompt the user types @kbd{y}.
1139 1138
1140@smallexample 1139@smallexample
1141@group 1140@group
1142(y-or-n-p "Do you need a lift? ") 1141(y-or-n-p "Do you need a lift? ")
1143 1142
1144;; @r{After evaluating the preceding expression,} 1143;; @r{After evaluation of the preceding expression,}
1145;; @r{the following prompt appears in the echo area:} 1144;; @r{the following prompt appears in the echo area:}
1146@end group 1145@end group
1147 1146
@@ -1175,20 +1174,20 @@ appears on the screen at a time.
1175@end defun 1174@end defun
1176 1175
1177@defun yes-or-no-p prompt 1176@defun yes-or-no-p prompt
1178 This function asks the user a question, expecting input in minibuffer. 1177This function asks the user a question, expecting input in the
1179It returns @code{t} if the user enters @samp{yes}, @code{nil} if the 1178minibuffer. It returns @code{t} if the user enters @samp{yes},
1180user types @samp{no}. The user must type @key{RET} to finalize the 1179@code{nil} if the user types @samp{no}. The user must type @key{RET} to
1181response. Upper and lower case are equivalent. 1180finalize the response. Upper and lower case are equivalent.
1182 1181
1183 @code{yes-or-no-p} starts by displaying @var{prompt} in the echo area, 1182@code{yes-or-no-p} starts by displaying @var{prompt} in the echo area,
1184followed by @w{@samp{(yes or no) }}. The user must type one of the 1183followed by @w{@samp{(yes or no) }}. The user must type one of the
1185expected responses; otherwise, the function responds @samp{Please answer 1184expected responses; otherwise, the function responds @samp{Please answer
1186yes or no.}, waits about two seconds and repeats the request. 1185yes or no.}, waits about two seconds and repeats the request.
1187 1186
1188 @code{yes-or-no-p} requires more work from the user than 1187@code{yes-or-no-p} requires more work from the user than
1189@code{y-or-n-p} and is appropriate for more crucial decisions. 1188@code{y-or-n-p} and is appropriate for more crucial decisions.
1190 1189
1191 If @code{yes-or-no-p} is called in a command that was invoked using 1190If @code{yes-or-no-p} is called in a command that was invoked using
1192the mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command 1191the mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command
1193Loop Info}) is either @code{nil} or a mouse event---then it uses a 1192Loop Info}) is either @code{nil} or a mouse event---then it uses a
1194dialog box or pop-up menu to ask the question. In this case, it does 1193dialog box or pop-up menu to ask the question. In this case, it does
@@ -1200,7 +1199,7 @@ Here is an example:
1200@group 1199@group
1201(yes-or-no-p "Do you really want to remove everything? ") 1200(yes-or-no-p "Do you really want to remove everything? ")
1202 1201
1203;; @r{After evaluating the preceding expression,} 1202;; @r{After evaluation of the preceding expression,}
1204;; @r{the following prompt appears,} 1203;; @r{the following prompt appears,}
1205;; @r{with an empty minibuffer:} 1204;; @r{with an empty minibuffer:}
1206@end group 1205@end group
@@ -1230,6 +1229,13 @@ Do you really want to remove everything? (yes or no)
1230@node Multiple Queries 1229@node Multiple Queries
1231@section Asking Multiple Y-or-N Questions 1230@section Asking Multiple Y-or-N Questions
1232 1231
1232 When you have a series of similar questions to ask, such as ``Do you
1233want to save this buffer'' for each buffer in turn, you should use
1234@code{map-y-or-n-p} to ask the collection of questions, rather than
1235asking each question individually. This gives the user certain
1236convenient facilities such as the ability to answer the whole series at
1237once.
1238
1233@defun map-y-or-n-p prompter actor list &optional help action-alist 1239@defun map-y-or-n-p prompter actor list &optional help action-alist
1234This function, new in Emacs 19, asks the user a series of questions, 1240This function, new in Emacs 19, asks the user a series of questions,
1235reading a single-character answer in the echo area for each one. 1241reading a single-character answer in the echo area for each one.
@@ -1328,16 +1334,24 @@ This command replaces the minibuffer contents with the value of the
1328 1334
1329@deffn Command previous-matching-history-element pattern 1335@deffn Command previous-matching-history-element pattern
1330This command replaces the minibuffer contents with the value of the 1336This command replaces the minibuffer contents with the value of the
1331previous (older) history element that matches @var{pattern}. 1337previous (older) history element that matches @var{pattern} (a regular
1338expression).
1332@end deffn 1339@end deffn
1333 1340
1334@deffn Command next-matching-history-element pattern 1341@deffn Command next-matching-history-element pattern
1335This command replaces the minibuffer contents with the value of the 1342This command replaces the minibuffer contents with the value of the next
1336next (newer) history element that matches @var{pattern}. 1343(newer) history element that matches @var{pattern} (a regular
1344expression).
1337@end deffn 1345@end deffn
1338 1346
1339@defvar minibuffer-setup-hook 1347@defvar minibuffer-setup-hook
1340This is a normal hook that is run whenever the minibuffer is entered. 1348This is a normal hook that is run whenever the minibuffer is entered.
1349@xref{Hooks}.
1350@end defvar
1351
1352@defvar minibuffer-setup-hook
1353This is a normal hook that is run whenever the minibuffer is exited.
1354@xref{Hooks}.
1341@end defvar 1355@end defvar
1342 1356
1343@defvar minibuffer-help-form 1357@defvar minibuffer-help-form
@@ -1383,9 +1397,19 @@ minibuffer, a nonnegative integer. If no minibuffers are active, it
1383returns zero. 1397returns zero.
1384@end defun 1398@end defun
1385 1399
1400@defun minibuffer-prompt
1401This function returns the prompt string of the currently active
1402minibuffer. If no minibuffer is active, it returns @code{nil}.
1403@end defun
1404
1405@defun minibuffer-prompt-width
1406This function returns the display width of the prompt string of the
1407currently active minibuffer. If no minibuffer is active, it returns 0.
1408@end defun
1409
1386@defopt enable-recursive-minibuffers 1410@defopt enable-recursive-minibuffers
1387If this variable is non-@code{nil}, you can invoke commands (such as 1411If this variable is non-@code{nil}, you can invoke commands (such as
1388@code{find-file}) which use minibuffers even while in the minibuffer 1412@code{find-file}) that use minibuffers even while in the minibuffer
1389window. Such invocation produces a recursive editing level for a new 1413window. Such invocation produces a recursive editing level for a new
1390minibuffer. The outer-level minibuffer is invisible while you are 1414minibuffer. The outer-level minibuffer is invisible while you are
1391editing the inner one. 1415editing the inner one.
@@ -1398,7 +1422,7 @@ window is selected.
1398 1422
1399@c Emacs 19 feature 1423@c Emacs 19 feature
1400If a command name has a property @code{enable-recursive-minibuffers} 1424If a command name has a property @code{enable-recursive-minibuffers}
1401which is non-@code{nil}, then the command can use the minibuffer to read 1425that is non-@code{nil}, then the command can use the minibuffer to read
1402arguments even if it is invoked from the minibuffer. The minibuffer 1426arguments even if it is invoked from the minibuffer. The minibuffer
1403command @code{next-matching-history-element} (normally bound to 1427command @code{next-matching-history-element} (normally bound to
1404@kbd{M-s} in the minibuffer) uses this feature. 1428@kbd{M-s} in the minibuffer) uses this feature.