diff --git a/IPython/completer.py b/IPython/completer.py index f0ed852..f6470c0 100644 --- a/IPython/completer.py +++ b/IPython/completer.py @@ -372,6 +372,22 @@ class IPCompleter(Completer): def protect_filename(s): return "".join([(ch in protectables and '\\' + ch or ch) for ch in s]) + + def single_dir_expand(matches): + "Recursively expand match lists containing a single dir." + + if len(matches) == 1 and os.path.isdir(matches[0]): + # Takes care of links to directories also. Use '/' + # explicitly, even under Windows, so that name completions + # don't end up escaped. + d = matches[0] + if d[-1] in ['/','\\']: + d = d[:-1] + + matches = [ (d + '/' + p) for p in os.listdir(d) ] + return single_dir_expand(matches) + else: + return matches lbuf = self.lbuf open_quotes = 0 # track strings with open quotes @@ -420,17 +436,8 @@ class IPCompleter(Completer): else: matches = [text_prefix + protect_filename(f) for f in m0] - if len(matches) == 1 and os.path.isdir(matches[0]): - # Takes care of links to directories also. Use '/' - # explicitly, even under Windows, so that name completions - # don't end up escaped. - d = matches[0] - if d[-1] in ['/','\\']: - d = d[:-1] - - matches = [ (d + '/' + p) for p in os.listdir(d) ] - - return matches + + return single_dir_expand(matches) def alias_matches(self, text): """Match internal system aliases""" diff --git a/doc/ChangeLog b/doc/ChangeLog index 1909f05..e9f1a7b 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,10 @@ 2007-03-18 Fernando Perez + * IPython/completer.py + (IPCompleter.file_matches.single_dir_expand): fix a problem + reported by Stefan, where directories containign a single subdir + would be completed too early. + * IPython/Shell.py (_load_pylab): Make the execution of 'from pylab import *' when -pylab is given be optional. A new flag, pylab_import_all controls this behavior, the default is True for