<div dir="ltr"></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span style="color:rgb(115,115,115);font-style:italic;line-height:18px"><font size="1" face="monospace, monospace">-- Carl Smith</font></span><br></div></div><div><span style="color:rgb(115,115,115);font-style:italic;line-height:18px"><font size="1" face="monospace, monospace"><a href="mailto:carl.input@gmail.com" target="_blank">carl.input@gmail.com</a></font></span></div></div></div></div></div></div>
<br><div class="gmail_quote">On 19 July 2016 at 12:10, Thomas Kluyver <span dir="ltr"><<a href="mailto:takowl@gmail.com" target="_blank">takowl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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.<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 18 July 2016 at 22:15, Carl Smith <span dir="ltr"><<a href="mailto:carl.input@gmail.com" target="_blank">carl.input@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_default"><div class="gmail_default"><font color="#444444" face="monospace, monospace">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.</font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">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.</font></div><div class="gmail_default"><br></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">    from prompt_toolkit.keys import Keys</font></div><div class="gmail_default"><div class="gmail_default"><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">    ip = get_ipython()</font></div><div><font color="#444444" face="monospace, monospace"><br></font></div></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">    def open_input_in_editor(event):</font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">        event.cli.current_buffer.tempfile_suffix = ".py"</font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">        event.cli.current_buffer.open_in_editor(event.cli)</font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">    bind_key = ip.pt_cli.application.key_bindings_registry.add_binding</font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">    bind_key(Keys.ControlN)(open_input_in_editor)</font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><span style="color:rgb(68,68,68);font-family:monospace,monospace">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.</span><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">Hope someone else finds this useful.</font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#444444" face="monospace, monospace">Best,</font></div></div><div><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span style="color:rgb(115,115,115);font-style:italic;line-height:18px"><font face="monospace, monospace" size="1">-- Carl Smith</font></span><br></div></div><div><span style="color:rgb(115,115,115);font-style:italic;line-height:18px"><font face="monospace, monospace" size="1"><a href="mailto:carl.input@gmail.com" target="_blank">carl.input@gmail.com</a></font></span></div></div></div></div></div></div>
</div>
<br></div></div>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/ipython-dev" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/ipython-dev" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br></div>