Show More
@@ -2988,6 +2988,26 b' class InteractiveShell(SingletonConfigurable):' | |||||
2988 | # For backwards compatibility |
|
2988 | # For backwards compatibility | |
2989 | runcode = run_code |
|
2989 | runcode = run_code | |
2990 |
|
2990 | |||
|
2991 | def check_complete(self, code): | |||
|
2992 | """Return whether a block of code is ready to execute, or should be continued | |||
|
2993 | ||||
|
2994 | Parameters | |||
|
2995 | ---------- | |||
|
2996 | source : string | |||
|
2997 | Python input code, which can be multiline. | |||
|
2998 | ||||
|
2999 | Returns | |||
|
3000 | ------- | |||
|
3001 | status : str | |||
|
3002 | One of 'complete', 'incomplete', or 'invalid' if source is not a | |||
|
3003 | prefix of valid code. | |||
|
3004 | indent : str | |||
|
3005 | When status is 'incomplete', this is some whitespace to insert on | |||
|
3006 | the next line of the prompt. | |||
|
3007 | """ | |||
|
3008 | status, nspaces = self.input_transformer_manager.check_complete(code) | |||
|
3009 | return status, ' ' * (nspaces or 0) | |||
|
3010 | ||||
2991 | #------------------------------------------------------------------------- |
|
3011 | #------------------------------------------------------------------------- | |
2992 | # Things related to GUI support and pylab |
|
3012 | # Things related to GUI support and pylab | |
2993 | #------------------------------------------------------------------------- |
|
3013 | #------------------------------------------------------------------------- |
@@ -291,7 +291,6 b' class EmbeddedSphinxShell(object):' | |||||
291 | self.IP = IP |
|
291 | self.IP = IP | |
292 | self.user_ns = self.IP.user_ns |
|
292 | self.user_ns = self.IP.user_ns | |
293 | self.user_global_ns = self.IP.user_global_ns |
|
293 | self.user_global_ns = self.IP.user_global_ns | |
294 | self.input_transformer_mgr = self.IP.input_transformer_manager |
|
|||
295 |
|
294 | |||
296 | self.lines_waiting = [] |
|
295 | self.lines_waiting = [] | |
297 | self.input = '' |
|
296 | self.input = '' | |
@@ -331,7 +330,7 b' class EmbeddedSphinxShell(object):' | |||||
331 | try: |
|
330 | try: | |
332 | sys.stdout = self.cout |
|
331 | sys.stdout = self.cout | |
333 | self.lines_waiting.append(line) |
|
332 | self.lines_waiting.append(line) | |
334 |
if self. |
|
333 | if self.IP.check_complete()[0] != 'incomplete': | |
335 | source_raw = ''.join(self.lines_waiting) |
|
334 | source_raw = ''.join(self.lines_waiting) | |
336 | self.lines_waiting = [] |
|
335 | self.lines_waiting = [] | |
337 | self.IP.run_cell(source_raw, store_history=store_history) |
|
336 | self.IP.run_cell(source_raw, store_history=store_history) |
@@ -231,11 +231,10 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
231 | # Fall back to plain non-interactive output for tests. |
|
231 | # Fall back to plain non-interactive output for tests. | |
232 | # This is very limited. |
|
232 | # This is very limited. | |
233 | def prompt(): |
|
233 | def prompt(): | |
234 | itm = self.input_transformer_manager |
|
|||
235 | prompt_text = "".join(x[1] for x in self.prompts.in_prompt_tokens()) |
|
234 | prompt_text = "".join(x[1] for x in self.prompts.in_prompt_tokens()) | |
236 | lines = [input(prompt_text)] |
|
235 | lines = [input(prompt_text)] | |
237 | prompt_continuation = "".join(x[1] for x in self.prompts.continuation_prompt_tokens()) |
|
236 | prompt_continuation = "".join(x[1] for x in self.prompts.continuation_prompt_tokens()) | |
238 |
while |
|
237 | while self.check_complete('\n'.join(lines))[0] == 'incomplete': | |
239 | lines.append( input(prompt_continuation) ) |
|
238 | lines.append( input(prompt_continuation) ) | |
240 | return '\n'.join(lines) |
|
239 | return '\n'.join(lines) | |
241 | self.prompt_for_code = prompt |
|
240 | self.prompt_for_code = prompt |
@@ -119,18 +119,18 b' def newline_or_execute_outer(shell):' | |||||
119 | check_text = d.text |
|
119 | check_text = d.text | |
120 | else: |
|
120 | else: | |
121 | check_text = d.text[:d.cursor_position] |
|
121 | check_text = d.text[:d.cursor_position] | |
122 |
status, indent = shell. |
|
122 | status, indent = shell.check_complete(check_text) | |
123 |
|
123 | |||
124 | if not (d.on_last_line or |
|
124 | if not (d.on_last_line or | |
125 | d.cursor_position_row >= d.line_count - d.empty_line_count_at_the_end() |
|
125 | d.cursor_position_row >= d.line_count - d.empty_line_count_at_the_end() | |
126 | ): |
|
126 | ): | |
127 |
b.insert_text('\n' + |
|
127 | b.insert_text('\n' + indent) | |
128 | return |
|
128 | return | |
129 |
|
129 | |||
130 | if (status != 'incomplete') and b.accept_action.is_returnable: |
|
130 | if (status != 'incomplete') and b.accept_action.is_returnable: | |
131 | b.accept_action.validate_and_handle(event.cli, b) |
|
131 | b.accept_action.validate_and_handle(event.cli, b) | |
132 | else: |
|
132 | else: | |
133 |
b.insert_text('\n' + |
|
133 | b.insert_text('\n' + indent) | |
134 | return newline_or_execute |
|
134 | return newline_or_execute | |
135 |
|
135 | |||
136 |
|
136 |
@@ -282,8 +282,8 b' IPython configuration::' | |||||
282 | else: # insert a newline with auto-indentation... |
|
282 | else: # insert a newline with auto-indentation... | |
283 |
|
283 | |||
284 | if document.line_count > 1: text = text[:document.cursor_position] |
|
284 | if document.line_count > 1: text = text[:document.cursor_position] | |
285 |
indent = shell. |
|
285 | indent = shell.check_complete(text)[1] | |
286 |
buffer.insert_text('\n' + |
|
286 | buffer.insert_text('\n' + indent) | |
287 |
|
287 | |||
288 | # if you just wanted a plain newline without any indentation, you |
|
288 | # if you just wanted a plain newline without any indentation, you | |
289 | # could use `buffer.insert_text('\n')` instead of the lines above |
|
289 | # could use `buffer.insert_text('\n')` instead of the lines above |
General Comments 0
You need to be logged in to leave comments.
Login now