4 import prompt_toolkit
as PTK
7 with
open('/dev/tty', 'w') as f
: f
.write('\a')
9 ## Key bindings. Alas, IPython's attempt at Emacs keybindings is abysmal.
12 BUF
= PTK
.enums
.DEFAULT_BUFFER
13 ipy
= IPY
.get_ipython()
15 except AttributeError: pass
17 reg
= pt
.application
.key_bindings_registry
18 try: bind
= reg
.add_binding
19 except AttributeError:
20 bind
= PTK
.key_binding
.bindings
.utils
.create_handle_decorator(reg
)
22 def inhibit_history_search(buf
, fn
):
23 searchp
, searchtext
= \
24 buf
.enable_history_search
, buf
.history_search_text
25 buf
.enable_history_search
= F
.Never()
29 buf
.enable_history_search
, buf
.history_search_text
= \
33 buf
= ev
.current_buffer
34 if buf
.document
.cursor_position_row
> 0:
36 elif not buf
.selection_state
:
37 inhibit_history_search(buf
, lambda: buf
.history_backward())
40 buf
= ev
.current_buffer
41 if buf
.document
.cursor_position_row
< buf
.document
.line_count
- 1:
43 elif not buf
.selection_state
:
44 inhibit_history_search(buf
, lambda: buf
.history_forward())
46 bind(K
.Escape
, u
'p')(lambda ev
: ev
.current_buffer
.history_backward())
47 bind(K
.Escape
, u
'n')(lambda ev
: ev
.current_buffer
.history_forward())