151 changes: 0 additions & 151 deletions addon/fold/foldcode.js
Original file line number Diff line number Diff line change
@@ -1,154 +1,3 @@
// the tagRangeFinder function is
// Copyright (C) 2011 by Daniel Glazman <daniel@glazman.org>
// released under the MIT license (../../LICENSE) like the rest of CodeMirror
CodeMirror.tagRangeFinder = function(cm, start) {
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
var xmlNAMERegExp = new RegExp("^[" + nameStartChar + "][" + nameChar + "]*");

var lineText = cm.getLine(start.line);
var found = false;
var tag = null;
var pos = start.ch;
while (!found) {
pos = lineText.indexOf("<", pos);
if (-1 == pos) // no tag on line
return;
if (pos + 1 < lineText.length && lineText[pos + 1] == "/") { // closing tag
pos++;
continue;
}
// ok we seem to have a start tag
if (!lineText.substr(pos + 1).match(xmlNAMERegExp)) { // not a tag name...
pos++;
continue;
}
var gtPos = lineText.indexOf(">", pos + 1);
if (-1 == gtPos) { // end of start tag not in line
var l = start.line + 1;
var foundGt = false;
var lastLine = cm.lineCount();
while (l < lastLine && !foundGt) {
var lt = cm.getLine(l);
gtPos = lt.indexOf(">");
if (-1 != gtPos) { // found a >
foundGt = true;
var slash = lt.lastIndexOf("/", gtPos);
if (-1 != slash && slash < gtPos) {
var str = lineText.substr(slash, gtPos - slash + 1);
if (!str.match( /\/\s*\>/ )) // yep, that's the end of empty tag
return;
}
}
l++;
}
found = true;
}
else {
var slashPos = lineText.lastIndexOf("/", gtPos);
if (-1 == slashPos) { // cannot be empty tag
found = true;
// don't continue
}
else { // empty tag?
// check if really empty tag
var str = lineText.substr(slashPos, gtPos - slashPos + 1);
if (!str.match( /\/\s*\>/ )) { // finally not empty
found = true;
// don't continue
}
}
}
if (found) {
var subLine = lineText.substr(pos + 1);
tag = subLine.match(xmlNAMERegExp);
if (tag) {
// we have an element name, wooohooo !
tag = tag[0];
// do we have the close tag on same line ???
if (-1 != lineText.indexOf("</" + tag + ">", pos)) // yep
{
found = false;
}
// we don't, so we have a candidate...
}
else
found = false;
}
if (!found)
pos++;
}

if (found) {
var startTag = "(\\<\\/" + tag + "\\>)|(\\<" + tag + "\\>)|(\\<" + tag + "\\s)|(\\<" + tag + "$)";
var startTagRegExp = new RegExp(startTag);
var endTag = "</" + tag + ">";
var depth = 1;
var l = start.line + 1;
var lastLine = cm.lineCount();
while (l < lastLine) {
lineText = cm.getLine(l);
var match = lineText.match(startTagRegExp);
if (match) {
for (var i = 0; i < match.length; i++) {
if (match[i] == endTag)
depth--;
else
depth++;
if (!depth) return {from: CodeMirror.Pos(start.line, gtPos + 1),
to: CodeMirror.Pos(l, match.index)};
}
}
l++;
}
return;
}
};

CodeMirror.braceRangeFinder = function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var at = lineText.length, startChar, tokenType;
for (;;) {
var found = lineText.lastIndexOf("{", at);
if (found < start.ch) break;
tokenType = cm.getTokenAt(CodeMirror.Pos(line, found + 1)).type;
if (!/^(comment|string)/.test(tokenType)) { startChar = found; break; }
at = found - 1;
}
if (startChar == null || lineText.lastIndexOf("}") > startChar) return;
var count = 1, lastLine = cm.lineCount(), end, endCh;
outer: for (var i = line + 1; i < lastLine; ++i) {
var text = cm.getLine(i), pos = 0;
for (;;) {
var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenAt(CodeMirror.Pos(i, pos + 1)).type == tokenType) {
if (pos == nextOpen) ++count;
else if (!--count) { end = i; endCh = pos; break outer; }
}
++pos;
}
}
if (end == null || end == line + 1) return;
return {from: CodeMirror.Pos(line, startChar + 1),
to: CodeMirror.Pos(end, endCh)};
};

CodeMirror.indentRangeFinder = function(cm, start) {
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
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 &&
CodeMirror.countColumn(cm.getLine(i-1), null, tabSize) > myIndent)
return {from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(i, curLine.length)};
}
};

CodeMirror.newFoldFunction = function(rangeFinder, widget) {
if (widget == null) widget = "\u2194";
if (typeof widget == "string") {
Expand Down
11 changes: 11 additions & 0 deletions addon/fold/indent-fold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CodeMirror.indentRangeFinder = function(cm, start) {
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
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 &&
CodeMirror.countColumn(cm.getLine(i-1), null, tabSize) > myIndent)
return {from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(i, curLine.length)};
}
};
64 changes: 64 additions & 0 deletions addon/fold/xml-fold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
CodeMirror.tagRangeFinder = (function() {
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g");

return function(cm, start) {
var line = start.line, ch = start.ch, lineText = cm.getLine(line);

function nextLine() {
if (line >= cm.lastLine()) return;
ch = 0;
lineText = cm.getLine(++line);
return true;
}
function toTagEnd() {
for (;;) {
var gt = lineText.indexOf(">", ch);
if (gt == -1) { if (nextLine()) continue; else return; }
var lastSlash = lineText.lastIndexOf("/", gt);
var selfClose = lastSlash > -1 && /^\s*$/.test(lineText.slice(lastSlash + 1, gt));
ch = gt + 1;
return selfClose ? "selfClose" : "regular";
}
}
function toNextTag() {
for (;;) {
xmlTagStart.lastIndex = ch;
var found = xmlTagStart.exec(lineText);
if (!found) { if (nextLine()) continue; else return; }
ch = found.index + found[0].length;
return found;
}
}

var stack = [], startCh;
for (;;) {
var openTag = toNextTag(), end;
if (!openTag || line != start.line || !(end = toTagEnd())) return;
if (!openTag[1] && end != "selfClose") {
stack.push(openTag[2]);
startCh = ch;
break;
}
}

for (;;) {
var next = toNextTag(), end, tagLine = line, tagCh = ch - (next ? next[0].length : 0);
if (!next || !(end = toTagEnd())) return;
if (end == "selfClose") continue;
if (next[1]) { // closing tag
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) {
stack.length = i;
break;
}
if (!stack.length) return {
from: CodeMirror.Pos(start.line, startCh),
to: CodeMirror.Pos(tagLine, tagCh)
};
} else { // opening tag
stack.push(next[2]);
}
}
};
})();
114 changes: 0 additions & 114 deletions addon/format/formatting.js

This file was deleted.

582 changes: 582 additions & 0 deletions addon/hint/html-hint.js

Large diffs are not rendered by default.

41 changes: 29 additions & 12 deletions addon/hint/show-hint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CodeMirror.showHint = function(cm, getHints, options) {
if (!options) options = {};
var startCh = cm.getCursor().ch, continued = false;
var closeOn = options.closeCharacters || /[\s()\[\]{};:]/;

function startHinting() {
// We want a single cursor position.
Expand All @@ -12,22 +13,35 @@ CodeMirror.showHint = function(cm, getHints, options) {
return showHints(getHints(cm, options));
}

function getText(completion) {
if (typeof completion == "string") return completion;
else return completion.text;
}

function pickCompletion(cm, data, completion) {
if (completion.hint) completion.hint(cm, data, completion);
else cm.replaceRange(getText(completion), data.from, data.to);
}

function showHints(data) {
if (!data || !data.list.length) return;
var completions = data.list;
// When there is only one completion, use it directly.
if (!continued && options.completeSingle !== false && completions.length == 1) {
cm.replaceRange(completions[0], data.from, data.to);
pickCompletion(cm, data, completions[0]);
return true;
}

// Build the select widget
var hints = document.createElement("ul"), selectedHint = 0;
hints.className = "CodeMirror-hints";
for (var i = 0; i < completions.length; ++i) {
var elt = hints.appendChild(document.createElement("li"));
elt.className = "CodeMirror-hint" + (i ? "" : " CodeMirror-hint-active");
elt.appendChild(document.createTextNode(completions[i]));
var elt = hints.appendChild(document.createElement("li")), completion = completions[i];
var className = "CodeMirror-hint" + (i ? "" : " CodeMirror-hint-active");
if (completion.className != null) className = completion.className + " " + className;
elt.className = className;
if (completion.render) completion.render(elt, data, completion);
else elt.appendChild(document.createTextNode(getText(completion)));
elt.hintId = i;
}
var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null);
Expand Down Expand Up @@ -63,9 +77,10 @@ CodeMirror.showHint = function(cm, getHints, options) {
function changeActive(i) {
i = Math.max(0, Math.min(i, completions.length - 1));
if (selectedHint == i) return;
hints.childNodes[selectedHint].className = "CodeMirror-hint";
var node = hints.childNodes[selectedHint = i];
node.className = "CodeMirror-hint CodeMirror-hint-active";
var node = hints.childNodes[selectedHint];
node.className = node.className.replace(" CodeMirror-hint-active", "");
node = hints.childNodes[selectedHint = i];
node.className += " CodeMirror-hint-active";
if (node.offsetTop < hints.scrollTop)
hints.scrollTop = node.offsetTop - 3;
else if (node.offsetTop + node.offsetHeight > hints.scrollTop + hints.clientHeight)
Expand Down Expand Up @@ -113,11 +128,12 @@ CodeMirror.showHint = function(cm, getHints, options) {
CodeMirror.on(hints, "dblclick", function(e) {
var t = e.target || e.srcElement;
if (t.hintId != null) {selectedHint = t.hintId; pick();}
setTimeout(function(){cm.focus();}, 20);
});
CodeMirror.on(hints, "click", function(e) {
var t = e.target || e.srcElement;
if (t.hintId != null) changeActive(t.hintId);
});
CodeMirror.on(hints, "mousedown", function() {
setTimeout(function(){cm.focus();}, 20);
});

Expand All @@ -134,16 +150,17 @@ CodeMirror.showHint = function(cm, getHints, options) {
cm.off("scroll", onScroll);
}
function pick() {
cm.replaceRange(completions[selectedHint], data.from, data.to);
pickCompletion(cm, data, completions[selectedHint]);
close();
}
var once, lastPos = cm.getCursor(), lastLen = cm.getLine(lastPos.line).length;
function cursorActivity() {
clearTimeout(once);

var pos = cm.getCursor(), len = cm.getLine(pos.line).length;
if (pos.line != lastPos.line || len - pos.ch != lastLen - lastPos.ch ||
pos.ch < startCh || cm.somethingSelected())
var pos = cm.getCursor(), line = cm.getLine(pos.line);
if (pos.line != lastPos.line || line.length - pos.ch != lastLen - lastPos.ch ||
pos.ch < startCh || cm.somethingSelected() ||
(pos.ch && closeOn.test(line.charAt(pos.ch - 1))))
close();
else
once = setTimeout(function(){close(); continued = true; startHinting();}, 70);
Expand Down
16 changes: 0 additions & 16 deletions addon/hint/simple-hint.css

This file was deleted.

102 changes: 0 additions & 102 deletions addon/hint/simple-hint.js

This file was deleted.

2 changes: 1 addition & 1 deletion addon/hint/xml-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

if(text.length >= 0) {

var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g');
var regex = new RegExp('<([^!?][^\\s/>]*)[\\s\\S]*?>', 'g');

var matches = [];
var match;
Expand Down
10 changes: 8 additions & 2 deletions addon/lint/javascript-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
"Unmatched ", " and instead saw", " is not defined",
"Unclosed string", "Stopping, unable to continue" ];

CodeMirror.javascriptValidator = function(text) {
JSHINT(text);
function validator(options, text) {
JSHINT(text, options);
var errors = JSHINT.data().errors, result = [];
if (errors) parseErrors(errors, result);
return result;
}

CodeMirror.javascriptValidatorWithOptions = function(options) {
return function(text) { return validator(options, text); };
};

CodeMirror.javascriptValidator = CodeMirror.javascriptValidatorWithOptions(null);

function cleanup(error) {
// All problems are warnings by default
fixWith(error, warnings, "warning", true);
Expand Down
1 change: 1 addition & 0 deletions addon/lint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ CodeMirror.validate = (function() {
if (state.hasGutter)
cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1));
}
if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
}

function onChange(cm) {
Expand Down
17 changes: 8 additions & 9 deletions addon/search/searchcursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
this.matches = function(reverse, pos) {
if (reverse) {
query.lastIndex = 0;
var line = cm.getLine(pos.line).slice(0, pos.ch), match = query.exec(line), start = 0;
while (match) {
start += match.index + 1;
line = line.slice(start);
query.lastIndex = 0;
var newmatch = query.exec(line);
if (newmatch) match = newmatch;
else break;
var line = cm.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
for (;;) {
query.lastIndex = cutOff;
var newMatch = query.exec(line);
if (!newMatch) break;
match = newMatch;
start = match.index;
cutOff = match.index + 1;
}
start--;
} else {
query.lastIndex = pos.ch;
var line = cm.getLine(pos.line), match = query.exec(line),
Expand Down
8 changes: 6 additions & 2 deletions demo/closebrackets.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
</style>
</head>
<body>

<h1>CodeMirror: Closebrackets Demo</h1>

<p>Type a bracket like '[', '(', '{', '&quot;', or '''
and <a href="../doc/manual.html#addon_closebrackets">the addon</a>
will auto-close it. Type the closing variant when directly in
front of a matching character and it will overwrite it.</p>

<p>If you backspace over a starting bracket while inside empty brackets
(e.g. <code>{|}</code>), it will delete the closing bracket for you.</p>


<form><textarea id="code" name="code">(function() {
var DEFAULT_BRACKETS = "()[]{}''\"\"";

Expand Down
104 changes: 0 additions & 104 deletions demo/collapserange.html

This file was deleted.

2 changes: 1 addition & 1 deletion demo/complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h1>CodeMirror: Autocomplete demo</h1>
</textarea></form>

<p>Press <strong>ctrl-space</strong> to activate autocompletion. See
the code (<a href="../addon/hint/simple-hint.js">here</a>
the code (<a href="../addon/hint/show-hint.js">here</a>
and <a href="../addon/hint/javascript-hint.js">here</a>) to figure out
how it works.</p>

Expand Down
4 changes: 3 additions & 1 deletion demo/folding.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../addon/fold/foldcode.js"></script>
<script src="../addon/fold/brace-fold.js"></script>
<script src="../addon/fold/xml-fold.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<script src="../mode/xml/xml.js"></script>
<link rel="stylesheet" href="../doc/docs.css">
Expand All @@ -27,7 +29,7 @@ <h1>CodeMirror: Code Folding Demo</h1>
<p>Demonstration of code folding using the code
in <a href="../addon/fold/foldcode.js"><code>foldcode.js</code></a>.
Press ctrl-q or click on the gutter to fold a block, again
to unfold.<br>Try the <a href="collapserange.html">Range Colapse demo</a> as well.</p>
to unfold.</p>
<form>
<div style="max-width: 50em; margin-bottom: 1em">JavaScript:<br><textarea id="code" name="code"></textarea></div>
<div style="max-width: 50em">HTML:<br><textarea id="code-html" name="code-html"></textarea></div>
Expand Down
89 changes: 0 additions & 89 deletions demo/formatting.html

This file was deleted.

92 changes: 92 additions & 0 deletions demo/html5complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Close-Tag Demo</title>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../addon/hint/show-hint.js"></script>
<link rel="stylesheet" href="../addon/hint/show-hint.css">
<script src="../addon/edit/closetag.js"></script>
<script src="../addon/hint/html-hint.js"></script>
<script src="../mode/xml/xml.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<script src="../mode/css/css.js"></script>
<script src="../mode/htmlmixed/htmlmixed.js"></script>

<link rel="stylesheet" href="../doc/docs.css">
<style type="text/css">
.CodeMirror {border-top: 1px solid #888; border-bottom: 1px solid #888;}
</style>
</head>
<body>

<h1>HTML5 code completation demo</h1>
<ul>
<li>Type an html tag. If you press Ctrl+Space a hint panel show the code suggest. You can type to autocomplete tags, attributes if your cursor are inner a tag or attribute values if your cursor are inner a attribute value.</li>
</ul>

<form><textarea id="code" name="code">
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Home - W2S Web IDE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>

<body>

<div class="container">

<div class="masthead">
<h3 class="muted">HTML5 Autocomplete</h3>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class=" active "><a href="#">Home</a></li>
<li class=""><a href="#">Features</a></li>
<li class=""><a href="#">Sign In</a></li>
</ul>
</div>
</div>
</div><!-- /.navbar -->
</div>

<!-- Jumbotron -->
<div class="jumbotron">
<img src="/Images/w2s.png" />
<h1>W2S Cloud IDE</h1>
</div>

<hr>


<hr>

<div class="footer">
Final of html5 autocomplete
</div>

</div> <!-- /container -->
</body>
</html>

</textarea></form>
<script type="text/javascript">
CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.htmlHint);
}

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: 'text/html',
autoCloseTags: true,
extraKeys: {"Ctrl-Space": "autocomplete"}
});
</script>
</body>
</html>
49 changes: 49 additions & 0 deletions demo/indentwrap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Indented wrapped line demo</title>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../mode/xml/xml.js"></script>
<link rel="stylesheet" href="../doc/docs.css">

<style type="text/css">
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
</style>
</head>
<body>
<h1>CodeMirror: Indented wrapped line demo</h1>

<form><textarea id="code" name="code">
<!doctype html>
<body>
<h2 id="overview">Overview</h2>

<p>CodeMirror is a code-editor component that can be embedded in Web pages. The core library provides <em>only</em> the editor component, no accompanying buttons, auto-completion, or other IDE functionality. It does provide a rich API on top of which such functionality can be straightforwardly implemented. See the <a href="#addons">add-ons</a> included in the distribution, and the <a href="https://github.com/jagthedrummer/codemirror-ui">CodeMirror UI</a> project, for reusable implementations of extra features.</p>

<p>CodeMirror works with language-specific modes. Modes are JavaScript programs that help color (and optionally indent) text written in a given language. The distribution comes with a number of modes (see the <a href="../mode/"><code>mode/</code></a> directory), and it isn't hard to <a href="#modeapi">write new ones</a> for other languages.</p>
</body>
</textarea></form>

<p>This page uses a hack on top of the <code>"renderLine"</code>
event to make wrapped text line up with the base indentation of
the line.</p>

<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
mode: "text/html"
});
var charWidth = editor.defaultCharWidth(), basePadding = 4;
editor.on("renderLine", function(cm, line, elt) {
var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth;
elt.style.textIndent = "-" + off + "px";
elt.style.paddingLeft = (basePadding + off) + "px";
});
editor.refresh();
</script>

</body>
</html>
36 changes: 36 additions & 0 deletions demo/placeholder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Placeholder demo</title>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../addon/display/placeholder.js"></script>
<link rel="stylesheet" href="../doc/docs.css">

<style type="text/css">
.CodeMirror { border: 1px solid silver; }
.CodeMirror-empty { outline: 1px solid #c22; }
.CodeMirror-empty.CodeMirror-focused { outline: none; }
.CodeMirror pre.CodeMirror-placeholder { color: #999; }
</style>
</head>
<body>
<h1>CodeMirror: Placeholder demo</h1>

<form><textarea id="code" name="code" placeholder="Code goes here..."></textarea></form>

<p>The <a href="../doc/manual.html#addon_placeholder">placeholder</a>
plug-in adds an option <code>placeholder</code> that can be set to
make text appear in the editor when it is empty and not focused.
If the source textarea has a <code>placeholder</code> attribute,
it will automatically be inherited.</p>

<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true
});
</script>

</body>
</html>
7 changes: 5 additions & 2 deletions demo/resize.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ <h1>CodeMirror: Autoresize demo</h1>
}
</textarea></form>

<p>By setting a few CSS properties, CodeMirror can be made to
<p>By setting a few CSS properties, and giving
the <a href="../doc/manual.html#option_viewportMargin"><code>viewportMargin</code></a>
a value of <code>Infinity</code>, CodeMirror can be made to
automatically resize to fit its content.</p>

<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true
lineNumbers: true,
viewportMargin: Infinity
});
</script>

Expand Down
73 changes: 73 additions & 0 deletions demo/spanaffectswrapping_shim.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Automatically derive odd wrapping behavior for your browser</title>
<link rel="stylesheet" href="../doc/docs.css">
</head>
<body>
<h1>CodeMirror: odd wrapping shim</h1>

<p>This is a hack to automatically derive
a <code>spanAffectsWrapping</code> regexp for a browser. See the
comments above that variable
in <a href="../lib/codemirror.js"><code>lib/codemirror.js</code></a>
for some more details.</p>

<div style="white-space: pre-wrap; width: 50px;" id="area"></div>
<pre id="output"></pre>

<script id="script">
var a = document.getElementById("area"), bad = Object.create(null);
var chars = "a~`!@#$%^&*()-_=+}{[]\|'\"/?.>,<:;", l = chars.length;
for (var x = 0; x < l; ++x) for (var y = 0; y < l; ++y) {
var s1 = "foooo" + chars.charAt(x), s2 = chars.charAt(y) + "br";
a.appendChild(document.createTextNode(s1 + s2));
var h1 = a.offsetHeight;
a.innerHTML = "";
a.appendChild(document.createElement("span")).appendChild(document.createTextNode(s1));
a.appendChild(document.createElement("span")).appendChild(document.createTextNode(s2));
if (a.offsetHeight != h1)
bad[chars.charAt(x)] = (bad[chars.charAt(x)] || "") + chars.charAt(y);
a.innerHTML = "";
}

var re = "";
function toREElt(str) {
if (str.length > 1) {
var invert = false;
if (str.length > chars.length * .6) {
invert = true;
var newStr = "";
for (var i = 0; i < l; ++i) if (str.indexOf(chars.charAt(i)) == -1) newStr += chars.charAt(i);
str = newStr;
}
str = str.replace(/[\-\.\]\"\'\\\/\^a]/g, function(orig) { return orig == "a" ? "\\w" : "\\" + orig; });
return "[" + (invert ? "^" : "") + str + "]";
} else if (str == "a") {
return "\\w";
} else if (/[?$*()+{}[\]\.|/\'\"]/.test(str)) {
return "\\" + str;
} else {
return str;
}
}

var newRE = "";
for (;;) {
var left = null;
for (var left in bad) break;
if (left == null) break;
var right = bad[left];
delete bad[left];
for (var other in bad) if (bad[other] == right) {
left += other;
delete bad[other];
}
newRE += (newRE ? "|" : "") + toREElt(left) + toREElt(right);
}

document.getElementById("output").appendChild(document.createTextNode("Your regexp is: " + (newRE || "^$")));
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions demo/theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<link rel="stylesheet" href="../theme/rubyblue.css">
<link rel="stylesheet" href="../theme/lesser-dark.css">
<link rel="stylesheet" href="../theme/xq-dark.css">
<link rel="stylesheet" href="../theme/xq-light.css">
<link rel="stylesheet" href="../theme/ambiance.css">
<link rel="stylesheet" href="../theme/blackboard.css">
<link rel="stylesheet" href="../theme/vibrant-ink.css">
Expand Down Expand Up @@ -62,6 +63,7 @@ <h1>CodeMirror: Theme demo</h1>
<option>twilight</option>
<option>vibrant-ink</option>
<option>xq-dark</option>
<option>xq-light</option>
</select>
</p>

Expand Down
2 changes: 1 addition & 1 deletion demo/visibletabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1>CodeMirror: Visible tabs demo</h1>
</textarea></form>

<p>Tabs inside the editor are spans with the
class <code>cm-tab</code>, and can be styled.
class <code>cm-tab</code>, and can be styled.</p>

<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
Expand Down
13 changes: 8 additions & 5 deletions doc/compress.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<input type="hidden" id="download" name="download" value="codemirror-compressed.js"/>
<p>Version: <select id="version" onchange="setVersion(this);" style="padding: 1px">
<option value="http://codemirror.net/">HEAD</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.11;f=">3.11</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.1;f=">3.1</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.02;f=">3.02</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.01;f=">3.01</option>
Expand Down Expand Up @@ -89,16 +90,16 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<option value="http://codemirror.net/mode/javascript/javascript.js">javascript.js</option>
<option value="http://codemirror.net/mode/jinja2/jinja2.js">jinja2.js</option>
<option value="http://codemirror.net/mode/less/less.js">less.js</option>
<option value="http://codemirror.net/mode/livescript/livescript.js">livescript.js</option>
<option value="http://codemirror.net/mode/lua/lua.js">lua.js</option>
<option value="http://codemirror.net/mode/markdown/markdown.js">markdown.js</option>
<option value="http://codemirror.net/mode/mysql/mysql.js">mysql.js</option>
<option value="http://codemirror.net/mode/mirc/mirc.js">mirc.js</option>
<option value="http://codemirror.net/mode/ntriples/ntriples.js">ntriples.js</option>
<option value="http://codemirror.net/mode/ocaml/ocaml.js">ocaml.js</option>
<option value="http://codemirror.net/mode/pascal/pascal.js">pascal.js</option>
<option value="http://codemirror.net/mode/perl/perl.js">perl.js</option>
<option value="http://codemirror.net/mode/php/php.js">php.js</option>
<option value="http://codemirror.net/mode/pig/pig.js">pig.js</option>
<option value="http://codemirror.net/mode/plsql/plsql.js">plsql.js</option>
<option value="http://codemirror.net/mode/properties/properties.js">properties.js</option>
<option value="http://codemirror.net/mode/python/python.js">python.js</option>
<option value="http://codemirror.net/mode/q/q.js">q.js</option>
Expand All @@ -118,6 +119,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<option value="http://codemirror.net/mode/sql/sql.js">sql.js</option>
<option value="http://codemirror.net/mode/sparql/sparql.js">sparql.js</option>
<option value="http://codemirror.net/mode/stex/stex.js">stex.js</option>
<option value="http://codemirror.net/mode/tcl/tcl.js">tcl.js</option>
<option value="http://codemirror.net/mode/tiddlywiki/tiddlywiki.js">tiddlywiki.js</option>
<option value="http://codemirror.net/mode/tiki/tiki.js">tiki.js</option>
<option value="http://codemirror.net/mode/turtle/turtle.js">turtle.js</option>
Expand All @@ -138,11 +140,12 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<option value="http://codemirror.net/addon/edit/matchbrackets.js">matchbrackets.js</option>
<option value="http://codemirror.net/addon/edit/closebrackets.js">closebrackets.js</option>
<option value="http://codemirror.net/addon/fold/foldcode.js">foldcode.js</option>
<option value="http://codemirror.net/addon/fold/collapserange.js">collapserange.js</option>
<option value="http://codemirror.net/addon/format/formatting.js">formatting.js</option>
<option value="http://codemirror.net/addon/hint/simple-hint.js">simple-hint.js</option>
<option value="http://codemirror.net/addon/fold/xml-fold.js">xml-fold.js</option>
<option value="http://codemirror.net/addon/fold/brace-fold.js">brace-fold.js</option>
<option value="http://codemirror.net/addon/fold/indent-fold.js">indent-fold.js</option>
<option value="http://codemirror.net/addon/hint/javascript-hint.js">javascript-hint.js</option>
<option value="http://codemirror.net/addon/hint/xml-hint.js">xml-hint.js</option>
<option value="http://codemirror.net/addon/hint/html-hint.js">html-hint.js</option>
<option value="http://codemirror.net/addon/hint/pig-hint.js">pig-hint.js</option>
<option value="http://codemirror.net/addon/hint/python-hint.js">python-hint.js</option>
<option value="http://codemirror.net/addon/mode/loadmode.js">loadmode.js</option>
Expand Down
125 changes: 85 additions & 40 deletions doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,18 @@ <h2 id="events">Events</h2>
<dl>
<dt id="event_change"><code>"change" (instance, changeObj)</code></dt>
<dd>Fires every time the content of the editor is changed.
The <code>changeObj</code> is a <code>{from, to, text,
The <code>changeObj</code> is a <code>{from, to, text, removed,
next}</code> object containing information about the changes
that occurred as second argument. <code>from</code>
and <code>to</code> are the positions (in the pre-change
coordinate system) where the change started and ended (for
example, it might be <code>{ch:0, line:18}</code> if the
position is at the beginning of line #19). <code>text</code> is
an array of strings representing the text that replaced the
changed range (split by line). If multiple changes happened
during a single operation, the object will have
changed range (split by line). <code>removed</code> is the text
that used to be between <code>from</code> and <code>to</code>,
which is overwritten by this change. If multiple changes
happened during a single operation, the object will have
a <code>next</code> property pointing to another change object
(which may point to another, etc).</dd>

Expand Down Expand Up @@ -423,6 +425,13 @@ <h2 id="events">Events</h2>

<dt id="event_update"><code>"update" (instance)</code></dt>
<dd>Will be fired whenever CodeMirror updates its DOM display.</dd>

<dt id="event_renderLine"><code>"renderLine" (instance, line, element)</code></dt>
<dd>Fired whenever a line is (re-)rendered to the DOM. Fired
right after the DOM element is built, <em>before</em> it is
added to the document. The handler may mess with the style of
the resulting element, or add event handlers, but
should <em>not</em> try to change the state of the editor.</dd>
</dl>

<p>It is also possible to <a href="#on">register</a> events on
Expand Down Expand Up @@ -466,9 +475,12 @@ <h2 id="events">Events</h2>
is associated with the <em>start</em> of the line. Mostly useful
when you need to find out when your <a href="#setGutterMarker">gutter
markers</a> on a given line are removed.</dd>
<dt id="event_line_change"><code>"change" ()</code></dt>
<dt id="event_line_change"><code>"change" (line, changeObj)</code></dt>
<dd>Fires when the line's text content is changed in any way
(but the line is not deleted outright).</dd>
(but the line is not deleted outright). The <code>change</code>
object is similar to the one passed
to <a href="#event_change">change event</a> on the editor
object.</dd>
</dl>

<p>Marked range handles, as returned
Expand All @@ -477,6 +489,11 @@ <h2 id="events">Events</h2>
following events:</p>

<dl>
<dt id="event_beforeCursorEnter"><code>"beforeCursorEnter" ()</code></dt>
<dd>Fired when the cursor enters the marked range. From this
event handler, the editor state may be inspected
but <em>not</em> modified, with the exception that the range on
which the event fires may be cleared.</dd>
<dt id="event_clear"><code>"clear" ()</code></dt>
<dd>Fired when the range is cleared, either through cursor
movement in combination
Expand Down Expand Up @@ -523,6 +540,17 @@ <h2 id="keymaps">Keymaps</h2>
for example, <code>Shift-Ctrl-Space</code> would be a valid key
identifier.</p>

<p>Common example: map the Tab key to insert spaces instead of a tab
character.</p>

<pre data-lang="javascript">
{
Tab: function(cm) {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
cm.replaceSelection(spaces, "end", "+input");
}
}</pre>

<p>Alternatively, a character can be specified directly by
surrounding it in single quotes, for example <code>'$'</code>
or <code>'q'</code>. Due to limitations in the way browsers fire
Expand Down Expand Up @@ -777,6 +805,9 @@ <h3 id="api_selection">Cursor and selection methods</h3>
to <a href="#extendSelection"><code>extendSelection</code></a>
to leave the selection anchor in place.</dd>

<dt id="hasFocus"><code>cm.hasFocus() → bool</code></dt>
<dd>Tells you whether the editor currently has focus.</dd>

<dt id="findPosH"><code>cm.findPosH(start, amount, unit, visually) → object</code></dt>
<dd>Used to find the target position for horizontal cursor
motion. <code>start</code> is a <code>{line, ch}</code>
Expand Down Expand Up @@ -810,16 +841,18 @@ <h3 id="api_configuration">Configuration methods</h3>
<dd>Retrieves the current value of the given option for this
editor instance.</dd>

<dt id="addKeyMap"><code>cm.addKeyMap(map)</code></dt>
<dd>Attach an additional <a href="#keymaps">keymap</a> to the editor. This is mostly
useful for add-ons that need to register some key handlers
without trampling on
<dt id="addKeyMap"><code>cm.addKeyMap(map, bottom)</code></dt>
<dd>Attach an additional <a href="#keymaps">keymap</a> to the
editor. This is mostly useful for add-ons that need to register
some key handlers without trampling on
the <a href="#option_extraKeys"><code>extraKeys</code></a>
option. Maps added in this way have a lower precedence
than <code>extraKeys</code>, a higher precedence than the
base <a href="#option_keyMap"><code>keyMap</code></a>, and
between them, the maps added earlier have a higher precedence
than those added later.</dd>
option. Maps added in this way have a higher precedence than
the <code>extraKeys</code>
and <a href="#option_keyMap"><code>keyMap</code></a> options,
and between them, the maps added earlier have a lower precedence
than those added later, unless the <code>bottom</code> argument
was passed, in which case they end up below other keymaps added
with this method.</dd>
<dt id="removeKeyMap"><code>cm.removeKeyMap(map)</code></dt>
<dd>Disable a keymap added
with <a href="#addKeyMap"><code>addKeyMap</code></a>. Either
Expand All @@ -835,7 +868,7 @@ <h3 id="api_configuration">Configuration methods</h3>
searched. <code>mode</code> can be a <a href="#option_mode">mode
spec</a> or a mode object (an object with
a <a href="#token"><code>token</code></a> method).
The <code>option</code> parameter is optional. If given it
The <code>options</code> parameter is optional. If given, it
should be an object. Currently, only the <code>opaque</code>
option is recognized. This defaults to off, but can be given to
allow the overlay styling, when not <code>null</code>, to
Expand Down Expand Up @@ -1159,12 +1192,14 @@ <h3 id="api_sizing">Sizing, scrolling and positioning methods</h3>
clientHeight}</code> object that represents the current scroll
position, the size of the scrollable area, and the size of the
visible area (minus scrollbars).</dd>
<dt id="scrollIntoView"><code>cm.scrollIntoView(pos)</code></dt>
<dt id="scrollIntoView"><code>cm.scrollIntoView(pos, margin)</code></dt>
<dd>Scrolls the given element into view. <code>pos</code> may be
either a <code>{line, ch}</code> position, referring to a given
character, <code>null</code>, to refer to the cursor, or
a <code>{left, top, right, bottom}</code> object, in
editor-local coordinates.</dd>
editor-local coordinates. The <code>margin</code> parameter is
optional. When given, it indicates the amount of pixels around
the given area that should be made visible as well.</dd>

<dt id="cursorCoords"><code>cm.cursorCoords(where, mode) → object</code></dt>
<dd>Returns an <code>{left, top, bottom}</code> object
Expand All @@ -1184,12 +1219,20 @@ <h3 id="api_sizing">Sizing, scrolling and positioning methods</h3>
it'll give the size of the whole character, rather than just the
position that the cursor would have when it would sit at that
position.</dd>
<dt id="coordsChar"><code>cm.coordsChar(object) → pos</code></dt>
<dd>Given an <code>{left, top}</code> object (in page coordinates),
returns the <code>{line, ch}</code> position that corresponds to
it.</dd>
<dt id="coordsChar"><code>cm.coordsChar(object, mode) → pos</code></dt>
<dd>Given an <code>{left, top}</code> object, returns
the <code>{line, ch}</code> position that corresponds to it. The
optional <code>mode</code> parameter determines relative to what
the coordinates are interpreted. It may
be <code>"window"</code>, <code>"page"</code> (the default),
or <code>"local"</code>.</dd>
<dt id="defaultTextHeight"><code>cm.defaultTextHeight() → number</code></dt>
<dd>Returns the line height of the default font for the editor.</dd>
<dt id="defaultCharWidth"><code>cm.defaultCharWidth() → number</code></dt>
<dd>Returns the pixel width of an 'x' in the default font for
the editor. (Note that for non-monospace fonts, this is mostly
useless, and even for monospace fonts, non-ascii characters
might have a different width).</dd>

<dt id="getViewport"><code>cm.getViewport() → object</code></dt>
<dd>Returns a <code>{from, to}</code> object indicating the
Expand All @@ -1210,7 +1253,7 @@ <h3 id="api_sizing">Sizing, scrolling and positioning methods</h3>
<h3 id="api_mode">Mode, state, and token-related methods</h3>

<p>When writing language-aware functionality, it can often be
useful to hook into the knowledge thate the CodeMirror language
useful to hook into the knowledge that the CodeMirror language
mode has. See <a href="#modeapi">the section on modes</a> for a
more detailed description of how these work.</p>

Expand Down Expand Up @@ -1423,19 +1466,15 @@ <h2 id="addons">Add-ons</h2>
a CodeMirror instance and a line number, attempt to fold or
unfold the block starting at the given line. A range-finder is a
language-specific function that also takes an instance and a
line number, and returns an range to be folded, or null if
no block is started on that line. This file
provides <code>CodeMirror.braceRangeFinder</code>, which finds
blocks in brace languages (JavaScript, C, Java,
line number, and returns an range to be folded, or null if no
block is started on that line. There are files in
the <a href="../addon/fold/"><code>addon/fold/</code></a>
directory providing <code>CodeMirror.braceRangeFinder</code>,
which finds blocks in brace languages (JavaScript, C, Java,
etc), <code>CodeMirror.indentRangeFinder</code>, for languages
where indentation determines block structure (Python, Haskell),
and <code>CodeMirror.tagRangeFinder</code>, for XML-style
languages.</dd>
<dt id="addon_collapserange"><a href="../addon/fold/collapserange.js"><code>fold/collapserange.js</code></a></dt>
<dd>Another approach to
folding. <a href="../demo/collapserange.html">See demo</a>.
Allows the user to select a range to fold by clicking in the
gutter.</dd>
<dt id="addon_runmode"><a href="../addon/runmode/runmode.js"><code>runmode/runmode.js</code></a></dt>
<dd>Can be used to run a CodeMirror mode over text without
actually opening an editor instance.
Expand Down Expand Up @@ -1529,10 +1568,17 @@ <h2 id="addons">Add-ons</h2>
editor instance to refresh its mode when the loading
succeeded. See the <a href="../demo/loadmode.html">demo</a>.</dd>
<dt id="addon_continuecomment"><a href="../addon/edit/continuecomment.js"><code>edit/continuecomment.js</code></a></dt>
<dd>Adds a <a href="#commands">command</a>
called <code>newlineAndIndentContinueComment</code> that you can
bind <code>Enter</code> to in order to have the editor prefix
new lines inside C-like block comments with an asterisk.</dd>
<dd>Adds an <code>continueComments</code> option, which can be
set to true to have the editor prefix new lines inside C-like
block comments with an asterisk when Enter is pressed. It can
also be set to a string in order to bind this functionality to a
specific key..</dd>
<dt id="addon_placeholder"><a href="../addon/display/placeholder.js"><code>display/placeholder.js</code></a></dt>
<dd>Adds a <code>placeholder</code> option that can be used to
make text appear in the editor when it is empty and not focused.
Also gives the editor a <code>CodeMirror-empty</code> CSS class
whenever it doesn't contain any text.
See <a href="../demo/placeholder.html">the demo</a>.</dd>
</dl>

<h2 id="modeapi">Writing CodeMirror Modes</h2>
Expand Down Expand Up @@ -1723,11 +1769,10 @@ <h2 id="modeapi">Writing CodeMirror Modes</h2>
extra methods, <code>innerMode</code> which, given a state object,
returns a <code>{state, mode}</code> object with the inner mode
and its state for the current position. These are used by utility
scripts such as the <a href="#addon_formatting">autoformatter</a>
and the <a href="#addon_closetag">tag closer</a> to get context
information. Use the <code>CodeMirror.innerMode</code> helper
function to, starting from a mode and a state, recursively walk
down to the innermost mode and state.</p>
scripts such as the <a href="#addon_closetag">tag closer</a> to
get context information. Use the <code>CodeMirror.innerMode</code>
helper function to, starting from a mode and a state, recursively
walk down to the innermost mode and state.</p>

<p>To make indentation work properly in a nested parser, it is
advisable to give the <code>startState</code> method of modes that
Expand Down
4 changes: 4 additions & 0 deletions doc/modes.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<li><a href="../mode/javascript/index.html">JavaScript</a></li>
<li><a href="../mode/jinja2/index.html">Jinja2</a></li>
<li><a href="../mode/less/index.html">LESS</a></li>
<li><a href="../mode/livescript/index.html">LiveScript</a></li>
<li><a href="../mode/lua/index.html">Lua</a></li>
<li><a href="../mode/markdown/index.html">Markdown</a> (<a href="../mode/gfm/index.html">GitHub-flavour</a>)</li>
<li><a href="../mode/mirc/index.html">mIRC</a></li>
<li><a href="../mode/ntriples/index.html">NTriples</a></li>
<li><a href="../mode/ocaml/index.html">OCaml</a></li>
<li><a href="../mode/pascal/index.html">Pascal</a></li>
Expand All @@ -64,13 +66,15 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<li><a href="../mode/sass/index.html">Sass</a></li>
<li><a href="../mode/clike/scala.html">Scala</a></li>
<li><a href="../mode/scheme/index.html">Scheme</a></li>
<li><a href="../mode/css/scss.html">SCSS</a></li>
<li><a href="../mode/shell/index.html">Shell</a></li>
<li><a href="../mode/sieve/index.html">Sieve</a></li>
<li><a href="../mode/smalltalk/index.html">Smalltalk</a></li>
<li><a href="../mode/smarty/index.html">Smarty</a></li>
<li><a href="../mode/sql/index.html">SQL</a> (several dialects)</li>
<li><a href="../mode/sparql/index.html">SPARQL</a></li>
<li><a href="../mode/stex/index.html">sTeX, LaTeX</a></li>
<li><a href="../mode/tcl/index.html">Tcl</a></li>
<li><a href="../mode/tiddlywiki/index.html">Tiddlywiki</a></li>
<li><a href="../mode/tiki/index.html">Tiki wiki</a></li>
<li><a href="../mode/turtle/index.html">Turtle</a></li>
Expand Down
16 changes: 16 additions & 0 deletions doc/oldrelease.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
</pre>
</div>

<p class="rel">22-10-2012: <a href="http://codemirror.net/codemirror-3.0beta2.zip">Version 3.0, beta 2</a>:</p>

<ul class="rel-note">
<li>Fix page-based coordinate computation.</li>
<li>Fix firing of <a href="manual.html#event_gutterClick"><code>gutterClick</code></a> event.</li>
<li>Add <a href="manual.html#option_cursorHeight"><code>cursorHeight</code></a> option.</li>
<li>Fix bi-directional text regression.</li>
<li>Add <a href="manual.html#option_viewportMargin"><code>viewportMargin</code></a> option.</li>
<li>Directly handle mousewheel events (again, hopefully better).</li>
<li>Make vertical cursor movement more robust (through widgets, big line gaps).</li>
<li>Add <a href="manual.html#option_flattenSpans"><code>flattenSpans</code></a> option.</li>
<li>Many optimizations. Poor responsiveness should be fixed.</li>
<li>Initialization in hidden state works again.</li>
<li>Full <a href="https://github.com/marijnh/CodeMirror/compare/v3.0beta1...v3.0beta2">list of patches</a>.</li>
</ul>

<p class="rel">19-09-2012: <a href="http://codemirror.net/codemirror-2.34.zip">Version 2.34</a>:</p>

<ul class="rel-note">
Expand Down
3 changes: 2 additions & 1 deletion doc/realworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<li><a href="http://bluegriffon.org/">BlueGriffon</a> (HTML editor)</li>
<li><a href="http://cargocollective.com/">Cargo Collective</a> (creative publishing platform)</li>
<li><a href="http://www.codebugapp.com/">Codebug</a> (PHP Xdebug front-end)</li>
<li><a href="http://emmet.io/blog/codemirror-movie/">CodeMirror movie</a> (scripted editing demos)</li>
<li><a href="http://code.google.com/p/codemirror2-gwt/">CodeMirror2-GWT</a> (Google Web Toolkit wrapper)</li>
<li><a href="http://www.crunchzilla.com/code-monster">Code Monster</a> & <a href="http://www.crunchzilla.com/code-maven">Code Maven</a> (learning environment)</li>
<li><a href="http://codepen.io">Codepen</a> (gallery of animations)</li>
Expand All @@ -42,6 +43,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<li><a href="http://www.dbninja.com">DbNinja</a> (MySQL access interface)</li>
<li><a href="http://elm-lang.org/Examples.elm">Elm language examples</a></li>
<li><a href="http://eloquentjavascript.net/chapter1.html">Eloquent JavaScript</a> (book)</li>
<li><a href="http://emmet.io">Emmet</a> (fast XML editing)</li>
<li><a href="http://www.fastfig.com/">Fastfig</a> (online computation/math tool)</li>
<li><a href="https://metacpan.org/module/Farabi">Farabi</a> (modern Perl IDE)</li>
<li><a href="http://blog.pamelafox.org/2012/02/interactive-html5-slides-with-fathomjs.html">FathomJS integration</a> (slides with editors, again)</li>
Expand Down Expand Up @@ -88,7 +90,6 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<li><a href="http://www.wescheme.org/">WeScheme</a> (learning tool)</li>
<li><a href="http://wordpress.org/extend/plugins/codemirror-for-codeeditor/">WordPress plugin</a></li>
<li><a href="http://www.xosystem.org/home/applications_websites/xosystem_website/xoside_EN.php">XOSide</a> (online editor)</li>
<li><a href="http://media.chikuyonok.ru/codemirror2/">Zen Coding</a> (fast XML editing)</li>
</ul>

</body>
Expand Down
44 changes: 27 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ <h2 style="margin-top: 0">Supported modes:</h2>
<li><a href="mode/sql/index.html">SQL</a> (several dialects)</li>
<li><a href="mode/sparql/index.html">SPARQL</a></li>
<li><a href="mode/stex/index.html">sTeX, LaTeX</a></li>
<li><a href="mode/tcl/index.html">Tcl</a></li>
<li><a href="mode/vb/index.html">VB.NET</a></li>
<li><a href="mode/vbscript/index.html">VBScript</a></li>
<li><a href="mode/velocity/index.html">Velocity</a></li>
Expand Down Expand Up @@ -126,7 +127,7 @@ <h2>Real-world uses:</h2>
<li><a href="https://script.google.com/">Google Apps Script</a></li>
<li><a href="https://github.com/github/android">GitHub's Android app</a></li>
<li><a href="http://eloquentjavascript.net/chapter1.html">Eloquent JavaScript</a> (book)</li>
<li><a href="http://media.chikuyonok.ru/codemirror2/">Zen Coding</a> (fast XML editing)</li>
<li><a href="http://emmet.io">Emmet</a> (fast XML editing)</li>
<li><a href="http://paperjs.org/">Paper.js</a> (graphics scripting)</li>
<li><a href="http://codev.it/">Codev</a> (collaborative IDE)</li>
<li><a href="http://enjalot.com/tributary/2636296/sinwaves.js">Tributary</a> (augmented editing)</li>
Expand Down Expand Up @@ -284,6 +285,31 @@ <h2>Reading material</h2>

<h2 id=releases>Releases</h2>

<p class="rel">20-03-2013: <a href="http://codemirror.net/codemirror-3.11.zip">Version 3.11</a>:</p>

<ul class="rel-note">
<li><strong>Removed code:</strong> <code>collapserange</code>,
<code>formatting</code>, and <code>simple-hint</code>
addons. <code>plsql</code> and <code>mysql</code> modes
(use <a href="mode/sql/index.html"><code>sql</code></a> mode).</li>
<li><strong>Moved code:</strong> the range-finding functions for folding now have <a href="addon/fold/">their own files</a>.</li>
<li><strong>Changed interface:</strong>
the <a href="doc/manual.html#addon_continuecomment"><code>continuecomment</code></a>
addon now exposes an option, rather than a command.</li>
<li>New
modes: <a href="mode/css/scss.html">SCSS</a>, <a href="mode/tcl/index.html">Tcl</a>, <a href="mode/livescript/index.html">LiveScript</a>,
and <a href="mode/mirc/index.html">mIRC</a>.</li>
<li>New addons: <a href="demo/placeholder.html"><code>placeholder</code></a>, <a href="demo/html5complete.html">HTML completion</a>.</li>
<li>New
methods: <a href="doc/manual.html#hasFocus"><code>hasFocus</code></a>, <a href="doc/manual.html#defaultCharWidth"><code>defaultCharWidth</code></a>.</li>
<li>New events: <a href="doc/manual.html#event_beforeCursorEnter"><code>beforeCursorEnter</code></a>, <a href="doc/manual.html#event_renderLine"><code>renderLine</code></a>.</li>
<li>Many improvements to the <a href="doc/manual.html#addon_show-hint"><code>show-hint</code></a> completion
dialog addon.</li>
<li>Tweak behavior of by-word cursor motion.</li>
<li>Further improvements to the <a href="demo/vim.html">vim mode</a>.</li>
<li>Full <a href="https://github.com/marijnh/CodeMirror/compare/v3.1...v3.11">list of patches</a>.</li>
</ul>

<p class="rel">21-02-2013: <a href="http://codemirror.net/codemirror-3.1.zip">Version 3.1</a>:</p>

<ul class="rel-note">
Expand Down Expand Up @@ -431,22 +457,6 @@ <h2 id=releases>Releases</h2>
<li>Full <a href="https://github.com/marijnh/CodeMirror/compare/v2.34...v2.35">list of patches</a>.</li>
</ul>

<p class="rel">22-10-2012: <a href="http://codemirror.net/codemirror-3.0beta2.zip">Version 3.0, beta 2</a>:</p>

<ul class="rel-note">
<li>Fix page-based coordinate computation.</li>
<li>Fix firing of <a href="doc/manual.html#event_gutterClick"><code>gutterClick</code></a> event.</li>
<li>Add <a href="doc/manual.html#option_cursorHeight"><code>cursorHeight</code></a> option.</li>
<li>Fix bi-directional text regression.</li>
<li>Add <a href="doc/manual.html#option_viewportMargin"><code>viewportMargin</code></a> option.</li>
<li>Directly handle mousewheel events (again, hopefully better).</li>
<li>Make vertical cursor movement more robust (through widgets, big line gaps).</li>
<li>Add <a href="doc/manual.html#option_flattenSpans"><code>flattenSpans</code></a> option.</li>
<li>Many optimizations. Poor responsiveness should be fixed.</li>
<li>Initialization in hidden state works again.</li>
<li>Full <a href="https://github.com/marijnh/CodeMirror/compare/v3.0beta1...v3.0beta2">list of patches</a>.</li>
</ul>

<p><a href="doc/oldrelease.html">Older releases...</a></p>

</div></div>
Expand Down
478 changes: 337 additions & 141 deletions keymap/vim.js

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions lib/codemirror.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

.CodeMirror div.CodeMirror-cursor {
border-left: 1px solid black;
z-index: 3;
}
/* Shown when moving in bi-directional text */
.CodeMirror div.CodeMirror-secondarycursor {
Expand All @@ -49,17 +50,14 @@
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor {
width: auto;
border: 0;
background: transparent;
background: rgba(0, 200, 0, .4);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#6600c800, endColorstr=#4c00c800);
}
/* Kludge to turn off filter in ie9+, which also accepts rgba */
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor:not(#nonsense_id) {
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
background: #7e7;
z-index: 1;
}
/* Can style cursor different in overwrite (non-insert) mode */
.CodeMirror div.CodeMirror-cursor.CodeMirror-overwrite {}

.cm-tab { display: inline-block; }

/* DEFAULT THEME */

.cm-s-default .cm-keyword {color: #708;}
Expand Down Expand Up @@ -90,7 +88,6 @@
.cm-positive {color: #292;}
.cm-header, .cm-strong {font-weight: bold;}
.cm-em {font-style: italic;}
.cm-emstrong {font-style: italic; font-weight: bold;}
.cm-link {text-decoration: underline;}

.cm-invalidchar {color: #f00;}
Expand All @@ -107,6 +104,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
line-height: 1;
position: relative;
overflow: hidden;
background: white;
color: black;
}

.CodeMirror-scroll {
Expand Down Expand Up @@ -153,6 +152,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
}
.CodeMirror-gutter {
height: 100%;
padding-bottom: 30px;
margin-bottom: -32px;
display: inline-block;
/* Hack to make IE7 behave */
*zoom:1;
Expand All @@ -169,7 +170,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
}
.CodeMirror pre {
/* Reset some styles that the rest of the page might have set */
-moz-border-radius: 0; -webkit-border-radius: 0; -o-border-radius: 0; border-radius: 0;
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
border-width: 0;
background: transparent;
font-family: inherit;
Expand Down
394 changes: 263 additions & 131 deletions lib/codemirror.js

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions mode/clojure/clojure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementation by Koh Zi Chun)
*/
CodeMirror.defineMode("clojure", function () {
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", CHARACTER = "string-2",
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword";
var INDENT_WORD_SKIP = 2;

Expand All @@ -19,7 +19,7 @@ CodeMirror.defineMode("clojure", function () {
"defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype defprotocol defrecord defproject deftest slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do case cond condp for loop recur when when-not when-let when-first if if-let if-not . .. -> ->> doto and or dosync doseq dotimes dorun doall load import unimport ns in-ns refer try catch finally throw with-open with-local-vars binding gen-class gen-and-load-class gen-and-save-class handler-case handle");

var builtins = makeKeywords(
"* *1 *2 *3 *agent* *allow-unresolved-vars* *assert *clojure-version* *command-line-args* *compile-files* *compile-path* *e *err* *file* *flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *read-eval* *source-path* *use-context-classloader* *warn-on-reflection* + - / < <= = == > >= accessor aclone agent agent-errors aget alength alias all-ns alter alter-meta! alter-var-root amap ancestors and apply areduce array-map aset aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in associative? atom await await-for await1 bases bean bigdec bigint binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array booleans bound-fn bound-fn* butlast byte byte-array bytes case cast char char-array char-escape-string char-name-string char? chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? class class? clear-agent-errors clojure-version coll? comment commute comp comparator compare compare-and-set! compile complement concat cond condp conj conj! cons constantly construct-proxy contains? count counted? create-ns create-struct cycle dec decimal? declare definline defmacro defmethod defmulti defn defn- defonce defstruct delay delay? deliver deref derive descendants destructure disj disj! dissoc dissoc! distinct distinct? doall doc dorun doseq dosync dotimes doto double double-array doubles drop drop-last drop-while empty empty? ensure enumeration-seq eval even? every? extend extend-protocol extend-type extends? extenders false? ffirst file-seq filter find find-doc find-ns find-var first float float-array float? floats flush fn fn? fnext for force format future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface gensym get get-in get-method get-proxy-class get-thread-bindings get-validator hash hash-map hash-set identical? identity if-let if-not ifn? import in-ns inc init-proxy instance? int int-array integer? interleave intern interpose into into-array ints io! isa? iterate iterator-seq juxt key keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list* list? load load-file load-reader load-string loaded-libs locking long long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy map map? mapcat max max-key memfn memoize merge merge-with meta method-sig methods min min-key mod name namespace neg? newline next nfirst nil? nnext not not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? or parents partial partition pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str prefer-method prefers primitives-classnames print print-ctor print-doc print-dup print-method print-namespace-doc print-simple print-special-doc print-str printf println println-str prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot rand rand-int range ratio? rational? rationalize re-find re-groups re-matcher re-matches re-pattern re-seq read read-line read-string reify reduce ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure release-pending-sends rem remove remove-method remove-ns repeat repeatedly replace replicate require reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq rsubseq satisfies? second select-keys send send-off seq seq? seque sequence sequential? set set-validator! set? short short-array shorts shutdown-agents slurp some sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-form-anchor special-symbol? split-at split-with str stream? string? struct struct-map subs subseq subvec supers swap! symbol symbol? sync syntax-symbol-anchor take take-last take-nth take-while test the-ns time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-dec unchecked-divide unchecked-inc unchecked-multiply unchecked-negate unchecked-remainder unchecked-subtract underive unquote unquote-splicing update-in update-proxy use val vals var-get var-set var? vary-meta vec vector vector? when when-first when-let when-not while with-bindings with-bindings* with-in-str with-loading-context with-local-vars with-meta with-open with-out-str with-precision xml-seq");
"* *' *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version* *command-line-args* *compile-files* *compile-path* *compiler-options* *data-readers* *e *err* *file* *flush-on-newline* *fn-loader* *in* *math-context* *ns* *out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *read-eval* *source-path* *unchecked-math* *use-context-classloader* *verbose-defrecords* *warn-on-reflection* + +' - -' -> ->> ->ArrayChunk ->Vec ->VecNode ->VecSeq -cache-protocol-fn -reset-methods .. / < <= = == > >= EMPTY-NODE accessor aclone add-classpath add-watch agent agent-error agent-errors aget alength alias all-ns alter alter-meta! alter-var-root amap ancestors and apply areduce array-map aset aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in associative? atom await await-for await1 bases bean bigdec bigint biginteger binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array booleans bound-fn bound-fn* bound? butlast byte byte-array bytes case cast char char-array char-escape-string char-name-string char? chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? class class? clear-agent-errors clojure-version coll? comment commute comp comparator compare compare-and-set! compile complement concat cond condp conj conj! cons constantly construct-proxy contains? count counted? create-ns create-struct cycle dec dec' decimal? declare default-data-readers definline definterface defmacro defmethod defmulti defn defn- defonce defprotocol defrecord defstruct deftype delay delay? deliver denominator deref derive descendants destructure disj disj! dissoc dissoc! distinct distinct? doall dorun doseq dosync dotimes doto double double-array doubles drop drop-last drop-while empty empty? ensure enumeration-seq error-handler error-mode eval even? every-pred every? ex-data ex-info extend extend-protocol extend-type extenders extends? false? ffirst file-seq filter filterv find find-keyword find-ns find-protocol-impl find-protocol-method find-var first flatten float float-array float? floats flush fn fn? fnext fnil for force format frequencies future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface gensym get get-in get-method get-proxy-class get-thread-bindings get-validator group-by hash hash-combine hash-map hash-set identical? identity if-let if-not ifn? import in-ns inc inc' init-proxy instance? int int-array integer? interleave intern interpose into into-array ints io! isa? iterate iterator-seq juxt keep keep-indexed key keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list* list? load load-file load-reader load-string loaded-libs locking long long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy map map-indexed map? mapcat mapv max max-key memfn memoize merge merge-with meta method-sig methods min min-key mod munge name namespace namespace-munge neg? newline next nfirst nil? nnext not not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth nthnext nthrest num number? numerator object-array odd? or parents partial partition partition-all partition-by pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str prefer-method prefers primitives-classnames print print-ctor print-dup print-method print-simple print-str printf println println-str prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot rand rand-int rand-nth range ratio? rational? rationalize re-find re-groups re-matcher re-matches re-pattern re-seq read read-line read-string realized? reduce reduce-kv reductions ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure reify release-pending-sends rem remove remove-all-methods remove-method remove-ns remove-watch repeat repeatedly replace replicate require reset! reset-meta! resolve rest restart-agent resultset-seq reverse reversible? rseq rsubseq satisfies? second select-keys send send-off seq seq? seque sequence sequential? set set-error-handler! set-error-mode! set-validator! set? short short-array shorts shuffle shutdown-agents slurp some some-fn sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-symbol? spit split-at split-with str string? struct struct-map subs subseq subvec supers swap! symbol symbol? sync take take-last take-nth take-while test the-ns thread-bound? time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-add-int unchecked-byte unchecked-char unchecked-dec unchecked-dec-int unchecked-divide-int unchecked-double unchecked-float unchecked-inc unchecked-inc-int unchecked-int unchecked-long unchecked-multiply unchecked-multiply-int unchecked-negate unchecked-negate-int unchecked-remainder-int unchecked-short unchecked-subtract unchecked-subtract-int underive unquote unquote-splicing update-in update-proxy use val vals var-get var-set var? vary-meta vec vector vector-of vector? when when-first when-let when-not while with-bindings with-bindings* with-in-str with-loading-context with-local-vars with-meta with-open with-out-str with-precision with-redefs with-redefs-fn xml-seq zero? zipmap *default-data-reader-fn* as-> cond-> cond->> reduced reduced? send-via set-agent-send-executor! set-agent-send-off-executor! some-> some->>");

var indentKeys = makeKeywords(
// Built-ins
Expand Down Expand Up @@ -95,6 +95,20 @@ CodeMirror.defineMode("clojure", function () {
return false;
}

// Eat character that starts after backslash \
function eatCharacter(stream) {
var first = stream.next();
// Read special literals: backspace, newline, space, return.
// Just read all lowercase letters.
if (first.match(/[a-z]/) && stream.match(/[a-z]+/, true)) {
return;
}
// Read unicode character: \u1000 \uA0a1
if (first === "u") {
stream.match(/[0-9a-z]{4}/i, true);
}
}

return {
startState: function () {
return {
Expand Down Expand Up @@ -135,6 +149,9 @@ CodeMirror.defineMode("clojure", function () {
if (ch == "\"") {
state.mode = "string";
returnType = STRING;
} else if (ch == "\\") {
eatCharacter(stream);
returnType = CHARACTER;
} else if (ch == "'" && !( tests.digit_or_colon.test(stream.peek()) )) {
returnType = ATOM;
} else if (ch == ";") { // comment
Expand Down
23 changes: 16 additions & 7 deletions mode/clojure/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ <h1>CodeMirror: Clojure mode</h1>

;; Core game of life's algorithm functions

(defn neighbours
(defn neighbours
"Given a cell's coordinates, returns the coordinates of its neighbours."
[[x y]]
(for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
[(+ dx x) (+ dy y)]))

(defn step
(defn step
"Given a set of living cells, computes the new set of living cells."
[cells]
(set (for [[cell n] (frequencies (mapcat neighbours cells))
Expand All @@ -36,14 +36,14 @@ <h1>CodeMirror: Clojure mode</h1>

;; Utility methods for displaying game on a text terminal

(defn print-board
(defn print-board
"Prints a board on *out*, representing a step in the game."
[board w h]
(doseq [x (range (inc w)) y (range (inc h))]
(if (= y 0) (print "\n"))
(if (= y 0) (print "\n"))
(print (if (board [x y]) "[X]" " . "))))

(defn display-grids
(defn display-grids
"Prints a squence of boards on *out*, representing several steps."
[grids w h]
(doseq [board grids]
Expand All @@ -52,11 +52,20 @@ <h1>CodeMirror: Clojure mode</h1>

;; Launches an example board

(def
(def
^{:doc "board represents the initial set of living cells"}
board #{[2 1] [2 2] [2 3]})

(display-grids (take 3 (iterate step board)) 5 5) </textarea></form>
(display-grids (take 3 (iterate step board)) 5 5)

;; Let's play with characters
(println \1 \a \# \\
\" \( \newline
\} \" \space
\tab \return \backspace
\u1000 \uAaAa \u9F9F)

</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
</script>
Expand Down
Loading