blob: b2a1eba7e1e3f0efdcd75c5c20b5355ffb31d460 [file] [log] [blame]
Fred Drake4755e7d1999-06-21 18:25:49 +00001\section{\module{rlcompleter} ---
Fred Drakef8ca7d82000-10-10 17:03:45 +00002 Completion function for GNU readline}
Fred Drake4755e7d1999-06-21 18:25:49 +00003
4\declaremodule{standard}{rlcompleter}
Fred Drake3c62d9e2000-07-06 04:51:04 +00005 \platform{Unix}
Fred Drake57657bc2000-12-01 15:25:23 +00006\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Fred Drakef8ca7d82000-10-10 17:03:45 +00007\modulesynopsis{Python identifier completion for the GNU readline library.}
Fred Drake4755e7d1999-06-21 18:25:49 +00008
9The \module{rlcompleter} module defines a completion function for
Fred Drake3c62d9e2000-07-06 04:51:04 +000010the \refmodule{readline} module by completing valid Python identifiers
11and keywords.
12
Fred Drake6d8d72b2001-08-10 16:15:08 +000013This module is \UNIX-specific due to its dependence on the
Fred Drake3c62d9e2000-07-06 04:51:04 +000014\refmodule{readline} module.
Fred Drake4755e7d1999-06-21 18:25:49 +000015
16The \module{rlcompleter} module defines the \class{Completer} class.
17
18Example:
19
20\begin{verbatim}
21>>> import rlcompleter
22>>> import readline
23>>> readline.parse_and_bind("tab: complete")
24>>> readline. <TAB PRESSED>
25readline.__doc__ readline.get_line_buffer readline.read_init_file
26readline.__file__ readline.insert_text readline.set_completer
27readline.__name__ readline.parse_and_bind
28>>> readline.
29\end{verbatim}
30
31The \module{rlcompleter} module is designed for use with Python's
32interactive mode. A user can add the following lines to his or her
33initialization file (identified by the \envvar{PYTHONSTARTUP}
34environment variable) to get automatic \kbd{Tab} completion:
35
36\begin{verbatim}
37try:
38 import readline
39except ImportError:
40 print "Module readline not available."
41else:
42 import rlcompleter
43 readline.parse_and_bind("tab: complete")
44\end{verbatim}
45
46
47\subsection{Completer Objects \label{completer-objects}}
48
49Completer objects have the following method:
50
51\begin{methoddesc}[Completer]{complete}{text, state}
52Return the \var{state}th completion for \var{text}.
53
Fred Drake3c62d9e2000-07-06 04:51:04 +000054If called for \var{text} that doesn't include a period character
Fred Drake4755e7d1999-06-21 18:25:49 +000055(\character{.}), it will complete from names currently defined in
Fred Drakece201121999-08-02 14:13:09 +000056\refmodule[main]{__main__}, \refmodule[builtin]{__builtin__} and
57keywords (as defined by the \refmodule{keyword} module).
Fred Drake4755e7d1999-06-21 18:25:49 +000058
59If called for a dotted name, it will try to evaluate anything without
Fred Drake907e76b2001-07-06 20:30:11 +000060obvious side-effects (functions will not be evaluated, but it
Andrew M. Kuchling44c62ef2003-04-14 15:32:18 +000061can generate calls to \method{__getattr__()}) up to the last part, and
Fred Drake4755e7d1999-06-21 18:25:49 +000062find matches for the rest via the \function{dir()} function.
63\end{methoddesc}