github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/bin/kernel_resources/kernel.js (about) 1 // Kernel specific extension for lgo. 2 // http://jupyter-notebook.readthedocs.io/en/stable/extending/frontend_extensions.html#kernel-specific-extensions 3 4 define(function(){ 5 var formatCells = function () { 6 var cells = Jupyter.notebook.get_selected_cells(); 7 for (var i = 0; i < cells.length; i++) { 8 (function(){ 9 var editor = cells[i].code_mirror; 10 var msg = {code: editor.getValue()}; 11 var cb = function(msg) { 12 if (!msg || !msg.content || msg.content.status != 'ok') { 13 // TODO: Show an error message. 14 return; 15 } 16 editor.setValue(msg.content.code); 17 }; 18 Jupyter.notebook.kernel.send_shell_message("gofmt_request", msg, {shell: {reply: cb}}); 19 })(); 20 } 21 }; 22 23 var action = { 24 icon: 'fa-align-left', // a font-awesome class used on buttons, etc 25 help : 'Format Go', 26 handler : formatCells 27 }; 28 var prefix = 'lgo-kernel'; 29 var actionName = 'format-code'; 30 31 var fullActionName = Jupyter.actions.register(action, actionName, prefix); 32 Jupyter.toolbar.add_buttons_group([fullActionName]); 33 34 return { 35 onload: function(){} 36 } 37 });