aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-02-15 21:45:02 +0800
committerChong Yidong2012-02-15 21:45:02 +0800
commit60236b0dca0416202da5c3e39564b85b2ae3c9fa (patch)
tree64a7ddc4416b0010b37b3edec55495331275ce9d
parent888ab66104667346aff8a1569b924fe92daac7e2 (diff)
downloademacs-60236b0dca0416202da5c3e39564b85b2ae3c9fa.tar.gz
emacs-60236b0dca0416202da5c3e39564b85b2ae3c9fa.zip
Docstring and manual updates for completion-at-point-functions.
* doc/lispref/minibuf.texi (Basic Completion): Define "completion table". Move completion-in-region to Completion in Buffers node. (Completion Commands): Use "completion table" terminology. (Completion in Buffers): New node. * doc/lispref/modes.texi (Hooks): add-hook can be used for abnormal hooks too. (Setting Hooks): Update minor mode usage example. (Major Mode Conventions): Note that completion-at-point-functions should be altered locally. Add xref to Completion in Buffers. * lisp/minibuffer.el (completion-at-point-functions): Doc fix.
-rw-r--r--doc/lispref/ChangeLog12
-rw-r--r--doc/lispref/elisp.texi1
-rw-r--r--doc/lispref/minibuf.texi147
-rw-r--r--doc/lispref/modes.texi53
-rw-r--r--doc/lispref/vol1.texi1
-rw-r--r--doc/lispref/vol2.texi1
-rw-r--r--lisp/ChangeLog2
-rw-r--r--lisp/minibuffer.el8
8 files changed, 155 insertions, 70 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 296b4e90b4b..1e369f3b627 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,15 @@
12012-02-15 Chong Yidong <cyd@gnu.org>
2
3 * minibuf.texi (Basic Completion): Define "completion table".
4 Move completion-in-region to Completion in Buffers node.
5 (Completion Commands): Use "completion table" terminology.
6 (Completion in Buffers): New node.
7
8 * modes.texi (Hooks): add-hook can be used for abnormal hooks too.
9 (Setting Hooks): Update minor mode usage example.
10 (Major Mode Conventions): Note that completion-at-point-functions
11 should be altered locally. Add xref to Completion in Buffers.
12
12012-02-15 Glenn Morris <rgm@gnu.org> 132012-02-15 Glenn Morris <rgm@gnu.org>
2 14
3 * processes.texi (Network): Document open-network-stream :parameters. 15 * processes.texi (Network): Document open-network-stream :parameters.
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 42c3613dd0b..5dd8994f439 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -654,6 +654,7 @@ Completion
654 shell commands. 654 shell commands.
655* Completion Styles:: Specifying rules for performing completion. 655* Completion Styles:: Specifying rules for performing completion.
656* Programmed Completion:: Writing your own completion-function. 656* Programmed Completion:: Writing your own completion-function.
657* Completion in Buffers:: Completing text in ordinary buffers.
657 658
658Command Loop 659Command Loop
659 660
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index a71138f5268..1224d80fdf8 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -633,6 +633,7 @@ for reading certain kinds of names with completion.
633 shell commands. 633 shell commands.
634* Completion Styles:: Specifying rules for performing completion. 634* Completion Styles:: Specifying rules for performing completion.
635* Programmed Completion:: Writing your own completion-function. 635* Programmed Completion:: Writing your own completion-function.
636* Completion in Buffers:: Completing text in ordinary buffers.
636@end menu 637@end menu
637 638
638@node Basic Completion 639@node Basic Completion
@@ -644,10 +645,12 @@ higher-level completion features that do use the minibuffer.
644 645
645@defun try-completion string collection &optional predicate 646@defun try-completion string collection &optional predicate
646This function returns the longest common substring of all possible 647This function returns the longest common substring of all possible
647completions of @var{string} in @var{collection}. The value of 648completions of @var{string} in @var{collection}.
648@var{collection} must be a list of strings, an alist whose keys are 649
649strings or symbols, an obarray, a hash table, or a completion function 650@cindex completion table
650(@pxref{Programmed Completion}). 651The @var{collection} argument is called the @dfn{completion table}.
652Its value must be a list of strings, an alist whose keys are strings
653or symbols, an obarray, a hash table, or a completion function.
651 654
652Completion compares @var{string} against each of the permissible 655Completion compares @var{string} against each of the permissible
653completions specified by @var{collection}. If no permissible 656completions specified by @var{collection}. If no permissible
@@ -678,13 +681,13 @@ Also, you cannot intern a given symbol in more than one obarray.
678If @var{collection} is a hash table, then the keys that are strings 681If @var{collection} is a hash table, then the keys that are strings
679are the possible completions. Other keys are ignored. 682are the possible completions. Other keys are ignored.
680 683
681You can also use a function as @var{collection}. 684You can also use a function as @var{collection}. Then the function is
682Then the function is solely responsible for performing completion; 685solely responsible for performing completion; @code{try-completion}
683@code{try-completion} returns whatever this function returns. The 686returns whatever this function returns. The function is called with
684function is called with three arguments: @var{string}, @var{predicate} 687three arguments: @var{string}, @var{predicate} and @code{nil} (the
685and @code{nil} (the reason for the third argument is so that the same 688reason for the third argument is so that the same function can be used
686function can be used in @code{all-completions} and do the appropriate 689in @code{all-completions} and do the appropriate thing in either
687thing in either case). @xref{Programmed Completion}. 690case). @xref{Programmed Completion}.
688 691
689If the argument @var{predicate} is non-@code{nil}, then it must be a 692If the argument @var{predicate} is non-@code{nil}, then it must be a
690function of one argument, unless @var{collection} is a hash table, in 693function of one argument, unless @var{collection} is a hash table, in
@@ -862,30 +865,13 @@ proper value is done the first time you do completion using @var{var}.
862It is done by calling @var{fun} with no arguments. The 865It is done by calling @var{fun} with no arguments. The
863value @var{fun} returns becomes the permanent value of @var{var}. 866value @var{fun} returns becomes the permanent value of @var{var}.
864 867
865Here is an example of use: 868Here is a usage example:
866 869
867@smallexample 870@smallexample
868(defvar foo (lazy-completion-table foo make-my-alist)) 871(defvar foo (lazy-completion-table foo make-my-alist))
869@end smallexample 872@end smallexample
870@end defmac 873@end defmac
871 874
872The function @code{completion-in-region} provides a convenient way to
873perform completion on an arbitrary stretch of text in an Emacs buffer:
874
875@defun completion-in-region start end collection &optional predicate
876This function completes the text in the current buffer between the
877positions @var{start} and @var{end}, using @var{collection}. The
878argument @var{collection} has the same meaning as in
879@code{try-completion} (@pxref{Basic Completion}).
880
881This function inserts the completion text directly into the current
882buffer. Unlike @code{completing-read} (@pxref{Minibuffer
883Completion}), it does not activate the minibuffer.
884
885For this function to work, point must be somewhere between @var{start}
886and @var{end}.
887@end defun
888
889@node Minibuffer Completion 875@node Minibuffer Completion
890@subsection Completion and the Minibuffer 876@subsection Completion and the Minibuffer
891@cindex minibuffer completion 877@cindex minibuffer completion
@@ -899,13 +885,14 @@ This function reads a string in the minibuffer, assisting the user by
899providing completion. It activates the minibuffer with prompt 885providing completion. It activates the minibuffer with prompt
900@var{prompt}, which must be a string. 886@var{prompt}, which must be a string.
901 887
902The actual completion is done by passing @var{collection} and 888The actual completion is done by passing the completion table
903@var{predicate} to the function @code{try-completion} (@pxref{Basic 889@var{collection} and the completion predicate @var{predicate} to the
904Completion}). This happens in certain commands bound in the local 890function @code{try-completion} (@pxref{Basic Completion}). This
905keymaps used for completion. Some of these commands also call 891happens in certain commands bound in the local keymaps used for
906@code{test-completion}. Thus, if @var{predicate} is non-@code{nil}, 892completion. Some of these commands also call @code{test-completion}.
907it should be compatible with @var{collection} and 893Thus, if @var{predicate} is non-@code{nil}, it should be compatible
908@code{completion-ignore-case}. @xref{Definition of test-completion}. 894with @var{collection} and @code{completion-ignore-case}.
895@xref{Definition of test-completion}.
909 896
910The value of the optional argument @var{require-match} determines how 897The value of the optional argument @var{require-match} determines how
911the user may exit the minibuffer: 898the user may exit the minibuffer:
@@ -1005,10 +992,11 @@ They are described in the following section.
1005in the minibuffer to do completion. 992in the minibuffer to do completion.
1006 993
1007@defvar minibuffer-completion-table 994@defvar minibuffer-completion-table
1008The value of this variable is the collection used for completion in 995The value of this variable is the completion table used for completion
1009the minibuffer. This is the global variable that contains what 996in the minibuffer. This is the global variable that contains what
1010@code{completing-read} passes to @code{try-completion}. It is used by 997@code{completing-read} passes to @code{try-completion}. It is used by
1011minibuffer completion commands such as @code{minibuffer-complete-word}. 998minibuffer completion commands such as
999@code{minibuffer-complete-word}.
1012@end defvar 1000@end defvar
1013 1001
1014@defvar minibuffer-completion-predicate 1002@defvar minibuffer-completion-predicate
@@ -1717,6 +1705,87 @@ completion via the variable @code{minibuffer-completion-table}
1717(@pxref{Completion Commands}). 1705(@pxref{Completion Commands}).
1718@end defvar 1706@end defvar
1719 1707
1708@node Completion in Buffers
1709@subsection Completion in Ordinary Buffers
1710@cindex inline completion
1711
1712@findex completion-at-point
1713 Although completion is usually done in the minibuffer, the
1714completion facility can also be used on the text in ordinary Emacs
1715buffers. In many major modes, in-buffer completion is performed by
1716the @kbd{C-M-i} or @kbd{M-@key{TAB}} command, bound to
1717@code{completion-at-point}. @xref{Symbol Completion,,, emacs, The GNU
1718Emacs Manual}. This command uses the abnormal hook variable
1719@code{completion-at-point-functions}:
1720
1721@defvar completion-at-point-functions
1722The value of this abnormal hook should be a list of functions, which
1723are used to compute a completion table for completing the text at
1724point. It can be used by major modes to provide mode-specific
1725completion tables (@pxref{Major Mode Conventions}).
1726
1727When the command @code{completion-at-point} runs, it calls the
1728functions in the list one by one, without any argument. Each function
1729should return @code{nil} if it is unable to produce a completion table
1730for the text at point. Otherwise it should return a list of the form
1731
1732@example
1733(@var{start} @var{end} @var{collection} . @var{props})
1734@end example
1735
1736@noindent
1737@var{start} and @var{end} delimit the text to complete (which should
1738enclose point). @var{collection} is a completion table for completing
1739that text, in a form suitable for passing as the second argument to
1740@code{try-completion} (@pxref{Basic Completion}); completion
1741alternatives will be generated from this completion table in the usual
1742way, via the completion styles defined in @code{completion-styles}
1743(@pxref{Completion Styles}). @var{props} is a property list for
1744additional information; the following optional properties are
1745recognized:
1746
1747@table @code
1748@item :predicate
1749The value should be a predicate that completion candidates need to
1750satisfy.
1751
1752@item :exclusive
1753If the value is @code{no}, then if the completion table fails to match
1754the text at point, then @code{completion-at-point} moves on to the
1755next function in @code{completion-at-point-functions} instead of
1756reporting a completion failure.
1757@end table
1758
1759A function in @code{completion-at-point-functions} may also return a
1760function. In that case, that returned function is called, with no
1761argument, and it is entirely responsible for performing the
1762completion. We discourage this usage; it is intended to help convert
1763old code to using @code{completion-at-point}.
1764
1765The first function in @code{completion-at-point-functions} to return a
1766non-@code{nil} value is used by @code{completion-at-point}. The
1767remaining functions are not called. The exception to this is when
1768there is a @code{:exclusive} specification, as described above.
1769@end defvar
1770
1771 The following function provides a convenient way to perform
1772completion on an arbitrary stretch of text in an Emacs buffer:
1773
1774@defun completion-in-region start end collection &optional predicate
1775This function completes the text in the current buffer between the
1776positions @var{start} and @var{end}, using @var{collection}. The
1777argument @var{collection} has the same meaning as in
1778@code{try-completion} (@pxref{Basic Completion}).
1779
1780This function inserts the completion text directly into the current
1781buffer. Unlike @code{completing-read} (@pxref{Minibuffer
1782Completion}), it does not activate the minibuffer.
1783
1784For this function to work, point must be somewhere between @var{start}
1785and @var{end}.
1786@end defun
1787
1788
1720@node Yes-or-No Queries 1789@node Yes-or-No Queries
1721@section Yes-or-No Queries 1790@section Yes-or-No Queries
1722@cindex asking the user questions 1791@cindex asking the user questions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 0b020bee0b0..94ae767586b 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -48,17 +48,16 @@ you it is normal. We try to make all hooks normal, as much as
48possible, so that you can use them in a uniform way. 48possible, so that you can use them in a uniform way.
49 49
50 Every major mode command is supposed to run a normal hook called the 50 Every major mode command is supposed to run a normal hook called the
51@dfn{mode hook} as the one of the last steps of initialization. This 51@dfn{mode hook} as one of the last steps of initialization. This makes
52makes it easy for a user to customize the behavior of the mode, by 52it easy for a user to customize the behavior of the mode, by overriding
53overriding the buffer-local variable assignments already made by the 53the buffer-local variable assignments already made by the mode. Most
54mode. Most minor mode functions also run a mode hook at the end. But 54minor mode functions also run a mode hook at the end. But hooks are
55hooks are used in other contexts too. For example, the hook 55used in other contexts too. For example, the hook @code{suspend-hook}
56@code{suspend-hook} runs just before Emacs suspends itself 56runs just before Emacs suspends itself (@pxref{Suspending Emacs}).
57(@pxref{Suspending Emacs}). 57
58 58 The recommended way to add a hook function to a hook is by calling
59 The recommended way to add a hook function to a normal hook is by 59@code{add-hook} (@pxref{Setting Hooks}). The hook functions may be any
60calling @code{add-hook} (see below). The hook functions may be any of 60of the valid kinds of functions that @code{funcall} accepts (@pxref{What
61the valid kinds of functions that @code{funcall} accepts (@pxref{What
62Is a Function}). Most normal hook variables are initially void; 61Is a Function}). Most normal hook variables are initially void;
63@code{add-hook} knows how to deal with this. You can add hooks either 62@code{add-hook} knows how to deal with this. You can add hooks either
64globally or buffer-locally with @code{add-hook}. 63globally or buffer-locally with @code{add-hook}.
@@ -178,7 +177,7 @@ calls @code{wrap-function} with arguments @code{fun} and @code{args}.
178in Lisp Interaction mode: 177in Lisp Interaction mode:
179 178
180@example 179@example
181(add-hook 'lisp-interaction-mode-hook 'turn-on-auto-fill) 180(add-hook 'lisp-interaction-mode-hook 'auto-fill-mode)
182@end example 181@end example
183 182
184@defun add-hook hook function &optional append local 183@defun add-hook hook function &optional append local
@@ -202,13 +201,13 @@ If @var{function} has a non-@code{nil} property
202changing major modes) won't delete it from the hook variable's local 201changing major modes) won't delete it from the hook variable's local
203value. 202value.
204 203
205It is best to design your hook functions so that the order in which 204For a normal hook, hook functions should be designed so that the order
206they are executed does not matter. Any dependence on the order is 205in which they are executed does not matter. Any dependence on the order
207asking for trouble. However, the order is predictable: normally, 206is asking for trouble. However, the order is predictable: normally,
208@var{function} goes at the front of the hook list, so it will be 207@var{function} goes at the front of the hook list, so it is executed
209executed first (barring another @code{add-hook} call). If the 208first (barring another @code{add-hook} call). If the optional argument
210optional argument @var{append} is non-@code{nil}, the new hook 209@var{append} is non-@code{nil}, the new hook function goes at the end of
211function goes at the end of the hook list and will be executed last. 210the hook list and is executed last.
212 211
213@code{add-hook} can handle the cases where @var{hook} is void or its 212@code{add-hook} can handle the cases where @var{hook} is void or its
214value is a single function; it sets or changes the value to a list of 213value is a single function; it sets or changes the value to a list of
@@ -302,8 +301,8 @@ initialization, function and variable names, and hooks.
302 301
303 If you use the @code{define-derived-mode} macro, it will take care of 302 If you use the @code{define-derived-mode} macro, it will take care of
304many of these conventions automatically. @xref{Derived Modes}. Note 303many of these conventions automatically. @xref{Derived Modes}. Note
305also that fundamental mode is an exception to many of these conventions, 304also that Fundamental mode is an exception to many of these conventions,
306because its definition is to present the global state of Emacs. 305because it represents the default state of Emacs.
307 306
308 The following list of conventions is only partial. Each major mode 307 The following list of conventions is only partial. Each major mode
309should aim for consistency in general with other Emacs major modes, as 308should aim for consistency in general with other Emacs major modes, as
@@ -460,8 +459,9 @@ The mode can specify a local value for
460this mode. 459this mode.
461 460
462@item 461@item
463The mode can specify how to complete various keywords by adding 462The mode can specify how to complete various keywords by adding one or
464to the special hook @code{completion-at-point-functions}. 463more buffer-local entries to the special hook
464@code{completion-at-point-functions}. @xref{Completion in Buffers}.
465 465
466@item 466@item
467Use @code{defvar} or @code{defcustom} to set mode-related variables, so 467Use @code{defvar} or @code{defcustom} to set mode-related variables, so
@@ -555,16 +555,15 @@ In the comments that document the file, you should provide a sample
555@cindex mode loading 555@cindex mode loading
556The top-level forms in the file defining the mode should be written so 556The top-level forms in the file defining the mode should be written so
557that they may be evaluated more than once without adverse consequences. 557that they may be evaluated more than once without adverse consequences.
558Even if you never load the file more than once, someone else will.
559@end itemize 558@end itemize
560 559
561@node Auto Major Mode 560@node Auto Major Mode
562@subsection How Emacs Chooses a Major Mode 561@subsection How Emacs Chooses a Major Mode
563@cindex major mode, automatic selection 562@cindex major mode, automatic selection
564 563
565 Based on information in the file name or in the file itself, Emacs 564 When Emacs visits a file, it automatically selects a major mode for
566automatically selects a major mode for the new buffer when a file is 565the buffer based on information in the file name or in the file itself.
567visited. It also processes local variables specified in the file text. 566It also processes local variables specified in the file text.
568 567
569@deffn Command normal-mode &optional find-file 568@deffn Command normal-mode &optional find-file
570This function establishes the proper major mode and buffer-local variable 569This function establishes the proper major mode and buffer-local variable
diff --git a/doc/lispref/vol1.texi b/doc/lispref/vol1.texi
index cc96726745f..dbab287b273 100644
--- a/doc/lispref/vol1.texi
+++ b/doc/lispref/vol1.texi
@@ -675,6 +675,7 @@ Completion
675 shell commands. 675 shell commands.
676* Completion Styles:: Specifying rules for performing completion. 676* Completion Styles:: Specifying rules for performing completion.
677* Programmed Completion:: Writing your own completion-function. 677* Programmed Completion:: Writing your own completion-function.
678* Completion in Buffers:: Completing text in ordinary buffers.
678 679
679Command Loop 680Command Loop
680 681
diff --git a/doc/lispref/vol2.texi b/doc/lispref/vol2.texi
index 33246cb567d..38e2f1dc5e9 100644
--- a/doc/lispref/vol2.texi
+++ b/doc/lispref/vol2.texi
@@ -674,6 +674,7 @@ Completion
674 shell commands. 674 shell commands.
675* Completion Styles:: Specifying rules for performing completion. 675* Completion Styles:: Specifying rules for performing completion.
676* Programmed Completion:: Writing your own completion-function. 676* Programmed Completion:: Writing your own completion-function.
677* Completion in Buffers:: Completing text in ordinary buffers.
677 678
678Command Loop 679Command Loop
679 680
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ccb1394e3d5..bdbe99d5452 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -5,6 +5,8 @@
5 5
62012-02-15 Chong Yidong <cyd@gnu.org> 62012-02-15 Chong Yidong <cyd@gnu.org>
7 7
8 * minibuffer.el (completion-at-point-functions): Doc fix.
9
8 * custom.el (defcustom): Doc fix; note use of defvar. 10 * custom.el (defcustom): Doc fix; note use of defvar.
9 11
102012-02-15 Glenn Morris <rgm@gnu.org> 122012-02-15 Glenn Morris <rgm@gnu.org>
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 611df1eb6d9..8564cc2009b 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1550,16 +1550,16 @@ the mode if ARG is omitted or nil."
1550Each function on this hook is called in turns without any argument and should 1550Each function on this hook is called in turns without any argument and should
1551return either nil to mean that it is not applicable at point, 1551return either nil to mean that it is not applicable at point,
1552or a function of no argument to perform completion (discouraged), 1552or a function of no argument to perform completion (discouraged),
1553or a list of the form (START END COLLECTION &rest PROPS) where 1553or a list of the form (START END COLLECTION . PROPS) where
1554 START and END delimit the entity to complete and should include point, 1554 START and END delimit the entity to complete and should include point,
1555 COLLECTION is the completion table to use to complete it, and 1555 COLLECTION is the completion table to use to complete it, and
1556 PROPS is a property list for additional information. 1556 PROPS is a property list for additional information.
1557Currently supported properties are all the properties that can appear in 1557Currently supported properties are all the properties that can appear in
1558`completion-extra-properties' plus: 1558`completion-extra-properties' plus:
1559 `:predicate' a predicate that completion candidates need to satisfy. 1559 `:predicate' a predicate that completion candidates need to satisfy.
1560 `:exclusive' If `no', means that if the completion data does not match the 1560 `:exclusive' If `no', means that if the completion table fails to
1561 text at point failure, then instead of reporting a completion failure, 1561 match the text at point, then instead of reporting a completion
1562 the completion should try the next completion function.") 1562 failure, the completion should try the next completion function.")
1563 1563
1564(defvar completion--capf-misbehave-funs nil 1564(defvar completion--capf-misbehave-funs nil
1565 "List of functions found on `completion-at-point-functions' that misbehave. 1565 "List of functions found on `completion-at-point-functions' that misbehave.