From 467667270d4d0e4ac3885d229b8f51cef72171b5 2019-11-03 03:51:25 From: Matthias Bussonnier Date: 2019-11-03 03:51:25 Subject: [PATCH] Do no precompute when using vi mode. --- diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 533c7cc..0dda428 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -377,12 +377,24 @@ class TerminalInteractiveShell(InteractiveShell): """ Return the current layout option for the current Terminal InteractiveShell """ + def get_message(): + return PygmentsTokens(self.prompts.in_prompt_tokens()) + + if self.editing_mode == 'emacs': + # with emacs mode the prompt is (usually) static, so we call only + # the function once. With VI mode it can toggle between [ins] and + # [nor] so we can't precompute. + # here I'm going to favor the default keybinding which almost + # everybody uses to decrease CPU usage. + # if we have issues with users with custom Prompts we can see how to + # work around this. + get_message = get_message() return { 'complete_in_thread': False, 'lexer':IPythonPTLexer(), 'reserve_space_for_menu':self.space_for_menu, - 'message': PygmentsTokens(self.prompts.in_prompt_tokens()), + 'message': get_message, 'prompt_continuation': ( lambda width, lineno, is_soft_wrap: PygmentsTokens(self.prompts.continuation_prompt_tokens(width))),