Auto-completion: why not module name?

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Mar 17 08:22:34 EDT 2015


On 17 March 2015 at 08:10, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Tuesday 17 March 2015 03:23, candide wrote:
>
> You might like my tab completion and command history module:
>
> http://code.google.com/p/tabhistory/
>
> I've been using it on Linux for about three or four years, and although I
> don't promise it is bug-free, it shouldn't blow up your computer :-)

Good work Steven. I just gave it a try and it works great.

> It supports module completion in `import` and `from ... import` statements.
> It even supports module attribute completion if the module is already
> cached.
>
> E.g. if the re module is cached, typing
>
>     from re import ma[TAB}
>
> will compete the "ma" to "match".

BTW ipython does this and goes one step further. It basically imports
the module while tab completion is ongoing so that you can complete
"from ...import" without needing to import the module first. In
principle that could be problematic but in practice I find it useful
and it has never caused me any actual problems.

> By default, the tabhistory module:
>
> * indents at the start of the line

Any reason for using 8 spaces for a tab? Or is that just my terminal
(gnome-terminal)?

> * completes on module names in `import` and `from` statements
> * completes on file names inside strings

I'm not sure what causes this but I have a symlink in my user
directory called "current" that just takes me to the things I'm
currently working on. When I tab complete it it puts in a quote
character:

>>> with open('current'

I think it thinks that "current" is a complete filename when it's
actually a symlink to a directory containing other things. If I delete
the quote and add a slash then it continues to complete normally.

Not sure if it's relevant but my .inputrc has:
set mark-symlinked-directories on

This setting changes the way that symlinks to directories are
completed so that a slash is automatically added when I tab complete
them.

> * and completes on global and builtin names and keywords everywhere else.
>
> You can read an announcement here:
>
> http://code.activestate.com/lists/python-list/672898/
>
> Feedback from Mac and Windows users is very, very welcome.

On Linux unfortunately.


Oscar



More information about the Python-list mailing list