Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
Bug report
Bug description:
readline.set_completer_delims
works fine with GNU readline, but not with libedit.
A quick example:
importreadlinereadline.set_completer_delims("\n")if"libedit"ingetattr(readline,"__doc__",""):readline.parse_and_bind("bind ^I rl_complete")else:readline.parse_and_bind("tab: complete")defcompleter(text,state):iftext=="$"andstate==0:return"$complete"returnNonereadline.set_completer(completer)input()# Type $ then <tab>
With GNU readline, it completes correctly, but with libedit, it can't - libedit still considers$
as a delimiter. You can confirm that by printing the text incompleter
function.
The issue is inreadline.c
:
Lines 576 to 581 ind4f83e1
if (break_chars) { | |
free(completer_word_break_characters); | |
completer_word_break_characters=break_chars; | |
rl_completer_word_break_characters=break_chars; | |
Py_RETURN_NONE; | |
} |
readline.c
writes torl_completer_word_break_characters
, which works finesource.
However, libedit does not do the same thing, it usesrl_basic_word_break_characters
instead:
if (rl_completion_word_break_hook!=NULL)breakchars= (*rl_completion_word_break_hook)();elsebreakchars=rl_basic_word_break_characters;
Thus, writing torl_completer_word_break_characters
will not have any effect on libedit. The simplest way I can think of, is to write to bothrl_completer_word_break_characters
andrl_basic_word_break_characters
. They both exist in GNU readline and libedit, for slightly different purposes.
- GNU readline:
rl_completer_word_break_characters
is the one that takes effectrl_basic_word_break_characters
just keeps a string as default value forrl_completer_word_break_characters
- libedit
rl_completer_word_break_characters
is not used at allrl_basic_word_break_characters
is used for break words
From what I can observe, writing to both variables has no unexpected side effect, becauserl_basic_word_break_characters
is not used on CPython with GNU readline.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux, macOS