[IPython-user] Tab completion question

Andrea Riciputi mr.rech.list@gmail....
Mon Apr 6 05:28:57 CDT 2009


Hi Thomas,
thanks for your hints they definetively work.

However I'd prefer not to patch IPython source code in order to get  
case-insensitive tab completion. I'm wondering if there a way to get  
it just setting readline in a proper manner. If this is not the case,  
it would be nice if IPython itself could be patched to make users able  
to set this case-insensiteveness by means of the regular config file.  
Comments or further suggestions are always appreciated?

Cheers,
Andrea

On 6 Apr, 2009, at 12:14, Thomas Heller wrote:

> Andrea Riciputi schrieb:
>> Hi,
>> how can I get the tab completion in IPython to work in a case-
>> insensitive way? I'd really like to  get:
>>
>> Foo.a[TAB][TAB]
>> Foo.amethod  Foo.AnotherMethod
>>
>> Is it a readline thing or a IPython thing?
>>
>> Cheers,
>> Andrea
>
> Don't know how IPython does it, but it seems that you can get
> case-insensitive tab completion in readline by changing the
> string comparisons in Lib\rlcompleter.py, in the last lines
> of the methods attr_matches() and global_matches():
>
> <snip>
>   def global_matches(self, text):
>       """Compute matches when text is a simple name.
>
>       Return a list of all keywords, built-in functions and names  
> currently
>       defined in self.namespace that match.
>
>       """
>       import keyword
>       matches = []
>       n = len(text)
>       for list in [keyword.kwlist,
>                    __builtin__.__dict__,
>                    self.namespace]:
>           for word in list:
>               if word[:n].lower() == text.lower() and word !=  
> "__builtins__":
> ####                       ^^^^^^^^         ^^^^^^^
>                   matches.append(word)
>       return matches
>
>   def attr_matches(self, text):
>       """Compute matches when text contains a dot.
>
>       Assuming the text is of the form NAME.NAME....[NAME], and is
>       evaluatable in self.namespace, it will be evaluated and its  
> attributes
>       (as revealed by dir()) are used as possible completions.  (For  
> class
>       instances, class members are also considered.)
>
>       WARNING: this can still invoke arbitrary C code, if an object
>       with a __getattr__ hook is evaluated.
>
>       """
>       import re
>       m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
>       if not m:
>           return
>       expr, attr = m.group(1, 3)
>       object = eval(expr, self.namespace)
>       words = dir(object)
>       if hasattr(object,'__class__'):
>           words.append('__class__')
>           words = words + get_class_members(object.__class__)
>       matches = []
>       n = len(attr)
>       for word in words:
>           if word[:n].lower() == attr.lower() and word !=  
> "__builtins__":
> ####                    ^^^^^^^^       ^^^^^^^
>               matches.append("%s.%s" % (expr, word))
>       return matches
> </snip>
>
> -- 
> Thomas
>
> _______________________________________________
> IPython-user mailing list
> IPython-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user



More information about the IPython-user mailing list