From d0556ec563b1e206e24e503cdff3b3ad1b344199 2006-11-03 07:01:39 From: fptest Date: 2006-11-03 07:01:39 Subject: [PATCH] - Fix tab-completion so that quotes are not closed unless the completion is unambiguous. - Small cleanups in ipy_stock_completers. --- diff --git a/IPython/Extensions/ipy_stock_completers.py b/IPython/Extensions/ipy_stock_completers.py index a65ceb2..7bfaa21 100755 --- a/IPython/Extensions/ipy_stock_completers.py +++ b/IPython/Extensions/ipy_stock_completers.py @@ -49,16 +49,16 @@ pkg_cache = None def module_completer(self,event): """ Give completions after user has typed 'import' """ - + # only a local version for py 2.4, pkgutil has no walk_packages() there - if sys.version_info < (2,5): - for el in [f[:-3] for f in glob.glob("*.py")]: - yield el + if sys.version_info < (2,5): + for el in [f[:-3] for f in glob.glob("*.py")]: + yield el return - + global pkg_cache import pkgutil,imp,time - #current = + #current = if pkg_cache is None: print "\n\n[Standby while scanning modules, this can take a while]\n\n" pkg_cache = list(pkgutil.walk_packages()) @@ -95,11 +95,14 @@ def runlistpy(self, event): comps = shlex.split(event.line) relpath = (len(comps) > 1 and comps[-1] or '') - print "rp",relpath + #print "rp",relpath # dbg + glob = glob.glob + isdir = os.path.isdir if relpath.startswith('~'): relpath = os.path.expanduser(relpath) - dirs = [f.replace('\\','/') + "/" for f in glob.glob(relpath+'*') if os.path.isdir(f)] - pys = [f.replace('\\','/') for f in glob.glob(relpath+'*.py')] + dirs = [f.replace('\\','/') + "/" for f in glob(relpath+'*') + if isdir(f)] + pys = [f.replace('\\','/') for f in glob(relpath+'*.py')] return dirs + pys ip.set_hook('complete_command', runlistpy, str_key = '%run') @@ -127,4 +130,4 @@ def cd_completer(self, event): return [relpath] return found -ip.set_hook('complete_command', cd_completer, str_key = '%cd') +ip.set_hook('complete_command', cd_completer, str_key = '%cd') diff --git a/IPython/completer.py b/IPython/completer.py index f26a8fb..0b9c57b 100644 --- a/IPython/completer.py +++ b/IPython/completer.py @@ -344,7 +344,7 @@ class IPCompleter(Completer): current (as of Python 2.3) Python readline it's possible to do better.""" - # print 'Completer->file_matches: <%s>' % text # dbg + #print 'Completer->file_matches: <%s>' % text # dbg # chars that require escaping with backslash - i.e. chars # that readline treats incorrectly as delimiters, but we @@ -406,7 +406,9 @@ class IPCompleter(Completer): # Takes care of links to directories also. Use '/' # explicitly, even under Windows, so that name completions # don't end up escaped. - matches[0] += '/' + pjoin = os.path.join + d = matches[0] + matches = [ pjoin(d,p) for p in os.listdir(d) ] return matches def alias_matches(self, text): diff --git a/doc/ChangeLog b/doc/ChangeLog index 04ca722..1c22e87 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2006-11-03 Fernando Perez + + * IPython/completer.py (IPCompleter.file_matches): Fix + tab-completion so that quotes are not closed unless the completion + is unambiguous. After a request by Stefan. Minor cleanups in + ipy_stock_completers. + 2006-11-02 Ville Vainio * ipy_stock_completers.py: Add %run and %cd completers.