Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

readline.set_completer_delims has no effect with libedit #112105

Closed
Labels
type-bugAn unexpected behavior, bug, or error
@gaogaotiantian

Description

@gaogaotiantian

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:

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_charactersinstead:

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 effect
    • rl_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 all
    • rl_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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp