From 6b0fdf23561f8622ac5ed84d485ba81d37a5cab3 Mon Sep 17 00:00:00 2001 From: Fernando Perez Date: Sun, 9 Oct 2011 02:05:13 -0700 Subject: [PATCH 1/4] Update CodeMirror code to v2.15 --- .../static/codemirror-2.12/mode/python/python.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/IPython/frontend/html/notebook/static/codemirror-2.12/mode/python/python.js b/IPython/frontend/html/notebook/static/codemirror-2.12/mode/python/python.js index 0cda2aafe..4f60d9e67 100644 --- a/IPython/frontend/html/notebook/static/codemirror-2.12/mode/python/python.js +++ b/IPython/frontend/html/notebook/static/codemirror-2.12/mode/python/python.js @@ -1,11 +1,11 @@ -CodeMirror.defineMode("python", function(conf) { +CodeMirror.defineMode("python", function(conf, parserConf) { var ERRORCLASS = 'error'; function wordRegexp(words) { return new RegExp("^((" + words.join(")|(") + "))\\b"); } - var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]"); + var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); @@ -29,7 +29,7 @@ CodeMirror.defineMode("python", function(conf) { 'open', 'range', 'zip'], 'keywords': ['nonlocal']}; - if (!!conf.mode.version && parseInt(conf.mode.version, 10) === 3) { + if (!!parserConf.version && parseInt(parserConf.version, 10) === 3) { commonkeywords = commonkeywords.concat(py3.keywords); commontypes = commontypes.concat(py3.types); var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i"); @@ -147,10 +147,9 @@ CodeMirror.defineMode("python", function(conf) { } function tokenStringFactory(delimiter) { - while ('rub'.indexOf(delimiter[0].toLowerCase()) >= 0) { + while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) { delimiter = delimiter.substr(1); } - var delim_re = new RegExp(delimiter); var singleline = delimiter.length == 1; var OUTCLASS = 'string'; @@ -162,7 +161,7 @@ CodeMirror.defineMode("python", function(conf) { if (singleline && stream.eol()) { return OUTCLASS; } - } else if (stream.match(delim_re)) { + } else if (stream.match(delimiter)) { state.tokenize = tokenBase; return OUTCLASS; } else { @@ -170,8 +169,8 @@ CodeMirror.defineMode("python", function(conf) { } } if (singleline) { - if (conf.mode.singleLineStringErrors) { - OUTCLASS = ERRORCLASS + if (parserConf.singleLineStringErrors) { + return ERRORCLASS; } else { state.tokenize = tokenBase; } From 9cca38f45256a4209ddb458d7373a330076f26f4 Mon Sep 17 00:00:00 2001 From: Fernando Perez Date: Sun, 9 Oct 2011 02:31:45 -0700 Subject: [PATCH 2/4] Do not use version # in codemirror directory name. Simply call it 'codemirror', so we don't have explicit version numbers inside a bunch of files. A file called ipython-version-N.NN will be kept to easily let us know which version we're shipping with IPython. --- .../mode/python/python.js | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) rename IPython/frontend/html/notebook/static/{codemirror-2.12 => codemirror}/mode/python/python.js (97%) diff --git a/IPython/frontend/html/notebook/static/codemirror-2.12/mode/python/python.js b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js similarity index 97% rename from IPython/frontend/html/notebook/static/codemirror-2.12/mode/python/python.js rename to IPython/frontend/html/notebook/static/codemirror/mode/python/python.js index 4f60d9e67..ca94e7a0a 100644 --- a/IPython/frontend/html/notebook/static/codemirror-2.12/mode/python/python.js +++ b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js @@ -1,10 +1,10 @@ CodeMirror.defineMode("python", function(conf, parserConf) { var ERRORCLASS = 'error'; - + function wordRegexp(words) { return new RegExp("^((" + words.join(")|(") + "))\\b"); } - + var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); @@ -65,15 +65,15 @@ CodeMirror.defineMode("python", function(conf, parserConf) { if (stream.eatSpace()) { return null; } - + var ch = stream.peek(); - + // Handle Comments if (ch === '#') { stream.skipToEnd(); return 'comment'; } - + // Handle Number Literals if (stream.match(/^[0-9\.]/, false)) { var floatLiteral = false; @@ -109,13 +109,13 @@ CodeMirror.defineMode("python", function(conf, parserConf) { return 'number'; } } - + // Handle Strings if (stream.match(stringPrefixes)) { state.tokenize = tokenStringFactory(stream.current()); return state.tokenize(stream, state); } - + // Handle operators and Delimiters if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { return null; @@ -128,31 +128,31 @@ CodeMirror.defineMode("python", function(conf, parserConf) { if (stream.match(singleDelimiters)) { return null; } - + if (stream.match(types)) { return 'builtin'; } - + if (stream.match(keywords)) { return 'keyword'; } - + if (stream.match(identifiers)) { return 'variable'; } - + // Handle non-detected items stream.next(); return ERRORCLASS; } - + function tokenStringFactory(delimiter) { while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) { delimiter = delimiter.substr(1); } var singleline = delimiter.length == 1; var OUTCLASS = 'string'; - + return function tokenString(stream, state) { while (!stream.eol()) { stream.eatWhile(/[^'"\\]/); @@ -178,7 +178,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) { return OUTCLASS; }; } - + function indent(stream, state, type) { type = type || 'py'; var indentUnit = 0; @@ -197,7 +197,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) { type: type }); } - + function dedent(stream, state) { if (state.scopes.length == 1) return; if (state.scopes[0].type === 'py') { @@ -237,7 +237,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) { return ERRORCLASS; } } - + // Handle decorators if (current === '@') { style = state.tokenize(stream, state); @@ -250,7 +250,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) { return ERRORCLASS; } } - + // Handle scope changes. if (current === 'pass' || current === 'return') { state.dedent += 1; @@ -278,7 +278,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) { if (state.scopes.length > 1) state.scopes.shift(); state.dedent -= 1; } - + return style; } @@ -292,27 +292,27 @@ CodeMirror.defineMode("python", function(conf, parserConf) { dedent: 0 }; }, - + token: function(stream, state) { var style = tokenLexer(stream, state); - + state.lastToken = {style:style, content: stream.current()}; - + if (stream.eol() && stream.lambda) { state.lambda = false; } - + return style; }, - + indent: function(state, textAfter) { if (state.tokenize != tokenBase) { return 0; } - + return state.scopes[0].offset; } - + }; return external; }); From b8bab4a051b40b7a209b85d70e772fe6e52cf24a Mon Sep 17 00:00:00 2001 From: Fernando Perez Date: Sun, 9 Oct 2011 02:32:36 -0700 Subject: [PATCH 3/4] Update templates to new directory name for codemirror. --- .../html/notebook/templates/notebook.html | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index e82cf7b08..86017eb93 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -21,10 +21,11 @@ } - - - - + + + + + @@ -208,13 +209,14 @@ - - - - - - - + + + + + + + + From 00af93da43d1ce064402a309004abd8c74a473fe Mon Sep 17 00:00:00 2001 From: Fernando Perez Date: Thu, 13 Oct 2011 19:55:21 -0700 Subject: [PATCH 4/4] IPython-specific changes to CodeMirror: recognize '?' in Python mode. --- .../html/notebook/static/codemirror/mode/python/python.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js index ca94e7a0a..fc9a5037f 100644 --- a/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js +++ b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js @@ -5,7 +5,11 @@ CodeMirror.defineMode("python", function(conf, parserConf) { return new RegExp("^((" + words.join(")|(") + "))\\b"); } - var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); + // IPython-specific changes: add '?' as recognized character. + //var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); + var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]"); + // End IPython changes. + var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");