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