Re: Using Prompt Toolkit to edit terminal inputs in a screen editor.
Thomas Kluyver <[email protected]> Tue, 19 Jul 2016 12:10:31 +0100
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <CAOvn4qinfdJUd_1kXDviP1RtXtD_Lz3ATQpnXCjQ4u_FXWR7zA@mail.gmail.com> |
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 <[email protected]> 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" > event.cli.current_buffer.open_in_editor(event.cli) > > bind_key = ip.pt_cli.application.key_bindings_registry.add_binding > bind_key(Keys.ControlN)(open_input_in_editor) > > 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 > highlighting. > > Hope someone else finds this useful. > > Best, > -- Carl Smith > [email protected] > > _______________________________________________ > IPython-dev mailing list > [email protected] > https://mail.scipy.org/mailman/listinfo/ipython-dev > > _______________________________________________ IPython-dev mailing list [email protected] https://mail.scipy.org/mailman/listinfo/ipython-dev