From 96727fe2bf9c5840eeff09e736c9250fcbd72a82 2017-04-26 10:33:30 From: Thomas Kluyver Date: 2017-04-26 10:33:30 Subject: [PATCH] Prefer execution when there's only a single line entered Closes gh-10425 The heuristic here is to treat a single line specially, and always evaluate it as if the cursor was at the end. An alternative heuristic could be to do this if the cursor is on the last line of the input. --- diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py index e626ccf..22b4ea8 100644 --- a/IPython/terminal/shortcuts.py +++ b/IPython/terminal/shortcuts.py @@ -108,8 +108,13 @@ def newline_or_execute_outer(shell): b.cancel_completion() return - before_text = d.text[:d.cursor_position] - status, indent = shell.input_splitter.check_complete(before_text + '\n') + # If there's only one line, treat it as if the cursor is at the end. + # See https://github.com/ipython/ipython/issues/10425 + if d.line_count == 1: + check_text = d.text + else: + check_text = d.text[:d.cursor_position] + status, indent = shell.input_splitter.check_complete(check_text + '\n') if not (d.on_last_line or d.cursor_position_row >= d.line_count - d.empty_line_count_at_the_end()