X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/be6f67499ecde598ec78e231fc64a0710a45633e..48a9c9c1a60f4f5ebc71a5e5269b01109c9dcfa4:/dot/ipython-key-bindings.py diff --git a/dot/ipython-key-bindings.py b/dot/ipython-key-bindings.py index 558d335..8795404 100644 --- a/dot/ipython-key-bindings.py +++ b/dot/ipython-key-bindings.py @@ -1,19 +1,21 @@ ### -*-python -*- -import IPython as IPY -import prompt_toolkit as PTK - -def ding(): - with open('/dev/tty', 'w') as f: f.write('\a') - -## Key bindings. Alas, IPython's attempt at Emacs keybindings is abysmal. -K = PTK.keys.Keys -F = PTK.filters -BUF = PTK.enums.DEFAULT_BUFFER -ipy = IPY.get_ipython() -try: pt = ipy.pt_cli -except AttributeError: pass -else: +def __mdw_hack_bindings(): + + import IPython as IPY + import prompt_toolkit as PTK + + def ding(): + with open('/dev/tty', 'w') as f: f.write('\a') + + ## Key bindings. Alas, IPython's attempt at Emacs keybindings is abysmal. + K = PTK.keys.Keys + F = PTK.filters + BUF = PTK.enums.DEFAULT_BUFFER + ipy = IPY.get_ipython() + try: pt = ipy.pt_cli + except AttributeError: return + reg = pt.application.key_bindings_registry try: bind = reg.add_binding except AttributeError: @@ -45,3 +47,6 @@ else: bind(K.Escape, u'p')(lambda ev: ev.current_buffer.history_backward()) bind(K.Escape, u'n')(lambda ev: ev.current_buffer.history_forward()) + +__mdw_hack_bindings() +del __mdw_hack_bindings