source: vendor/python/2.5/Doc/lib/librlcompleter.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 2.3 KB
Line 
1\section{\module{rlcompleter} ---
2 Completion function for GNU readline}
3
4\declaremodule{standard}{rlcompleter}
5\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
6\modulesynopsis{Python identifier completion, suitable for the GNU readline library.}
7
8The \module{rlcompleter} module defines a completion function suitable for
9the \refmodule{readline} module by completing valid Python identifiers
10and keywords.
11
12When 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.
16
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
46On platforms without \module{readline}, the \class{Completer} class defined
47by this module can still be used for custom purposes.
48
49\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
56If called for \var{text} that doesn't include a period character
57(\character{.}), it will complete from names currently defined in
58\refmodule[main]{__main__}, \refmodule[builtin]{__builtin__} and
59keywords (as defined by the \refmodule{keyword} module).
60
61If called for a dotted name, it will try to evaluate anything without
62obvious side-effects (functions will not be evaluated, but it
63can generate calls to \method{__getattr__()}) up to the last part, and
64find matches for the rest via the \function{dir()} function.
65\end{methoddesc}
Note: See TracBrowser for help on using the repository browser.