[IPython-dev] Small change to MagicCompleter fixes filename completion on Windows

Gary Bishop gb at cs.unc.edu
Thu May 22 15:24:14 EDT 2003


Now that I've got my Python readline starting to work, I've found a 
problem that prevents filename completion on windows. Unfixed, it does this

In [1]: cd ~/pyt<TAB>
@ddir   @dhist  @dir    @dirs

In[1]: cd @d

The problem is in MagicCompleter. It only tests to see if the string 
begins with os.sep but a Windows file name may well begin with d: 
(after ~ expansion). I put in a small hack to fix this. I think a 
better patch would test the string to see if it looks like a legal 
python variable before subjecting it to these other completions. But my 
simple change fixes things well enough...

$ diff -Naur iplib.py~ iplib.py
--- iplib.py~   2003-05-13 16:24:11.000000000 -0400
+++ iplib.py    2003-05-22 15:15:21.000000000 -0400
@@ -123,7 +123,9 @@
             This is called successively with state == 0, 1, 2, ... until it
             returns None.  The completion should begin with 'text'.  """

+            doing_magic = False
             if text.startswith('@'):
+                doing_magic = True
                 text = text.replace('@','__IP.magic_')
             if text.startswith('~'):
                 text = os.path.expanduser(text)
@@ -138,7 +140,7 @@
                 else:
                     self.matches = self.global_matches(text)
                     # this is so completion finds magics when automagic is on:
-                    if self.matches == [] and not text.startswith(os.sep):
+                    if self.matches == [] and doing_magic:
                         self.matches = self.attr_matches('__IP.magic_'+text)
             try:
                 return self.matches[state].replace('__IP.magic_','@')



More information about the IPython-dev mailing list