diff options
| author | Richard M. Stallman | 1994-04-30 07:00:37 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-30 07:00:37 +0000 |
| commit | 793da230a15d1b1293a667e569e02480408dd2c7 (patch) | |
| tree | 8e8a07157ae931414478bc94da752d227cfe1536 | |
| parent | e333e8646bf92525dadc074d466901111e169a91 (diff) | |
| download | emacs-793da230a15d1b1293a667e569e02480408dd2c7.tar.gz emacs-793da230a15d1b1293a667e569e02480408dd2c7.zip | |
*** empty log message ***
| -rw-r--r-- | lispref/minibuf.texi | 226 |
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 | |||
| 41 | no minibuffer window, and sometimes a special kind of frame contains | 41 | no minibuffer window, and sometimes a special kind of frame contains |
| 42 | nothing but a minibuffer window; see @ref{Minibuffers and Frames}.) | 42 | nothing 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 |
| 45 | temporarily with the window sizing commands; it reverts to its normal | 45 | temporarily with the window sizing commands; it reverts to its normal |
| 46 | size when the minibuffer is exited. You can resize it permanently by | 46 | size when the minibuffer is exited. You can resize it permanently by |
| 47 | using the window sizing commands in the frame's other window, when the | 47 | using 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 |
| 86 | string. It can also be used to read a Lisp object in textual form. The | 86 | also be used to read a Lisp object in textual form. The most basic |
| 87 | most basic primitive for minibuffer input is | 87 | primitive for minibuffer input is @code{read-from-minibuffer}; it can do |
| 88 | @code{read-from-minibuffer}; it can do either one. | 88 | either 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 |
| 91 | This function is the most general way to get input through the | 91 | This 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: | |||
| 241 | minibuffer. | 244 | minibuffer. |
| 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, | 247 | This function reads a Lisp object in the minibuffer and returns it, |
| 245 | without evaluating it. The arguments @var{prompt} and @var{initial} are | 248 | without evaluating it. The arguments @var{prompt} and @var{initial} are |
| 246 | used as in @code{read-from-minibuffer}; in particular, @var{initial} | 249 | used as in @code{read-from-minibuffer}. |
| 247 | must be a string or @code{nil}. | ||
| 248 | 250 | ||
| 249 | This is a simplified interface to the | 251 | This 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, | 286 | This function reads a Lisp expression in the minibuffer, evaluates it, |
| 285 | then returns the result. The arguments @var{prompt} and @var{initial} | 287 | then returns the result. The arguments @var{prompt} and @var{initial} |
| 286 | are used as in @code{read-from-minibuffer}. | 288 | are used as in @code{read-from-minibuffer}. |
| 287 | 289 | ||
| 288 | This function simply evaluates the result of a call to | 290 | This 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 | 303 | This function reads a Lisp expression in the minibuffer, and then |
| 302 | evaluates it. The difference between this command and | 304 | evaluates 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 |
| 304 | optional and it is treated as a Lisp object to be converted to printed | 306 | optional 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{"}) |
| 307 | appear in the initial text. @xref{Output Functions}. | 309 | appear in the initial text. @xref{Output Functions}. |
| 308 | 310 | ||
| 309 | The first thing @code{edit-and-eval-command} does is to activate the | 311 | The first thing @code{edit-and-eval-command} does is to activate the |
| 310 | minibuffer with @var{prompt} as the prompt. Then it inserts the printed | 312 | minibuffer with @var{prompt} as the prompt. Then it inserts the printed |
| 311 | representation of @var{form} in the minibuffer, and lets the user edit. | 313 | representation of @var{form} in the minibuffer, and lets the user edit. |
| 312 | When the user exits the minibuffer, the edited text is read with | 314 | When 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 |
| 314 | of @code{edit-and-eval-command}. | 316 | of @code{edit-and-eval-command}. |
| 315 | 317 | ||
| 316 | In the following example, we offer the user an expression with initial | 318 | In the following example, we offer the user an expression with initial |
| 317 | text which is a valid form already: | 319 | text 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 | ||
| 345 | A @dfn{minibuffer history list} records previous minibuffer inputs so | 347 | A @dfn{minibuffer history list} records previous minibuffer inputs so |
| 346 | the user can reuse them conveniently. A history list is a symbol, a | 348 | the user can reuse them conveniently. A history list is actually a |
| 347 | variable whose value is a list of strings (previous inputs), most recent | 349 | symbol, not a list; it is a variable whose value is a list of strings |
| 348 | first. | 350 | (previous inputs), most recent first. |
| 349 | 351 | ||
| 350 | There are many separate history lists, used for different kinds of | 352 | There are many separate history lists, used for different kinds of |
| 351 | inputs. It's the Lisp programmer's job to specify the right history | 353 | inputs. 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} | ||
| 458 | have nothing in themselves to do with minibuffers. We describe them in | ||
| 459 | this chapter so as to keep them near the higher-level completion | ||
| 460 | features that do use the minibuffer. | ||
| 461 | |||
| 455 | @defun try-completion string collection &optional predicate | 462 | @defun try-completion string collection &optional predicate |
| 456 | This function returns the longest common substring of all possible | 463 | This function returns the longest common substring of all possible |
| 457 | completions of @var{string} in @var{collection}. The value of | 464 | completions 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 |
| 459 | implements a virtual set of strings (see below). | 466 | implements a virtual set of strings (see below). |
| 460 | 467 | ||
| 461 | Completion compares @var{string} against each of the permissible | 468 | Completion 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 |
| 488 | symbol name) from the obarray. | 495 | symbol name) from the obarray. |
| 489 | 496 | ||
| 490 | You can also use a function symbol as @var{collection}. Then the | 497 | You can also use a symbol that is a function as @var{collection}. Then |
| 491 | function is solely responsible for performing completion; | 498 | the 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 |
| 493 | function is called with three arguments: @var{string}, @var{predicate} | 500 | function is called with three arguments: @var{string}, @var{predicate} |
| 494 | and @code{nil}. (The reason for the third argument is so that the same | 501 | and @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 | |||
| 581 | non-@code{nil}, Emacs does not consider case significant in completion. | 588 | non-@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} | ||
| 585 | have nothing in themselves to do with minibuffers. We describe them in | ||
| 586 | this chapter so as to keep them near the higher-level completion | ||
| 587 | features 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 | |||
| 608 | won't exit unless the input completes to an element of @var{collection}. | 610 | won't exit unless the input completes to an element of @var{collection}. |
| 609 | If @var{require-match} is neither @code{nil} nor @code{t}, then the exit | 611 | If @var{require-match} is neither @code{nil} nor @code{t}, then the exit |
| 610 | commands won't exit unless the input typed is itself an element of | 612 | commands 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 |
| 614 | commands work regardless of the input in the minibuffer. | ||
| 612 | 615 | ||
| 613 | The function @code{completing-read} works by calling | 616 | The 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} |
| 615 | as the keymap if @var{require-match} is @code{nil}, and uses | 618 | as 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 |
| 617 | non-@code{nil}. | 620 | non-@code{nil}. @xref{Completion Commands}. |
| 618 | 621 | ||
| 619 | The argument @var{hist} specifies which history list variable to use for | 622 | The argument @var{hist} specifies which history list variable to use for |
| 620 | saving the input and for minibuffer history commands. It defaults to | 623 | saving 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 | ||
| 651 | The @code{completing-read} function binds three variables to pass | 654 | The @code{completing-read} function binds three variables to pass |
| 652 | information to the commands which actually do completion. Here they | 655 | information to the commands that actually do completion. These |
| 653 | are: | 656 | variables 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 | 659 | see @ref{Completion Commands}. |
| 657 | This variable is bound to the @var{collection} argument. It is passed | ||
| 658 | to the @code{try-completion} function. | ||
| 659 | |||
| 660 | @item minibuffer-completion-predicate | ||
| 661 | This variable is bound to the @var{predicate} argument. It is passed to | ||
| 662 | the @code{try-completion} function. | ||
| 663 | |||
| 664 | @item minibuffer-completion-confirm | ||
| 665 | This variable is bound to the @var{require-match} argument. It is used | ||
| 666 | in 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. | |||
| 674 | the minibuffer to do completion. | 666 | the 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 |
| 678 | exact match of one of the completions is not required. By default, this | 670 | exact match of one of the completions is not required. By default, this |
| 679 | keymap makes the following bindings: | 671 | keymap 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 |
| 693 | with other characters bound as in @code{minibuffer-local-map}. | 685 | with 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 |
| 698 | exact match of one of the completions is required. Therefore, no keys | 691 | exact match of one of the completions is required. Therefore, no keys |
| 699 | are bound to @code{exit-minibuffer}, the command which exits the | 692 | are bound to @code{exit-minibuffer}, the command that exits the |
| 700 | minibuffer unconditionally. By default, this keymap makes the following | 693 | minibuffer unconditionally. By default, this keymap makes the following |
| 701 | bindings: | 694 | bindings: |
| 702 | 695 | ||
| @@ -749,7 +742,9 @@ This function completes the minibuffer contents as far as possible. | |||
| 749 | This function completes the minibuffer contents, and exits if | 742 | This function completes the minibuffer contents, and exits if |
| 750 | confirmation is not required, i.e., if | 743 | confirmation 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 |
| 746 | immediately---the command is programmed to work without confirmation | ||
| 747 | when 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 | |||
| 809 | is not inserted in the minibuffer as initial input. | 804 | is not inserted in the minibuffer as initial input. |
| 810 | 805 | ||
| 811 | If @var{existing} is non-@code{nil}, then the name specified must be | 806 | If @var{existing} is non-@code{nil}, then the name specified must be |
| 812 | that of an existing buffer. The usual commands to exit the | 807 | that of an existing buffer. The usual commands to exit the minibuffer |
| 813 | minibuffer do not exit if the text is not valid, and @key{RET} does | 808 | do not exit if the text is not valid, and @key{RET} does completion to |
| 814 | completion to attempt to find a valid name. (However, @var{default} is | 809 | attempt to find a valid name. (However, @var{default} is not checked |
| 815 | not checked for this; it is returned, whatever it is, if the user exits | 810 | for validity; it is returned, whatever it is, if the user exits with the |
| 816 | with the minibuffer empty.) | 811 | minibuffer empty.) |
| 817 | 812 | ||
| 818 | In the following example, the user enters @samp{minibuffer.t}, and | 813 | In the following example, the user enters @samp{minibuffer.t}, and |
| 819 | then types @key{RET}. The argument @var{existing} is @code{t}, and the | 814 | then 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. | |||
| 933 | This function reads a file name in the minibuffer, prompting with | 928 | This 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 |
| 935 | non-@code{nil}, then the function returns @var{default} if the user just | 930 | non-@code{nil}, then the function returns @var{default} if the user just |
| 936 | types @key{RET}. | 931 | types @key{RET}. @var{default} is not checked for validity; it is |
| 932 | returned, whatever it is, if the user exits with the minibuffer empty. | ||
| 937 | 933 | ||
| 938 | If @var{existing} is non-@code{nil}, then the name must refer to an | 934 | If @var{existing} is non-@code{nil}, then the user must specify the name |
| 939 | existing file; then @key{RET} performs completion to make the name valid | 935 | of an existing file; @key{RET} performs completion to make the name |
| 940 | if possible, and then refuses to exit if it is not valid. If the value | 936 | valid if possible, and then refuses to exit if it is not valid. If the |
| 941 | of @var{existing} is neither @code{nil} nor @code{t}, then @key{RET} | 937 | value of @var{existing} is neither @code{nil} nor @code{t}, then |
| 942 | also 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 | ||
| 940 | acceptable. | ||
| 943 | 941 | ||
| 944 | The argument @var{directory} specifies the directory to use for | 942 | The argument @var{directory} specifies the directory to use for |
| 945 | completion of relative file names. Usually it is inserted in the | 943 | completion of relative file names. If @code{insert-default-directory} |
| 946 | minibuffer as initial input as well. It defaults to the current | 944 | is non-@code{nil}, @var{directory} is also inserted in the minibuffer as |
| 947 | buffer's value of @code{default-directory}. | 945 | initial 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 |
| 950 | If you specify @var{initial}, that is an initial file name to insert in | 949 | If you specify @var{initial}, that is an initial file name to insert in |
| 951 | the buffer along with @var{directory}. In this case, point goes after | 950 | the buffer (after with @var{directory}, if that is inserted). In this |
| 952 | @var{directory}, before @var{initial}. The default for @var{initial} is | 951 | case, 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 |
| 954 | does, try the command @kbd{C-x C-v}. | 953 | @var{initial} does, try the command @kbd{C-x C-v}. |
| 955 | 954 | ||
| 956 | Here is an example: | 955 | Here 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. | |||
| 1036 | This is called @dfn{programmed completion}. | 1035 | This 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 |
| 1040 | arranges to pass your completion function along to @code{try-completion} | 1039 | @code{completing-read} arranges to pass your completion function along |
| 1041 | and @code{all-completions}, which will then let your function do all the | 1040 | to @code{try-completion} and @code{all-completions}, which will then let |
| 1042 | work. | 1041 | your 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 |
| 1080 | lambda expressions (lists which are functions) as well as function | 1079 | lambda expressions (lists tha are functions) as well as function |
| 1081 | symbols as @var{collection}, but this is impossible. Lists as | 1080 | symbols as @var{collection}, but this is impossible. Lists as |
| 1082 | completion tables are already assigned another meaning---as alists. It | 1081 | completion tables are already assigned another meaning---as alists. It |
| 1083 | would be unreliable to fail to handle an alist normally because it is | 1082 | would 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 | 1106 | This function asks the user a question, expecting input in the echo |
| 1108 | area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the | 1107 | area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the |
| 1109 | user types @kbd{n}. This function also accepts @key{SPC} to mean yes | 1108 | user types @kbd{n}. This function also accepts @key{SPC} to mean yes |
| 1110 | and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit'', like | 1109 | and @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 | |||
| 1113 | is a single character, with no @key{RET} needed to terminate it. Upper | 1112 | is a single character, with no @key{RET} needed to terminate it. Upper |
| 1114 | and lower case are equivalent. | 1113 | and 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, |
| 1117 | followed by the string @w{@samp{(y or n) }}. If the input is not one of | 1116 | followed by the string @w{@samp{(y or n) }}. If the input is not one of |
| 1118 | the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}}, | 1117 | the 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 | 1121 | This function does not actually use the minibuffer, since it does not |
| 1123 | allow editing of the answer. It actually uses the echo area (@pxref{The | 1122 | allow editing of the answer. It actually uses the echo area (@pxref{The |
| 1124 | Echo Area}), which uses the same screen space as the minibuffer. The | 1123 | Echo Area}), which uses the same screen space as the minibuffer. The |
| 1125 | cursor moves to the echo area while the question is being asked. | 1124 | cursor 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 | 1126 | The answers and their meanings, even @samp{y} and @samp{n}, are not |
| 1128 | hardwired. The keymap @code{query-replace-map} specifies them. | 1127 | hardwired. 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 | 1130 | If @code{y-or-n-p} is called in a command that was invoked using the |
| 1132 | mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command | 1131 | mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command |
| 1133 | Loop Info}) is either @code{nil} or a mouse event---then it uses a | 1132 | Loop Info}) is either @code{nil} or a mouse event---then it uses a |
| 1134 | dialog box or pop-up menu to ask the question. In this case, it does | 1133 | dialog box or pop-up menu to ask the question. In this case, it does |
| 1135 | not use keyboard input or the echo area. | 1134 | not use keyboard input or the echo area. |
| 1136 | 1135 | ||
| 1137 | In the following example, the user first types @kbd{q}, which is | 1136 | In the following example, the user first types @kbd{q}, which is |
| 1138 | invalid. At the next prompt the user types @kbd{y}. | 1137 | invalid. 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. | 1177 | This function asks the user a question, expecting input in the |
| 1179 | It returns @code{t} if the user enters @samp{yes}, @code{nil} if the | 1178 | minibuffer. It returns @code{t} if the user enters @samp{yes}, |
| 1180 | user 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 |
| 1181 | response. Upper and lower case are equivalent. | 1180 | finalize 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, |
| 1184 | followed by @w{@samp{(yes or no) }}. The user must type one of the | 1183 | followed by @w{@samp{(yes or no) }}. The user must type one of the |
| 1185 | expected responses; otherwise, the function responds @samp{Please answer | 1184 | expected responses; otherwise, the function responds @samp{Please answer |
| 1186 | yes or no.}, waits about two seconds and repeats the request. | 1185 | yes 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 | 1190 | If @code{yes-or-no-p} is called in a command that was invoked using |
| 1192 | the mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command | 1191 | the mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command |
| 1193 | Loop Info}) is either @code{nil} or a mouse event---then it uses a | 1192 | Loop Info}) is either @code{nil} or a mouse event---then it uses a |
| 1194 | dialog box or pop-up menu to ask the question. In this case, it does | 1193 | dialog 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 | ||
| 1233 | want 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 | ||
| 1235 | asking each question individually. This gives the user certain | ||
| 1236 | convenient facilities such as the ability to answer the whole series at | ||
| 1237 | once. | ||
| 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 |
| 1234 | This function, new in Emacs 19, asks the user a series of questions, | 1240 | This function, new in Emacs 19, asks the user a series of questions, |
| 1235 | reading a single-character answer in the echo area for each one. | 1241 | reading 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 |
| 1330 | This command replaces the minibuffer contents with the value of the | 1336 | This command replaces the minibuffer contents with the value of the |
| 1331 | previous (older) history element that matches @var{pattern}. | 1337 | previous (older) history element that matches @var{pattern} (a regular |
| 1338 | expression). | ||
| 1332 | @end deffn | 1339 | @end deffn |
| 1333 | 1340 | ||
| 1334 | @deffn Command next-matching-history-element pattern | 1341 | @deffn Command next-matching-history-element pattern |
| 1335 | This command replaces the minibuffer contents with the value of the | 1342 | This command replaces the minibuffer contents with the value of the next |
| 1336 | next (newer) history element that matches @var{pattern}. | 1343 | (newer) history element that matches @var{pattern} (a regular |
| 1344 | expression). | ||
| 1337 | @end deffn | 1345 | @end deffn |
| 1338 | 1346 | ||
| 1339 | @defvar minibuffer-setup-hook | 1347 | @defvar minibuffer-setup-hook |
| 1340 | This is a normal hook that is run whenever the minibuffer is entered. | 1348 | This is a normal hook that is run whenever the minibuffer is entered. |
| 1349 | @xref{Hooks}. | ||
| 1350 | @end defvar | ||
| 1351 | |||
| 1352 | @defvar minibuffer-setup-hook | ||
| 1353 | This 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 | |||
| 1383 | returns zero. | 1397 | returns zero. |
| 1384 | @end defun | 1398 | @end defun |
| 1385 | 1399 | ||
| 1400 | @defun minibuffer-prompt | ||
| 1401 | This function returns the prompt string of the currently active | ||
| 1402 | minibuffer. If no minibuffer is active, it returns @code{nil}. | ||
| 1403 | @end defun | ||
| 1404 | |||
| 1405 | @defun minibuffer-prompt-width | ||
| 1406 | This function returns the display width of the prompt string of the | ||
| 1407 | currently active minibuffer. If no minibuffer is active, it returns 0. | ||
| 1408 | @end defun | ||
| 1409 | |||
| 1386 | @defopt enable-recursive-minibuffers | 1410 | @defopt enable-recursive-minibuffers |
| 1387 | If this variable is non-@code{nil}, you can invoke commands (such as | 1411 | If 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 |
| 1389 | window. Such invocation produces a recursive editing level for a new | 1413 | window. Such invocation produces a recursive editing level for a new |
| 1390 | minibuffer. The outer-level minibuffer is invisible while you are | 1414 | minibuffer. The outer-level minibuffer is invisible while you are |
| 1391 | editing the inner one. | 1415 | editing the inner one. |
| @@ -1398,7 +1422,7 @@ window is selected. | |||
| 1398 | 1422 | ||
| 1399 | @c Emacs 19 feature | 1423 | @c Emacs 19 feature |
| 1400 | If a command name has a property @code{enable-recursive-minibuffers} | 1424 | If a command name has a property @code{enable-recursive-minibuffers} |
| 1401 | which is non-@code{nil}, then the command can use the minibuffer to read | 1425 | that is non-@code{nil}, then the command can use the minibuffer to read |
| 1402 | arguments even if it is invoked from the minibuffer. The minibuffer | 1426 | arguments even if it is invoked from the minibuffer. The minibuffer |
| 1403 | command @code{next-matching-history-element} (normally bound to | 1427 | command @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. |