Show More
@@ -23,6 +23,19 b' import IPython' | |||||
23 | from frontendbase import FrontEndBase |
|
23 | from frontendbase import FrontEndBase | |
24 | from IPython.kernel.core.interpreter import Interpreter |
|
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 | # Base class for the line-oriented front ends |
|
40 | # Base class for the line-oriented front ends | |
28 | #------------------------------------------------------------------------------- |
|
41 | #------------------------------------------------------------------------------- | |
@@ -49,20 +62,24 b' class LineFrontEndBase(FrontEndBase):' | |||||
49 | % IPython.__version__ |
|
62 | % IPython.__version__ | |
50 |
|
63 | |||
51 |
|
64 | |||
52 |
def complete(self, |
|
65 | def complete(self, line): | |
53 |
"""Complete |
|
66 | """Complete line in engine's user_ns | |
54 |
|
67 | |||
55 | Parameters |
|
68 | Parameters | |
56 | ---------- |
|
69 | ---------- | |
57 |
|
|
70 | line : string | |
58 |
|
71 | |||
59 | Result |
|
72 | Result | |
60 | ------ |
|
73 | ------ | |
61 | Deferred result of |
|
74 | The replacement for the line and the list of possible completions. | |
62 | IPython.kernel.engineservice.IEngineBase.complete |
|
|||
63 | """ |
|
75 | """ | |
64 |
|
76 | completions = self.shell.complete(line) | ||
65 | return self.shell.complete(token) |
|
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 | def render_result(self, result): |
|
85 | def render_result(self, result): |
@@ -280,14 +280,30 b' class ConsoleWidget(editwindow.EditWindow):' | |||||
280 |
|
280 | |||
281 | def write_completion(self, possibilities, mode=None): |
|
281 | def write_completion(self, possibilities, mode=None): | |
282 | if mode=='text' or self.autocomplete_mode == 'text': |
|
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 | current_buffer = self.get_current_edit_buffer() |
|
285 | current_buffer = self.get_current_edit_buffer() | |
285 |
|
286 | |||
286 | self.write('\n') |
|
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 | for symbol in possibilities: |
|
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 | self.new_prompt(self.prompt % (self.last_result['number'] + 1)) |
|
304 | self.new_prompt(self.prompt % (self.last_result['number'] + 1)) | |
290 | self.replace_current_edit_buffer(current_buffer) |
|
305 | self.replace_current_edit_buffer(current_buffer) | |
|
306 | ||||
291 | else: |
|
307 | else: | |
292 | self.AutoCompSetIgnoreCase(False) |
|
308 | self.AutoCompSetIgnoreCase(False) | |
293 | self.AutoCompSetAutoHide(False) |
|
309 | self.AutoCompSetAutoHide(False) |
@@ -69,13 +69,13 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):' | |||||
69 | mode can be 'text', 'popup' or 'none' to use default. |
|
69 | mode can be 'text', 'popup' or 'none' to use default. | |
70 | """ |
|
70 | """ | |
71 | line = self.get_current_edit_buffer() |
|
71 | line = self.get_current_edit_buffer() | |
72 | completions = self.complete(line) |
|
72 | new_line, completions = self.complete(line) | |
73 |
if len(completions)> |
|
73 | if len(completions)>1: | |
74 | self.write_completion(completions, mode=mode) |
|
74 | self.write_completion(completions, mode=mode) | |
|
75 | self.replace_current_edit_buffer(new_line) | |||
75 |
|
76 | |||
76 |
|
77 | |||
77 | def do_calltip(self): |
|
78 | def do_calltip(self): | |
78 | # compute the length ot the last word |
|
|||
79 | separators = [' ', '(', '[', '{', '\n', '\t'] |
|
79 | separators = [' ', '(', '[', '{', '\n', '\t'] | |
80 | symbol = self.get_current_edit_buffer() |
|
80 | symbol = self.get_current_edit_buffer() | |
81 | for separator in separators: |
|
81 | for separator in separators: | |
@@ -93,6 +93,7 b' class IPythonWxController(PrefilterFrontEnd, ConsoleWidget):' | |||||
93 | symbol = getattr(symbol, name) |
|
93 | symbol = getattr(symbol, name) | |
94 | self.CallTipShow(self.GetCurrentPos(), symbol) |
|
94 | self.CallTipShow(self.GetCurrentPos(), symbol) | |
95 |
|
95 | |||
|
96 | ||||
96 | def update_completion(self): |
|
97 | def update_completion(self): | |
97 | line = self.get_current_edit_buffer() |
|
98 | line = self.get_current_edit_buffer() | |
98 | if self.AutoCompActive() and not line[-1] == '.': |
|
99 | if self.AutoCompActive() and not line[-1] == '.': |
General Comments 0
You need to be logged in to leave comments.
Login now