##// END OF EJS Templates
Misc review cleanup....
Matthias Bussonnier -
Show More
@@ -6,52 +6,38 b' Module to define and register Terminal IPython shortcuts with'
6 # Copyright (c) IPython Development Team.
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8
8
9 import warnings
9 import os
10 import re
10 import signal
11 import signal
11 import sys
12 import sys
12 import re
13 import warnings
13 import os
14 from typing import Callable, Dict, Union
14 from typing import Callable, Dict, Union
15
15
16
17 from prompt_toolkit.application.current import get_app
16 from prompt_toolkit.application.current import get_app
18 from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER
17 from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER
18 from prompt_toolkit.filters import Condition, emacs_insert_mode, has_completions
19 from prompt_toolkit.filters import has_focus as has_focus_impl
19 from prompt_toolkit.filters import (
20 from prompt_toolkit.filters import (
20 has_focus as has_focus_impl,
21 has_selection,
21 has_selection,
22 Condition,
22 has_suggestion,
23 vi_insert_mode,
23 vi_insert_mode,
24 emacs_insert_mode,
25 has_completions,
26 vi_mode,
24 vi_mode,
27 )
25 )
26 from prompt_toolkit.key_binding import KeyBindings
27 from prompt_toolkit.key_binding.bindings import named_commands as nc
28 from prompt_toolkit.key_binding.bindings.completion import (
28 from prompt_toolkit.key_binding.bindings.completion import (
29 display_completions_like_readline,
29 display_completions_like_readline,
30 )
30 )
31 from prompt_toolkit.key_binding import KeyBindings
32 from prompt_toolkit.key_binding.bindings import named_commands as nc
33 from prompt_toolkit.key_binding.vi_state import InputMode, ViState
31 from prompt_toolkit.key_binding.vi_state import InputMode, ViState
34 from prompt_toolkit.layout.layout import FocusableElement
32 from prompt_toolkit.layout.layout import FocusableElement
35
33
34 from IPython.terminal.shortcuts import auto_match as match
35 from IPython.terminal.shortcuts import auto_suggest
36 from IPython.utils.decorators import undoc
36 from IPython.utils.decorators import undoc
37 from . import auto_match as match, auto_suggest
38
39
37
40 __all__ = ["create_ipython_shortcuts"]
38 __all__ = ["create_ipython_shortcuts"]
41
39
42
40
43 try:
44 # only added in 3.0.30
45 from prompt_toolkit.filters import has_suggestion
46 except ImportError:
47
48 @undoc
49 @Condition
50 def has_suggestion():
51 buffer = get_app().current_buffer
52 return buffer.suggestion is not None and buffer.suggestion.text != ""
53
54
55 @undoc
41 @undoc
56 @Condition
42 @Condition
57 def cursor_in_leading_ws():
43 def cursor_in_leading_ws():
@@ -66,8 +52,24 b' def has_focus(value: FocusableElement):'
66 return Condition(tester)
52 return Condition(tester)
67
53
68
54
69 def create_ipython_shortcuts(shell, for_all_platforms: bool = False):
55 def create_ipython_shortcuts(shell, for_all_platforms: bool = False) -> KeyBindings:
70 """Set up the prompt_toolkit keyboard shortcuts for IPython."""
56 """Set up the prompt_toolkit keyboard shortcuts for IPython.
57
58 Parameters
59 ----------
60 shell: InteractiveShell
61 The current IPython shell Instance
62 for_all_platforms: bool (default false)
63 This parameter is mostly used in generating the documentation
64 to create the shortcut binding for all the platforms, and export
65 them.
66
67 Returns
68 -------
69 KeyBindings
70 the keybinding instance for prompt toolkit.
71
72 """
71 # Warning: if possible, do NOT define handler functions in the locals
73 # Warning: if possible, do NOT define handler functions in the locals
72 # scope of this function, instead define functions in the global
74 # scope of this function, instead define functions in the global
73 # scope, or a separate module, and include a user-friendly docstring
75 # scope, or a separate module, and include a user-friendly docstring
@@ -613,8 +615,8 b' if sys.platform == "win32":'
613 from IPython.core.error import TryNext
615 from IPython.core.error import TryNext
614 from IPython.lib.clipboard import (
616 from IPython.lib.clipboard import (
615 ClipboardEmpty,
617 ClipboardEmpty,
616 win32_clipboard_get,
617 tkinter_clipboard_get,
618 tkinter_clipboard_get,
619 win32_clipboard_get,
618 )
620 )
619
621
620 @undoc
622 @undoc
@@ -260,7 +260,7 b' def _swap_autosuggestion('
260 """
260 """
261 We skip most recent history entry (in either direction) if it equals the
261 We skip most recent history entry (in either direction) if it equals the
262 current autosuggestion because if user cycles when auto-suggestion is shown
262 current autosuggestion because if user cycles when auto-suggestion is shown
263 they most likely want something else than what was suggested (othewrise
263 they most likely want something else than what was suggested (otherwise
264 they would have accepted the suggestion).
264 they would have accepted the suggestion).
265 """
265 """
266 suggestion = buffer.suggestion
266 suggestion = buffer.suggestion
@@ -37,7 +37,7 b' install_requires ='
37 matplotlib-inline
37 matplotlib-inline
38 pexpect>4.3; sys_platform != "win32"
38 pexpect>4.3; sys_platform != "win32"
39 pickleshare
39 pickleshare
40 prompt_toolkit>=3.0.11,<3.1.0
40 prompt_toolkit>=3.0.30,<3.1.0
41 pygments>=2.4.0
41 pygments>=2.4.0
42 stack_data
42 stack_data
43 traitlets>=5
43 traitlets>=5
General Comments 0
You need to be logged in to leave comments. Login now