diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-11-28 06:39:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 06:39:47 (GMT) |
commit | 42dd2613fe4bc61e1f633078560f2d84a0a16c3f (patch) | |
tree | a2c5677def1c138e4280dc377cb681a425009b16 | |
parent | b85070ceaf99acf1b8707764fe5214506a8e7389 (diff) | |
download | cpython-42dd2613fe4bc61e1f633078560f2d84a0a16c3f.zip cpython-42dd2613fe4bc61e1f633078560f2d84a0a16c3f.tar.gz cpython-42dd2613fe4bc61e1f633078560f2d84a0a16c3f.tar.bz2 |
[3.11] gh-112105: Make completer delims work on libedit (gh-112106) (gh-112488)
gh-112105: Make completer delims work on libedit (gh-112106)
(cherry picked from commit 2df26d83486b8f9ac6b7df2a9a4669508aa61983)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
-rw-r--r-- | Lib/test/test_readline.py | 20 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-11-15-04-53-37.gh-issue-112105.I3RcVN.rst | 1 | ||||
-rw-r--r-- | Modules/readline.c | 16 |
3 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py index 835280f..6c2726d 100644 --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -5,6 +5,7 @@ import locale import os import sys import tempfile +import textwrap import unittest from test.support import verbose from test.support.import_helper import import_module @@ -163,6 +164,25 @@ print("History length:", readline.get_current_history_length()) # end, so don't expect it in the output. self.assertIn(b"History length: 0", output) + def test_set_complete_delims(self): + script = textwrap.dedent(""" + import readline + def complete(text, state): + if state == 0 and text == "$": + return "$complete" + return None + if "libedit" in getattr(readline, "__doc__", ""): + readline.parse_and_bind(r'bind "\\t" rl_complete') + else: + readline.parse_and_bind(r'"\\t": complete') + readline.set_completer_delims(" \\t\\n") + readline.set_completer(complete) + print(input()) + """) + + output = run_pty(script, input=b"$\t\n") + self.assertIn(b"$complete", output) + def test_nonascii(self): loc = locale.setlocale(locale.LC_CTYPE, None) if loc in ('C', 'POSIX'): diff --git a/Misc/NEWS.d/next/Library/2023-11-15-04-53-37.gh-issue-112105.I3RcVN.rst b/Misc/NEWS.d/next/Library/2023-11-15-04-53-37.gh-issue-112105.I3RcVN.rst new file mode 100644 index 0000000..4243dcb --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-15-04-53-37.gh-issue-112105.I3RcVN.rst @@ -0,0 +1 @@ +Make :func:`readline.set_completer_delims` work with libedit diff --git a/Modules/readline.c b/Modules/readline.c index 8c7f526..1e13a0e 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -572,6 +572,13 @@ readline_set_completer_delims(PyObject *module, PyObject *string) if (break_chars) { free(completer_word_break_characters); completer_word_break_characters = break_chars; +#ifdef WITH_EDITLINE + rl_basic_word_break_characters = break_chars; +#else + if (using_libedit_emulation) { + rl_basic_word_break_characters = break_chars; + } +#endif rl_completer_word_break_characters = break_chars; Py_RETURN_NONE; } @@ -1260,6 +1267,15 @@ setup_readline(readlinestate *mod_state) completer_word_break_characters = strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"); /* All nonalphanums except '.' */ +#ifdef WITH_EDITLINE + // libedit uses rl_basic_word_break_characters instead of + // rl_completer_word_break_characters as complete delimiter + rl_basic_word_break_characters = completer_word_break_characters; +#else + if (using_libedit_emulation) { + rl_basic_word_break_characters = completer_word_break_characters; + } +#endif rl_completer_word_break_characters = completer_word_break_characters; mod_state->begidx = PyLong_FromLong(0L); |