Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6afbc653
Commit
6afbc653
authored
Jun 14, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16182: set_pre_input_hook() may not exist; document, and update test
parent
11a693d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
Doc/library/readline.rst
Doc/library/readline.rst
+5
-2
Lib/test/test_readline.py
Lib/test/test_readline.py
+15
-7
No files found.
Doc/library/readline.rst
View file @
6afbc653
...
...
@@ -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
: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
...
...
@@ -185,7 +187,8 @@ Startup hooks
be used as the new hook function; if omitted or ``None``, any
function already installed is removed. The hook is called
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
...
...
Lib/test/test_readline.py
View file @
6afbc653
...
...
@@ -129,24 +129,32 @@ class TestReadline(unittest.TestCase):
script
=
r"""import readline
if readline.__doc__ and "libedit" in readline.__doc__:
readline.parse_and_bind(r'bind ^B ed-prev-char')
readline.parse_and_bind(r'bind "\t" rl_complete')
is_editline = readline.__doc__ and "libedit" in readline.__doc__
inserted = "[\xEFnserted]"
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,
# 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:
readline.parse_and_bind(r'Control-b: backward-char')
readline.parse_and_bind(r'"\t": complete')
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-unmodified off')
readline.parse_and_bind(
'Control-a: "|t\xEB[after]"'
)
readline.parse_and_bind(
r'Control-a: "{}"'.format(macro)
)
def pre_input_hook():
readline.insert_text(
"[\xEFnserted]"
)
readline.insert_text(
inserted
)
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):
if text == "t\xEB":
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment