Show More
@@ -2093,20 +2093,28 b' class InteractiveShell(Configurable, Magic):' | |||||
2093 | cell : str |
|
2093 | cell : str | |
2094 | A single or multiline string. |
|
2094 | A single or multiline string. | |
2095 | """ |
|
2095 | """ | |
|
2096 | # We need to break up the input into executable blocks that can be run | |||
|
2097 | # in 'single' mode, to provide comfortable user behavior. | |||
2096 | blocks = self.input_splitter.split_blocks(cell) |
|
2098 | blocks = self.input_splitter.split_blocks(cell) | |
|
2099 | ||||
2097 | if not blocks: |
|
2100 | if not blocks: | |
2098 | return |
|
2101 | return | |
2099 |
|
2102 | |||
|
2103 | # Single-block input should behave like an interactive prompt | |||
2100 | if len(blocks) == 1: |
|
2104 | if len(blocks) == 1: | |
2101 | self.runlines(blocks[0]) |
|
2105 | self.runlines(blocks[0]) | |
2102 | return |
|
2106 | return | |
2103 |
|
2107 | |||
|
2108 | # In multi-block input, if the last block is a simple (one-two lines) | |||
|
2109 | # expression, run it in single mode so it produces output. Otherwise | |||
|
2110 | # just feed the whole thing to runcode. | |||
|
2111 | # This seems like a reasonable usability design. | |||
2104 | last = blocks[-1] |
|
2112 | last = blocks[-1] | |
2105 | if len(last.splitlines()) < 2: |
|
2113 | if len(last.splitlines()) < 2: | |
2106 |
|
|
2114 | self.runcode('\n'.join(blocks[:-1])) | |
2107 | self.runlines(last) |
|
2115 | self.runlines(last) | |
2108 | else: |
|
2116 | else: | |
2109 |
|
|
2117 | self.runcode(cell) | |
2110 |
|
2118 | |||
2111 | def runlines(self, lines, clean=False): |
|
2119 | def runlines(self, lines, clean=False): | |
2112 | """Run a string of one or more lines of source. |
|
2120 | """Run a string of one or more lines of source. | |
@@ -2226,6 +2234,11 b' class InteractiveShell(Configurable, Magic):' | |||||
2226 | - 1: an error occurred. |
|
2234 | - 1: an error occurred. | |
2227 | """ |
|
2235 | """ | |
2228 |
|
2236 | |||
|
2237 | # It's also possible that we've been fed a plain string. In that case, | |||
|
2238 | # we must store it in the input history. | |||
|
2239 | if isinstance(code_obj, basestring): | |||
|
2240 | self.input_hist_raw.append(code_obj) | |||
|
2241 | ||||
2229 | # Set our own excepthook in case the user code tries to call it |
|
2242 | # Set our own excepthook in case the user code tries to call it | |
2230 | # directly, so that the IPython crash handler doesn't get triggered |
|
2243 | # directly, so that the IPython crash handler doesn't get triggered | |
2231 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
2244 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
General Comments 0
You need to be logged in to leave comments.
Login now