Showing with 4,768 additions and 3,090 deletions.
  1. +1 −1 LICENSE
  2. +1 −1 README.md
  3. 0 {lib/util → addon/dialog}/dialog.css
  4. +1 −0 {lib/util → addon/dialog}/dialog.js
  5. 0 {lib/util → addon/edit}/closetag.js
  6. 0 {lib/util → addon/edit}/continuecomment.js
  7. 0 {lib/util → addon/edit}/continuelist.js
  8. 0 {lib/util → addon/edit}/matchbrackets.js
  9. +68 −0 addon/fold/collapserange.js
  10. +2 −1 {lib/util → addon/fold}/foldcode.js
  11. +9 −3 {lib/util → addon/format}/formatting.js
  12. +5 −4 {lib/util → addon/hint}/javascript-hint.js
  13. 0 {lib/util → addon/hint}/pig-hint.js
  14. +93 −0 addon/hint/python-hint.js
  15. 0 {lib/util → addon/hint}/simple-hint.css
  16. 0 {lib/util → addon/hint}/simple-hint.js
  17. 0 {lib/util → addon/hint}/xml-hint.js
  18. 0 {lib/util → addon/mode}/loadmode.js
  19. 0 {lib/util → addon/mode}/multiplex.js
  20. 0 {lib/util → addon/mode}/overlay.js
  21. 0 {lib/util → addon/runmode}/colorize.js
  22. +131 −0 addon/runmode/runmode-standalone.js
  23. 0 {lib/util → addon/runmode}/runmode.js
  24. 0 lib/util/runmode-standalone.js → addon/runmode/runmode.node.js
  25. 0 {lib/util → addon/search}/match-highlighter.js
  26. +20 −8 {lib/util → addon/search}/search.js
  27. +17 −10 {lib/util → addon/search}/searchcursor.js
  28. +2 −1 bin/compress
  29. +1 −1 demo/closetag.html
  30. +104 −0 demo/collapserange.html
  31. +5 −5 demo/complete.html
  32. +3 −3 demo/folding.html
  33. +2 −2 demo/formatting.html
  34. +1 −1 demo/loadmode.html
  35. +2 −2 demo/matchhighlighter.html
  36. +3 −3 demo/multiplex.html
  37. +2 −2 demo/mustache.html
  38. +2 −2 demo/runmode.html
  39. +8 −8 demo/search.html
  40. +3 −3 demo/vim.html
  41. +8 −9 demo/xmlcomplete.html
  42. +32 −20 doc/compress.html
  43. +109 −45 doc/manual.html
  44. +87 −0 doc/modes.html
  45. +44 −3 doc/oldrelease.html
  46. +8 −0 doc/realworld.html
  47. +4 −4 doc/upgrade_v3.html
  48. +41 −56 index.html
  49. +279 −66 keymap/vim.js
  50. +10 −9 lib/codemirror.css
  51. +369 −147 lib/codemirror.js
  52. +160 −0 mode/apl/apl.js
  53. +61 −0 mode/apl/index.html
  54. +183 −0 mode/asterisk/asterisk.js
  55. +142 −0 mode/asterisk/index.html
  56. +2 −0 mode/clike/clike.js
  57. +1 −1 mode/clike/index.html
  58. +1 −1 mode/clike/scala.html
  59. +3 −3 mode/clojure/clojure.js
  60. +2 −2 mode/css/css.js
  61. +76 −471 mode/css/test.js
  62. +205 −0 mode/d/d.js
  63. +262 −0 mode/d/index.html
  64. +1 −1 mode/erlang/index.html
  65. +2 −1 mode/gfm/gfm.js
  66. +1 −2 mode/gfm/index.html
  67. +84 −225 mode/gfm/test.js
  68. +1 −1 mode/go/index.html
  69. +1 −1 mode/groovy/index.html
  70. +1 −1 mode/haskell/index.html
  71. +2 −2 mode/javascript/index.html
  72. +13 −2 mode/javascript/javascript.js
  73. +1 −1 mode/less/index.html
  74. +1 −1 mode/lua/index.html
  75. +1 −1 mode/markdown/index.html
  76. +8 −7 mode/markdown/markdown.js
  77. +579 −1,266 mode/markdown/test.js
  78. +71 −0 mode/meta.js
  79. +2 −0 mode/mysql/index.html
  80. +1 −1 mode/ocaml/index.html
  81. +1 −1 mode/php/index.html
  82. +2 −0 mode/plsql/index.html
  83. +1 −1 mode/python/index.html
  84. +1 −1 mode/ruby/index.html
  85. +54 −0 mode/sass/index.html
  86. +349 −0 mode/sass/sass.js
  87. +1 −1 mode/shell/index.html
  88. +0 −4 mode/sieve/LICENSE
  89. +37 −10 mode/sieve/sieve.js
  90. +1 −1 mode/smalltalk/index.html
  91. +1 −1 mode/sparql/index.html
  92. +68 −0 mode/sql/index.html
  93. +268 −0 mode/sql/sql.js
  94. +104 −343 mode/stex/test.js
  95. +1 −1 mode/tiddlywiki/index.html
  96. +1 −1 mode/vb/index.html
  97. +54 −67 mode/xquery/test.js
  98. +8 −8 mode/xquery/xquery.js
  99. +1 −1 package.json
  100. +15 −11 test/driver.js
  101. +13 −6 test/index.html
  102. +170 −170 test/mode_test.js
  103. +1 −0 test/run.js
  104. +39 −3 test/test.js
  105. +232 −48 test/vim_test.js
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2012 by Marijn Haverbeke <marijnh@gmail.com>
Copyright (C) 2013 by Marijn Haverbeke <marijnh@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ in, it will color your code, and optionally help with indentation.

The project page is http://codemirror.net
The manual is at http://codemirror.net/doc/manual.html
The contributing guidelines are in the CONTRIBUTING.md file
The contributing guidelines are in [CONTRIBUTING.md](https://github.com/marijnh/CodeMirror/blob/master/CONTRIBUTING.md)
File renamed without changes.
1 change: 1 addition & 0 deletions lib/util/dialog.js → addon/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
if (e.keyCode == 13) callback(inp.value);
}
});
if (options && options.value) inp.value = options.value;
inp.focus();
CodeMirror.on(inp, "blur", close);
} else if (button = dialog.getElementsByTagName("button")[0]) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions addon/fold/collapserange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
(function() {
CodeMirror.defineOption("collapseRange", false, function(cm, val, old) {
var wasOn = old && old != CodeMirror.Init;
if (val && !wasOn)
enableRangeCollapsing(cm);
else if (!val && wasOn)
disableRangeCollapsing(cm);
});

var gutterClass = "CodeMirror-collapserange";

function enableRangeCollapsing(cm) {
cm.on("gutterClick", gutterClick);
cm.setOption("gutters", (cm.getOption("gutters") || []).concat([gutterClass]));
}

function disableRangeCollapsing(cm) {
cm.rangeCollapseStart = null;
cm.off("gutterClick", gutterClick);
var gutters = cm.getOption("gutters");
for (var i = 0; i < gutters.length && gutters[i] != gutterClass; ++i) {}
cm.setOption("gutters", gutters.slice(0, i).concat(gutters.slice(i + 1)));
}

function gutterClick(cm, line, gutter) {
if (gutter != gutterClass) return;

var start = cm.rangeCollapseStart;
if (start) {
var old = cm.getLineNumber(start);
cm.setGutterMarker(start, gutterClass, null);
cm.rangeCollapseStart = null;
var from = Math.min(old, line), to = Math.max(old, line);
if (from != to) {
// Finish this fold
var fold = cm.markText({line: from + 1, ch: 0}, {line: to - 1}, {
collapsed: true,
inclusiveLeft: true,
inclusiveRight: true,
clearOnEnter: true
});
var clear = function() {
cm.setGutterMarker(topLine, gutterClass, null);
cm.setGutterMarker(botLine, gutterClass, null);
fold.clear();
};
var topLine = cm.setGutterMarker(from, gutterClass, makeMarker(true, true, clear));
var botLine = cm.setGutterMarker(to, gutterClass, makeMarker(false, true, clear));
CodeMirror.on(fold, "clear", clear);

return;
}
}

// Start a new fold
cm.rangeCollapseStart = cm.setGutterMarker(line, gutterClass, makeMarker(true, false));
}

function makeMarker(isTop, isFinished, handler) {
var node = document.createElement("div");
node.innerHTML = isTop ? "\u25bc" : "\u25b2";
if (!isFinished) node.style.color = "red";
node.style.fontSize = "85%";
node.style.cursor = "pointer";
if (handler) CodeMirror.on(node, "mousedown", handler);
return node;
}
})();
3 changes: 2 additions & 1 deletion lib/util/foldcode.js → addon/fold/foldcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ CodeMirror.indentRangeFinder = function(cm, start) {
var myIndent = CodeMirror.countColumn(firstLine, null, tabSize);
for (var i = start.line + 1, end = cm.lineCount(); i < end; ++i) {
var curLine = cm.getLine(i);
if (CodeMirror.countColumn(curLine, null, tabSize) < myIndent)
if (CodeMirror.countColumn(curLine, null, tabSize) < myIndent &&
CodeMirror.countColumn(cm.getLine(i-1), null, tabSize) > myIndent)
return {from: {line: start.line, ch: firstLine.length},
to: {line: i, ch: curLine.length}};
}
Expand Down
12 changes: 9 additions & 3 deletions lib/util/formatting.js → addon/format/formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
}
});

var inlineElements = /^(a|abbr|acronym|area|base|bdo|big|br|button|caption|cite|code|col|colgroup|dd|del|dfn|em|frame|hr|iframe|img|input|ins|kbd|label|legend|link|map|object|optgroup|option|param|q|samp|script|select|small|span|strong|sub|sup|textarea|tt|var)$/;

CodeMirror.extendMode("xml", {
commentStart: "<!--",
commentEnd: "-->",
newlineAfterToken: function(type, content, textAfter) {
return type == "tag" && />$/.test(content) || /^</.test(textAfter);
newlineAfterToken: function(type, content, textAfter, state) {
var inline = false;
if (this.configuration == "html")
inline = state.context ? inlineElements.test(state.context.tagName) : false;
return !inline && ((type == "tag" && />$/.test(content) && state.context) ||
/^</.test(textAfter));
}
});

Expand Down Expand Up @@ -95,7 +101,7 @@
newline();
}
if (!stream.pos && outer.blankLine) outer.blankLine(state);
if (!atSol) newline();
if (!atSol && i < text.length - 1) newline();
}

cm.operation(function () {
Expand Down
9 changes: 5 additions & 4 deletions lib/util/javascript-hint.js → addon/hint/javascript-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
}
} while (level > 0);
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
if (tprop.type == 'variable')
tprop.type = 'function';
if (tprop.type.indexOf("variable") === 0)
tprop.type = "function";
else return; // no clue
}
if (!context) var context = [];
Expand Down Expand Up @@ -106,7 +106,7 @@
// If this is a property, see if it belongs to some object we can
// find in the current environment.
var obj = context.pop(), base;
if (obj.type == "variable") {
if (obj.type.indexOf("variable") === 0) {
if (options && options.additionalContext)
base = options.additionalContext[obj.string];
base = base || window[obj.string];
Expand All @@ -127,8 +127,9 @@
}
else {
// If not, just look in the window object and any local scope
// (reading into JS mode internals to get at the local variables)
// (reading into JS mode internals to get at the local and global variables)
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
gatherCompletions(window);
forEach(keywords, maybeAdd);
}
Expand Down
File renamed without changes.
93 changes: 93 additions & 0 deletions addon/hint/python-hint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
(function () {
function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}

function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
return true;
}
}
return false;
}
return arr.indexOf(item) != -1;
}

function scriptHint(editor, _keywords, getToken) {
// Find the token at the cursor
var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
// If it's not a 'word-style' token, ignore the token.

if (!/^[\w$_]*$/.test(token.string)) {
token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
className: token.string == ":" ? "python-type" : null};
}

if (!context) var context = [];
context.push(tprop);

var completionList = getCompletions(token, context);
completionList = completionList.sort();
//prevent autocomplete for last word, instead show dropdown with one word
if(completionList.length == 1) {
completionList.push(" ");
}

return {list: completionList,
from: {line: cur.line, ch: token.start},
to: {line: cur.line, ch: token.end}};
}

CodeMirror.pythonHint = function(editor) {
return scriptHint(editor, pythonKeywordsU, function (e, cur) {return e.getTokenAt(cur);});
};

var pythonKeywords = "and del from not while as elif global or with assert else if pass yield"
+ "break except import print class exec in raise continue finally is return def for lambda try";
var pythonKeywordsL = pythonKeywords.split(" ");
var pythonKeywordsU = pythonKeywords.toUpperCase().split(" ");

var pythonBuiltins = "abs divmod input open staticmethod all enumerate int ord str "
+ "any eval isinstance pow sum basestring execfile issubclass print super"
+ "bin file iter property tuple bool filter len range type"
+ "bytearray float list raw_input unichr callable format locals reduce unicode"
+ "chr frozenset long reload vars classmethod getattr map repr xrange"
+ "cmp globals max reversed zip compile hasattr memoryview round __import__"
+ "complex hash min set apply delattr help next setattr buffer"
+ "dict hex object slice coerce dir id oct sorted intern ";
var pythonBuiltinsL = pythonBuiltins.split(" ").join("() ").split(" ");
var pythonBuiltinsU = pythonBuiltins.toUpperCase().split(" ").join("() ").split(" ");

function getCompletions(token, context) {
var found = [], start = token.string;
function maybeAdd(str) {
if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
}

function gatherCompletions(_obj) {
forEach(pythonBuiltinsL, maybeAdd);
forEach(pythonBuiltinsU, maybeAdd);
forEach(pythonKeywordsL, maybeAdd);
forEach(pythonKeywordsU, maybeAdd);
}

if (context) {
// If this is a property, see if it belongs to some object we can
// find in the current environment.
var obj = context.pop(), base;

if (obj.type == "variable")
base = obj.string;
else if(obj.type == "variable-3")
base = ":" + obj.string;

while (base != null && context.length)
base = base[context.pop().string];
if (base != null) gatherCompletions(base);
}
return found;
}
})();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
131 changes: 131 additions & 0 deletions addon/runmode/runmode-standalone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* Just enough of CodeMirror to run runMode under node.js */

window.CodeMirror = {};

function splitLines(string){ return string.split(/\r?\n|\r/); };

function StringStream(string) {
this.pos = this.start = 0;
this.string = string;
}
StringStream.prototype = {
eol: function() {return this.pos >= this.string.length;},
sol: function() {return this.pos == 0;},
peek: function() {return this.string.charAt(this.pos) || null;},
next: function() {
if (this.pos < this.string.length)
return this.string.charAt(this.pos++);
},
eat: function(match) {
var ch = this.string.charAt(this.pos);
if (typeof match == "string") var ok = ch == match;
else var ok = ch && (match.test ? match.test(ch) : match(ch));
if (ok) {++this.pos; return ch;}
},
eatWhile: function(match) {
var start = this.pos;
while (this.eat(match)){}
return this.pos > start;
},
eatSpace: function() {
var start = this.pos;
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
return this.pos > start;
},
skipToEnd: function() {this.pos = this.string.length;},
skipTo: function(ch) {
var found = this.string.indexOf(ch, this.pos);
if (found > -1) {this.pos = found; return true;}
},
backUp: function(n) {this.pos -= n;},
column: function() {return this.start;},
indentation: function() {return 0;},
match: function(pattern, consume, caseInsensitive) {
if (typeof pattern == "string") {
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
if (consume !== false) this.pos += pattern.length;
return true;
}
}
else {
var match = this.string.slice(this.pos).match(pattern);
if (match && consume !== false) this.pos += match[0].length;
return match;
}
},
current: function(){return this.string.slice(this.start, this.pos);}
};
CodeMirror.StringStream = StringStream;

CodeMirror.startState = function (mode, a1, a2) {
return mode.startState ? mode.startState(a1, a2) : true;
};

var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
CodeMirror.defineMode = function (name, mode) { modes[name] = mode; };
CodeMirror.defineMIME = function (mime, spec) { mimeModes[mime] = spec; };
CodeMirror.getMode = function (options, spec) {
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
spec = mimeModes[spec];
if (typeof spec == "string")
var mname = spec, config = {};
else if (spec != null)
var mname = spec.name, config = spec;
var mfactory = modes[mname];
if (!mfactory) throw new Error("Unknown mode: " + spec);
return mfactory(options, config || {});
};

CodeMirror.runMode = function (string, modespec, callback, options) {
var mode = CodeMirror.getMode({ indentUnit: 2 }, modespec);

if (callback.nodeType == 1) {
var tabSize = (options && options.tabSize) || 4;
var node = callback, col = 0;
node.innerHTML = "";
callback = function (text, style) {
if (text == "\n") {
node.appendChild(document.createElement("br"));
col = 0;
return;
}
var content = "";
// replace tabs
for (var pos = 0; ;) {
var idx = text.indexOf("\t", pos);
if (idx == -1) {
content += text.slice(pos);
col += text.length - pos;
break;
} else {
col += idx - pos;
content += text.slice(pos, idx);
var size = tabSize - col % tabSize;
col += size;
for (var i = 0; i < size; ++i) content += " ";
pos = idx + 1;
}
}

if (style) {
var sp = node.appendChild(document.createElement("span"));
sp.className = "cm-" + style.replace(/ +/g, " cm-");
sp.appendChild(document.createTextNode(content));
} else {
node.appendChild(document.createTextNode(content));
}
};
}

var lines = splitLines(string), state = CodeMirror.startState(mode);
for (var i = 0, e = lines.length; i < e; ++i) {
if (i) callback("\n");
var stream = new CodeMirror.StringStream(lines[i]);
while (!stream.eol()) {
var style = mode.token(stream, state);
callback(stream.current(), style, i, stream.start);
stream.start = stream.pos;
}
}
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading