From 66bc9c0932a2ceda0f8fea94f1791c88e10a6b05 2017-02-21 17:12:26 From: Min RK Date: 2017-02-21 17:12:26 Subject: [PATCH] Backport PR #10305: Respect completions display style in terminal debugger Make the debugger prompt use the same completions style as the main IPython prompt. Closes gh-9746 --- diff --git a/IPython/terminal/debugger.py b/IPython/terminal/debugger.py index a2efbd6..9ca0307 100644 --- a/IPython/terminal/debugger.py +++ b/IPython/terminal/debugger.py @@ -5,11 +5,14 @@ from IPython.core.debugger import Pdb from IPython.core.completer import IPCompleter from .ptutils import IPythonPTCompleter -from .shortcuts import suspend_to_bg +from .shortcuts import suspend_to_bg, cursor_in_leading_ws -from prompt_toolkit.filters import Condition +from prompt_toolkit.enums import DEFAULT_BUFFER +from prompt_toolkit.filters import (Condition, HasFocus, HasSelection, + ViInsertMode, EmacsInsertMode) from prompt_toolkit.keys import Keys from prompt_toolkit.key_binding.manager import KeyBindingManager +from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline from prompt_toolkit.token import Token from prompt_toolkit.shortcuts import create_prompt_application from prompt_toolkit.interface import CommandLineInterface @@ -43,6 +46,15 @@ class TerminalPdb(Pdb): kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend )(suspend_to_bg) + if self.shell.display_completions == 'readlinelike': + kbmanager.registry.add_binding(Keys.ControlI, + filter=(HasFocus(DEFAULT_BUFFER) + & ~HasSelection() + & ViInsertMode() | EmacsInsertMode() + & ~cursor_in_leading_ws + ))(display_completions_like_readline) + multicolumn = (self.shell.display_completions == 'multicolumn') + self._pt_app = create_prompt_application( editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), key_bindings_registry=kbmanager.registry, @@ -50,7 +62,8 @@ class TerminalPdb(Pdb): completer= self._ptcomp, enable_history_search=True, mouse_support=self.shell.mouse_support, - get_prompt_tokens=get_prompt_tokens + get_prompt_tokens=get_prompt_tokens, + display_completions_in_columns=multicolumn, ) self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)