blob: 74b0c78540ddf49720c4bc77dc1aa190ab4c8da8 [file] [log] [blame]
Fred Drake4755e7d1999-06-21 18:25:49 +00001\section{\module{rlcompleter} ---
2 Completion function for readline}
3
4\declaremodule{standard}{rlcompleter}
5\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
6\modulesynopsis{Python identifier completion in the readline library.}
7
8The \module{rlcompleter} module defines a completion function for
9the \module{readline} module by completing valid Python identifiers and
10keyword.
11
12The \module{rlcompleter} module defines the \class{Completer} class.
13
14Example:
15
16\begin{verbatim}
17>>> import rlcompleter
18>>> import readline
19>>> readline.parse_and_bind("tab: complete")
20>>> readline. <TAB PRESSED>
21readline.__doc__ readline.get_line_buffer readline.read_init_file
22readline.__file__ readline.insert_text readline.set_completer
23readline.__name__ readline.parse_and_bind
24>>> readline.
25\end{verbatim}
26
27The \module{rlcompleter} module is designed for use with Python's
28interactive mode. A user can add the following lines to his or her
29initialization file (identified by the \envvar{PYTHONSTARTUP}
30environment variable) to get automatic \kbd{Tab} completion:
31
32\begin{verbatim}
33try:
34 import readline
35except ImportError:
36 print "Module readline not available."
37else:
38 import rlcompleter
39 readline.parse_and_bind("tab: complete")
40\end{verbatim}
41
42
43\subsection{Completer Objects \label{completer-objects}}
44
45Completer objects have the following method:
46
47\begin{methoddesc}[Completer]{complete}{text, state}
48Return the \var{state}th completion for \var{text}.
49
50If called for \var{text} that doesn't includea period character
51(\character{.}), it will complete from names currently defined in
Fred Drakece201121999-08-02 14:13:09 +000052\refmodule[main]{__main__}, \refmodule[builtin]{__builtin__} and
53keywords (as defined by the \refmodule{keyword} module).
Fred Drake4755e7d1999-06-21 18:25:49 +000054
55If called for a dotted name, it will try to evaluate anything without
56obvious side-effects (i.e., functions will not be evaluated, but it
57can generate calls to \method{__getattr__()}) upto the last part, and
58find matches for the rest via the \function{dir()} function.
59\end{methoddesc}