[IPython-dev] Moving IPython javascript methods from cells to custom.js
taleb brost
mkpaustin at gmail.com
Sun Jun 14 16:31:30 EDT 2015
I would like to make two keyboard shortcuts posted in
http://stackoverflow.com/questions/28309430/edit-ipython-cell-in-an-external-editor
default mappings for all my notebooks. Can someone point
me to the correct syntax to append to static/custom.js, given the
working cell code below?
%%javascript
IPython.keyboard_manager.command_shortcuts.add_shortcut('g', {
handler : function (event) {
var input = IPython.notebook.get_selected_cell().get_text();
var cmd = "f = open('.toto.py', 'w');f.close()";
if (input != "") {
cmd = '%%writefile .toto.py\n' + input;
}
IPython.notebook.kernel.execute(cmd);
cmd = "import os;os.system('gvim .toto.py')";
IPython.notebook.kernel.execute(cmd);
return false;
}}
);
IPython.keyboard_manager.command_shortcuts.add_shortcut('u', {
handler : function (event) {
function handle_output(msg) {
var ret = msg.content.text;
IPython.notebook.get_selected_cell().set_text(ret);
}
var callback = {'output': handle_output};
var cmd = "f = open('.toto.py', 'r');print(f.read())";
IPython.notebook.kernel.execute(cmd, {iopub: callback},
{silent: false});
return false;
}}
);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150614/e50447a6/attachment.html>
More information about the IPython-dev
mailing list