Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d1d2f2

Browse files
committed
Issue #16182: Merge readline update from 3.5
2 parents 006a56c + 6afbc65 commit 6d1d2f2

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

Doc/library/readline.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ The following functions operate on a history file:
104104

105105
Append the last *nelements* items of history to a file. The default filename is
106106
:file:`~/.history`. The file must already exist. This calls
107-
:c:func:`append_history` in the underlying library.
107+
:c:func:`append_history` in the underlying library. This function
108+
only exists if Python was compiled for a version of the library
109+
that supports it.
108110

109111
.. versionadded:: 3.5
110112

@@ -199,7 +201,8 @@ Startup hooks
199201
be used as the new hook function; if omitted or ``None``, any
200202
function already installed is removed. The hook is called
201203
with no arguments after the first prompt has been printed and just before
202-
readline starts reading input characters.
204+
readline starts reading input characters. This function only exists
205+
if Python was compiled for a version of the library that supports it.
203206

204207

205208
Completion

Lib/test/test_readline.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,32 @@ def test_nonascii(self):
144144

145145
script = r"""import readline
146146
147-
if readline.__doc__ and "libedit" in readline.__doc__:
148-
readline.parse_and_bind(r'bind ^B ed-prev-char')
149-
readline.parse_and_bind(r'bind "\t" rl_complete')
147+
is_editline = readline.__doc__ and "libedit" in readline.__doc__
148+
inserted = "[\xEFnserted]"
149+
macro = "|t\xEB[after]"
150+
set_pre_input_hook = getattr(readline, "set_pre_input_hook", None)
151+
if is_editline or not set_pre_input_hook:
150152
# The insert_line() call via pre_input_hook() does nothing with Editline,
151153
# so include the extra text that would have been inserted here
152-
readline.parse_and_bind('bind -s ^A "[\xEFnserted]|t\xEB[after]"')
154+
macro = inserted + macro
155+
156+
if is_editline:
157+
readline.parse_and_bind(r'bind ^B ed-prev-char')
158+
readline.parse_and_bind(r'bind "\t" rl_complete')
159+
readline.parse_and_bind(r'bind -s ^A "{}"'.format(macro))
153160
else:
154161
readline.parse_and_bind(r'Control-b: backward-char')
155162
readline.parse_and_bind(r'"\t": complete')
156163
readline.parse_and_bind(r'set disable-completion off')
157164
readline.parse_and_bind(r'set show-all-if-ambiguous off')
158165
readline.parse_and_bind(r'set show-all-if-unmodified off')
159-
readline.parse_and_bind('Control-a: "|t\xEB[after]"')
166+
readline.parse_and_bind(r'Control-a: "{}"'.format(macro))
160167
161168
def pre_input_hook():
162-
readline.insert_text("[\xEFnserted]")
169+
readline.insert_text(inserted)
163170
readline.redisplay()
164-
readline.set_pre_input_hook(pre_input_hook)
171+
if set_pre_input_hook:
172+
set_pre_input_hook(pre_input_hook)
165173
166174
def completer(text, state):
167175
if text == "t\xEB":

0 commit comments

Comments
 (0)