lambdalisue / jupyter-vim-binding

Jupyter meets Vim. Vimmer will fall in love.
2.1k stars 136 forks source link

Inserted cells don't load the extension properly? #39

Closed JobJob closed 8 years ago

JobJob commented 8 years ago

I'm not 100% sure about this, but is it possible the extension changes are not being loaded correctly for cells created after the notebook is loaded? e.g. when you execute a cell and insert a cell after with alt-enter

https://github.com/lambdalisue/jupyter-vim-binding/blob/master/vim_binding.js#L459-L469 applies the options to existing cells, but how are they applied to new cells?

I noticed this problem when some indentation changes I made by modifying this extension weren't working on new cells created. The following changes fixed that issue for me:

var initvimstuff = function initvimstuff(cm) {
  if (cm) {
    cm.setOption('keyMap', options.cm_config.keyMap);
    cm.setOption('extraKeys', options.cm_config.extraKeys);
    cm.setOption('tabSize', 2)
    cm.setOption('indentUnit', 2)
  }
}
var exports = {
  'load_ipython_extension': function() {
    // apply options and events on all existing CodeMirror instances
    namespace.notebook.get_cells().map(function(cell){
      var cm = cell.code_mirror;
      initvimstuff(cm)
    })
    // apply options and events when new CodeMirror instances are created
    CodeMirror.defineInitHook(initvimstuff)
  },
  ...
}
lambdalisue commented 8 years ago

https://github.com/lambdalisue/jupyter-vim-binding/blob/master/vim_binding.js#L452-L457

The code above set default settings and Jupyter uses that settings to create a new cell so it should work for new one as well. Which version do you use?

JobJob commented 8 years ago

A modified 0.1.0

JobJob commented 8 years ago

Anyway, I don't really have the version of the code that doesn't work. So I think I will just close the issue if that's how it should work. Cheers for your help.

JobJob commented 8 years ago

Ok looking at what you pointed out, I get what I was doing wrong, I wasn't changing the defaults in my changes, was just changing the options for existing cells. Thanks!