Show More
@@ -2181,6 +2181,11 b' class InteractiveShell(Configurable, Magic):' | |||
|
2181 | 2181 | |
|
2182 | 2182 | if not blocks: |
|
2183 | 2183 | return |
|
2184 | ||
|
2185 | # Store the 'ipython' version of the cell as well, since that's what | |
|
2186 | # needs to go into the translated history and get executed (the | |
|
2187 | # original cell may contain non-python syntax). | |
|
2188 | ipy_cell = ''.join(blocks) | |
|
2184 | 2189 | |
|
2185 | 2190 | # Single-block input should behave like an interactive prompt |
|
2186 | 2191 | if len(blocks) == 1: |
@@ -2192,23 +2197,31 b' class InteractiveShell(Configurable, Magic):' | |||
|
2192 | 2197 | # just feed the whole thing to runcode. |
|
2193 | 2198 | # This seems like a reasonable usability design. |
|
2194 | 2199 | last = blocks[-1] |
|
2200 | last_nlines = len(last.splitlines()) | |
|
2195 | 2201 | |
|
2196 | 2202 | # Note: below, whenever we call runcode, we must sync history |
|
2197 | 2203 | # ourselves, because runcode is NOT meant to manage history at all. |
|
2198 |
if l |
|
|
2204 | if last_nlines < 2: | |
|
2205 | # Here we consider the cell split between 'body' and 'last', store | |
|
2206 | # all history and execute 'body', and if successful, then proceed | |
|
2207 | # to execute 'last'. | |
|
2208 | ||
|
2209 | # Raw history must contain the unmodified cell | |
|
2210 | raw_body = '\n'.join(cell.splitlines()[:-last_nlines])+'\n' | |
|
2211 | self.input_hist_raw.append(raw_body) | |
|
2199 | 2212 | # Get the main body to run as a cell |
|
2200 | body = ''.join(blocks[:-1]) | |
|
2201 | self.input_hist.append(body) | |
|
2202 | self.input_hist_raw.append(body) | |
|
2203 | retcode = self.runcode(body, post_execute=False) | |
|
2213 | ipy_body = ''.join(blocks[:-1]) | |
|
2214 | self.input_hist.append(ipy_body) | |
|
2215 | retcode = self.runcode(ipy_body, post_execute=False) | |
|
2204 | 2216 | if retcode==0: |
|
2205 | 2217 | # And the last expression via runlines so it produces output |
|
2206 | 2218 | self.runlines(last) |
|
2207 | 2219 | else: |
|
2208 | # Run the whole cell as one entity | |
|
2209 |
|
|
|
2220 | # Run the whole cell as one entity, storing both raw and processed | |
|
2221 | # input in history | |
|
2210 | 2222 | self.input_hist_raw.append(cell) |
|
2211 |
self. |
|
|
2223 | self.input_hist.append(ipy_cell) | |
|
2224 | self.runcode(ipy_cell) | |
|
2212 | 2225 | |
|
2213 | 2226 | def runlines(self, lines, clean=False): |
|
2214 | 2227 | """Run a string of one or more lines of source. |
General Comments 0
You need to be logged in to leave comments.
Login now