diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index 3b03d7c1b..492793b3a 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -1529,7 +1529,7 @@ define([
}
this.codemirror_mode = newmode;
codecell.CodeCell.options_default.cm_config.mode = newmode;
- modename = newmode.name || newmode
+ modename = newmode.mode || newmode.name || newmode
that = this;
utils.requireCodeMirrorMode(modename, function () {