Skip to content

Commit 2df26d8

Browse files
gh-112105: Make completer delims work on libedit (gh-112106)
1 parent ac4b442 commit 2df26d8

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Lib/test/test_readline.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import sys
77
import tempfile
8+
import textwrap
89
import unittest
910
from test.support import verbose
1011
from test.support.import_helper import import_module
@@ -163,6 +164,25 @@ def test_auto_history_disabled(self):
163164
# end, so don't expect it in the output.
164165
self.assertIn(b"History length: 0", output)
165166

167+
def test_set_complete_delims(self):
168+
script = textwrap.dedent("""
169+
import readline
170+
def complete(text, state):
171+
if state == 0 and text == "$":
172+
return "$complete"
173+
return None
174+
if "libedit" in getattr(readline, "__doc__", ""):
175+
readline.parse_and_bind(r'bind "\\t" rl_complete')
176+
else:
177+
readline.parse_and_bind(r'"\\t": complete')
178+
readline.set_completer_delims(" \\t\\n")
179+
readline.set_completer(complete)
180+
print(input())
181+
""")
182+
183+
output = run_pty(script, input=b"$\t\n")
184+
self.assertIn(b"$complete", output)
185+
166186
def test_nonascii(self):
167187
loc = locale.setlocale(locale.LC_CTYPE, None)
168188
if loc in ('C', 'POSIX'):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make :func:`readline.set_completer_delims` work with libedit

Modules/readline.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,13 @@ readline_set_completer_delims(PyObject *module, PyObject *string)
592592
if (break_chars) {
593593
free(completer_word_break_characters);
594594
completer_word_break_characters = break_chars;
595+
#ifdef WITH_EDITLINE
596+
rl_basic_word_break_characters = break_chars;
597+
#else
598+
if (using_libedit_emulation) {
599+
rl_basic_word_break_characters = break_chars;
600+
}
601+
#endif
595602
rl_completer_word_break_characters = break_chars;
596603
Py_RETURN_NONE;
597604
}
@@ -1309,6 +1316,15 @@ setup_readline(readlinestate *mod_state)
13091316
completer_word_break_characters =
13101317
strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
13111318
/* All nonalphanums except '.' */
1319+
#ifdef WITH_EDITLINE
1320+
// libedit uses rl_basic_word_break_characters instead of
1321+
// rl_completer_word_break_characters as complete delimiter
1322+
rl_basic_word_break_characters = completer_word_break_characters;
1323+
#else
1324+
if (using_libedit_emulation) {
1325+
rl_basic_word_break_characters = completer_word_break_characters;
1326+
}
1327+
#endif
13121328
rl_completer_word_break_characters = completer_word_break_characters;
13131329

13141330
mod_state->begidx = PyLong_FromLong(0L);

0 commit comments

Comments
 (0)