diff options
| author | Luc Teirlinck | 2004-02-04 03:08:59 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2004-02-04 03:08:59 +0000 |
| commit | 4b574f3d8ec5dc9a58a89d970e09715041d9f4a0 (patch) | |
| tree | 0f4d579037fd9c442d6236ee3b41cd580d526ab5 | |
| parent | 13c5d120fc89e35407b0092bef93c809a0b715fd (diff) | |
| download | emacs-4b574f3d8ec5dc9a58a89d970e09715041d9f4a0.tar.gz emacs-4b574f3d8ec5dc9a58a89d970e09715041d9f4a0.zip | |
(Text from Minibuffer): Various corrections and clarifications.
(Object from Minibuffer): Correct Lisp description of read-minibuffer.
(Minibuffer History): Clarify description of cons values for HISTORY arguments.
(Basic Completion): Various corrections and clarifications.
Add completion-regexp-list.
(Minibuffer Completion): Correct and clarify description of completing-read.
(Completion Commands): Mention partial-completion-mode.
Various other minor changes.
(High-Level Completion): Various corrections and clarifications.
(Reading File Names): Ditto.
(Minibuffer Misc): Ditto.
| -rw-r--r-- | lispref/ChangeLog | 18 | ||||
| -rw-r--r-- | lispref/minibuf.texi | 337 |
2 files changed, 247 insertions, 108 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog index 20dd4f13d03..7ec7f992ea0 100644 --- a/lispref/ChangeLog +++ b/lispref/ChangeLog | |||
| @@ -1,3 +1,21 @@ | |||
| 1 | 2004-02-03 Luc Teirlinck <teirllm@auburn.edu> | ||
| 2 | |||
| 3 | * minibuf.texi (Text from Minibuffer): Various corrections and | ||
| 4 | clarifications. | ||
| 5 | (Object from Minibuffer): Correct Lisp description of | ||
| 6 | read-minibuffer. | ||
| 7 | (Minibuffer History): Clarify description of cons values for | ||
| 8 | HISTORY arguments. | ||
| 9 | (Basic Completion): Various corrections and clarifications. Add | ||
| 10 | completion-regexp-list. | ||
| 11 | (Minibuffer Completion): Correct and clarify description of | ||
| 12 | completing-read. | ||
| 13 | (Completion Commands): Mention partial-completion-mode. Various | ||
| 14 | other minor changes. | ||
| 15 | (High-Level Completion): Various corrections and clarifications. | ||
| 16 | (Reading File Names): Ditto. | ||
| 17 | (Minibuffer Misc): Ditto. | ||
| 18 | |||
| 1 | 2004-01-26 Luc Teirlinck <teirllm@auburn.edu> | 19 | 2004-01-26 Luc Teirlinck <teirllm@auburn.edu> |
| 2 | 20 | ||
| 3 | * strings.texi (Text Comparison): assoc-string also matches | 21 | * strings.texi (Text Comparison): assoc-string also matches |
diff --git a/lispref/minibuf.texi b/lispref/minibuf.texi index 473859ccd6c..e0e2e4a80b1 100644 --- a/lispref/minibuf.texi +++ b/lispref/minibuf.texi | |||
| @@ -135,13 +135,17 @@ reads the text and returns the resulting Lisp object, unevaluated. | |||
| 135 | (@xref{Input Functions}, for information about reading.) | 135 | (@xref{Input Functions}, for information about reading.) |
| 136 | 136 | ||
| 137 | The argument @var{default} specifies a default value to make available | 137 | The argument @var{default} specifies a default value to make available |
| 138 | through the history commands. It should be a string, or @code{nil}. If | 138 | through the history commands. It should be a string, or @code{nil}. |
| 139 | @var{read} is non-@code{nil}, then @var{default} is also used as the | 139 | If non-@code{nil}, the user can access it using |
| 140 | input to @code{read}, if the user enters empty input. However, in the | 140 | @code{next-history-element}, usually bound in the minibuffer to |
| 141 | usual case (where @var{read} is @code{nil}), @code{read-from-minibuffer} | 141 | @kbd{M-n}. If @var{read} is non-@code{nil}, then @var{default} is |
| 142 | does not return @var{default} when the user enters empty input; it | 142 | also used as the input to @code{read}, if the user enters empty input. |
| 143 | returns an empty string, @code{""}. In this respect, it is different | 143 | (If @var{read} is non-@code{nil} and @var{default} is @code{nil}, empty |
| 144 | from all the other minibuffer input functions in this chapter. | 144 | input results in an @code{end-of-file} error.) However, in the usual |
| 145 | case (where @var{read} is @code{nil}), @code{read-from-minibuffer} | ||
| 146 | ignores @var{default} when the user enters empty input and returns an | ||
| 147 | empty string, @code{""}. In this respect, it is different from all | ||
| 148 | the other minibuffer input functions in this chapter. | ||
| 145 | 149 | ||
| 146 | If @var{keymap} is non-@code{nil}, that keymap is the local keymap to | 150 | If @var{keymap} is non-@code{nil}, that keymap is the local keymap to |
| 147 | use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the | 151 | use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the |
| @@ -171,8 +175,9 @@ its initial contents. | |||
| 171 | 175 | ||
| 172 | Alternatively, @var{initial-contents} can be a cons cell of the form | 176 | Alternatively, @var{initial-contents} can be a cons cell of the form |
| 173 | @code{(@var{string} . @var{position})}. This means to insert | 177 | @code{(@var{string} . @var{position})}. This means to insert |
| 174 | @var{string} in the minibuffer but put point @var{position} characters | 178 | @var{string} in the minibuffer but put point at @emph{one-indexed} |
| 175 | from the beginning, rather than at the end. | 179 | @var{position} in the minibuffer, rather than at the end. Any integer |
| 180 | value less or equal to one puts point at the beginning of the string. | ||
| 176 | 181 | ||
| 177 | @strong{Usage note:} The @var{initial-contents} argument and the | 182 | @strong{Usage note:} The @var{initial-contents} argument and the |
| 178 | @var{default} argument are two alternative features for more or less the | 183 | @var{default} argument are two alternative features for more or less the |
| @@ -180,21 +185,21 @@ same job. It does not make sense to use both features in a single call | |||
| 180 | to @code{read-from-minibuffer}. In general, we recommend using | 185 | to @code{read-from-minibuffer}. In general, we recommend using |
| 181 | @var{default}, since this permits the user to insert the default value | 186 | @var{default}, since this permits the user to insert the default value |
| 182 | when it is wanted, but does not burden the user with deleting it from | 187 | when it is wanted, but does not burden the user with deleting it from |
| 183 | the minibuffer on other occasions. | 188 | the minibuffer on other occasions. For an exception to this rule, |
| 189 | see @ref{Minibuffer History}. | ||
| 184 | @end defun | 190 | @end defun |
| 185 | 191 | ||
| 186 | @defun read-string prompt &optional initial history default inherit-input-method | 192 | @defun read-string prompt &optional initial history default inherit-input-method |
| 187 | This function reads a string from the minibuffer and returns it. The | 193 | This function reads a string from the minibuffer and returns it. The |
| 188 | arguments @var{prompt} and @var{initial} are used as in | 194 | arguments @var{prompt}, @var{initial}, @var{history} and |
| 189 | @code{read-from-minibuffer}. The keymap used is | 195 | @var{inherit-input-method} are used as in @code{read-from-minibuffer}. |
| 190 | @code{minibuffer-local-map}. | 196 | The keymap used is @code{minibuffer-local-map}. |
| 191 | 197 | ||
| 192 | The optional argument @var{history}, if non-@code{nil}, specifies a | 198 | The optional argument @var{default} is used as in |
| 193 | history list and optionally the initial position in the list. The | 199 | @code{read-from-minibuffer}, except that, if non-@code{nil}, it also |
| 194 | optional argument @var{default} specifies a default value to return if | 200 | specifies a default value to return if the user enters null input. As |
| 195 | the user enters null input; it should be a string. The optional | 201 | in @code{read-from-minibuffer} it should be a string, or @code{nil}, |
| 196 | argument @var{inherit-input-method} specifies whether to inherit the | 202 | which is equivalent to an empty string. |
| 197 | current buffer's input method. | ||
| 198 | 203 | ||
| 199 | This function is a simplified interface to the | 204 | This function is a simplified interface to the |
| 200 | @code{read-from-minibuffer} function: | 205 | @code{read-from-minibuffer} function: |
| @@ -206,7 +211,7 @@ This function is a simplified interface to the | |||
| 206 | (let ((value | 211 | (let ((value |
| 207 | (read-from-minibuffer @var{prompt} @var{initial} nil nil | 212 | (read-from-minibuffer @var{prompt} @var{initial} nil nil |
| 208 | @var{history} @var{default} @var{inherit}))) | 213 | @var{history} @var{default} @var{inherit}))) |
| 209 | (if (equal value "") | 214 | (if (and (equal value "") @var{default}) |
| 210 | @var{default} | 215 | @var{default} |
| 211 | value)) | 216 | value)) |
| 212 | @end group | 217 | @end group |
| @@ -216,13 +221,15 @@ This function is a simplified interface to the | |||
| 216 | @defvar minibuffer-allow-text-properties | 221 | @defvar minibuffer-allow-text-properties |
| 217 | If this variable is @code{nil}, then @code{read-from-minibuffer} strips | 222 | If this variable is @code{nil}, then @code{read-from-minibuffer} strips |
| 218 | all text properties from the minibuffer input before returning it. | 223 | all text properties from the minibuffer input before returning it. |
| 219 | Since all minibuffer input uses @code{read-from-minibuffer}, this | 224 | This variable also affects @code{read-string}. However, |
| 220 | variable applies to all minibuffer input. | 225 | @code{read-no-blanks-input} (see below), as well as |
| 221 | 226 | @code{read-minibuffer} and related functions (@pxref{Object from | |
| 222 | Note that the completion functions discard text properties unconditionally, | 227 | Minibuffer,, Reading Lisp Objects With the Minibuffer}), and all |
| 223 | regardless of the value of this variable. | 228 | functions that do minibuffer input with completion, discard text |
| 229 | properties unconditionally, regardless of the value of this variable. | ||
| 224 | @end defvar | 230 | @end defvar |
| 225 | 231 | ||
| 232 | @anchor{Definition of minibuffer-local-map} | ||
| 226 | @defvar minibuffer-local-map | 233 | @defvar minibuffer-local-map |
| 227 | This is the default local keymap for reading from the minibuffer. By | 234 | This is the default local keymap for reading from the minibuffer. By |
| 228 | default, it makes the following bindings: | 235 | default, it makes the following bindings: |
| @@ -243,10 +250,10 @@ default, it makes the following bindings: | |||
| 243 | @item @kbd{M-p} | 250 | @item @kbd{M-p} |
| 244 | @code{previous-history-element} | 251 | @code{previous-history-element} |
| 245 | 252 | ||
| 246 | @item @kbd{M-r} | 253 | @item @kbd{M-s} |
| 247 | @code{next-matching-history-element} | 254 | @code{next-matching-history-element} |
| 248 | 255 | ||
| 249 | @item @kbd{M-s} | 256 | @item @kbd{M-r} |
| 250 | @code{previous-matching-history-element} | 257 | @code{previous-matching-history-element} |
| 251 | @end table | 258 | @end table |
| 252 | @end defvar | 259 | @end defvar |
| @@ -265,11 +272,15 @@ keymap as the @var{keymap} argument for that function. Since the keymap | |||
| 265 | @code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is} | 272 | @code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is} |
| 266 | possible to put a space into the string, by quoting it. | 273 | possible to put a space into the string, by quoting it. |
| 267 | 274 | ||
| 275 | This function discards text properties, regardless of the value of | ||
| 276 | @code{minibuffer-allow-text-properties}. | ||
| 277 | |||
| 268 | @smallexample | 278 | @smallexample |
| 269 | @group | 279 | @group |
| 270 | (read-no-blanks-input @var{prompt} @var{initial}) | 280 | (read-no-blanks-input @var{prompt} @var{initial}) |
| 271 | @equiv{} | 281 | @equiv{} |
| 272 | (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map) | 282 | (let (minibuffer-allow-text-properties) |
| 283 | (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map)) | ||
| 273 | @end group | 284 | @end group |
| 274 | @end smallexample | 285 | @end smallexample |
| 275 | @end defun | 286 | @end defun |
| @@ -312,7 +323,8 @@ This is a simplified interface to the | |||
| 312 | @group | 323 | @group |
| 313 | (read-minibuffer @var{prompt} @var{initial}) | 324 | (read-minibuffer @var{prompt} @var{initial}) |
| 314 | @equiv{} | 325 | @equiv{} |
| 315 | (read-from-minibuffer @var{prompt} @var{initial} nil t) | 326 | (let (minibuffer-allow-text-properties) |
| 327 | (read-from-minibuffer @var{prompt} @var{initial} nil t)) | ||
| 316 | @end group | 328 | @end group |
| 317 | @end smallexample | 329 | @end smallexample |
| 318 | 330 | ||
| @@ -421,11 +433,16 @@ Use @var{variable} (a symbol) as the history list. | |||
| 421 | 433 | ||
| 422 | @item (@var{variable} . @var{startpos}) | 434 | @item (@var{variable} . @var{startpos}) |
| 423 | Use @var{variable} (a symbol) as the history list, and assume that the | 435 | Use @var{variable} (a symbol) as the history list, and assume that the |
| 424 | initial history position is @var{startpos} (an integer, counting from | 436 | initial history position is @var{startpos} (a nonnegative integer). |
| 425 | zero which specifies the most recent element of the history). | 437 | |
| 426 | 438 | Specifying 0 for @var{startpos} is equivalent to just specifying the | |
| 427 | If you specify @var{startpos}, then you should also specify that element | 439 | symbol @var{variable}. @code{previous-history-element} will display |
| 428 | of the history as the initial minibuffer contents, for consistency. | 440 | the most recent element of the history list in the minibuffer. If you |
| 441 | specify a positive @var{startpos}, the minibuffer history functions | ||
| 442 | behave as if @code{(elt @var{variable} (1- @var{STARTPOS}))} were the | ||
| 443 | history element currently shown in the minibuffer. For consistency, | ||
| 444 | you should also specify that element of the history as the initial | ||
| 445 | minibuffer contents. | ||
| 429 | @end table | 446 | @end table |
| 430 | 447 | ||
| 431 | If you don't specify @var{hist}, then the default history list | 448 | If you don't specify @var{hist}, then the default history list |
| @@ -539,8 +556,9 @@ the higher-level completion features that do use the minibuffer. | |||
| 539 | @defun try-completion string collection &optional predicate | 556 | @defun try-completion string collection &optional predicate |
| 540 | This function returns the longest common substring of all possible | 557 | This function returns the longest common substring of all possible |
| 541 | completions of @var{string} in @var{collection}. The value of | 558 | completions of @var{string} in @var{collection}. The value of |
| 542 | @var{collection} must be a list of strings, an alist, an obarray, or a | 559 | @var{collection} must be a list of strings, an alist, an obarray, a |
| 543 | function that implements a virtual set of strings (see below). | 560 | hash table, or a function that implements a virtual set of strings |
| 561 | (see below). | ||
| 544 | 562 | ||
| 545 | Completion compares @var{string} against each of the permissible | 563 | Completion compares @var{string} against each of the permissible |
| 546 | completions specified by @var{collection}; if the beginning of the | 564 | completions specified by @var{collection}; if the beginning of the |
| @@ -552,7 +570,12 @@ longest initial sequence common to all the permissible completions that | |||
| 552 | match. | 570 | match. |
| 553 | 571 | ||
| 554 | If @var{collection} is an alist (@pxref{Association Lists}), the | 572 | If @var{collection} is an alist (@pxref{Association Lists}), the |
| 555 | @sc{car}s of the alist elements form the set of permissible completions. | 573 | permissible completions are the elements of the alist that are either |
| 574 | strings or conses whose @sc{car} is a string. Other elements of the | ||
| 575 | alist are ignored. (Remember that in Emacs Lisp, the elements of | ||
| 576 | alists do not @emph{have} to be conses.) As all elements of the alist | ||
| 577 | can be strings, this case actually includes lists of strings, even | ||
| 578 | though we usually do not think of such lists as alists. | ||
| 556 | 579 | ||
| 557 | @cindex obarray in completion | 580 | @cindex obarray in completion |
| 558 | If @var{collection} is an obarray (@pxref{Creating Symbols}), the names | 581 | If @var{collection} is an obarray (@pxref{Creating Symbols}), the names |
| @@ -564,6 +587,9 @@ Note that the only valid way to make a new obarray is to create it | |||
| 564 | empty and then add symbols to it one by one using @code{intern}. | 587 | empty and then add symbols to it one by one using @code{intern}. |
| 565 | Also, you cannot intern a given symbol in more than one obarray. | 588 | Also, you cannot intern a given symbol in more than one obarray. |
| 566 | 589 | ||
| 590 | If @var{collection} is a hash table, then the keys that are strings | ||
| 591 | are the possible completions. Other keys are ignored. | ||
| 592 | |||
| 567 | You can also use a symbol that is a function as @var{collection}. Then | 593 | You can also use a symbol that is a function as @var{collection}. Then |
| 568 | the function is solely responsible for performing completion; | 594 | the function is solely responsible for performing completion; |
| 569 | @code{try-completion} returns whatever this function returns. The | 595 | @code{try-completion} returns whatever this function returns. The |
| @@ -573,11 +599,20 @@ function can be used in @code{all-completions} and do the appropriate | |||
| 573 | thing in either case.) @xref{Programmed Completion}. | 599 | thing in either case.) @xref{Programmed Completion}. |
| 574 | 600 | ||
| 575 | If the argument @var{predicate} is non-@code{nil}, then it must be a | 601 | If the argument @var{predicate} is non-@code{nil}, then it must be a |
| 576 | function of one argument. It is used to test each possible match, and | 602 | function of one argument, unless @var{collection} is a hash table, in |
| 577 | the match is accepted only if @var{predicate} returns non-@code{nil}. | 603 | which case it should be a function of two arguments. It is used to |
| 578 | The argument given to @var{predicate} is either a string from the | 604 | test each possible match, and the match is accepted only if |
| 579 | list, a cons cell from the alist (the @sc{car} of which is a string) | 605 | @var{predicate} returns non-@code{nil}. The argument given to |
| 580 | or a symbol (@emph{not} a symbol name) from the obarray. | 606 | @var{predicate} is either a string or a cons cell (the @sc{car} of |
| 607 | which is a string) from the alist, or a symbol (@emph{not} a symbol | ||
| 608 | name) from the obarray. If @var{collection} is a hash table, | ||
| 609 | @var{predicate} is called with two arguments, the string key and the | ||
| 610 | associated value. | ||
| 611 | |||
| 612 | In addition, to be acceptable, a completion must also match all the | ||
| 613 | regular expressions in @code{completion-regexp-list}. (Unless | ||
| 614 | @var{collection} is a function, in which case that function has to | ||
| 615 | handle @code{completion-regexp-list} itself.) | ||
| 581 | 616 | ||
| 582 | In the first of the following examples, the string @samp{foo} is | 617 | In the first of the following examples, the string @samp{foo} is |
| 583 | matched by three of the alist @sc{car}s. All of the matches begin with | 618 | matched by three of the alist @sc{car}s. All of the matches begin with |
| @@ -633,10 +668,13 @@ too short). Both of those begin with the string @samp{foobar}. | |||
| 633 | 668 | ||
| 634 | @defun all-completions string collection &optional predicate nospace | 669 | @defun all-completions string collection &optional predicate nospace |
| 635 | This function returns a list of all possible completions of | 670 | This function returns a list of all possible completions of |
| 636 | @var{string}. The arguments to this function (aside from @var{nospace}) | 671 | @var{string}. The arguments to this function (aside from |
| 637 | are the same as those of @code{try-completion}. If @var{nospace} is | 672 | @var{nospace}) are the same as those of @code{try-completion}. Also, |
| 638 | non-@code{nil}, completions that start with a space are ignored unless | 673 | this function uses @code{completion-regexp-list} in the same way that |
| 639 | @var{string} also starts with a space. | 674 | @code{try-completion} does. The optional argument @var{nospace} only |
| 675 | matters if @var{string} is the empty string. In that case, if | ||
| 676 | @var{nospace} is non-@code{nil}, completions that start with a space | ||
| 677 | are ignored. | ||
| 640 | 678 | ||
| 641 | If @var{collection} is a function, it is called with three arguments: | 679 | If @var{collection} is a function, it is called with three arguments: |
| 642 | @var{string}, @var{predicate} and @code{t}; then @code{all-completions} | 680 | @var{string}, @var{predicate} and @code{t}; then @code{all-completions} |
| @@ -662,13 +700,24 @@ example for @code{try-completion}: | |||
| 662 | @end smallexample | 700 | @end smallexample |
| 663 | @end defun | 701 | @end defun |
| 664 | 702 | ||
| 703 | @anchor{Definition of test-completion} | ||
| 665 | @defun test-completion string collection &optional predicate | 704 | @defun test-completion string collection &optional predicate |
| 666 | This function returns non-@code{nil} if @var{string} is a valid | 705 | This function returns non-@code{nil} if @var{string} is a valid |
| 667 | completion possibility specified by @var{collection} and | 706 | completion possibility specified by @var{collection} and |
| 668 | @var{predicate}. The other arguments are the same as in | 707 | @var{predicate}. The arguments are the same as in |
| 669 | @code{try-completion}. For instance, if @var{collection} is a list, | 708 | @code{try-completion}. For instance, if @var{collection} is a list of |
| 670 | this is true if @var{string} appears in the list and @var{predicate} | 709 | strings, this is true if @var{string} appears in the list and |
| 671 | is satisfied. | 710 | @var{predicate} is satisfied. |
| 711 | |||
| 712 | @code{test-completion} uses @code{completion-regexp-list} in the same | ||
| 713 | way that @code{try-completion} does. | ||
| 714 | |||
| 715 | If @var{predicate} is non-@code{nil} and if @var{collection} contains | ||
| 716 | several strings that are equal to each other, as determined by | ||
| 717 | @code{compare-strings} according to @code{completion-ignore-case}, | ||
| 718 | then @var{predicate} should accept either all or none of them. | ||
| 719 | Otherwise, the return value of @code{test-completion} is essentially | ||
| 720 | unpredictable. | ||
| 672 | 721 | ||
| 673 | If @var{collection} is a function, it is called with three arguments, | 722 | If @var{collection} is a function, it is called with three arguments, |
| 674 | the values @var{string}, @var{predicate} and @code{lambda}; whatever | 723 | the values @var{string}, @var{predicate} and @code{lambda}; whatever |
| @@ -680,6 +729,13 @@ If the value of this variable is non-@code{nil}, Emacs does not | |||
| 680 | consider case significant in completion. | 729 | consider case significant in completion. |
| 681 | @end defvar | 730 | @end defvar |
| 682 | 731 | ||
| 732 | @defvar completion-regexp-list | ||
| 733 | This is a list of regular expressions. The completion functions only | ||
| 734 | consider a completion acceptable if it matches all regular expressions | ||
| 735 | in this list, with @code{case-fold-search} (@pxref{Searching and Case}) | ||
| 736 | bound to the value of @code{completion-ignore-case}. | ||
| 737 | @end defvar | ||
| 738 | |||
| 683 | @defmac lazy-completion-table var fun &rest args | 739 | @defmac lazy-completion-table var fun &rest args |
| 684 | This macro provides a way to initialize the variable @var{var} as a | 740 | This macro provides a way to initialize the variable @var{var} as a |
| 685 | collection for completion in a lazy way, not computing its actual | 741 | collection for completion in a lazy way, not computing its actual |
| @@ -711,8 +767,12 @@ providing completion. It activates the minibuffer with prompt | |||
| 711 | @var{prompt}, which must be a string. | 767 | @var{prompt}, which must be a string. |
| 712 | 768 | ||
| 713 | The actual completion is done by passing @var{collection} and | 769 | The actual completion is done by passing @var{collection} and |
| 714 | @var{predicate} to the function @code{try-completion}. This happens in | 770 | @var{predicate} to the function @code{try-completion}. This happens |
| 715 | certain commands bound in the local keymaps used for completion. | 771 | in certain commands bound in the local keymaps used for completion. |
| 772 | Some of these commands also call @code{test-completion}. Thus, if | ||
| 773 | @var{predicate} is non-@code{nil}, it should be compatible with | ||
| 774 | @var{collection} and @code{completion-ignore-case}. @xref{Definition | ||
| 775 | of test-completion}. | ||
| 716 | 776 | ||
| 717 | If @var{require-match} is @code{nil}, the exit commands work regardless | 777 | If @var{require-match} is @code{nil}, the exit commands work regardless |
| 718 | of the input in the minibuffer. If @var{require-match} is @code{t}, the | 778 | of the input in the minibuffer. If @var{require-match} is @code{t}, the |
| @@ -723,19 +783,13 @@ input already in the buffer matches an element of @var{collection}. | |||
| 723 | 783 | ||
| 724 | However, empty input is always permitted, regardless of the value of | 784 | However, empty input is always permitted, regardless of the value of |
| 725 | @var{require-match}; in that case, @code{completing-read} returns | 785 | @var{require-match}; in that case, @code{completing-read} returns |
| 726 | @var{default}. The value of @var{default} (if non-@code{nil}) is also | 786 | @var{default}, or @code{""}, if @var{default} is @code{nil}. The |
| 727 | available to the user through the history commands. | 787 | value of @var{default} (if non-@code{nil}) is also available to the |
| 728 | 788 | user through the history commands. | |
| 729 | The user can exit with null input by typing @key{RET} with an empty | 789 | |
| 730 | minibuffer. Then @code{completing-read} returns @code{""}. This is how | 790 | The function @code{completing-read} uses |
| 731 | the user requests whatever default the command uses for the value being | 791 | @code{minibuffer-local-completion-map} as the keymap if |
| 732 | read. The user can return using @key{RET} in this way regardless of the | 792 | @var{require-match} is @code{nil}, and uses |
| 733 | value of @var{require-match}, and regardless of whether the empty string | ||
| 734 | is included in @var{collection}. | ||
| 735 | |||
| 736 | The function @code{completing-read} works by calling | ||
| 737 | @code{read-minibuffer}. It uses @code{minibuffer-local-completion-map} | ||
| 738 | as the keymap if @var{require-match} is @code{nil}, and uses | ||
| 739 | @code{minibuffer-local-must-match-map} if @var{require-match} is | 793 | @code{minibuffer-local-must-match-map} if @var{require-match} is |
| 740 | non-@code{nil}. @xref{Completion Commands}. | 794 | non-@code{nil}. @xref{Completion Commands}. |
| 741 | 795 | ||
| @@ -744,15 +798,21 @@ saving the input and for minibuffer history commands. It defaults to | |||
| 744 | @code{minibuffer-history}. @xref{Minibuffer History}. | 798 | @code{minibuffer-history}. @xref{Minibuffer History}. |
| 745 | 799 | ||
| 746 | If @var{initial} is non-@code{nil}, @code{completing-read} inserts it | 800 | If @var{initial} is non-@code{nil}, @code{completing-read} inserts it |
| 747 | into the minibuffer as part of the input. Then it allows the user to | 801 | into the minibuffer as part of the input, with point at the end. Then |
| 748 | edit the input, providing several commands to attempt completion. | 802 | it allows the user to edit the input, providing several commands to |
| 749 | In most cases, we recommend using @var{default}, and not @var{initial}. | 803 | attempt completion. @var{initial} can also be a cons cell of the form |
| 804 | @code{(@var{string} . @var{position})}. In that case, point is put at | ||
| 805 | @emph{zero-indexed} position @var{position} in @var{string}. Note | ||
| 806 | that this is different from @code{read-from-minibuffer} and related | ||
| 807 | functions, which use a one-indexed position. In most cases, we | ||
| 808 | recommend using @var{default}, and not @var{initial}. | ||
| 750 | 809 | ||
| 751 | @strong{We discourage use of a non-@code{nil} value for | 810 | @strong{We discourage use of a non-@code{nil} value for |
| 752 | @var{initial}}, because it is an intrusive interface. The history | 811 | @var{initial}}, because it is an intrusive interface. The history |
| 753 | list feature (which did not exist when we introduced @var{initial}) | 812 | list feature (which did not exist when we introduced @var{initial}) |
| 754 | offers a far more convenient and general way for the user to get the | 813 | offers a far more convenient and general way for the user to get the |
| 755 | default and edit it, and it is always available. | 814 | default and edit it, and it is always available. For an exception to |
| 815 | this rule, see @ref{Minibuffer History}. | ||
| 756 | 816 | ||
| 757 | If the argument @var{inherit-input-method} is non-@code{nil}, then the | 817 | If the argument @var{inherit-input-method} is non-@code{nil}, then the |
| 758 | minibuffer inherits the current input method (@pxref{Input | 818 | minibuffer inherits the current input method (@pxref{Input |
| @@ -799,8 +859,11 @@ see @ref{Completion Commands}. | |||
| 799 | @node Completion Commands | 859 | @node Completion Commands |
| 800 | @subsection Minibuffer Commands that Do Completion | 860 | @subsection Minibuffer Commands that Do Completion |
| 801 | 861 | ||
| 802 | This section describes the keymaps, commands and user options used in | 862 | This section describes the keymaps, commands and user options used |
| 803 | the minibuffer to do completion. | 863 | in the minibuffer to do completion. The description refers to the |
| 864 | situation when @code{partial-completion-mode} is disabled (as it is by | ||
| 865 | default). When enabled, this minor mode uses its own alternatives to | ||
| 866 | some of the commands described below. | ||
| 804 | 867 | ||
| 805 | @defvar minibuffer-local-completion-map | 868 | @defvar minibuffer-local-completion-map |
| 806 | @code{completing-read} uses this value as the local keymap when an | 869 | @code{completing-read} uses this value as the local keymap when an |
| @@ -820,7 +883,7 @@ keymap makes the following bindings: | |||
| 820 | 883 | ||
| 821 | @noindent | 884 | @noindent |
| 822 | with other characters bound as in @code{minibuffer-local-map} | 885 | with other characters bound as in @code{minibuffer-local-map} |
| 823 | (@pxref{Text from Minibuffer}). | 886 | (@pxref{Definition of minibuffer-local-map}). |
| 824 | @end defvar | 887 | @end defvar |
| 825 | 888 | ||
| 826 | @defvar minibuffer-local-must-match-map | 889 | @defvar minibuffer-local-must-match-map |
| @@ -852,8 +915,8 @@ with other characters bound as in @code{minibuffer-local-map}. | |||
| 852 | @end defvar | 915 | @end defvar |
| 853 | 916 | ||
| 854 | @defvar minibuffer-completion-table | 917 | @defvar minibuffer-completion-table |
| 855 | The value of this variable is the alist or obarray used for completion | 918 | The value of this variable is the collection used for completion in |
| 856 | in the minibuffer. This is the global variable that contains what | 919 | the minibuffer. This is the global variable that contains what |
| 857 | @code{completing-read} passes to @code{try-completion}. It is used by | 920 | @code{completing-read} passes to @code{try-completion}. It is used by |
| 858 | minibuffer completion commands such as @code{minibuffer-complete-word}. | 921 | minibuffer completion commands such as @code{minibuffer-complete-word}. |
| 859 | @end defvar | 922 | @end defvar |
| @@ -907,8 +970,10 @@ This function displays @var{completions} to the stream in | |||
| 907 | information about streams.) The argument @var{completions} is normally | 970 | information about streams.) The argument @var{completions} is normally |
| 908 | a list of completions just returned by @code{all-completions}, but it | 971 | a list of completions just returned by @code{all-completions}, but it |
| 909 | does not have to be. Each element may be a symbol or a string, either | 972 | does not have to be. Each element may be a symbol or a string, either |
| 910 | of which is simply printed, or a list of two strings, which is printed | 973 | of which is simply printed. It can also be a list of two strings, |
| 911 | as if the strings were concatenated. | 974 | which is printed as if the strings were concatenated. The first of |
| 975 | the two strings is the actual completion, the second string serves as | ||
| 976 | annotation. | ||
| 912 | 977 | ||
| 913 | This function is called by @code{minibuffer-completion-help}. The | 978 | This function is called by @code{minibuffer-completion-help}. The |
| 914 | most common way to use it is together with | 979 | most common way to use it is together with |
| @@ -948,9 +1013,10 @@ is not inserted in the minibuffer as initial input. | |||
| 948 | If @var{existing} is non-@code{nil}, then the name specified must be | 1013 | If @var{existing} is non-@code{nil}, then the name specified must be |
| 949 | that of an existing buffer. The usual commands to exit the minibuffer | 1014 | that of an existing buffer. The usual commands to exit the minibuffer |
| 950 | do not exit if the text is not valid, and @key{RET} does completion to | 1015 | do not exit if the text is not valid, and @key{RET} does completion to |
| 951 | attempt to find a valid name. (However, @var{default} is not checked | 1016 | attempt to find a valid name. If @var{existing} is neither @code{nil} |
| 952 | for validity; it is returned, whatever it is, if the user exits with the | 1017 | nor @code{t}, confirmation is required after completion. (However, |
| 953 | minibuffer empty.) | 1018 | @var{default} is not checked for validity; it is returned, whatever it |
| 1019 | is, if the user exits with the minibuffer empty.) | ||
| 954 | 1020 | ||
| 955 | In the following example, the user enters @samp{minibuffer.t}, and | 1021 | In the following example, the user enters @samp{minibuffer.t}, and |
| 956 | then types @key{RET}. The argument @var{existing} is @code{t}, and the | 1022 | then types @key{RET}. The argument @var{existing} is @code{t}, and the |
| @@ -996,7 +1062,8 @@ The argument @var{default} specifies what to return if the user enters | |||
| 996 | null input. It can be a symbol or a string; if it is a string, | 1062 | null input. It can be a symbol or a string; if it is a string, |
| 997 | @code{read-command} interns it before returning it. If @var{default} is | 1063 | @code{read-command} interns it before returning it. If @var{default} is |
| 998 | @code{nil}, that means no default has been specified; then if the user | 1064 | @code{nil}, that means no default has been specified; then if the user |
| 999 | enters null input, the return value is @code{nil}. | 1065 | enters null input, the return value is @code{(intern "")}, that is, a |
| 1066 | symbol whose name is an empty string. | ||
| 1000 | 1067 | ||
| 1001 | @example | 1068 | @example |
| 1002 | (read-command "Command name? ") | 1069 | (read-command "Command name? ") |
| @@ -1041,7 +1108,7 @@ The argument @var{default} specifies what to return if the user enters | |||
| 1041 | null input. It can be a symbol or a string; if it is a string, | 1108 | null input. It can be a symbol or a string; if it is a string, |
| 1042 | @code{read-variable} interns it before returning it. If @var{default} | 1109 | @code{read-variable} interns it before returning it. If @var{default} |
| 1043 | is @code{nil}, that means no default has been specified; then if the | 1110 | is @code{nil}, that means no default has been specified; then if the |
| 1044 | user enters null input, the return value is @code{nil}. | 1111 | user enters null input, the return value is @code{(intern "")}. |
| 1045 | 1112 | ||
| 1046 | @example | 1113 | @example |
| 1047 | @group | 1114 | @group |
| @@ -1090,10 +1157,7 @@ of the default directory. | |||
| 1090 | 1157 | ||
| 1091 | @defun read-file-name prompt &optional directory default existing initial predicate | 1158 | @defun read-file-name prompt &optional directory default existing initial predicate |
| 1092 | This function reads a file name in the minibuffer, prompting with | 1159 | This function reads a file name in the minibuffer, prompting with |
| 1093 | @var{prompt} and providing completion. If @var{default} is | 1160 | @var{prompt} and providing completion. |
| 1094 | non-@code{nil}, then the function returns @var{default} if the user just | ||
| 1095 | types @key{RET}. @var{default} is not checked for validity; it is | ||
| 1096 | returned, whatever it is, if the user exits with the minibuffer empty. | ||
| 1097 | 1161 | ||
| 1098 | If @var{existing} is non-@code{nil}, then the user must specify the name | 1162 | If @var{existing} is non-@code{nil}, then the user must specify the name |
| 1099 | of an existing file; @key{RET} performs completion to make the name | 1163 | of an existing file; @key{RET} performs completion to make the name |
| @@ -1104,10 +1168,10 @@ value of @var{existing} is neither @code{nil} nor @code{t}, then | |||
| 1104 | acceptable. | 1168 | acceptable. |
| 1105 | 1169 | ||
| 1106 | The argument @var{directory} specifies the directory to use for | 1170 | The argument @var{directory} specifies the directory to use for |
| 1107 | completion of relative file names. If @code{insert-default-directory} | 1171 | completion of relative file names. It should be an absolute directory |
| 1108 | is non-@code{nil}, @var{directory} is also inserted in the minibuffer as | 1172 | name. If @code{insert-default-directory} is non-@code{nil}, |
| 1109 | initial input. It defaults to the current buffer's value of | 1173 | @var{directory} is also inserted in the minibuffer as initial input. |
| 1110 | @code{default-directory}. | 1174 | It defaults to the current buffer's value of @code{default-directory}. |
| 1111 | 1175 | ||
| 1112 | @c Emacs 19 feature | 1176 | @c Emacs 19 feature |
| 1113 | If you specify @var{initial}, that is an initial file name to insert | 1177 | If you specify @var{initial}, that is an initial file name to insert |
| @@ -1118,11 +1182,45 @@ case, point goes at the beginning of @var{initial}. The default for | |||
| 1118 | note:} we recommend using @var{default} rather than @var{initial} in | 1182 | note:} we recommend using @var{default} rather than @var{initial} in |
| 1119 | most cases. | 1183 | most cases. |
| 1120 | 1184 | ||
| 1185 | If @var{default} is non-@code{nil}, then the function returns | ||
| 1186 | @var{default} if the user exits the minibuffer with the same non-empty | ||
| 1187 | contents that @code{read-file-name} inserted initially. The initial | ||
| 1188 | minibuffer contents are always non-empty if | ||
| 1189 | @code{insert-default-directory} is non-@code{nil}, as it is by | ||
| 1190 | default. @var{default} is not checked for validity, regardless of the | ||
| 1191 | value of @var{existing}. However, if @var{existing} is | ||
| 1192 | non-@code{nil}, the initial minibuffer contents should be a valid file | ||
| 1193 | (or directory) name. Otherwise @code{read-file-name} attempts | ||
| 1194 | completion if the user exits without any editing, and does not return | ||
| 1195 | @var{default}. @var{default} is also available through the history | ||
| 1196 | commands. | ||
| 1197 | |||
| 1198 | If @var{default} is @code{nil}, @code{read-file-name} tries to find a | ||
| 1199 | substitute default to use in its place, which it treats in exactly the | ||
| 1200 | same way as if it had been specified explicitly. If @var{default} is | ||
| 1201 | @code{nil}, but @var{initial} is non-@code{nil}, then the default is | ||
| 1202 | the absolute file name obtained from @var{directory} and | ||
| 1203 | @var{initial}. If both @var{default} and @var{initial} are @code{nil} | ||
| 1204 | and the buffer is visiting a file, @code{read-file-name} uses the | ||
| 1205 | absolute file name of that file as default. If the buffer is not | ||
| 1206 | visiting a file, then there is no default. In that case, if the user | ||
| 1207 | types @key{RET} without any editing, @code{read-file-name} simply | ||
| 1208 | returns the pre-inserted contents of the minibuffer. | ||
| 1209 | |||
| 1210 | If the user types @key{RET} in an empty minibuffer, this function | ||
| 1211 | returns an empty string, regardless of the value of @var{existing}. | ||
| 1212 | This is, for instance, how the user can make the current buffer visit | ||
| 1213 | no file using @code{M-x set-visited-file-name}. | ||
| 1214 | |||
| 1121 | If @var{predicate} is non-@code{nil}, it specifies a function of one | 1215 | If @var{predicate} is non-@code{nil}, it specifies a function of one |
| 1122 | argument that decides which file names are acceptable completion | 1216 | argument that decides which file names are acceptable completion |
| 1123 | possibilities. A file name is an acceptable value if @var{predicate} | 1217 | possibilities. A file name is an acceptable value if @var{predicate} |
| 1124 | returns non-@code{nil} for it. | 1218 | returns non-@code{nil} for it. |
| 1125 | 1219 | ||
| 1220 | @code{read-file-name} does not automatically expand file names. You | ||
| 1221 | must call @code{expand-file-name} yourself if an absolute file name is | ||
| 1222 | required. | ||
| 1223 | |||
| 1126 | Here is an example: | 1224 | Here is an example: |
| 1127 | 1225 | ||
| 1128 | @example | 1226 | @example |
| @@ -1160,17 +1258,35 @@ as the string @code{"/gp/gnu/elisp/manual.texi"}. | |||
| 1160 | @defun read-directory-name prompt &optional directory default existing initial | 1258 | @defun read-directory-name prompt &optional directory default existing initial |
| 1161 | This function is like @code{read-file-name} but allows only directory | 1259 | This function is like @code{read-file-name} but allows only directory |
| 1162 | names as completion possibilities. | 1260 | names as completion possibilities. |
| 1261 | |||
| 1262 | If @var{default} is @code{nil} and @var{initial} is non-@code{nil}, | ||
| 1263 | @code{read-directory-name} constructs a substitute default by | ||
| 1264 | combining @var{directory} (or the current buffer's default directory | ||
| 1265 | if @var{directory} is @code{nil}) and @var{initial}. If both | ||
| 1266 | @var{default} and @var{initial} are @code{nil}, this function uses the | ||
| 1267 | current buffer's default directory as substitute default, ignoring | ||
| 1268 | @var{directory}. | ||
| 1163 | @end defun | 1269 | @end defun |
| 1164 | 1270 | ||
| 1165 | @defopt insert-default-directory | 1271 | @defopt insert-default-directory |
| 1166 | This variable is used by @code{read-file-name}. Its value controls | 1272 | This variable is used by @code{read-file-name}, and thus, indirectly, |
| 1167 | whether @code{read-file-name} starts by placing the name of the default | 1273 | by most commands reading file names. (This includes all commands that |
| 1168 | directory in the minibuffer, plus the initial file name if any. If the | 1274 | use the code letters @samp{f} or @samp{F} in their interactive form. |
| 1169 | value of this variable is @code{nil}, then @code{read-file-name} does | 1275 | @xref{Interactive Codes,, Code Characters for interactive}.) Its |
| 1170 | not place any initial input in the minibuffer (unless you specify | 1276 | value controls whether @code{read-file-name} starts by placing the |
| 1171 | initial input with the @var{initial} argument). In that case, the | 1277 | name of the default directory in the minibuffer, plus the initial file |
| 1172 | default directory is still used for completion of relative file names, | 1278 | name if any. If the value of this variable is @code{nil}, then |
| 1173 | but is not displayed. | 1279 | @code{read-file-name} does not place any initial input in the |
| 1280 | minibuffer (unless you specify initial input with the @var{initial} | ||
| 1281 | argument). In that case, the default directory is still used for | ||
| 1282 | completion of relative file names, but is not displayed. | ||
| 1283 | |||
| 1284 | If this variable is @code{nil} and the initial minibuffer contents are | ||
| 1285 | empty, the user may have to explicitly fetch the next history element | ||
| 1286 | to access a default value. If the variable is non-@code{nil}, the | ||
| 1287 | initial minibuffer contents are always non-empty and the user can | ||
| 1288 | always request a default value by immediately typing @key{RET} in an | ||
| 1289 | unedited minibuffer. (See above.) | ||
| 1174 | 1290 | ||
| 1175 | For example: | 1291 | For example: |
| 1176 | 1292 | ||
| @@ -1627,9 +1743,10 @@ The current value of this variable is used to rebind @code{help-form} | |||
| 1627 | locally inside the minibuffer (@pxref{Help Functions}). | 1743 | locally inside the minibuffer (@pxref{Help Functions}). |
| 1628 | @end defvar | 1744 | @end defvar |
| 1629 | 1745 | ||
| 1630 | @defun minibufferp &optional buffer | 1746 | @defun minibufferp &optional buffer-or-name |
| 1631 | This function returns non-@code{nil} if @var{buffer} is a minibuffer. | 1747 | This function returns non-@code{nil} if @var{buffer-or-name} is a |
| 1632 | If @var{buffer} is omitted, it tests the current buffer. | 1748 | minibuffer. If @var{buffer-or-name} is omitted, it tests the current |
| 1749 | buffer. | ||
| 1633 | @end defun | 1750 | @end defun |
| 1634 | 1751 | ||
| 1635 | @defun active-minibuffer-window | 1752 | @defun active-minibuffer-window |
| @@ -1654,8 +1771,10 @@ choosing the minibuffer window according to the current frame. | |||
| 1654 | @end defun | 1771 | @end defun |
| 1655 | 1772 | ||
| 1656 | @c Emacs 19 feature | 1773 | @c Emacs 19 feature |
| 1657 | @defun window-minibuffer-p window | 1774 | @defun window-minibuffer-p &optional window |
| 1658 | This function returns non-@code{nil} if @var{window} is a minibuffer window. | 1775 | This function returns non-@code{nil} if @var{window} is a minibuffer |
| 1776 | window. | ||
| 1777 | @var{window} defaults to the selected window. | ||
| 1659 | @end defun | 1778 | @end defun |
| 1660 | 1779 | ||
| 1661 | It is not correct to determine whether a given window is a minibuffer by | 1780 | It is not correct to determine whether a given window is a minibuffer by |
| @@ -1704,14 +1823,16 @@ another window to do it. | |||
| 1704 | @c Emacs 19 feature | 1823 | @c Emacs 19 feature |
| 1705 | If a command name has a property @code{enable-recursive-minibuffers} | 1824 | If a command name has a property @code{enable-recursive-minibuffers} |
| 1706 | that is non-@code{nil}, then the command can use the minibuffer to read | 1825 | that is non-@code{nil}, then the command can use the minibuffer to read |
| 1707 | arguments even if it is invoked from the minibuffer. The minibuffer | 1826 | arguments even if it is invoked from the minibuffer. A command can |
| 1708 | command @code{next-matching-history-element} (normally @kbd{M-s} in the | 1827 | also achieve this by binding @code{enable-recursive-minibuffers} |
| 1709 | minibuffer) uses this feature. | 1828 | to @code{t} in the interactive declaration (@pxref{Using Interactive}). |
| 1829 | The minibuffer command @code{next-matching-history-element} (normally | ||
| 1830 | @kbd{M-s} in the minibuffer) does the latter. | ||
| 1710 | 1831 | ||
| 1711 | @defun minibuffer-message string &optional timeout | 1832 | @defun minibuffer-message string |
| 1712 | This function displays @var{string} temporarily at the end of the | 1833 | This function displays @var{string} temporarily at the end of the |
| 1713 | minibuffer text, for @var{timeout} seconds. (The default is 2 | 1834 | minibuffer text, for two seconds, or until the next input event |
| 1714 | seconds.) | 1835 | arrives, whichever comes first. |
| 1715 | @end defun | 1836 | @end defun |
| 1716 | 1837 | ||
| 1717 | @ignore | 1838 | @ignore |