cpython: 6137c46cb8df (original) (raw)

--- a/Doc/library/readline.rst +++ b/Doc/library/readline.rst @@ -9,15 +9,18 @@ The :mod:readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. -This module can be used directly or via the :mod:rlcompleter module. Settings +This module can be used directly, or via the :mod:rlcompleter module, which +supports completion of Python identifiers at the interactive prompt. Settings made using this module affect the behaviour of both the interpreter's interactive prompt and the prompts offered by the :func:raw_input and :func:input built-in functions. .. note::

+ +.. function:: read_init_file([filename]) +

+ +Line buffer +----------- + +The following functions operate on the line buffer: .. function:: get_line_buffer()

.. function:: insert_text(string)

-.. function:: read_init_file([filename]) +.. function:: redisplay() +

+History file +------------ + +The following functions operate on a history file: .. function:: read_history_file([filename])

.. function:: write_history_file([filename])

+ +.. function:: get_history_length()

+

+ +History list +------------ + +The following functions operate on a global history list: .. function:: clear_history()

-.. function:: get_history_length() -

- -.. function:: set_history_length(length) -

- .. function:: get_current_history_length()

@@ -91,7 +127,8 @@ The :mod:readline module defines the f .. function:: get_history_item(index)

@@ -99,42 +136,63 @@ The :mod:readline module defines the f .. function:: remove_history_item(pos) Remove history item specified by its position from the history.

.. function:: replace_history_item(pos, line)

-.. function:: redisplay() +.. function:: add_history(line)

+ +Startup hooks +------------- .. versionadded:: 2.3 .. function:: set_startup_hook([function])

.. function:: set_pre_input_hook([function])

+Completion +---------- + +The following functions relate to implementing a custom word completion +function. This is typically operated by the Tab key, and can suggest and +automatically complete a word being typed. By default, Readline is set up +to be used by :mod:rlcompleter to complete Python identifiers for +the interactive interpreter. If the :mod:readline module is to be used +with a custom completer, a different set of word delimiters should be set. + + .. function:: set_completer([function]) Set or remove the completer function. If function is specified, it will be @@ -144,6 +202,12 @@ The :mod:readline module defines the f returns a non-string value. It should return the next possible completion starting with text.

.. function:: get_completer() @@ -154,50 +218,42 @@ The :mod:readline module defines the f .. function:: get_completion_type()

.. function:: get_begidx() -

-.. function:: get_endidx() -

.. function:: set_completer_delims(string) -

-.. function:: get_completer_delims() -

.. function:: set_completion_display_matches_hook([function]) Set or remove the completion display function. If function is specified, it will be used as the new completion display function; if omitted or None, any completion display function already

-.. function:: add_history(line) -

-.. seealso:: -

- - .. _readline-example: Example

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -184,6 +184,13 @@ IDLE installing IDLE 2.7 on OS X: default configuration settings are no longer installed from OS X specific copies. +Documentation +------------- + +- Issue #6953: Rework the Readline module documentation to group related

--- a/Modules/readline.c +++ b/Modules/readline.c @@ -96,7 +96,7 @@ parse_and_bind(PyObject self, PyObject PyDoc_STRVAR(doc_parse_and_bind, "parse_and_bind(string) -> None\n[](#l3.6) -Parse and execute single line of a readline init file."); +Execute the init line provided in the string argument."); / Exported function to parse a readline init file */ @@ -115,7 +115,7 @@ read_init_file(PyObject *self, PyObject PyDoc_STRVAR(doc_read_init_file, "read_init_file([filename]) -> None\n[](#l3.15) -Parse a readline initialization file.\n[](#l3.16) +Execute a readline initialization file.\n[](#l3.17) The default filename is the last filename used."); @@ -176,7 +176,7 @@ set_history_length(PyObject *self, PyObj PyDoc_STRVAR(set_history_length_doc, "set_history_length(length) -> None\n[](#l3.24) -set the maximal number of items which will be written to\n[](#l3.25) +set the maximal number of lines which will be written to\n[](#l3.26) the history file. A negative length is used to inhibit\n[](#l3.27) history truncation."); @@ -191,7 +191,7 @@ get_history_length(PyObject *self, PyObj PyDoc_STRVAR(get_history_length_doc, "get_history_length() -> int\n[](#l3.33) -return the maximum number of items that will be written to\n[](#l3.34) +return the maximum number of lines that will be written to\n[](#l3.35) the history file."); @@ -269,7 +269,7 @@ set_startup_hook(PyObject *self, PyObjec PyDoc_STRVAR(doc_set_startup_hook, "set_startup_hook([function]) -> None\n[](#l3.42) -Set or remove the startup_hook function.\n[](#l3.43) +Set or remove the function invoked by the rl_startup_hook callback.\n[](#l3.44) The function is called with no arguments just\n[](#l3.45) before readline prints the first prompt."); @@ -286,7 +286,7 @@ set_pre_input_hook(PyObject *self, PyObj PyDoc_STRVAR(doc_set_pre_input_hook, "set_pre_input_hook([function]) -> None\n[](#l3.51) -Set or remove the pre_input_hook function.\n[](#l3.52) +Set or remove the function invoked by the rl_pre_input_hook callback.\n[](#l3.53) The function is called with no arguments after the first prompt\n[](#l3.54) has been printed and just before readline starts reading input\n[](#l3.55) characters."); @@ -325,7 +325,7 @@ get_begidx(PyObject *self, PyObject noa PyDoc_STRVAR(doc_get_begidx, "get_begidx() -> int\n[](#l3.60) -get the beginning index of the readline tab-completion scope"); +get the beginning index of the completion scope"); / Get the ending index for the scope of the tab-completion */ @@ -339,7 +339,7 @@ get_endidx(PyObject *self, PyObject noa PyDoc_STRVAR(doc_get_endidx, "get_endidx() -> int\n[](#l3.69) -get the ending index of the readline tab-completion scope"); +get the ending index of the completion scope"); / Set the tab-completion word-delimiters that readline uses */ @@ -368,7 +368,7 @@ set_completer_delims(PyObject self, PyO PyDoc_STRVAR(doc_set_completer_delims, "set_completer_delims(string) -> None\n[](#l3.78) -set the readline word delimiters for tab-completion"); +set the word delimiters for completion"); / _py_free_history_entry: Utility function to free a history entry. */ @@ -408,7 +408,7 @@ py_remove_history(PyObject *self, PyObje int entry_number; HIST_ENTRY *entry;

@@ -438,7 +438,7 @@ py_replace_history(PyObject *self, PyObj char *line; HIST_ENTRY *old_entry;

#ifdef APPLE if (using_libedit_emulation) { @@ -645,7 +645,7 @@ insert_text(PyObject *self, PyObject ar PyDoc_STRVAR(doc_insert_text, "insert_text(string) -> None\n[](#l3.132) -Insert text into the command line."); +Insert text into the line buffer at the cursor position."); / Redisplay the line buffer */