Skip to content

Commit

Permalink
Merge pull request #10312 from ipython/auto-backport-of-pr-10231
Browse files Browse the repository at this point in the history
Backport PR #10231 on branch 5.x
  • Loading branch information
Carreau committed Feb 21, 2017
2 parents 07bdb40 + e2b6ae9 commit 8a75204
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion IPython/terminal/interactiveshell.py
Expand Up @@ -13,6 +13,7 @@
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
Expand Down Expand Up @@ -434,7 +435,18 @@ def ask_exit(self):

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)
if hasattr(self.pt_cli, 'pre_run_callables'):
self.pt_cli.pre_run_callables.append(set_doc)
else:
# Older version of prompt_toolkit; it's OK to set the document
# directly here.
set_doc()
self.rl_next_input = None

def interact(self, display_banner=DISPLAY_BANNER_DEPRECATED):
Expand Down

0 comments on commit 8a75204

Please sign in to comment.