blob: cb2ac59c5836eba60013cad4cdc135e1b23efc34 [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 Drake57657bc2000-12-01 15:25:23 +00005\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Georg Brandl3583cff2006-04-30 18:14:54 +00006\modulesynopsis{Python identifier completion, suitable for the GNU readline library.}
Fred Drake4755e7d1999-06-21 18:25:49 +00007
Georg Brandl3583cff2006-04-30 18:14:54 +00008The \module{rlcompleter} module defines a completion function suitable for
Fred Drake3c62d9e2000-07-06 04:51:04 +00009the \refmodule{readline} module by completing valid Python identifiers
10and keywords.
11
Georg Brandl3583cff2006-04-30 18:14:54 +000012When this module is imported on a \UNIX\ platform with the \module{readline}
13module available, an instance of the \class{Completer} class is automatically
14created and its \method{complete} method is set as the \module{readline}
15completer.
Fred Drake4755e7d1999-06-21 18:25:49 +000016
17Example:
18
19\begin{verbatim}
20>>> import rlcompleter
21>>> import readline
22>>> readline.parse_and_bind("tab: complete")
23>>> readline. <TAB PRESSED>
24readline.__doc__ readline.get_line_buffer readline.read_init_file
25readline.__file__ readline.insert_text readline.set_completer
26readline.__name__ readline.parse_and_bind
27>>> readline.
28\end{verbatim}
29
30The \module{rlcompleter} module is designed for use with Python's
31interactive mode. A user can add the following lines to his or her
32initialization file (identified by the \envvar{PYTHONSTARTUP}
33environment variable) to get automatic \kbd{Tab} completion:
34
35\begin{verbatim}
36try:
37 import readline
38except ImportError:
39 print "Module readline not available."
40else:
41 import rlcompleter
42 readline.parse_and_bind("tab: complete")
43\end{verbatim}
44
45
Georg Brandl3583cff2006-04-30 18:14:54 +000046On platforms without \module{readline}, the \class{Completer} class defined
47by this module can still be used for custom purposes.
48
Fred Drake4755e7d1999-06-21 18:25:49 +000049\subsection{Completer Objects \label{completer-objects}}
50
51Completer objects have the following method:
52
53\begin{methoddesc}[Completer]{complete}{text, state}
54Return the \var{state}th completion for \var{text}.
55
Fred Drake3c62d9e2000-07-06 04:51:04 +000056If called for \var{text} that doesn't include a period character
Fred Drake4755e7d1999-06-21 18:25:49 +000057(\character{.}), it will complete from names currently defined in
Fred Drakece201121999-08-02 14:13:09 +000058\refmodule[main]{__main__}, \refmodule[builtin]{__builtin__} and
59keywords (as defined by the \refmodule{keyword} module).
Fred Drake4755e7d1999-06-21 18:25:49 +000060
61If called for a dotted name, it will try to evaluate anything without
Fred Drake907e76b2001-07-06 20:30:11 +000062obvious side-effects (functions will not be evaluated, but it
Andrew M. Kuchling44c62ef2003-04-14 15:32:18 +000063can generate calls to \method{__getattr__()}) up to the last part, and
Fred Drake4755e7d1999-06-21 18:25:49 +000064find matches for the rest via the \function{dir()} function.
65\end{methoddesc}