./vendor/assets/javascripts/codemirror/modes/clike.js in codemirror-rails-0.2.0 vs ./vendor/assets/javascripts/codemirror/modes/clike.js in codemirror-rails-0.2.1

- old
+ new

@@ -1,8 +1,9 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { var indentUnit = config.indentUnit, keywords = parserConfig.keywords || {}, + blockKeywords = parserConfig.blockKeywords || {}, atoms = parserConfig.atoms || {}, hooks = parserConfig.hooks || {}, multiLineStrings = parserConfig.multiLineStrings; var isOperatorChar = /[+\-*&%=<>!?|\/]/; @@ -40,11 +41,14 @@ stream.eatWhile(isOperatorChar); return "operator"; } stream.eatWhile(/[\w\$_]/); var cur = stream.current(); - if (keywords.propertyIsEnumerable(cur)) return "keyword"; + if (keywords.propertyIsEnumerable(cur)) { + if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; + return "keyword"; + } if (atoms.propertyIsEnumerable(cur)) return "atom"; return "word"; } function tokenString(quote) { @@ -77,15 +81,17 @@ this.column = column; this.type = type; this.align = align; this.prev = prev; } - function pushContext(state, col, type) { return state.context = new Context(state.indented, col, type, null, state.context); } function popContext(state) { + var t = state.context.type; + if (t == ")" || t == "]" || t == "}") + state.indented = state.context.indented; return state.context = state.context.prev; } // Interface @@ -107,24 +113,25 @@ state.startOfLine = true; } if (stream.eatSpace()) return null; curPunc = null; var style = (state.tokenize || tokenBase)(stream, state); - if (style == "comment") return style; + if (style == "comment" || style == "meta") return style; if (ctx.align == null) ctx.align = true; if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state); else if (curPunc == "{") pushContext(state, stream.column(), "}"); else if (curPunc == "[") pushContext(state, stream.column(), "]"); else if (curPunc == "(") pushContext(state, stream.column(), ")"); else if (curPunc == "}") { - if (ctx.type == "statement") ctx = popContext(state); + while (ctx.type == "statement") ctx = popContext(state); if (ctx.type == "}") ctx = popContext(state); - if (ctx.type == "statement") ctx = popContext(state); + while (ctx.type == "statement") ctx = popContext(state); } else if (curPunc == ctx.type) popContext(state); - else if (ctx.type == "}" || ctx.type == "top") pushContext(state, stream.column(), "statement"); + else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement")) + pushContext(state, stream.column(), "statement"); state.startOfLine = false; return style; }, indent: function(state, textAfter) { @@ -168,29 +175,32 @@ } CodeMirror.defineMIME("text/x-csrc", { name: "clike", keywords: words(cKeywords), + blockKeywords: words("case do else for if switch while struct"), atoms: words("null"), hooks: {"#": cppHook} }); CodeMirror.defineMIME("text/x-c++src", { name: "clike", keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " + "static_cast typeid catch operator template typename class friend private " + "this using const_cast inline public throw virtual delete mutable protected " + "wchar_t"), + blockKeywords: words("catch class do else finally for if struct switch try while"), atoms: words("true false null"), hooks: {"#": cppHook} }); CodeMirror.defineMIME("text/x-java", { name: "clike", keywords: words("abstract assert boolean break byte case catch char class const continue default " + "do double else enum extends final finally float for goto if implements import " + "instanceof int interface long native new package private protected public " + "return short static strictfp super switch synchronized this throw throws transient " + "try void volatile while"), + blockKeywords: words("catch class do else finally for if switch try while"), atoms: words("true false null"), hooks: { "@": function(stream, state) { stream.eatWhile(/[\w\$_]/); return "meta"; @@ -204,16 +214,32 @@ " foreach goto if implicit in int interface internal is lock long namespace new object" + " operator out override params private protected public readonly ref return sbyte sealed short" + " sizeof stackalloc static string struct switch this throw try typeof uint ulong unchecked" + " unsafe ushort using virtual void volatile while add alias ascending descending dynamic from get" + " global group into join let orderby partial remove select set value var yield"), + blockKeywords: words("catch class do else finally for foreach if struct switch try while"), atoms: words("true false null"), hooks: { "@": function(stream, state) { if (stream.eat('"')) { state.tokenize = tokenAtString; return tokenAtString(stream, state); } + stream.eatWhile(/[\w\$_]/); + return "meta"; + } + } + }); + CodeMirror.defineMIME("text/x-groovy", { + name: "clike", + keywords: words("abstract as assert boolean break byte case catch char class const continue def default " + + "do double else enum extends final finally float for goto if implements import " + + "in instanceof int interface long native new package property private protected public " + + "return short static strictfp super switch synchronized this throw throws transient " + + "try void volatile while"), + atoms: words("true false null"), + hooks: { + "@": function(stream, state) { stream.eatWhile(/[\w\$_]/); return "meta"; } } });