[IPython-dev] filename completion - anyone working on it?

Fernando Perez fperez.net@gmail....
Tue Oct 26 14:15:40 CDT 2010


Hi Hans,

On Tue, Oct 26, 2010 at 6:31 AM, Hans Meine <hans_meine@gmx.net> wrote:
>
> I am constantly bugged by filename completion in IPython.  To be specific,
> there are two cases that maybe need to be considered separately:
> 1) Completion of filenames in arguments to IPython magics, e.g. %run foo<tab>
> 2) Completion of filenames in strings, i.e. filename = "../subdir/bar<tab>"
>
> In the second case, I don't want to have completions of other types (i.e.
> variable/function names), and in both cases I want filenames with spaces to be
> supported!
>
> The failure w.r.t. the latter is a serious bug for me, so I'd like to ask if
> anybody is working on the relevant code ATM, and if not, which hints you
> want/can give me for fixing this.

Could you pull from trunk and let me know if you find the situation
any better?  Invoking my time machine for your question, I rewound to
yesterday afternoon and put more time than I'd like to admit into this
very problem:

http://github.com/ipython/ipython/commit/02eecaf061408f26a3c6029886b8794f73581938

Things already work as you imagine, with a custom completer for magics
without quotes, and a generic file completer that should work in
strings.  This weekend John and I actually ran into the limitations of
the completions-in-strings, and that prompted my effort to fix this.

The code for this is surprisingly tricky, but I think things are
better now.  One caveat: readline itself (without any ability for us
to control/prevent, as best I can tell) automatically closes the
quotes when there's a single completion.  Which very annoyingly means
that if you stop at a directory boundary

a = f('some<tab>

-> produces:

a = f('somedir/'

even if somedir/ is not empty.  I spent a lot of time trying to
prevent readline from doing this, but failed.  If anyone knows how to
do it, I'd love to hear.  The problem doesn't appear in the Qt
console, as it's only done by readline itself, and in Qt we use our
own completion machinery that's totally independent of readline.

Cheers,

f


More information about the IPython-dev mailing list