Show More
@@ -159,3 +159,37 b' With (X)EMacs >= 24, You can enable IPython in python-mode with:' | |||
|
159 | 159 | .. _`(X)Emacs`: http://www.gnu.org/software/emacs/ |
|
160 | 160 | .. _TextMate: http://macromates.com/ |
|
161 | 161 | .. _vim: http://www.vim.org/ |
|
162 | ||
|
163 | .. _custom_keyboard_shortcuts | |
|
164 | ||
|
165 | Keyboard Shortcuts | |
|
166 | ================== | |
|
167 | ||
|
168 | .. versionchanged:: 5.0 | |
|
169 | ||
|
170 | You can customise keyboard shortcuts for terminal IPython. Put code like this in | |
|
171 | a :ref:`startup file <startup_files>`:: | |
|
172 | ||
|
173 | from IPython import get_ipython | |
|
174 | from prompt_toolkit.enums import DEFAULT_BUFFER | |
|
175 | from prompt_toolkit.keys import Keys | |
|
176 | from prompt_toolkit.filters import HasFocus, HasSelection, ViInsertMode, EmacsInsertMode | |
|
177 | ||
|
178 | ip = get_ipython() | |
|
179 | insert_mode = ViInsertMode() | EmacsInsertMode() | |
|
180 | ||
|
181 | def insert_unexpected(event): | |
|
182 | buf = event.current_buffer | |
|
183 | buf.insert_text('The Spanish Inquisition') | |
|
184 | ||
|
185 | # Register the shortcut if IPython is using prompt_toolkit | |
|
186 | if getattr(ip, 'pt_cli'): | |
|
187 | registry = ip.pt_cli.application.key_bindings_registry | |
|
188 | registry.add_binding(Keys.ControlN, | |
|
189 | filter=(HasFocus(DEFAULT_BUFFER) | |
|
190 | & ~HasSelection() | |
|
191 | & insert_mode))(insert_unexpected) | |
|
192 | ||
|
193 | For more information on filters and what you can do with the ``event`` object, | |
|
194 | `see the prompt_toolkit docs | |
|
195 | <http://python-prompt-toolkit.readthedocs.io/en/latest/pages/building_prompts.html#adding-custom-key-bindings>`__. |
General Comments 0
You need to be logged in to leave comments.
Login now