diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 39f66be..f57ef92 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -202,7 +202,7 @@ class InputSplitter(object): # object; it will be None if the source doesn't compile to valid Python. code = None # Input mode - input_mode = 'append' + input_mode = 'line' # Private attributes @@ -222,14 +222,18 @@ class InputSplitter(object): ---------- input_mode : str - One of ['append', 'replace']; default is 'append'. This controls how - new inputs are used: in 'append' mode, they are appended to the - existing buffer and the whole buffer is compiled; in 'replace' mode, - each new input completely replaces all prior inputs. Replace mode is - thus equivalent to prepending a full reset() to every push() call. + One of ['line', 'block']; default is 'line'. - In practice, line-oriented clients likely want to use 'append' mode - while block-oriented ones will want to use 'replace'. + The input_mode parameter controls how new inputs are used when fed via + the :meth:`push` method: + + - 'line': meant for line-oriented clients, inputs are appended one at a + time to the internal buffer and the whole buffer is compiled. + + - 'block': meant for clients that can edit multi-line blocks of text at + a time. Each new input new input completely replaces all prior + inputs. Block mode is thus equivalent to prepending a full reset() + to every push() call. """ self._buffer = [] self._compile = codeop.CommandCompiler() @@ -275,7 +279,7 @@ class InputSplitter(object): this value is also stored as a private attribute (_is_complete), so it can be queried at any time. """ - if self.input_mode == 'replace': + if self.input_mode == 'block': self.reset() # If the source code has leading blanks, add 'if 1:\n' to it @@ -829,18 +833,18 @@ class IPythonInputSplitter(InputSplitter): # # FIXME: try to find a cleaner approach for this last bit. - # If we were in 'replace' mode, since we're going to pump the parent + # If we were in 'block' mode, since we're going to pump the parent # class by hand line by line, we need to temporarily switch out to - # 'append' mode, do a single manual reset and then feed the lines one + # 'line' mode, do a single manual reset and then feed the lines one # by one. Note that this only matters if the input has more than one # line. changed_input_mode = False - if len(lines_list)>1 and self.input_mode == 'replace': + if len(lines_list)>1 and self.input_mode == 'block': self.reset() changed_input_mode = True - saved_input_mode = 'replace' - self.input_mode = 'append' + saved_input_mode = 'block' + self.input_mode = 'line' try: push = super(IPythonInputSplitter, self).push diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index 67605a5..c2ebe0b 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -204,7 +204,7 @@ class InputSplitterTestCase(unittest.TestCase): def test_replace_mode(self): isp = self.isp - isp.input_mode = 'replace' + isp.input_mode = 'block' isp.push('x=1') self.assertEqual(isp.source, 'x=1\n') isp.push('x=2') @@ -556,7 +556,7 @@ class IPythonInputTestCase(InputSplitterTestCase): """ def setUp(self): - self.isp = isp.IPythonInputSplitter(input_mode='append') + self.isp = isp.IPythonInputSplitter(input_mode='line') def test_syntax(self): """Call all single-line syntax tests from the main object""" @@ -590,7 +590,7 @@ class BlockIPythonInputTestCase(IPythonInputTestCase): test_push3 = test_split = lambda s: None def setUp(self): - self.isp = isp.IPythonInputSplitter(input_mode='replace') + self.isp = isp.IPythonInputSplitter(input_mode='block') def test_syntax_multiline(self): isp = self.isp diff --git a/IPython/frontend/qt/console/frontend_widget.py b/IPython/frontend/qt/console/frontend_widget.py index f7086fd..593683c 100644 --- a/IPython/frontend/qt/console/frontend_widget.py +++ b/IPython/frontend/qt/console/frontend_widget.py @@ -103,7 +103,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): self._completion_lexer = CompletionLexer(PythonLexer()) self._hidden = False self._highlighter = self._highlighter_class(self) - self._input_splitter = self._input_splitter_class(input_mode='replace') + self._input_splitter = self._input_splitter_class(input_mode='block') self._kernel_manager = None # Configure the ConsoleWidget.