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