cmd, readline, and /path/filename completion

holger krekel pyth at devel.trillke.net
Thu Jul 25 07:04:00 EDT 2002


Dave Cinege wrote:
> On Wednesday 24 July 2002 17:51, Michael Gilfix wrote:
> >   The readline library is sufficiently general such that it's meant
> ...
> > consider to be the atomic words are. Maybe that makes sense?
> 
> I've generally understood this from the get go. What I'm not clear
> on is to what extent readline 'just works' and what need to be coded 
> explictly. For instance I understand, '/' was removed as a delimiter.
> But I don't know where readlines's behavior is defined to know that it
> should match a path where '/' is involved...and furthermore how to
> altered that behavior should I want to.
> 
> >   I once implemented an application where I wanted to complete against
> > files in a 'current dir'. My solution was to gobble up a list of files
> > in teh current directory (I assume you have that part down), and then
> > set an attribute of "completion words". Now I wrote this particular app
> 
> I'm by no means a coding novice, and I already know I (or somewhere in 
> readline) must walk the path and gather a list of executable files. Where I'm 
> lost is how to pass this to readline. (Or activate it in readline)

Have you looked at the 'rlcompleter' module with the standard python
distribution? Basically you hook your own completer function into
readline and you get called.  It's a bit strange because you have
to pass back completion words one-by-one to readline and can't simply
pass a list back.  Actually i have written a new completion-module
which i still haven't gotten around to publish.  It is a bit more
instructive on how readline works and how to avoid some ugly problems
with it.

    holger




More information about the Python-list mailing list