From b53578c9c033461e1954e0872ed99fde779b0a87 2010-09-14 03:35:26 From: epatters Date: 2010-09-14 03:35:26 Subject: [PATCH] Pressing Enter now always executes when the input buffer has one line. --- diff --git a/IPython/core/usage.py b/IPython/core/usage.py index 01387e2..c9069e8 100644 --- a/IPython/core/usage.py +++ b/IPython/core/usage.py @@ -306,9 +306,8 @@ once you learn a few basic keybindings it will be a much more efficient environment. For single expressions or indented blocks, the console behaves almost like the -terminal IPython: single expressions are immediately evaluated *if the cursor -is at the end of the line*, and indented blocks are evaluated once a single -blank line is entered:: +terminal IPython: single expressions are immediately evaluated, and indented +blocks are evaluated once a single blank line is entered:: In [1]: print "Hello IPython!" # Enter was pressed at the end of the line Hello IPython! @@ -318,12 +317,6 @@ blank line is entered:: ...: 0 1 2 3 4 5 6 7 8 9 -If you have a single expression and you go back to edit something in the -beginning, hitting ``Enter`` will split the line (like a text editor) instead -of executing it. To execute, you can either go to the end of the line to hit -``Enter``, or hit ``Shift-Enter`` anywhere, which is the 'force execution' -keybinding. - If you want to enter more than one expression in a single input block (something not possible in the terminal), you can use ``Control-Enter`` at the end of your first line instead of ``Enter``. At that point the console goes diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index ee20135..805ad4d 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -806,13 +806,16 @@ class ConsoleWidget(Configurable, QtGui.QWidget): if self._reading_callback: self._reading_callback() - # If there is only whitespace after the cursor, execute. - # Otherwise, split the line with a continuation prompt. + # If the input buffer is a single line or there is only + # whitespace after the cursor, execute. Otherwise, split the + # line with a continuation prompt. elif not self._executing: cursor.movePosition(QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor) at_end = cursor.selectedText().trimmed().isEmpty() - if (at_end or shift_down) and not ctrl_down: + single_line = (self._get_end_cursor().blockNumber() == + self._get_prompt_cursor().blockNumber()) + if (at_end or shift_down or single_line) and not ctrl_down: self.execute(interactive = not shift_down) else: # Do this inside an edit block for clean undo/redo.