##// END OF EJS Templates
Merge pull request #10500 from takluyver/config-return-handler...
meeseeksdev[bot] -
r23581:f3fc2511 merge
parent child Browse files
Show More
@@ -10,7 +10,10 b' from IPython.utils import io'
10 from IPython.utils.py3compat import cast_unicode_py2, input
10 from IPython.utils.py3compat import cast_unicode_py2, input
11 from IPython.utils.terminal import toggle_set_term_title, set_term_title
11 from IPython.utils.terminal import toggle_set_term_title, set_term_title
12 from IPython.utils.process import abbrev_cwd
12 from IPython.utils.process import abbrev_cwd
13 from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union
13 from traitlets import (
14 Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union,
15 Any,
16 )
14
17
15 from prompt_toolkit.document import Document
18 from prompt_toolkit.document import Document
16 from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
19 from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
@@ -192,6 +195,12 b' class TerminalInteractiveShell(InteractiveShell):'
192 "This is in addition to the F2 binding, which is always enabled."
195 "This is in addition to the F2 binding, which is always enabled."
193 ).tag(config=True)
196 ).tag(config=True)
194
197
198 handle_return = Any(None,
199 help="Provide an alternative handler to be called when the user presses "
200 "Return. This is an advanced option intended for debugging, which "
201 "may be changed or removed in later releases."
202 ).tag(config=True)
203
195 @observe('term_title')
204 @observe('term_title')
196 def init_term_title(self, change=None):
205 def init_term_title(self, change=None):
197 # Enable or disable the terminal title.
206 # Enable or disable the terminal title.
@@ -31,12 +31,17 b' def register_ipython_shortcuts(registry, shell):'
31 """Set up the prompt_toolkit keyboard shortcuts for IPython"""
31 """Set up the prompt_toolkit keyboard shortcuts for IPython"""
32 insert_mode = ViInsertMode() | EmacsInsertMode()
32 insert_mode = ViInsertMode() | EmacsInsertMode()
33
33
34 if getattr(shell, 'handle_return', None):
35 return_handler = shell.handle_return(shell)
36 else:
37 return_handler = newline_or_execute_outer(shell)
38
34 # Ctrl+J == Enter, seemingly
39 # Ctrl+J == Enter, seemingly
35 registry.add_binding(Keys.ControlJ,
40 registry.add_binding(Keys.ControlJ,
36 filter=(HasFocus(DEFAULT_BUFFER)
41 filter=(HasFocus(DEFAULT_BUFFER)
37 & ~HasSelection()
42 & ~HasSelection()
38 & insert_mode
43 & insert_mode
39 ))(newline_or_execute_outer(shell))
44 ))(return_handler)
40
45
41 registry.add_binding(Keys.ControlBackslash)(force_exit)
46 registry.add_binding(Keys.ControlBackslash)(force_exit)
42
47
General Comments 0
You need to be logged in to leave comments. Login now