diff --git a/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js old mode 100644 new mode 100755 index 7d6a5599f..50828a3ff --- a/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js +++ b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js @@ -18,28 +18,35 @@ CodeMirror.defineMode("python", function(conf, parserConf) { 'for', 'from', 'global', 'if', 'import', 'lambda', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']; - var commontypes = ['bool', 'classmethod', 'complex', 'dict', 'enumerate', - 'float', 'frozenset', 'int', 'list', 'object', - 'property', 'reversed', 'set', 'slice', 'staticmethod', - 'str', 'super', 'tuple', 'type']; - var py2 = {'types': ['basestring', 'buffer', 'file', 'long', 'unicode', - 'xrange'], + var commonBuiltins = ['abs', 'all', 'any', 'bin', 'bool', 'bytearray', 'callable', 'chr', + 'classmethod', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod', + 'enumerate', 'eval', 'filter', 'float', 'format', 'frozenset', + 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', + 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', + 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', + 'object', 'oct', 'open', 'ord', 'pow', 'property', 'range', + 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', + 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', + 'type', 'vars', 'zip', '__import__', 'NotImplemented', + 'Ellipsis', '__debug__']; + var py2 = {'builtins': ['apply', 'basestring', 'buffer', 'cmp', 'coerce', 'execfile', + 'file', 'intern', 'long', 'raw_input', 'reduce', 'reload', + 'unichr', 'unicode', 'xrange', 'False', 'True', 'None'], 'keywords': ['exec', 'print']}; - var py3 = {'types': ['bytearray', 'bytes', 'filter', 'map', 'memoryview', - 'open', 'range', 'zip'], - 'keywords': ['nonlocal']}; + var py3 = {'builtins': ['ascii', 'bytes', 'exec', 'print'], + 'keywords': ['nonlocal', 'False', 'True', 'None']}; if (!!parserConf.version && parseInt(parserConf.version, 10) === 3) { commonkeywords = commonkeywords.concat(py3.keywords); - commontypes = commontypes.concat(py3.types); + commonBuiltins = commonBuiltins.concat(py3.builtins); var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i"); } else { commonkeywords = commonkeywords.concat(py2.keywords); - commontypes = commontypes.concat(py2.types); + commonBuiltins = commonBuiltins.concat(py2.builtins); var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i"); } var keywords = wordRegexp(commonkeywords); - var types = wordRegexp(commontypes); + var builtins = wordRegexp(commonBuiltins); var indentInfo = null; @@ -129,14 +136,14 @@ CodeMirror.defineMode("python", function(conf, parserConf) { return null; } - if (stream.match(types)) { - return 'builtin'; - } - if (stream.match(keywords)) { return 'keyword'; } + if (stream.match(builtins)) { + return 'builtin'; + } + if (stream.match(identifiers)) { return 'variable'; } @@ -244,7 +251,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) { if (current === '.') { style = state.tokenize(stream, state); current = stream.current(); - if (style === 'variable') { + if (style === 'variable' || style === 'builtin') { return 'variable'; } else { return ERRORCLASS; diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index efcd422ae..9cf29bde1 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -530,11 +530,11 @@ var IPython = (function (IPython) { CodeCell.prototype.select = function () { IPython.Cell.prototype.select.apply(this); - // In some cases (inserting a new cell) we need a refresh before and - // after the focus. Not sure why this is the case. this.code_mirror.refresh(); this.code_mirror.focus(); - this.code_mirror.refresh(); + // We used to need an additional refresh() after the focus, but + // it appears that this has been fixed in CM. This bug would show + // up on FF when a newly loaded markdown cell was edited. }; diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 07dd4c800..7c2d9bcda 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -96,14 +96,11 @@ var IPython = (function (IPython) { var output = text_cell.find("div.text_cell_render"); output.hide(); text_cell.find('div.text_cell_input').show(); - // I don't know why I need to do this, but if I don't do - // refresh/focus/refresh, the to_markdown method won't work. this.code_mirror.refresh(); this.code_mirror.focus(); - // This final refresh is needed on Firefox to trigger the editor - // to be auto-sized. This glitch only happens on cell that are - // loaded initially and haven't had their editor focused before. - this.code_mirror.refresh(); + // We used to need an additional refresh() after the focus, but + // it appears that this has been fixed in CM. This bug would show + // up on FF when a newly loaded markdown cell was edited. this.rendered = false; if (this.get_text() === this.placeholder) { this.set_text('');