[IPython-dev] Using Prompt Toolkit to edit terminal inputs in a screen editor.
takowl at gmail.com
Tue Jul 19 07:10:31 EDT 2016
Ooh, nice find. If we can agree on a keyboard shortcut that people like for
this, I'd like to enable it by default in IPython.
On 18 July 2016 at 22:15, Carl Smith <carl.input at gmail.com> wrote:
> Prompt Toolkit allows you to open the current input in your favourite
> editor, edit the code, and when you exit, you have the edited code in the
> input buffer. This is different to %edit, and is really useful in practice.
> If you chuck this code in a startup file, it will create a keybinding for
> the feature. This code uses Ctrl-N (because ne is currently my favourite
> tool for these kinds of edits), but you can easily change the keybinding.
> from prompt_toolkit.keys import Keys
> ip = get_ipython()
> def open_input_in_editor(event):
> event.cli.current_buffer.tempfile_suffix = ".py"
> bind_key = ip.pt_cli.application.key_bindings_registry.add_binding
> It'd be nice to have a better way of setting the tempfile suffix, so it
> isn't redundantly reassigned every time you use the function, but doing it
> this way is fine for now. Removing that causes the tempfile to have no
> suffix, so you wouldn't get language specific features like syntax
> Hope someone else finds this useful.
> -- Carl Smith
> carl.input at gmail.com
> IPython-dev mailing list
> IPython-dev at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev