@ -1514,29 +1514,50 @@ define(function (require) {
Notebook . prototype . cell _toggle _line _numbers = function ( ) {
this . get _selected _cell ( ) . toggle _line _numbers ( ) ;
} ;
//dispatch codemirror mode to all cells.
Notebook . prototype . _dispatch _mode = function ( spec , newmode ) {
this . codemirror _mode = newmode ;
codecell . CodeCell . options _default . cm _config . mode = newmode ;
this . get _cells ( ) . map ( function ( cell , i ) {
if ( cell . cell _type === 'code' ) {
cell . code _mirror . setOption ( 'mode' , spec ) ;
// This is currently redundant, because cm_config ends up as
// codemirror's own .options object, but I don't want to
// rely on that.
cell . cm _config . mode = spec ;
}
} ) ;
} ;
// roughly try to check mode equality
var _mode _equal = function ( mode1 , mode2 ) {
return ( ( mode1 || { } ) . name || mode1 ) === ( ( mode2 || { } ) . name || mode2 ) ;
} ;
/ * *
* Set the codemirror mode for all code cells , including the default for
* new code cells .
* Set the mode to 'null' ( no highlighting ) if it can ' t be found .
* /
Notebook . prototype . set _codemirror _mode = function ( newmode ) {
if ( newmode === this . codemirror _mode ) {
// if mode is the same don't reset,
// to avoid n-time re-highlighting.
if ( _mode _equal ( newmode , this . codemirror _mode ) ) {
return ;
}
this . codemirror _mode = newmode ;
codecell . CodeCell . options _default . cm _config . mode = newmode ;
var that = this ;
utils . requireCodeMirrorMode ( newmode , function ( spec ) {
that . get _cells ( ) . map ( function ( cell , i ) {
if ( cell . cell _type === 'code' ) {
cell . code _mirror . setOption ( 'mode' , spec ) ;
// This is currently redundant, because cm_config ends up as
// codemirror's own .options object, but I don't want to
// rely on that.
cell . cm _config . mode = spec ;
}
} ) ;
that . _dispatch _mode ( spec , newmode ) ;
} , function ( ) {
// on error don't dispatch the new mode as re-setting it later will not work.
// don't either set to null mode if it has been changed in the meantime
if ( _mode _equal ( newmode , this . codemirror _mode ) ) {
that . _dispatch _mode ( 'null' , 'null' ) ;
}
} ) ;
} ;
@ -2121,7 +2142,6 @@ define(function (require) {
* @ param { string } notebook _path - A notebook to load
* /
Notebook . prototype . load _notebook = function ( notebook _path ) {
var that = this ;
this . notebook _path = notebook _path ;
this . notebook _name = utils . url _path _split ( this . notebook _path ) [ 1 ] ;
this . events . trigger ( 'notebook_loading.Notebook' ) ;