Show More
@@ -1009,6 +1009,15 class IPythonDirective(Directive): | |||||
1009 |
|
1009 | |||
1010 | if figure is not None: |
|
1010 | if figure is not None: | |
1011 | figures.append(figure) |
|
1011 | figures.append(figure) | |
|
1012 | else: | |||
|
1013 | message = 'Code input with no code at {}, line {}'\ | |||
|
1014 | .format( | |||
|
1015 | self.state.document.current_source, | |||
|
1016 | self.state.document.current_line) | |||
|
1017 | if self.shell.warning_is_error: | |||
|
1018 | raise RuntimeError(message) | |||
|
1019 | else: | |||
|
1020 | warnings.warn(message) | |||
1012 |
|
1021 | |||
1013 | for figure in figures: |
|
1022 | for figure in figures: | |
1014 | lines.append('') |
|
1023 | lines.append('') |
@@ -216,15 +216,35 a :ref:`startup file <startup_files>`:: | |||||
216 | def insert_unexpected(event): |
|
216 | def insert_unexpected(event): | |
217 | buf = event.current_buffer |
|
217 | buf = event.current_buffer | |
218 | buf.insert_text('The Spanish Inquisition') |
|
218 | buf.insert_text('The Spanish Inquisition') | |
219 |
|
||||
220 | # Register the shortcut if IPython is using prompt_toolkit |
|
219 | # Register the shortcut if IPython is using prompt_toolkit | |
221 |
if getattr(ip, 'pt_ |
|
220 | if getattr(ip, 'pt_app', None): | |
222 |
registry = ip.pt_ |
|
221 | registry = ip.pt_app.key_bindings | |
223 | registry.add_binding(Keys.ControlN, |
|
222 | registry.add_binding(Keys.ControlN, | |
224 | filter=(HasFocus(DEFAULT_BUFFER) |
|
223 | filter=(HasFocus(DEFAULT_BUFFER) | |
225 | & ~HasSelection() |
|
224 | & ~HasSelection() | |
226 | & insert_mode))(insert_unexpected) |
|
225 | & insert_mode))(insert_unexpected) | |
227 |
|
226 | |||
|
227 | ||||
|
228 | Here is a second example that bind the key sequence ``j``, ``k`` to switch to | |||
|
229 | VI input mode to ``Normal`` when in insert mode:: | |||
|
230 | ||||
|
231 | from IPython import get_ipython | |||
|
232 | from prompt_toolkit.enums import DEFAULT_BUFFER | |||
|
233 | from prompt_toolkit.filters import HasFocus, ViInsertMode | |||
|
234 | from prompt_toolkit.key_binding.vi_state import InputMode | |||
|
235 | ||||
|
236 | ip = get_ipython() | |||
|
237 | ||||
|
238 | def switch_to_navigation_mode(event): | |||
|
239 | vi_state = event.cli.vi_state | |||
|
240 | vi_state.input_mode = InputMode.NAVIGATION | |||
|
241 | ||||
|
242 | if getattr(ip, 'pt_app', None): | |||
|
243 | registry = ip.pt_app.key_bindings | |||
|
244 | registry.add_binding(u'j',u'k', | |||
|
245 | filter=(HasFocus(DEFAULT_BUFFER) | |||
|
246 | & ViInsertMode()))(switch_to_navigation_mode) | |||
|
247 | ||||
228 | For more information on filters and what you can do with the ``event`` object, |
|
248 | For more information on filters and what you can do with the ``event`` object, | |
229 | `see the prompt_toolkit docs |
|
249 | `see the prompt_toolkit docs | |
230 | <http://python-prompt-toolkit.readthedocs.io/en/latest/pages/building_prompts.html#adding-custom-key-bindings>`__. |
|
250 | <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