customizing the readline module

bruce edge bruce_edge at
Wed Aug 21 23:33:35 CEST 2002

On Wed, 21 Aug 2002 12:42:39 -0700, Huaiyu Zhu wrote:

> holger krekel <pyth at> wrote: [snip]
> Thanks for the help.  As I understand, in the end I need to write the
> completer to return either a partial completion or a list of choices,
> and take care to pass the result back to readline in such a way as to
> defeat its builtin behavior.  Looks like too much effort for the
> intended usage.

It's not really defeating it's built in behavior, it's just providing a
new completer. It's pretty simple actually.

Take a look at thr rlcompleter class. You just subclass from that and
override the complete method.

>>> Is there a way to tweak the protocol for readline to allow the
>>> semantics of passing back [aaa] as the accepted words and [bbb1, bbb2]
>>> as possible completions?  That would allow the command line to remain
>>> 'aaa ' while the completions be 'bbb1 bbb2'.
>>newer readline libs might help but python will not integrate that soon
>>enough, i guess.  The above approach works for me and is fairly backward
> I would think that even with existing readline lib, the python module
> could be redesigned to handle this, if it was aimed at providing a high
> level interface to the low level facility, instead of exposing the low
> level facility directly.  When I have time I'll try to write a wrapper
> of readline to do this.
> In the mean time I'm back to typing various command line options.
> Huaiyu

I had to add a few extensions to the python readline module as it didn't
expose all of the gnu readline API. But that wasn't really neccessary for
a basic completer.


More information about the Python-list mailing list