Skip to content

Commit

Permalink
Fix missing history in cell execution mode.
Browse files Browse the repository at this point in the history
Also cleaned up and commented run_cell a little better, no need to run
using map() when a single run_code call suffices.
  • Loading branch information
fperez committed Sep 7, 2010
1 parent 3658d7b commit 205d124
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions IPython/core/interactiveshell.py
Expand Up @@ -2093,20 +2093,28 @@ def run_cell(self, cell):
cell : str
A single or multiline string.
"""
# We need to break up the input into executable blocks that can be run
# in 'single' mode, to provide comfortable user behavior.
blocks = self.input_splitter.split_blocks(cell)

if not blocks:
return


# Single-block input should behave like an interactive prompt
if len(blocks) == 1:
self.runlines(blocks[0])
return

# In multi-block input, if the last block is a simple (one-two lines)
# expression, run it in single mode so it produces output. Otherwise
# just feed the whole thing to runcode.
# This seems like a reasonable usability design.
last = blocks[-1]
if len(last.splitlines()) < 2:
map(self.runcode, blocks[:-1])
self.runcode('\n'.join(blocks[:-1]))
self.runlines(last)
else:
map(self.runcode, blocks)
self.runcode(cell)

def runlines(self, lines, clean=False):
"""Run a string of one or more lines of source.
Expand Down Expand Up @@ -2226,6 +2234,11 @@ def runcode(self, code_obj):
- 1: an error occurred.
"""

# It's also possible that we've been fed a plain string. In that case,
# we must store it in the input history.
if isinstance(code_obj, basestring):
self.input_hist_raw.append(code_obj)

# Set our own excepthook in case the user code tries to call it
# directly, so that the IPython crash handler doesn't get triggered
old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
Expand Down

0 comments on commit 205d124

Please sign in to comment.