##// END OF EJS Templates
Add method to change codemirror mode of all code cells
Thomas Kluyver -
Show More
@@ -121,6 +121,7 b' define(['
121 this.notebook_name_blacklist_re = /[\/\\:]/;
121 this.notebook_name_blacklist_re = /[\/\\:]/;
122 this.nbformat = 3; // Increment this when changing the nbformat
122 this.nbformat = 3; // Increment this when changing the nbformat
123 this.nbformat_minor = 0; // Increment this when changing the nbformat
123 this.nbformat_minor = 0; // Increment this when changing the nbformat
124 this.codemirror_mode = 'ipython'
124 this.style();
125 this.style();
125 this.create_elements();
126 this.create_elements();
126 this.bind_events();
127 this.bind_events();
@@ -1499,6 +1500,35 b' define(['
1499 Notebook.prototype.cell_toggle_line_numbers = function() {
1500 Notebook.prototype.cell_toggle_line_numbers = function() {
1500 this.get_selected_cell().toggle_line_numbers();
1501 this.get_selected_cell().toggle_line_numbers();
1501 };
1502 };
1503
1504 /**
1505 * Set the codemirror mode for all code cells, including the default for
1506 * new code cells.
1507 *
1508 * @method set_codemirror_mode
1509 */
1510 Notebook.prototype.set_codemirror_mode = function(newmode){
1511 if (newmode === this.codemirror_mode) {
1512 return;
1513 }
1514 this.codemirror_mode = newmode;
1515 IPython.CodeCell.options_default.cm_config.mode = newmode;
1516 modename = newmode.name || newmode
1517
1518 CodeMirror.requireMode(modename, function(){
1519 cells = IPython.notebook.get_cells();
1520 for(var i in cells){
1521 c = cells[i];
1522 if (c.cell_type === 'code'){
1523 c.code_mirror.setOption('mode', newmode);
1524 // This is currently redundant, because cm_config ends up as
1525 // codemirror's own .options object, but I don't want to
1526 // rely on that.
1527 c.cm_config.mode = newmode;
1528 }
1529 }
1530 })
1531 };
1502
1532
1503 // Session related things
1533 // Session related things
1504
1534
General Comments 0
You need to be logged in to leave comments. Login now