2015-08-23 206 views
0

当进入编辑模式,立即(火狐,OSX,虽然这不应该的问题),表现如下:在Jupyter笔记本笔记本,分配降价或标题类型我想配置我Jupyter笔记本电池

当单元格被分配Markdown或标题类,它应该立即切换到编辑模式。在标题的情况下,光标应该位于之后的的哈希标记。

单元格应该在失去焦点时自动渲染(模糊)。

总体思路是让笔记本以“不太模态”的方式运行;不像vi,更像Emacs和Mathematica笔记本。

大概这可以通过添加keybinding代码到custom.js来完成。

谢谢!

回答

2

(假设默认的配置文件和类似Unix的系统),下面的代码进入〜/ .ipython/profile_default /静态/定制/ custom.js

$([IPython.events]).on("app_initialized.NotebookApp", function() { 

/* this is a utility function */ 
function set_editable_heading(event, level){ 
    event.notebook.command_mode(); 
    event.notebook.to_heading(undefined, level); 
    event.notebook.edit_mode(); 

    var cm = event.notebook.get_selected_cell().code_mirror; 
    cm.setCursor({line:0, ch: level+1 }); 
    cm.on("blur", function(){ 
     event.notebook.get_selected_cell().render(); 
    }); 
    return false; 
} 

/* ... and analogously for other heading levels and for the command mode 
    (... command_shortcuts.add_shortcut()) 
*/ 
IPython.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-1', { 
    help: 'Set cell to Heading 1, editable', 
    handler: function (event) { 
     set_editable_heading(event, 1); 
     return false; 
    } 
}); 

IPython.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-m', { 
    help: 'Set cell to markdown, editable', 
    handler: function (event) { 
     event.notebook.command_mode(); 
     event.notebook.to_markdown(); 

     event.notebook.get_selected_cell().code_mirror.on("blur", function(){ 
      event.notebook.get_selected_cell().render(); 
     }); 

     event.notebook.edit_mode(); 
     return false; 
    } 
}); 

return true; 
});