Show More
@@ -0,0 +1,37 b'' | |||||
|
1 | """ | |||
|
2 | comp | |||
|
3 | """ | |||
|
4 | ||||
|
5 | # The prefilter always ends in a call to some self.handle_X method. We swap | |||
|
6 | # all of those out so that we can capture which one was called. | |||
|
7 | ||||
|
8 | import sys | |||
|
9 | sys.path.append('..') | |||
|
10 | import IPython | |||
|
11 | import IPython.ipapi | |||
|
12 | ||||
|
13 | IPython.Shell.start() | |||
|
14 | ||||
|
15 | ip = IPython.ipapi.get() | |||
|
16 | ||||
|
17 | completer = ip.IP.Completer | |||
|
18 | ||||
|
19 | print completer | |||
|
20 | ||||
|
21 | def do_test(text, line): | |||
|
22 | def get_endix(): | |||
|
23 | idx = len(line) -1 | |||
|
24 | print "Call endidx =>",idx | |||
|
25 | return idx | |||
|
26 | def get_line_buffer(): | |||
|
27 | print "Lbuf =>",line | |||
|
28 | return line | |||
|
29 | completer.get_line_buffer = get_line_buffer | |||
|
30 | completer.get_endidx = get_endix | |||
|
31 | l = completer.all_completions(text) | |||
|
32 | return l | |||
|
33 | ||||
|
34 | l = do_test ('p', 'print p') | |||
|
35 | assert 'pow' in l | |||
|
36 | l = do_test ('p', 'import p') | |||
|
37 | assert 'pprint' in l No newline at end of file |
@@ -247,6 +247,7 b' class IPCompleter(Completer):' | |||||
247 | delims = delims.replace(self.magic_escape,'') |
|
247 | delims = delims.replace(self.magic_escape,'') | |
248 | self.readline.set_completer_delims(delims) |
|
248 | self.readline.set_completer_delims(delims) | |
249 | self.get_line_buffer = self.readline.get_line_buffer |
|
249 | self.get_line_buffer = self.readline.get_line_buffer | |
|
250 | self.get_endidx = self.readline.get_endidx | |||
250 | self.omit__names = omit__names |
|
251 | self.omit__names = omit__names | |
251 | self.merge_completions = shell.rc.readline_merge_completions |
|
252 | self.merge_completions = shell.rc.readline_merge_completions | |
252 | if alias_table is None: |
|
253 | if alias_table is None: | |
@@ -272,6 +273,7 b' class IPCompleter(Completer):' | |||||
272 | self.alias_matches, |
|
273 | self.alias_matches, | |
273 | self.python_func_kw_matches] |
|
274 | self.python_func_kw_matches] | |
274 |
|
275 | |||
|
276 | ||||
275 | # Code contributed by Alex Schmolck, for ipython/emacs integration |
|
277 | # Code contributed by Alex Schmolck, for ipython/emacs integration | |
276 | def all_completions(self, text): |
|
278 | def all_completions(self, text): | |
277 | """Return all possible completions for the benefit of emacs.""" |
|
279 | """Return all possible completions for the benefit of emacs.""" | |
@@ -561,7 +563,6 b' class IPCompleter(Completer):' | |||||
561 |
|
563 | |||
562 | return None |
|
564 | return None | |
563 |
|
565 | |||
564 |
|
||||
565 | def complete(self, text, state,line_buffer=None): |
|
566 | def complete(self, text, state,line_buffer=None): | |
566 | """Return the next possible completion for 'text'. |
|
567 | """Return the next possible completion for 'text'. | |
567 |
|
568 | |||
@@ -584,6 +585,9 b' class IPCompleter(Completer):' | |||||
584 | # his tab! Incidentally, this enables pasting of tabbed text from |
|
585 | # his tab! Incidentally, this enables pasting of tabbed text from | |
585 | # an editor (as long as autoindent is off). |
|
586 | # an editor (as long as autoindent is off). | |
586 |
|
587 | |||
|
588 | # It should be noted that at least pyreadline still shows | |||
|
589 | # file completions - is there a way around it? | |||
|
590 | ||||
587 | # don't apply this on 'dumb' terminals, such as emacs buffers, so we |
|
591 | # don't apply this on 'dumb' terminals, such as emacs buffers, so we | |
588 | # don't interfere with their own tab-completion mechanism. |
|
592 | # don't interfere with their own tab-completion mechanism. | |
589 | if line_buffer is None: |
|
593 | if line_buffer is None: | |
@@ -598,7 +602,7 b' class IPCompleter(Completer):' | |||||
598 | magic_escape = self.magic_escape |
|
602 | magic_escape = self.magic_escape | |
599 | magic_prefix = self.magic_prefix |
|
603 | magic_prefix = self.magic_prefix | |
600 |
|
604 | |||
601 |
self.lbuf = self.full_lbuf[:self. |
|
605 | self.lbuf = self.full_lbuf[:self.get_endidx()] | |
602 |
|
606 | |||
603 | try: |
|
607 | try: | |
604 | if text.startswith(magic_escape): |
|
608 | if text.startswith(magic_escape): |
@@ -7,6 +7,9 b'' | |||||
7 | * ipy_user_conf.py: Added an example on how to change term |
|
7 | * ipy_user_conf.py: Added an example on how to change term | |
8 | colors in config file (through using autoexec). |
|
8 | colors in config file (through using autoexec). | |
9 |
|
9 | |||
|
10 | * completer.py, test_completer.py: Ability to specify custom | |||
|
11 | get_endidx to replace readline.get_endidx. For emacs users. | |||
|
12 | ||||
10 | 2008-01-10 Ville Vainio <vivainio@gmail.com> |
|
13 | 2008-01-10 Ville Vainio <vivainio@gmail.com> | |
11 |
|
14 | |||
12 | * Prompts.py (set_p_str): do not crash on illegal prompt strings |
|
15 | * Prompts.py (set_p_str): do not crash on illegal prompt strings |
General Comments 0
You need to be logged in to leave comments.
Login now