From 093cb7e6059c8d53cb2b99c338cfaa99ae372c7d 2017-02-01 13:06:48 From: Thomas Kluyver Date: 2017-02-01 13:06:48 Subject: [PATCH] Fix set_next_input with prompt_toolkit 1.0.10 Closes gh-10229 --- diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 2aabab0..1b5c389 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -12,6 +12,7 @@ from IPython.utils.terminal import toggle_set_term_title, set_term_title from IPython.utils.process import abbrev_cwd from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union +from prompt_toolkit.document import Document from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode from prompt_toolkit.filters import (HasFocus, Condition, IsDone) from prompt_toolkit.history import InMemoryHistory @@ -399,7 +400,13 @@ class TerminalInteractiveShell(InteractiveShell): def pre_prompt(self): if self.rl_next_input: - self.pt_cli.application.buffer.text = cast_unicode_py2(self.rl_next_input) + # We can't set the buffer here, because it will be reset just after + # this. Adding a callable to pre_run_callables does what we need + # after the buffer is reset. + s = cast_unicode_py2(self.rl_next_input) + def set_doc(): + self.pt_cli.application.buffer.document = Document(s) + self.pt_cli.pre_run_callables.append(set_doc) self.rl_next_input = None def interact(self, display_banner=DISPLAY_BANNER_DEPRECATED):