Show More
@@ -2988,6 +2988,26 b' class InteractiveShell(SingletonConfigurable):' | |||
|
2988 | 2988 | # For backwards compatibility |
|
2989 | 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 | 3012 | # Things related to GUI support and pylab |
|
2993 | 3013 | #------------------------------------------------------------------------- |
@@ -291,7 +291,6 b' class EmbeddedSphinxShell(object):' | |||
|
291 | 291 | self.IP = IP |
|
292 | 292 | self.user_ns = self.IP.user_ns |
|
293 | 293 | self.user_global_ns = self.IP.user_global_ns |
|
294 | self.input_transformer_mgr = self.IP.input_transformer_manager | |
|
295 | 294 | |
|
296 | 295 | self.lines_waiting = [] |
|
297 | 296 | self.input = '' |
@@ -331,7 +330,7 b' class EmbeddedSphinxShell(object):' | |||
|
331 | 330 | try: |
|
332 | 331 | sys.stdout = self.cout |
|
333 | 332 | self.lines_waiting.append(line) |
|
334 |
if self. |
|
|
333 | if self.IP.check_complete()[0] != 'incomplete': | |
|
335 | 334 | source_raw = ''.join(self.lines_waiting) |
|
336 | 335 | self.lines_waiting = [] |
|
337 | 336 | self.IP.run_cell(source_raw, store_history=store_history) |
@@ -231,11 +231,10 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
231 | 231 | # Fall back to plain non-interactive output for tests. |
|
232 | 232 | # This is very limited. |
|
233 | 233 | def prompt(): |
|
234 | itm = self.input_transformer_manager | |
|
235 | 234 | prompt_text = "".join(x[1] for x in self.prompts.in_prompt_tokens()) |
|
236 | 235 | lines = [input(prompt_text)] |
|
237 | 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 | 238 | lines.append( input(prompt_continuation) ) |
|
240 | 239 | return '\n'.join(lines) |
|
241 | 240 | self.prompt_for_code = prompt |
@@ -119,18 +119,18 b' def newline_or_execute_outer(shell):' | |||
|
119 | 119 | check_text = d.text |
|
120 | 120 | else: |
|
121 | 121 | check_text = d.text[:d.cursor_position] |
|
122 |
status, indent = shell. |
|
|
122 | status, indent = shell.check_complete(check_text) | |
|
123 | 123 | |
|
124 | 124 | if not (d.on_last_line or |
|
125 | 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 | 128 | return |
|
129 | 129 | |
|
130 | 130 | if (status != 'incomplete') and b.accept_action.is_returnable: |
|
131 | 131 | b.accept_action.validate_and_handle(event.cli, b) |
|
132 | 132 | else: |
|
133 |
b.insert_text('\n' + |
|
|
133 | b.insert_text('\n' + indent) | |
|
134 | 134 | return newline_or_execute |
|
135 | 135 | |
|
136 | 136 |
@@ -282,8 +282,8 b' IPython configuration::' | |||
|
282 | 282 | else: # insert a newline with auto-indentation... |
|
283 | 283 | |
|
284 | 284 | if document.line_count > 1: text = text[:document.cursor_position] |
|
285 |
indent = shell. |
|
|
286 |
buffer.insert_text('\n' + |
|
|
285 | indent = shell.check_complete(text)[1] | |
|
286 | buffer.insert_text('\n' + indent) | |
|
287 | 287 | |
|
288 | 288 | # if you just wanted a plain newline without any indentation, you |
|
289 | 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