##// END OF EJS Templates
create new terminals with POST /api/terminals...
create new terminals with POST /api/terminals instead of GET terminals/new to be consistent with creating new notebooks. We had to stop using GET notebooks/new because browsers would create new notebooks when making preview thumbnails for commonly visited pages, etc. I assume the same issue would apply to terminals

File last commit:

r17496:b0d6ca14
r18616:d4e327ea
Show More
Custom Keyboard Shortcuts.ipynb
148 lines | 4.0 KiB | text/plain | TextLexer
/ examples / Notebook / Custom Keyboard Shortcuts.ipynb

Keyboard Shortcut Customization

Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the IPython JavaScript API. Here is an example that makes the r key available for running a cell:

In [7]:
%%javascript

IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {
    help : 'run cell',
    help_index : 'zz',
    handler : function (event) {
        IPython.notebook.execute_cell();
        return false;
    }}
);
SandBoxed(IPython.core.display.Javascript object)

There are a couple of points to mention about this API:

  • The help_index field is used to sort the shortcuts in the Keyboard Shortcuts help dialog. It defaults to zz.
  • When a handler returns false it indicates that the event should stop propagating and the default action should not be performed. For further details about the event object or event handling, see the jQuery docs.
  • If you don't need a help or help_index field, you can simply pass a function as the second argument to add_shortcut.
In [11]:
%%javascript

IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {
    IPython.notebook.execute_cell();
    return false;
});
SandBoxed(IPython.core.display.Javascript object)

Likewise, to remove a shortcut, use remove_shortcut:

In [8]:
%%javascript

IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');
SandBoxed(IPython.core.display.Javascript object)

If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your <profile>/static/custom/custom.js file.