Show More
@@ -23,6 +23,19 b' import IPython' | |||
|
23 | 23 | from frontendbase import FrontEndBase |
|
24 | 24 | from IPython.kernel.core.interpreter import Interpreter |
|
25 | 25 | |
|
26 | ||
|
27 | def common_prefix(strings): | |
|
28 | ref = strings[0] | |
|
29 | prefix = '' | |
|
30 | for size in range(len(ref)): | |
|
31 | test_prefix = ref[:size+1] | |
|
32 | for string in strings[1:]: | |
|
33 | if not string.startswith(test_prefix): | |
|
34 | return prefix | |
|
35 | prefix = test_prefix | |
|
36 | ||
|
37 | return prefix | |
|
38 | ||
|
26 | 39 | #------------------------------------------------------------------------------- |
|
27 | 40 | # Base class for the line-oriented front ends |
|
28 | 41 | #------------------------------------------------------------------------------- |
@@ -49,20 +62,24 b' class LineFrontEndBase(FrontEndBase):' | |||
|
49 | 62 | % IPython.__version__ |
|
50 | 63 | |
|
51 | 64 | |
|
52 |
def complete(self, |
|
|
53 |
"""Complete |
|
|
65 | def complete(self, line): | |
|
66 | """Complete line in engine's user_ns | |
|
54 | 67 | |
|
55 | 68 | Parameters |
|
56 | 69 | ---------- |
|
57 |
|
|
|
70 | line : string | |
|
58 | 71 | |
|
59 | 72 | Result |
|
60 | 73 | ------ |
|
61 | Deferred result of | |
|
62 | IPython.kernel.engineservice.IEngineBase.complete | |
|
74 | The replacement for the line and the list of possible completions. | |
|
63 | 75 | """ |
|
64 | ||
|
65 | return self.shell.complete(token) | |
|
76 | completions = self.shell.complete(line) | |
|
77 | complete_sep = re.compile('[\s\{\}\[\]\(\)\=]') | |
|
78 | if completions: | |
|
79 | prefix = common_prefix(completions) | |
|
80 | residual = complete_sep.split(line)[:-1] | |
|
81 | line = line[:-len(residual)] + prefix | |
|
82 | return line, completions | |
|
66 | 83 | |
|
67 | 84 | |
|
68 | 85 | def render_result(self, result): |
@@ -280,14 +280,30 b' class ConsoleWidget(editwindow.EditWindow):' | |||
|
280 | 280 | |
|
281 | 281 | def write_completion(self, possibilities, mode=None): |
|
282 | 282 | if mode=='text' or self.autocomplete_mode == 'text': |
|
283 | max_len = len(max(possibilities, key=len)) | |
|
283 | # FIXME: This is non Wx specific and needs to be moved into | |
|
284 | # the base class. | |
|
284 | 285 | current_buffer = self.get_current_edit_buffer() |
|
285 | 286 | |
|
286 | 287 | self.write('\n') |
|
288 | max_len = len(max(possibilities, key=len)) | |
|
289 | ||
|
290 | #now we check how much symbol we can put on a line... | |
|
291 | chars_per_line = self.GetSize()[0]/self.GetCharWidth() | |
|
292 | symbols_per_line = max(1, chars_per_line/max_len) | |
|
293 | ||
|
294 | pos = 1 | |
|
295 | buf = [] | |
|
287 | 296 | for symbol in possibilities: |
|
288 | self.write(symbol.ljust(max_len)) | |
|
297 | if pos < symbols_per_line: | |
|
298 | buf.append(symbol.ljust(max_len)) | |
|
299 | pos += 1 | |
|
300 | else: | |
|
301 | buf.append(symbol.rstrip() +'\n') | |
|
302 | pos = 1 | |
|
303 | self.write(''.join(buf)) | |
|
289 | 304 | self.new_prompt(self.prompt % (self.last_result['number'] + 1)) |
|
290 | 305 | self.replace_current_edit_buffer(current_buffer) |
|
306 | ||
|
291 | 307 | else: |
|
292 | 308 | self.AutoCompSetIgnoreCase(False) |
|
293 | 309 | self.AutoCompSetAutoHide(False) |
@@ -69,13 +69,13 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):' | |||
|
69 | 69 | mode can be 'text', 'popup' or 'none' to use default. |
|
70 | 70 | """ |
|
71 | 71 | line = self.get_current_edit_buffer() |
|
72 | completions = self.complete(line) | |
|
73 |
if len(completions)> |
|
|
72 | new_line, completions = self.complete(line) | |
|
73 | if len(completions)>1: | |
|
74 | 74 | self.write_completion(completions, mode=mode) |
|
75 | self.replace_current_edit_buffer(new_line) | |
|
75 | 76 | |
|
76 | 77 | |
|
77 | 78 | def do_calltip(self): |
|
78 | # compute the length ot the last word | |
|
79 | 79 | separators = [' ', '(', '[', '{', '\n', '\t'] |
|
80 | 80 | symbol = self.get_current_edit_buffer() |
|
81 | 81 | for separator in separators: |
@@ -93,6 +93,7 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):' | |||
|
93 | 93 | symbol = getattr(symbol, name) |
|
94 | 94 | self.CallTipShow(self.GetCurrentPos(), symbol) |
|
95 | 95 | |
|
96 | ||
|
96 | 97 | def update_completion(self): |
|
97 | 98 | line = self.get_current_edit_buffer() |
|
98 | 99 | if self.AutoCompActive() and not line[-1] == '.': |
General Comments 0
You need to be logged in to leave comments.
Login now