readline rl_completion_append_character equivalent

Andrew Lusk alusk at uiuc.edu
Fri Dec 20 13:43:57 EST 2002


I've been writing a readline application with a custom completer.
What I can't figure out is an equivalent to
rl_completion_append_character in the underlying C library.
rl_completion_append_character tells readline to append a character
(usually ' ') after the number of completions has dropped down to
one.  Either I'm doing something wrong elsewhere, or I need a function
like this, because when my number of completions drops to one with the
python readline, I keep hitting tab and it keeps writing out the
single completion option.  Here's my completer, for what it's worth:

def completer(text,state):
    global comp_list
    regex = re.compile("^%s.*"%text)
    if readline.get_begidx() == 0:
        pos_list = []
        for pos in comp_list:
            if regex.match(pos):
                pos_list.append(pos)

        if state > len(pos_list):
            return None
        else:
            return pos_list[state]
    else:
        cwd = os.getcwd()
        list = os.listdir(cwd)
        pos_list = filter(regex.match,list).sort()
        if state > len(pos_list):
            return None
        else:
            return pos_list[state]

though I think that this part is doing it's job fine.  

Thanks,

--Andrew



More information about the Python-list mailing list