Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve doc for readline.set_completer_delims() #55005

Closed
rheise mannequin opened this issue Dec 30, 2010 · 7 comments
Closed

Improve doc for readline.set_completer_delims() #55005

rheise mannequin opened this issue Dec 30, 2010 · 7 comments
Labels
docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error

Comments

@rheise
Copy link
Mannequin

rheise mannequin commented Dec 30, 2010

BPO 10796
Nosy @merwok, @vadmium
Dependencies
  • bpo-6953: readline documentation needs work
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-04-05.22:23:53.747>
    created_at = <Date 2010-12-30.13:08:07.363>
    labels = ['easy', 'type-bug', 'docs']
    title = 'Improve doc for readline.set_completer_delims()'
    updated_at = <Date 2016-04-05.22:23:53.744>
    user = 'https://bugs.python.org/rheise'

    bugs.python.org fields:

    activity = <Date 2016-04-05.22:23:53.744>
    actor = 'martin.panter'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2016-04-05.22:23:53.747>
    closer = 'martin.panter'
    components = ['Documentation']
    creation = <Date 2010-12-30.13:08:07.363>
    creator = 'rheise'
    dependencies = ['6953']
    files = []
    hgrepos = []
    issue_num = 10796
    keywords = ['easy']
    message_count = 7.0
    messages = ['124917', '156739', '174683', '174686', '255316', '262898', '262925']
    nosy_count = 6.0
    nosy_names = ['eric.araujo', 'docs@python', 'rheise', 'python-dev', 'martin.panter', 'hideaki_t']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10796'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @rheise
    Copy link
    Mannequin Author

    rheise mannequin commented Dec 30, 2010

    Python's readline library generates out of the choices provided by a custom completion function the wrong terminal input. Say, the completion function suggests 'foobar' and 'foobaz' as matching completion strings, readline should produce the characters 'fooba' to prompt and await further interaction by the user.
    This is the intended behaviour of readline and this works in Python as well. However this does nod work anymore as soon, as the suggestion
    list contains dashes `-' as input argument.

    A working as supposed example:

    >>> import readline
    >>> 
    >>> def complete(text, state):
    ...   if (state == 0):
    ...     return "abc"
    ...   if (state == 1):
    ...     return "ade"
    ...   else:
    ...     return None
    ... 
    >>> 
    >>> readline.parse_and_bind("Tab: complete")
    >>> readline.set_completer(complete)
    >>> 
    >>> raw_input()
    a
    abc  ade  
    a
    'a'
    >>> 

    remark: I entered a and hit tab. readline produces abc/ade as valid choices, stopping at the first ambiguous character. Now consider the following example:

    >>> import readline
    >>> 
    >>> def complete(text, state):
    ...   if (state == 0):
    ...     return "a-bc"
    ...   if (state == 1):
    ...     return "a-de"
    ...   else:
    ...     return None
    ... 
    >>> 
    >>> readline.parse_and_bind("Tab: complete")
    >>> readline.set_completer(complete)
    >>> 
    >>> raw_input()
    a-a-a-
    'a-a-a-'
    >>> 

    The intended behaviour is the very same as for the first example. Readline should produce 'a-' and offer a-bc and a-de as valid choices. Instead it produces an additional a- for every time I hit tab.

    Same for Python3.1:

    $ python3.1
    Python 3.1.2 (release31-maint, Sep 26 2010, 13:51:01) 
    [GCC 4.4.5] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import readline
    >>> 
    >>> def complete(text, state):
    ...   if (state == 0):
    ...     return "a-bc"
    ...   if (state == 1):
    ...     return "a-de"
    ...   else:
    ...     return None
    ... 
    >>> 
    >>> readline.parse_and_bind("Tab: complete")
    >>> readline.set_completer(complete)
    >>> 
    >>> input()
    a-a-a-a-a-
    'a-a-a-a-a-'
    >>> 

    Other programming languages falling back to the GNU C-readline library don't have this problem. Consider the roughly equivalent example in Perl which works as expected:

    use Term::ReadLine;

    sub complete
    {
            my ($text, $state) = @_;
            if ($state == 0)
            {
                    return "a-bc";
            }
            elsif ($state == 1)
            {
                    return "a-cd";
            }
            else
            {
                    return undef;
            }
    }

    my $term = new Term::ReadLine 'sample';
    my $attribs = $term->Attribs;

    $term->parse_and_bind("Tab: complete");
    $attribs->{completion_entry_function} = \&complete;

    $term->readline();

    Running it:

    $ perl rl 
    a-
    a-bc  a-cd  
    a-

    @rheise rheise mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 30, 2010
    @merwok
    Copy link
    Member

    merwok commented Mar 25, 2012

    I can’t reproduce with 2.7 or 3.2 with a readline module linked to GNU readline.

    @hideakit
    Copy link
    Mannequin

    hideakit mannequin commented Nov 3, 2012

    I think this is the default behavior of readline module.

    the default word delimiters for completion contains dash(-). so completion breaks at dash.

      >>> import readline
      >>> readline.get_completer_delims()
      ' \t\n`~!@#$%^&*()-=+[{]}\\|;:\'",<>/?'

    In contrast, the default word delimitors of GNU readline is "\t\n\"\\'`@$><=;|&{(" and perl binding does not change it.

    when I remove dash from delims like below, it works.

       >>> readline.set_completer_delims(readline.get_completer_delims().replace('-', ''))
       >>> input()
       a-
       a-bc  a-de
       a-

    @merwok
    Copy link
    Member

    merwok commented Nov 3, 2012

    I think I get it: Python sets custom delimiters that include '-' because for the Python REPL, it’s not possible to have one identifier with a dash, so it’s considered a delimiter and when you press tab, a new completion is started. For a custom REPL however, you may want to have dashes as legal parts of your completed words, so you want to call set_completer_delims. Reclassifying as a doc patch.

    @merwok merwok added easy docs Documentation in the Doc dir and removed stdlib Python modules in the Lib dir labels Nov 3, 2012
    @vadmium
    Copy link
    Member

    vadmium commented Nov 25, 2015

    I propose to address this with the general documentation bug, bpo-6953

    @vadmium vadmium changed the title readline completion flaw Improve doc for readline.set_completer_delims() Nov 25, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 5, 2016

    New changeset 6137c46cb8df by Martin Panter in branch '2.7':
    Issue bpo-6953: Rearrange and expand Readline module documentation
    https://hg.python.org/cpython/rev/6137c46cb8df

    New changeset b1acd6cf15b6 by Martin Panter in branch '3.5':
    Issue bpo-6953: Rearrange and expand Readline module documentation
    https://hg.python.org/cpython/rev/b1acd6cf15b6

    @vadmium
    Copy link
    Member

    vadmium commented Apr 5, 2016

    My update includes a new section called Completion, with the following text:

    By default, Readline is set up to be used by “rlcompleter” to complete Python identifiers for the interactive interpreter. If the “readline” module is to be used with a custom completer, a different set of word delimiters should be set.

    I hope that is enough to call this fixed :)

    @vadmium vadmium closed this as completed Apr 5, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants