Show More
@@ -9,16 +9,18 b' only whitespace as completer delimiter. If this works well, we will' | |||||
9 | do the same in default completer. |
|
9 | do the same in default completer. | |
10 |
|
10 | |||
11 | """ |
|
11 | """ | |
|
12 | ||||
|
13 | from IPython.utils.dir2 import dir2 | |||
|
14 | from IPython.utils import generics | |||
12 | from IPython.core import ipapi |
|
15 | from IPython.core import ipapi | |
13 | from IPython.core.error import TryNext |
|
16 | from IPython.core.error import TryNext | |
14 | from IPython.utils import generics |
|
17 | import IPython.utils.rlineimpl as readline | |
15 | from IPython.utils.dir2 import dir2 |
|
18 | ||
|
19 | import re | |||
16 |
|
20 | |||
17 | def attr_matches(self, text): |
|
21 | def attr_matches(self, text): | |
18 | """Compute matches when text contains a dot. |
|
22 | """Compute matches when text contains a dot. | |
19 |
|
23 | |||
20 | MONKEYPATCHED VERSION (ipy_greedycompleter.py) |
|
|||
21 |
|
||||
22 | Assuming the text is of the form NAME.NAME....[NAME], and is |
|
24 | Assuming the text is of the form NAME.NAME....[NAME], and is | |
23 | evaluatable in self.namespace or self.global_namespace, it will be |
|
25 | evaluatable in self.namespace or self.global_namespace, it will be | |
24 | evaluated and its attributes (as revealed by dir()) are used as |
|
26 | evaluated and its attributes (as revealed by dir()) are used as | |
@@ -29,9 +31,11 b' def attr_matches(self, text):' | |||||
29 | with a __getattr__ hook is evaluated. |
|
31 | with a __getattr__ hook is evaluated. | |
30 |
|
32 | |||
31 | """ |
|
33 | """ | |
32 | import re |
|
34 | ||
33 |
|
||||
34 | force_complete = 1 |
|
35 | force_complete = 1 | |
|
36 | #print 'Completer->attr_matches, txt=%r' % text # dbg | |||
|
37 | lbuf = readline.get_line_buffer() | |||
|
38 | ||||
35 | # Another option, seems to work great. Catches things like ''.<tab> |
|
39 | # Another option, seems to work great. Catches things like ''.<tab> | |
36 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) |
|
40 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) | |
37 |
|
41 | |||
@@ -42,13 +46,13 b' def attr_matches(self, text):' | |||||
42 | if not force_complete: |
|
46 | if not force_complete: | |
43 | return [] |
|
47 | return [] | |
44 |
|
48 | |||
45 |
m2 = re.match(r"(.+)\.(\w*)$", |
|
49 | m2 = re.match(r"(.+)\.(\w*)$", lbuf) | |
46 | if not m2: |
|
50 | if not m2: | |
47 | return [] |
|
51 | return [] | |
48 | expr, attr = m2.group(1,2) |
|
52 | expr, attr = m2.group(1,2) | |
49 |
|
53 | |||
50 |
|
54 | |||
51 |
try: |
|
55 | try: | |
52 | obj = eval(expr, self.namespace) |
|
56 | obj = eval(expr, self.namespace) | |
53 | except: |
|
57 | except: | |
54 | try: |
|
58 | try: | |
@@ -57,7 +61,7 b' def attr_matches(self, text):' | |||||
57 | return [] |
|
61 | return [] | |
58 |
|
62 | |||
59 | words = dir2(obj) |
|
63 | words = dir2(obj) | |
60 |
|
64 | |||
61 | try: |
|
65 | try: | |
62 | words = generics.complete_object(obj, words) |
|
66 | words = generics.complete_object(obj, words) | |
63 | except TryNext: |
|
67 | except TryNext: | |
@@ -67,11 +71,13 b' def attr_matches(self, text):' | |||||
67 | res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ] |
|
71 | res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ] | |
68 | return res |
|
72 | return res | |
69 |
|
73 | |||
|
74 | ||||
|
75 | ||||
70 | def main(): |
|
76 | def main(): | |
71 |
import IPython |
|
77 | #import IPython.rlineimpl as readline | |
72 | readline.set_completer_delims(" \n\t") |
|
78 | readline.set_completer_delims(" \n\t") | |
73 | # monkeypatch - the code will be folded to normal completer later on |
|
79 | # monkeypatch - the code will be folded to normal completer later on | |
74 | import IPython.core.completer |
|
80 | import IPython.core.completer | |
75 | IPython.core.completer.Completer.attr_matches = attr_matches |
|
81 | IPython.core.completer.Completer.attr_matches = attr_matches | |
76 |
|
82 | |||
77 | main() No newline at end of file |
|
83 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now