readline rl_completion_append_character equivalent
holger krekel
pyth at devel.trillke.net
Fri Dec 20 21:11:16 EST 2002
Andrew Lusk wrote:
> 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.
ASFAIK there is no equivalent.
> rl_completion_append_character tells readline to append a character
> (usually ' ') after the number of completions has dropped down to
> one.
The readline module in python2.2.2 defaults to an empty
rl_completion_append_character. This is the desired behaviour
for the stdlib rlcompleter.
> 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 i am not mistaken you should/could write here
for pos in comp_list:
if pos.startswith(text) and pos!=text:
pos_list.append(pos)
this would prevent completion if the complete completion
is already there.
>
> if state > len(pos_list):
> return None
maybe you want to insert
elif len(pos_list)==1:
return pos_list[0]+' '
> else:
> return pos_list[state]
if you provide the complete thing (stripped down if possible)
i could also test it myself.
HTH,
holger
More information about the Python-list
mailing list