Show More
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
@@ -27,6 +27,7 b' from traitlets import (' | |||||
27 | Float, |
|
27 | Float, | |
28 | ) |
|
28 | ) | |
29 |
|
29 | |||
|
30 | from prompt_toolkit.auto_suggest import AutoSuggestFromHistory | |||
30 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode |
|
31 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode | |
31 | from prompt_toolkit.filters import (HasFocus, Condition, IsDone) |
|
32 | from prompt_toolkit.filters import (HasFocus, Condition, IsDone) | |
32 | from prompt_toolkit.formatted_text import PygmentsTokens |
|
33 | from prompt_toolkit.formatted_text import PygmentsTokens | |
@@ -353,18 +354,20 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
353 |
|
354 | |||
354 | self.pt_loop = asyncio.new_event_loop() |
|
355 | self.pt_loop = asyncio.new_event_loop() | |
355 | self.pt_app = PromptSession( |
|
356 | self.pt_app = PromptSession( | |
356 | editing_mode=editing_mode, |
|
357 | auto_suggest=AutoSuggestFromHistory(), | |
357 | key_bindings=key_bindings, |
|
358 | editing_mode=editing_mode, | |
358 | history=history, |
|
359 | key_bindings=key_bindings, | |
359 | completer=IPythonPTCompleter(shell=self), |
|
360 | history=history, | |
360 | enable_history_search = self.enable_history_search, |
|
361 | completer=IPythonPTCompleter(shell=self), | |
361 | style=self.style, |
|
362 | enable_history_search=self.enable_history_search, | |
362 | include_default_pygments_style=False, |
|
363 | style=self.style, | |
363 | mouse_support=self.mouse_support, |
|
364 | include_default_pygments_style=False, | |
364 | enable_open_in_editor=self.extra_open_editor_shortcuts, |
|
365 | mouse_support=self.mouse_support, | |
365 | color_depth=self.color_depth, |
|
366 | enable_open_in_editor=self.extra_open_editor_shortcuts, | |
366 | tempfile_suffix=".py", |
|
367 | color_depth=self.color_depth, | |
367 | **self._extra_prompt_options()) |
|
368 | tempfile_suffix=".py", | |
|
369 | **self._extra_prompt_options() | |||
|
370 | ) | |||
368 |
|
371 | |||
369 | def _make_style_from_name_or_cls(self, name_or_cls): |
|
372 | def _make_style_from_name_or_cls(self, name_or_cls): | |
370 | """ |
|
373 | """ |
@@ -24,6 +24,75 b' Need to be updated:' | |||||
24 |
|
24 | |||
25 |
|
25 | |||
26 |
|
26 | |||
|
27 | Autosuggestion is a very useful feature available in `fish <https://fishshell.com/>`__, `zsh <https://en.wikipedia.org/wiki/Z_shell>`__, and `prompt-toolkit <https://python-prompt-toolkit.readthedocs.io/en/master/pages/asking_for_input.html#auto-suggestion>`__. | |||
|
28 | ||||
|
29 | `Ptpython <https://github.com/prompt-toolkit/ptpython#ptpython>`__ allows users to enable this feature in | |||
|
30 | `ptpython/config.py <https://github.com/prompt-toolkit/ptpython/blob/master/examples/ptpython_config/config.py#L90>`__. | |||
|
31 | ||||
|
32 | This feature allows users to accept autosuggestions with ctrl e, ctrl f, | |||
|
33 | or right arrow as described below. | |||
|
34 | ||||
|
35 | 1. Start ipython | |||
|
36 | ||||
|
37 | .. image:: ../_images/auto_suggest_prompt_no_text.png | |||
|
38 | ||||
|
39 | 2. Run ``print("hello")`` | |||
|
40 | ||||
|
41 | .. image:: ../_images/auto_suggest_print_hello_suggest.png | |||
|
42 | ||||
|
43 | 3. Press p to see the autosuggestion | |||
|
44 | ||||
|
45 | .. image:: ../_images/auto_suggest_print_hello_suggest.png | |||
|
46 | ||||
|
47 | 4. Press ctrl f, or ctrl e, or right arrow to accept the suggestion | |||
|
48 | ||||
|
49 | .. image:: ../_images/auto_suggest_print_hello.png | |||
|
50 | ||||
|
51 | You can also complete word by word: | |||
|
52 | ||||
|
53 | 1. Run ``def say_hello(): print("hello")`` | |||
|
54 | ||||
|
55 | .. image:: ../_images/auto_suggest_second_prompt.png | |||
|
56 | ||||
|
57 | 2. Press d to see the autosuggestion | |||
|
58 | ||||
|
59 | .. image:: ../_images/audo_suggest_d_phantom.png | |||
|
60 | ||||
|
61 | 3. Press alt f to accept the first word of the suggestion | |||
|
62 | ||||
|
63 | .. image:: ../_images/auto_suggest_def_phantom.png | |||
|
64 | ||||
|
65 | Importantly, this feature does not interfere with tab completion: | |||
|
66 | ||||
|
67 | 1. After running ``def say_hello(): print("hello")``, press d | |||
|
68 | ||||
|
69 | .. image:: ../_images/audo_suggest_d_phantom.png | |||
|
70 | ||||
|
71 | 2. Press Tab to start tab completion | |||
|
72 | ||||
|
73 | .. image:: ../_images/auto_suggest_d_completions.png | |||
|
74 | ||||
|
75 | 3A. Press Tab again to select the first option | |||
|
76 | ||||
|
77 | .. image:: ../_images/auto_suggest_def_completions.png | |||
|
78 | ||||
|
79 | 3B. Press alt f to accept to accept the first word of the suggestion | |||
|
80 | ||||
|
81 | .. image:: ../_images/auto_suggest_def_phantom.png | |||
|
82 | ||||
|
83 | 3C. Press ctrl f or ctrl e to accept the entire suggestion | |||
|
84 | ||||
|
85 | .. image:: ../_images/auto_suggest_match_parens.png | |||
|
86 | ||||
|
87 | To install a version of ipython with autosuggestions enabled, run: | |||
|
88 | ||||
|
89 | ``pip install git+https://github.com/mskar/ipython@auto_suggest`` | |||
|
90 | ||||
|
91 | Currently, autosuggestions are only shown in the emacs or vi insert editing modes: | |||
|
92 | ||||
|
93 | - The ctrl e, ctrl f, and alt f shortcuts work by default in emacs mode. | |||
|
94 | - To use these shortcuts in vi insert mode, you will have to create `custom keybindings in your config.py <https://github.com/mskar/setup/commit/2892fcee46f9f80ef7788f0749edc99daccc52f4/>`__. | |||
|
95 | ||||
27 | .. DO NOT EDIT THIS LINE BEFORE RELEASE. FEATURE INSERTION POINT. |
|
96 | .. DO NOT EDIT THIS LINE BEFORE RELEASE. FEATURE INSERTION POINT. | |
28 |
|
97 | |||
29 | As a reminder, IPython master has diverged from the 7.x branch, thus master may |
|
98 | As a reminder, IPython master has diverged from the 7.x branch, thus master may |
General Comments 0
You need to be logged in to leave comments.
Login now