comparison lispref/minibuf.texi @ 51989:13ba58726a52

(Basic Completion): Describe test-completion. Collections can be lists of strings. Clean up lazy-completion-table. (Programmed Completion): Mention test-completion. Clarify why lambda expressions are not accepted. (Minibuffer Misc): Describe minibufferp.
author Richard M. Stallman <rms@gnu.org>
date Tue, 22 Jul 2003 15:13:58 +0000
parents 9cd313749c97
children c78c690c99e8
comparison
equal deleted inserted replaced
51988:307806e982a5 51989:13ba58726a52
524 @end menu 524 @end menu
525 525
526 @node Basic Completion 526 @node Basic Completion
527 @subsection Basic Completion Functions 527 @subsection Basic Completion Functions
528 528
529 The two functions @code{try-completion} and @code{all-completions} 529 The functions @code{try-completion}, @code{all-completions} and
530 have nothing in themselves to do with minibuffers. We describe them in 530 @code{test-completion} have nothing in themselves to do with
531 this chapter so as to keep them near the higher-level completion 531 minibuffers. We describe them in this chapter so as to keep them near
532 features that do use the minibuffer. 532 the higher-level completion features that do use the minibuffer.
533 533
534 @defun try-completion string collection &optional predicate 534 @defun try-completion string collection &optional predicate
535 This function returns the longest common substring of all possible 535 This function returns the longest common substring of all possible
536 completions of @var{string} in @var{collection}. The value of 536 completions of @var{string} in @var{collection}. The value of
537 @var{collection} must be an alist, an obarray, or a function that 537 @var{collection} must be a list of strings, an alist, an obarray, or a
538 implements a virtual set of strings (see below). 538 function that implements a virtual set of strings (see below).
539 539
540 Completion compares @var{string} against each of the permissible 540 Completion compares @var{string} against each of the permissible
541 completions specified by @var{collection}; if the beginning of the 541 completions specified by @var{collection}; if the beginning of the
542 permissible completion equals @var{string}, it matches. If no permissible 542 permissible completion equals @var{string}, it matches. If no permissible
543 completions match, @code{try-completion} returns @code{nil}. If only 543 completions match, @code{try-completion} returns @code{nil}. If only
557 557
558 Note that the only valid way to make a new obarray is to create it 558 Note that the only valid way to make a new obarray is to create it
559 empty and then add symbols to it one by one using @code{intern}. 559 empty and then add symbols to it one by one using @code{intern}.
560 Also, you cannot intern a given symbol in more than one obarray. 560 Also, you cannot intern a given symbol in more than one obarray.
561 561
562 If the argument @var{predicate} is non-@code{nil}, then it must be a
563 function of one argument. It is used to test each possible match, and
564 the match is accepted only if @var{predicate} returns non-@code{nil}.
565 The argument given to @var{predicate} is either a cons cell from the alist
566 (the @sc{car} of which is a string) or else it is a symbol (@emph{not} a
567 symbol name) from the obarray.
568
569 You can also use a symbol that is a function as @var{collection}. Then 562 You can also use a symbol that is a function as @var{collection}. Then
570 the function is solely responsible for performing completion; 563 the function is solely responsible for performing completion;
571 @code{try-completion} returns whatever this function returns. The 564 @code{try-completion} returns whatever this function returns. The
572 function is called with three arguments: @var{string}, @var{predicate} 565 function is called with three arguments: @var{string}, @var{predicate}
573 and @code{nil}. (The reason for the third argument is so that the same 566 and @code{nil}. (The reason for the third argument is so that the same
574 function can be used in @code{all-completions} and do the appropriate 567 function can be used in @code{all-completions} and do the appropriate
575 thing in either case.) @xref{Programmed Completion}. 568 thing in either case.) @xref{Programmed Completion}.
576 569
570 If the argument @var{predicate} is non-@code{nil}, then it must be a
571 function of one argument. It is used to test each possible match, and
572 the match is accepted only if @var{predicate} returns non-@code{nil}.
573 The argument given to @var{predicate} is either a string from the
574 list, a cons cell from the alist (the @sc{car} of which is a string)
575 or a symbol (@emph{not} a symbol name) from the obarray.
576
577 In the first of the following examples, the string @samp{foo} is 577 In the first of the following examples, the string @samp{foo} is
578 matched by three of the alist @sc{car}s. All of the matches begin with 578 matched by three of the alist @sc{car}s. All of the matches begin with
579 the characters @samp{fooba}, so that is the result. In the second 579 the characters @samp{fooba}, so that is the result. In the second
580 example, there is only one possible match, and it is exact, so the value 580 example, there is only one possible match, and it is exact, so the value
581 is @code{t}. 581 is @code{t}.
655 @result{} ("foobar1" "foobar2") 655 @result{} ("foobar1" "foobar2")
656 @end group 656 @end group
657 @end smallexample 657 @end smallexample
658 @end defun 658 @end defun
659 659
660 @defun test-completion string collection &optional predicate
661 This function returns non-@code{nil} if @var{string} is a valid
662 completion possibility specified by @var{collection} and
663 @var{predicate}. The other arguments are the same as in
664 @code{try-completion}. For instance, if @var{collection} is a list,
665 this is true if @var{string} appears in the list and @var{predicate}
666 is satisfied.
667
668 If @var{collection} is a function, it is called with three arguments,
669 the values @var{string}, @var{predicate} and @code{lambda}; whatever
670 it returns, @code{test-completion} returns in turn.
671 @end defun
672
660 @defvar completion-ignore-case 673 @defvar completion-ignore-case
661 If the value of this variable is 674 If the value of this variable is non-@code{nil}, Emacs does not
662 non-@code{nil}, Emacs does not consider case significant in completion. 675 consider case significant in completion.
663 @end defvar 676 @end defvar
664 677
665 @defmac lazy-completion-table var fun &rest args 678 @defmac lazy-completion-table var fun &rest args
666 This macro provides a way to initialize the variable @var{var} as a 679 This macro provides a way to initialize the variable @var{var} as a
667 completion table in a lazy way, not computing its actual contents 680 collection for completion in a lazy way, not computing its actual
668 until they are first needed. You use this macro to produce a value 681 contents until they are first needed. You use this macro to produce a
669 that you store in @var{var}. The actual computation of the proper 682 value that you store in @var{var}. The actual computation of the
670 value is done the first time you do completion using @var{var}. It is 683 proper value is done the first time you do completion using @var{var}.
671 done by calling @var{fun} with the arguments @var{args}. The value 684 It is done by calling @var{fun} with the arguments @var{args}. The
672 @var{fun} returns becomes the permanent value of @var{var}. 685 value @var{fun} returns becomes the permanent value of @var{var}.
686
687 Here are two examples of use:
673 688
674 @example 689 @example
675 (defvar foo (lazy-completion-table foo make-my-alist 'global)) 690 (defvar foo (lazy-completion-table foo make-my-alist 'global))
691
676 (make-local-variable 'bar) 692 (make-local-variable 'bar)
677 (setq bar (lazy-completion-table foo make-my-alist 'local) 693 (setq bar (lazy-completion-table foo make-my-alist 'local)
678 @end example 694 @end example
679 @end defmac 695 @end defmac
680 696
1217 @code{t} specifies @code{all-completions}. The completion function 1233 @code{t} specifies @code{all-completions}. The completion function
1218 should return a list of all possible completions of the specified 1234 should return a list of all possible completions of the specified
1219 string. 1235 string.
1220 1236
1221 @item 1237 @item
1222 @code{lambda} specifies a test for an exact match. The completion 1238 @code{lambda} specifies @code{test-completion}. The completion
1223 function should return @code{t} if the specified string is an exact 1239 function should return @code{t} if the specified string is an exact
1224 match for some possibility; @code{nil} otherwise. 1240 match for some possibility; @code{nil} otherwise.
1225 @end itemize 1241 @end itemize
1226 1242
1227 It would be consistent and clean for completion functions to allow 1243 It would be consistent and clean for completion functions to allow
1228 lambda expressions (lists that are functions) as well as function 1244 lambda expressions (lists that are functions) as well as function
1229 symbols as @var{collection}, but this is impossible. Lists as 1245 symbols as @var{collection}, but this is impossible. Lists as
1230 completion tables are already assigned another meaning---as alists. It 1246 completion tables already have other meanings, and it would be
1231 would be unreliable to fail to handle an alist normally because it is 1247 unreliable to treat one differently just because it is also a possible
1232 also a possible function. So you must arrange for any function you wish 1248 function. So you must arrange for any function you wish to use for
1233 to use for completion to be encapsulated in a symbol. 1249 completion to be encapsulated in a symbol.
1234 1250
1235 Emacs uses programmed completion when completing file names. 1251 Emacs uses programmed completion when completing file names.
1236 @xref{File Name Completion}. 1252 @xref{File Name Completion}.
1237 1253
1238 @defmac dynamic-completion-table function 1254 @defmac dynamic-completion-table function
1593 @defvar minibuffer-help-form 1609 @defvar minibuffer-help-form
1594 The current value of this variable is used to rebind @code{help-form} 1610 The current value of this variable is used to rebind @code{help-form}
1595 locally inside the minibuffer (@pxref{Help Functions}). 1611 locally inside the minibuffer (@pxref{Help Functions}).
1596 @end defvar 1612 @end defvar
1597 1613
1614 @defun minibufferp &optional buffer
1615 This function returns non-@code{nil} if @var{buffer} is a minibuffer.
1616 If @var{buffer} is omitted, it tests the current buffer.
1617 @end defun
1618
1598 @defun active-minibuffer-window 1619 @defun active-minibuffer-window
1599 This function returns the currently active minibuffer window, or 1620 This function returns the currently active minibuffer window, or
1600 @code{nil} if none is currently active. 1621 @code{nil} if none is currently active.
1601 @end defun 1622 @end defun
1602 1623