2000-07-06 03:25:26 +00:00
|
|
|
\section{\module{readline} ---
|
2000-07-06 04:51:04 +00:00
|
|
|
GNU readline interface}
|
2000-07-06 03:25:26 +00:00
|
|
|
|
|
|
|
\declaremodule{builtin}{readline}
|
2000-07-06 04:51:04 +00:00
|
|
|
\platform{Unix}
|
2000-07-06 03:25:26 +00:00
|
|
|
\sectionauthor{Skip Montanaro}{skip@mojam.com}
|
2000-10-10 17:03:45 +00:00
|
|
|
\modulesynopsis{GNU readline support for Python.}
|
2000-07-06 03:25:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
The \module{readline} module defines a number of functions used either
|
2000-07-06 04:51:04 +00:00
|
|
|
directly or from the \refmodule{rlcompleter} module to facilitate
|
|
|
|
completion and history file read and write from the Python
|
|
|
|
interpreter.
|
2000-07-06 03:25:26 +00:00
|
|
|
|
|
|
|
The \module{readline} module defines the following functions:
|
|
|
|
|
2000-07-06 04:51:04 +00:00
|
|
|
|
2000-07-06 03:25:26 +00:00
|
|
|
\begin{funcdesc}{parse_and_bind}{string}
|
|
|
|
Parse and execute single line of a readline init file.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{get_line_buffer}{}
|
|
|
|
Return the current contents of the line buffer.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{insert_text}{string}
|
|
|
|
Insert text into the command line.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{read_init_file}{\optional{filename}}
|
|
|
|
Parse a readline initialization file.
|
|
|
|
The default filename is the last filename used.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{read_history_file}{\optional{filename}}
|
|
|
|
Load a readline history file.
|
2000-07-06 04:51:04 +00:00
|
|
|
The default filename is \file{\~{}/.history}.
|
2000-07-06 03:25:26 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{write_history_file}{\optional{filename}}
|
|
|
|
Save a readline history file.
|
2000-07-06 04:51:04 +00:00
|
|
|
The default filename is \file{\~{}/.history}.
|
2000-07-06 03:25:26 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
2000-07-19 16:56:26 +00:00
|
|
|
\begin{funcdesc}{get_history_length}{}
|
|
|
|
Return the desired length of the history file. Negative values imply
|
|
|
|
unlimited history file size.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{set_history_length}{length}
|
|
|
|
Set the number of lines to save in the history file.
|
2000-08-09 14:37:05 +00:00
|
|
|
\function{write_history_file()} uses this value to truncate the
|
|
|
|
history file when saving. Negative values imply unlimited history
|
|
|
|
file size.
|
2000-07-19 16:56:26 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
2000-07-06 03:25:26 +00:00
|
|
|
\begin{funcdesc}{set_completer}{\optional{function}}
|
2000-07-06 04:51:04 +00:00
|
|
|
Set or remove the completer function. The completer function is
|
|
|
|
called as \code{\var{function}(\var{text}, \var{state})},
|
2000-07-06 03:25:26 +00:00
|
|
|
\code{for i in [0, 1, 2, ...]} until it returns a non-string.
|
2000-07-06 04:51:04 +00:00
|
|
|
It should return the next possible completion starting with \var{text}.
|
2000-07-06 03:25:26 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{get_begidx}{}
|
|
|
|
Get the beginning index of the readline tab-completion scope.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{get_endidx}{}
|
|
|
|
Get the ending index of the readline tab-completion scope.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{set_completer_delims}{string}
|
|
|
|
Set the readline word delimiters for tab-completion.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{get_completer_delims}{}
|
|
|
|
Get the readline word delimiters for tab-completion.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
|
2000-07-06 04:51:04 +00:00
|
|
|
\begin{seealso}
|
|
|
|
\seemodule{rlcompleter}{Completion of Python identifiers at the
|
|
|
|
interactive prompt.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
|
|
|
|
|
|
\subsection{Example \label{readline-example}}
|
|
|
|
|
|
|
|
The following example demonstrates how to use the
|
|
|
|
\module{readline} module's history reading and writing functions to
|
|
|
|
automatically load and save a history file named \file{.pyhist} from
|
|
|
|
the user's home directory. The code below would normally be executed
|
|
|
|
automatically during interactive sessions from the user's
|
|
|
|
\envvar{PYTHONSTARTUP} file.
|
2000-07-06 03:25:26 +00:00
|
|
|
|
|
|
|
\begin{verbatim}
|
2000-07-06 04:51:04 +00:00
|
|
|
import os
|
|
|
|
histfile = os.path.join(os.environ["HOME"], ".pyhist")
|
|
|
|
try:
|
|
|
|
readline.read_history_file(histfile)
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
import atexit
|
|
|
|
atexit.register(readline.write_history_file, histfile)
|
|
|
|
del os, histfile
|
2000-07-06 03:25:26 +00:00
|
|
|
\end{verbatim}
|