Greedy completer #668

Closed
wants to merge 2 commits into
from
@@ -228,7 +228,8 @@ class CompletionSplitter(object):
# A string of delimiter characters. The default value makes sense for
# IPython's most typical usage patterns.
- _delims = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?'
+ #_delims = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?'
+ _delims = ' \n\t'
@fperez
fperez Sep 13, 2011 Member

Mmh, why were the default completer delimiters disabled in the main code? I thought this was only about updating the extension, but this seems to change the default completion behavior completely... Was that your intent?

# The expression (a normal string) to be compiled into a regular expression
# for actual splitting. We store it as an attribute mostly for ease of
@@ -349,14 +350,18 @@ def attr_matches(self, text):
"""
- #print 'Completer->attr_matches, txt=%r' % text # dbg
+ #io.rprint('Completer->attr_matches, txt=%r' % text) # dbg
# Another option, seems to work great. Catches things like ''.<tab>
m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
- if not m:
- return []
-
- expr, attr = m.group(1, 3)
+ if m:
+ expr, attr = m.group(1, 3)
+ else:
+ m2 = re.match(r"(.+)\.(\w*)$", self.line_buffer)
+ if not m2:
+ return []
+ expr, attr = m2.group(1,2)
+
try:
obj = eval(expr, self.namespace)
except:
@@ -579,7 +584,7 @@ def alias_matches(self, text):
def python_matches(self,text):
"""Match attributes or global python names"""
- #print 'Completer->python_matches, txt=%r' % text # dbg
+ #io.rprint('Completer->python_matches, txt=%r' % text) # dbg
if "." in text:
try:
matches = self.attr_matches(text)
@@ -680,7 +685,7 @@ def python_func_kw_matches(self,text):
return argMatches
def dispatch_custom_completer(self, text):
- #print "Custom! '%s' %s" % (text, self.custom_completers) # dbg
+ #io.rprint("Custom! '%s' %s" % (text, self.custom_completers)) # dbg
line = self.line_buffer
if not line.strip():
return None
@@ -9,16 +9,18 @@
do the same in default completer.
"""
+
+from IPython.utils.dir2 import dir2
+from IPython.utils import generics
from IPython.core import ipapi
from IPython.core.error import TryNext
-from IPython.utils import generics
-from IPython.utils.dir2 import dir2
+import IPython.utils.rlineimpl as readline
+
+import re
def attr_matches(self, text):
"""Compute matches when text contains a dot.
- MONKEYPATCHED VERSION (ipy_greedycompleter.py)
-
Assuming the text is of the form NAME.NAME....[NAME], and is
evaluatable in self.namespace or self.global_namespace, it will be
evaluated and its attributes (as revealed by dir()) are used as
@@ -29,9 +31,11 @@ def attr_matches(self, text):
with a __getattr__ hook is evaluated.
"""
- import re
-
+
force_complete = 1
+ #print 'Completer->attr_matches, txt=%r' % text # dbg
+ lbuf = readline.get_line_buffer()
+
# Another option, seems to work great. Catches things like ''.<tab>
m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
@@ -42,13 +46,13 @@ def attr_matches(self, text):
if not force_complete:
return []
- m2 = re.match(r"(.+)\.(\w*)$", self.lbuf)
+ m2 = re.match(r"(.+)\.(\w*)$", lbuf)
if not m2:
return []
expr, attr = m2.group(1,2)
-
-
- try:
+
+
+ try:
obj = eval(expr, self.namespace)
except:
try:
@@ -57,7 +61,7 @@ def attr_matches(self, text):
return []
words = dir2(obj)
-
+
try:
words = generics.complete_object(obj, words)
except TryNext:
@@ -67,11 +71,13 @@ def attr_matches(self, text):
res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ]
return res
+
+
def main():
- import IPython.utils.rlineimpl as readline
+ #import IPython.rlineimpl as readline
readline.set_completer_delims(" \n\t")
# monkeypatch - the code will be folded to normal completer later on
import IPython.core.completer
IPython.core.completer.Completer.attr_matches = attr_matches
-main()
+main()