Show More
@@ -6,52 +6,38 b' Module to define and register Terminal IPython shortcuts with' | |||
|
6 | 6 | # Copyright (c) IPython Development Team. |
|
7 | 7 | # Distributed under the terms of the Modified BSD License. |
|
8 | 8 | |
|
9 |
import |
|
|
9 | import os | |
|
10 | import re | |
|
10 | 11 | import signal |
|
11 | 12 | import sys |
|
12 |
import |
|
|
13 | import os | |
|
13 | import warnings | |
|
14 | 14 | from typing import Callable, Dict, Union |
|
15 | 15 | |
|
16 | ||
|
17 | 16 | from prompt_toolkit.application.current import get_app |
|
18 | 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 | 20 | from prompt_toolkit.filters import ( |
|
20 | has_focus as has_focus_impl, | |
|
21 | 21 | has_selection, |
|
22 | Condition, | |
|
22 | has_suggestion, | |
|
23 | 23 | vi_insert_mode, |
|
24 | emacs_insert_mode, | |
|
25 | has_completions, | |
|
26 | 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 | 28 | from prompt_toolkit.key_binding.bindings.completion import ( |
|
29 | 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 | 31 | from prompt_toolkit.key_binding.vi_state import InputMode, ViState |
|
34 | 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 | 36 | from IPython.utils.decorators import undoc |
|
37 | from . import auto_match as match, auto_suggest | |
|
38 | ||
|
39 | 37 | |
|
40 | 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 | 41 | @undoc |
|
56 | 42 | @Condition |
|
57 | 43 | def cursor_in_leading_ws(): |
@@ -66,8 +52,24 b' def has_focus(value: FocusableElement):' | |||
|
66 | 52 | return Condition(tester) |
|
67 | 53 | |
|
68 | 54 | |
|
69 | def create_ipython_shortcuts(shell, for_all_platforms: bool = False): | |
|
70 |
"""Set up the prompt_toolkit keyboard shortcuts for IPython. |
|
|
55 | def create_ipython_shortcuts(shell, for_all_platforms: bool = False) -> KeyBindings: | |
|
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 | 73 | # Warning: if possible, do NOT define handler functions in the locals |
|
72 | 74 | # scope of this function, instead define functions in the global |
|
73 | 75 | # scope, or a separate module, and include a user-friendly docstring |
@@ -613,8 +615,8 b' if sys.platform == "win32":' | |||
|
613 | 615 | from IPython.core.error import TryNext |
|
614 | 616 | from IPython.lib.clipboard import ( |
|
615 | 617 | ClipboardEmpty, |
|
616 | win32_clipboard_get, | |
|
617 | 618 | tkinter_clipboard_get, |
|
619 | win32_clipboard_get, | |
|
618 | 620 | ) |
|
619 | 621 | |
|
620 | 622 | @undoc |
@@ -260,7 +260,7 b' def _swap_autosuggestion(' | |||
|
260 | 260 | """ |
|
261 | 261 | We skip most recent history entry (in either direction) if it equals the |
|
262 | 262 | current autosuggestion because if user cycles when auto-suggestion is shown |
|
263 |
they most likely want something else than what was suggested (othe |
|
|
263 | they most likely want something else than what was suggested (otherwise | |
|
264 | 264 | they would have accepted the suggestion). |
|
265 | 265 | """ |
|
266 | 266 | suggestion = buffer.suggestion |
General Comments 0
You need to be logged in to leave comments.
Login now