Get emacs key bindings back in jupyter notebook 4.2.2

1,068 views
Skip to first unread message

ssin...@coe.edu

unread,
Aug 17, 2016, 11:46:46 PM8/17/16
to Project Jupyter
Hello,

Congratulations on the recent releases!

I upgraded to (conda linux) Jupyter notebook 4.2.2 and IPython 5.1.0  and seem to have lost emacs keybindings again.  I have the passage below in .jupyter/custom/custom.js which used to work (I believe Min helped with that one several versions ago?).  Does this need to be updated to get emacs bindings back?

I admit an utter lack of javascript foo, so here's a thought: Would it be possible to simply have a line in jupyter_notebook_config.py that lets one set the keymap and leave the JS to the experts?

Sorry if I'm missing something obvious, or if the question belongs in a github issue.

Thanks,
Steve

$([IPython.events]).on('app_initialized.NotebookApp', function(){
    function to(mode) {
    // this can be either 'vim' or 'emacs'
    var mode = mode || 'emacs';
    // first let's apply mode to all current cells
    function to_mode(c) { return c.code_mirror.setOption('keyMap', mode);};
    var cells = IPython.notebook.get_cells();
    if (cells != null) {
        cells.map(to_mode);
    }
   
    // apply the mode to future cells created
    IPython.Cell.options_default.cm_config.keyMap = mode;
    };
    require(["codemirror/keymap/emacs"],
        function (_) {
        if (IPython.notebook != undefined) {
            to('emacs');
        };
        });
});

Martin Hunt

unread,
Aug 18, 2016, 5:13:14 PM8/18/16
to Project Jupyter
I have this in my  .jupyter/custom/custom.js

require(["codemirror/keymap/emacs", "notebook/js/cell", "base/js/namespace"],
    function(emacs_keymap, cell, IPython) {
        cell.Cell.options_default.cm_config.keyMap = 'emacs';
        var cells = IPython.notebook.get_cells();
        for(var c=0; c< cells.length ; c++){
            cells[c].code_mirror.setOption('keyMap', 'emacs');
        }
    }
);

ssin...@coe.edu

unread,
Aug 18, 2016, 6:59:44 PM8/18/16
to Project Jupyter

On Thursday, August 18, 2016 at 4:13:14 PM UTC-5, Martin Hunt wrote:
I have this in my  .jupyter/custom/custom.js

require(["codemirror/keymap/emacs", "notebook/js/cell", "base/js/namespace"],
    function(emacs_keymap, cell, IPython) {
        cell.Cell.options_default.cm_config.keyMap = 'emacs';
        var cells = IPython.notebook.get_cells();
        for(var c=0; c< cells.length ; c++){
            cells[c].code_mirror.setOption('keyMap', 'emacs');
        }
    }
);


Works great...

Thanks,
Steve
Reply all
Reply to author
Forward
0 new messages