Issue #16182: Merge readline update from 3.5
This commit is contained in:
commit
6d1d2f229e
|
@ -104,7 +104,9 @@ The following functions operate on a history file:
|
||||||
|
|
||||||
Append the last *nelements* items of history to a file. The default filename is
|
Append the last *nelements* items of history to a file. The default filename is
|
||||||
:file:`~/.history`. The file must already exist. This calls
|
:file:`~/.history`. The file must already exist. This calls
|
||||||
:c:func:`append_history` in the underlying library.
|
:c:func:`append_history` in the underlying library. This function
|
||||||
|
only exists if Python was compiled for a version of the library
|
||||||
|
that supports it.
|
||||||
|
|
||||||
.. versionadded:: 3.5
|
.. versionadded:: 3.5
|
||||||
|
|
||||||
|
@ -199,7 +201,8 @@ Startup hooks
|
||||||
be used as the new hook function; if omitted or ``None``, any
|
be used as the new hook function; if omitted or ``None``, any
|
||||||
function already installed is removed. The hook is called
|
function already installed is removed. The hook is called
|
||||||
with no arguments after the first prompt has been printed and just before
|
with no arguments after the first prompt has been printed and just before
|
||||||
readline starts reading input characters.
|
readline starts reading input characters. This function only exists
|
||||||
|
if Python was compiled for a version of the library that supports it.
|
||||||
|
|
||||||
|
|
||||||
Completion
|
Completion
|
||||||
|
|
|
@ -144,24 +144,32 @@ print("History length:", readline.get_current_history_length())
|
||||||
|
|
||||||
script = r"""import readline
|
script = r"""import readline
|
||||||
|
|
||||||
if readline.__doc__ and "libedit" in readline.__doc__:
|
is_editline = readline.__doc__ and "libedit" in readline.__doc__
|
||||||
readline.parse_and_bind(r'bind ^B ed-prev-char')
|
inserted = "[\xEFnserted]"
|
||||||
readline.parse_and_bind(r'bind "\t" rl_complete')
|
macro = "|t\xEB[after]"
|
||||||
|
set_pre_input_hook = getattr(readline, "set_pre_input_hook", None)
|
||||||
|
if is_editline or not set_pre_input_hook:
|
||||||
# The insert_line() call via pre_input_hook() does nothing with Editline,
|
# The insert_line() call via pre_input_hook() does nothing with Editline,
|
||||||
# so include the extra text that would have been inserted here
|
# so include the extra text that would have been inserted here
|
||||||
readline.parse_and_bind('bind -s ^A "[\xEFnserted]|t\xEB[after]"')
|
macro = inserted + macro
|
||||||
|
|
||||||
|
if is_editline:
|
||||||
|
readline.parse_and_bind(r'bind ^B ed-prev-char')
|
||||||
|
readline.parse_and_bind(r'bind "\t" rl_complete')
|
||||||
|
readline.parse_and_bind(r'bind -s ^A "{}"'.format(macro))
|
||||||
else:
|
else:
|
||||||
readline.parse_and_bind(r'Control-b: backward-char')
|
readline.parse_and_bind(r'Control-b: backward-char')
|
||||||
readline.parse_and_bind(r'"\t": complete')
|
readline.parse_and_bind(r'"\t": complete')
|
||||||
readline.parse_and_bind(r'set disable-completion off')
|
readline.parse_and_bind(r'set disable-completion off')
|
||||||
readline.parse_and_bind(r'set show-all-if-ambiguous off')
|
readline.parse_and_bind(r'set show-all-if-ambiguous off')
|
||||||
readline.parse_and_bind(r'set show-all-if-unmodified off')
|
readline.parse_and_bind(r'set show-all-if-unmodified off')
|
||||||
readline.parse_and_bind('Control-a: "|t\xEB[after]"')
|
readline.parse_and_bind(r'Control-a: "{}"'.format(macro))
|
||||||
|
|
||||||
def pre_input_hook():
|
def pre_input_hook():
|
||||||
readline.insert_text("[\xEFnserted]")
|
readline.insert_text(inserted)
|
||||||
readline.redisplay()
|
readline.redisplay()
|
||||||
readline.set_pre_input_hook(pre_input_hook)
|
if set_pre_input_hook:
|
||||||
|
set_pre_input_hook(pre_input_hook)
|
||||||
|
|
||||||
def completer(text, state):
|
def completer(text, state):
|
||||||
if text == "t\xEB":
|
if text == "t\xEB":
|
||||||
|
|
Loading…
Reference in New Issue