17 changes: 10 additions & 7 deletions addon/hint/show-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@
var baseMap = {
Up: function() {handle.moveFocus(-1);},
Down: function() {handle.moveFocus(1);},
PageUp: function() {handle.moveFocus(-handle.menuSize());},
PageDown: function() {handle.moveFocus(handle.menuSize());},
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
Home: function() {handle.setFocus(0);},
End: function() {handle.setFocus(handle.length);},
End: function() {handle.setFocus(handle.length - 1);},
Enter: handle.pick,
Tab: handle.pick,
Esc: handle.close
Expand Down Expand Up @@ -167,6 +167,7 @@
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
(options.container || document.body).appendChild(hints);
var box = hints.getBoundingClientRect();
var overlapX = box.right - winW, overlapY = box.bottom - winH;
if (overlapX > 0) {
Expand All @@ -187,10 +188,9 @@
}
hints.style.top = (top = pos.bottom - overlapY) + "px";
}
(options.container || document.body).appendChild(hints);

cm.addKeyMap(this.keyMap = buildKeyMap(options, {
moveFocus: function(n) { widget.changeActive(widget.selectedHint + n); },
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
setFocus: function(n) { widget.changeActive(n); },
menuSize: function() { return widget.screenAmount(); },
length: completions.length,
Expand Down Expand Up @@ -250,8 +250,11 @@
this.completion.pick(this.data, this.selectedHint);
},

changeActive: function(i) {
i = Math.max(0, Math.min(i, this.data.list.length - 1));
changeActive: function(i, avoidWrap) {
if (i >= this.data.list.length)
i = avoidWrap ? this.data.list.length - 1 : 0;
else if (i < 0)
i = avoidWrap ? 0 : this.data.list.length - 1;
if (this.selectedHint == i) return;
var node = this.hints.childNodes[this.selectedHint];
node.className = node.className.replace(" CodeMirror-hint-active", "");
Expand Down
17 changes: 17 additions & 0 deletions addon/lint/css-lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Depends on csslint.js from https://github.com/stubbornella/csslint

CodeMirror.registerHelper("lint", "css", function(text) {
var found = [];
var results = CSSLint.verify(text), messages = results.messages, message = null;
for ( var i = 0; i < messages.length; i++) {
message = messages[i];
var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
found.push({
from: CodeMirror.Pos(startLine, startCol),
to: CodeMirror.Pos(endLine, endCol),
message: message.message,
severity : message.type
});
}
return found;
});
30 changes: 3 additions & 27 deletions addon/lint/lint.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,16 @@
}

.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
background-image: url("data:image/gif;base64,R0lGODlhEAAQANUAAPVvcvWHiPVucvRuc+ttcfV6f91KVN5LU99PV/FZY/JhaM4oN84pONE4Rd1ATfJLWutVYPRgbdxpcsgWKMgZKs4lNfE/UvE/U+artcpdSc5uXveimslHPuBhW/eJhfV5efaCgO2CgP+/v+PExP///////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAACUALAAAAAAQABAAAAZ+wJJwSCwaScgkySgkjTQZTkYzWhadnE5oE+pwqkSshwQqkzxfa4kkQXxEpA9J9EFI1KQGQQBAigYCBA14ExEWF0gXihETeA0QD3AkD5QQg0NsDnAJmwkOd5gYFSQKpXAFDBhqaxgLBwQBBAapq00YEg0UDRKqTGtKSL7Cw8JBADs=");
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
}

.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
background-image: url("data:image/gif;base64,R0lGODlhEAAQANUAAP7bc//egf/ij/7ijv/jl/7kl//mnv7lnv/uwf7CTP7DTf7DT/7IW//Na/7Na//NbP7QdP/dmbltAIJNAF03AMSAJMSCLKqASa2DS6uBSquCSrGHTq6ETbCHT7WKUrKIUcCVXL+UXMOYX8GWXsSZYMiib6+ETbOIUcOXX86uhd3Muf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAACsALAAAAAAQABAAAAZowJVwSCwaj0ihikRSJYcoBEL0XKlGkcjImQQhJBREKFnyICoThKeE/AAW6AXgdPyUAgrLJBEo0YsbAQyDhAEdRRwDDw8OaA4NDQImRBgFEJdglxAEGEQZKQcHBqOkKRpFF6mqq1WtrUEAOw==");
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
}

.CodeMirror-lint-marker-multiple {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAAAXNSR0IArs4c6QAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJEAQvB2JVdrAAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAD1JREFUCNdtjkESADAEAzemf69f66HMqGlOIhYiFRFRtSQBWAY7mzx+EDTL6sSgb1jTk7Q87rxyqe37fXsAa78gLyZnRgEAAAAASUVORK5CYII=");
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
background-repeat: no-repeat;
background-position: right bottom;
width: 100%; height: 100%;
}

/* Styles for the overview ruler
.annotationOverview {
cursor: pointer;
border-radius: 2px;
left: 2px;
width: 8px;
}
.annotationOverview.error {
background-color: lightcoral;
border: 1px solid darkred;
}
.annotationOverview.warning {
background-color: Gold;
border: 1px solid black;
}
.annotationHTML.overlay {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAAAXNSR0IArs4c6QAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJEAQvB2JVdrAAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAD1JREFUCNdtjkESADAEAzemf69f66HMqGlOIhYiFRFRtSQBWAY7mzx+EDTL6sSgb1jTk7Q87rxyqe37fXsAa78gLyZnRgEAAAAASUVORK5CYII=");
background-position: right bottom;
position: relative;
top: -16px;
}
*/
2 changes: 1 addition & 1 deletion addon/lint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
if (options.async)
options.getAnnotations(cm, updateLinting, options);
else
updateLinting(cm, options.getAnnotations(cm.getValue()));
updateLinting(cm, options.getAnnotations(cm.getValue(), options));
}

function updateLinting(cm, annotationsNotSorted) {
Expand Down
38 changes: 32 additions & 6 deletions addon/merge/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,56 @@
this.diff = getDiff(orig, options.value);
this.diffOutOfDate = false;

this.showDifferences = options.showDifferences !== false;
this.forceUpdate = registerUpdate(this);
setScrollLock(this, true, false);
registerScroll(this);
},
setShowDifferences: function(val) {
val = val !== false;
if (val != this.showDifferences) {
this.showDifferences = val;
this.forceUpdate("full");
}
}
};

function registerUpdate(dv) {
var edit = {from: 0, to: 0, marked: []};
var orig = {from: 0, to: 0, marked: []};
var debounceChange;
function update() {
function update(mode) {
if (mode == "full") {
if (dv.svg) clear(dv.svg);
clear(dv.copyButtons);
clearMarks(dv.edit, edit.marked, dv.classes);
clearMarks(dv.orig, orig.marked, dv.classes);
edit.from = edit.to = orig.from = orig.to = 0;
}
if (dv.diffOutOfDate) {
dv.diff = getDiff(dv.orig.getValue(), dv.edit.getValue());
dv.diffOutOfDate = false;
CodeMirror.signal(dv.edit, "updateDiff", dv.diff);
}
if (dv.showDifferences) {
updateMarks(dv.edit, dv.diff, edit, DIFF_INSERT, dv.classes);
updateMarks(dv.orig, dv.diff, orig, DIFF_DELETE, dv.classes);
}
updateMarks(dv.edit, dv.diff, edit, DIFF_INSERT, dv.classes);
updateMarks(dv.orig, dv.diff, orig, DIFF_DELETE, dv.classes);
drawConnectors(dv);
}
function set(slow) {
clearTimeout(debounceChange);
debounceChange = setTimeout(update, slow == true ? 250 : 100);
}
dv.edit.on("change", function() {
function change() {
if (!dv.diffOutOfDate) {
dv.diffOutOfDate = true;
edit.from = edit.to = orig.from = orig.to = 0;
}
set(true);
});
}
dv.edit.on("change", change);
dv.orig.on("change", change);
dv.edit.on("viewportChange", set);
dv.orig.on("viewportChange", set);
update();
Expand Down Expand Up @@ -211,6 +231,8 @@
// Updating the gap between editor and original

function drawConnectors(dv) {
if (!dv.showDifferences) return;

if (dv.svg) {
clear(dv.svg);
var w = dv.gap.offsetWidth;
Expand Down Expand Up @@ -322,7 +344,11 @@
constuctor: MergeView,
editor: function() { return this.edit; },
rightOriginal: function() { return this.right && this.right.orig; },
leftOriginal: function() { return this.left && this.left.orig; }
leftOriginal: function() { return this.left && this.left.orig; },
setShowDifferences: function(val) {
if (this.right) this.right.setShowDifferences(val);
if (this.left) this.left.setShowDifferences(val);
}
};

// Operations on diffs
Expand Down
2 changes: 1 addition & 1 deletion addon/runmode/runmode-standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ CodeMirror.runMode = function (string, modespec, callback, options) {
var stream = new CodeMirror.StringStream(lines[i]);
while (!stream.eol()) {
var style = mode.token(stream, state);
callback(stream.current(), style, i, stream.start);
callback(stream.current(), style, i, stream.start, state);
stream.start = stream.pos;
}
}
Expand Down
2 changes: 1 addition & 1 deletion addon/runmode/runmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CodeMirror.runMode = function(string, modespec, callback, options) {
var stream = new CodeMirror.StringStream(lines[i]);
while (!stream.eol()) {
var style = mode.token(stream, state);
callback(stream.current(), style, i, stream.start);
callback(stream.current(), style, i, stream.start, state);
stream.start = stream.pos;
}
}
Expand Down
2 changes: 1 addition & 1 deletion addon/runmode/runmode.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ exports.runMode = function(string, modespec, callback) {
var stream = new exports.StringStream(lines[i]);
while (!stream.eol()) {
var style = mode.token(stream, state);
callback(stream.current(), style, i, stream.start);
callback(stream.current(), style, i, stream.start, state);
stream.start = stream.pos;
}
}
Expand Down
4 changes: 2 additions & 2 deletions addon/search/searchcursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
this.matches = function(reverse, pos) {
var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(doc.getLine(ln));
var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
if (reverse ? offsetA >= pos.ch || offsetA != match.length
: offsetA <= pos.ch || offsetA != line.length - match.length)
if (reverse ? offsetA > pos.ch || offsetA != match.length
: offsetA < pos.ch || offsetA != line.length - match.length)
return;
for (;;) {
if (reverse ? !ln : ln == doc.lineCount() - 1) return;
Expand Down
35 changes: 29 additions & 6 deletions addon/tern/tern.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
// no tip should be shown. By default the docstring is shown.
// * typeTip: Like completionTip, but for the tooltips shown for type
// queries.
// * responseFilter: A function(doc, query, request, error, data) that
// will be applied to the Tern responses before treating them
//
//
// It is possible to run the Tern server in a web worker by specifying
// these additional options:
Expand Down Expand Up @@ -102,8 +105,16 @@

rename: function(cm) { rename(this, cm); },

request: function(cm, query, c) {
this.server.request(buildRequest(this, findDoc(this, cm.getDoc()), query), c);
request: function (cm, query, c) {
var self = this;
var doc = findDoc(this, cm.getDoc());
var request = buildRequest(this, doc, query);

this.server.request(request, function (error, data) {
if (!error && self.options.responseFilter)
data = self.options.responseFilter(doc, query, request, error, data);
c(error, data);
});
}
};

Expand Down Expand Up @@ -233,12 +244,24 @@
closeArgHints(ts);

if (cm.somethingSelected()) return;
var lex = cm.getTokenAt(cm.getCursor()).state.lexical;
var state = cm.getTokenAt(cm.getCursor()).state;
var inner = CodeMirror.innerMode(cm.getMode(), state);
if (inner.mode.name != "javascript") return;
var lex = inner.state.lexical;
if (lex.info != "call") return;

var ch = lex.column, pos = lex.pos || 0;
for (var line = cm.getCursor().line, e = Math.max(0, line - 9), found = false; line >= e; --line)
if (cm.getLine(line).charAt(ch) == "(") {found = true; break;}
var ch, pos = lex.pos || 0, tabSize = cm.getOption("tabSize");
for (var line = cm.getCursor().line, e = Math.max(0, line - 9), found = false; line >= e; --line) {
var str = cm.getLine(line), extra = 0;
for (var pos = 0;;) {
var tab = str.indexOf("\t", pos);
if (tab == -1) break;
extra += tabSize - (tab + extra) % tabSize - 1;
pos = tab + 1;
}
ch = lex.column - extra;
if (str.charAt(ch) == "(") {found = true; break;}
}
if (!found) return;

var start = Pos(line, ch);
Expand Down
5 changes: 3 additions & 2 deletions bin/lint
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node

var lint = require("../test/lint/lint");
var lint = require("../test/lint/lint"),
path = require("path");

if (process.argv.length > 2) {
lint.checkDir(process.argv[2]);
} else {
process.chdir(__dirname.slice(0, __dirname.lastIndexOf("/")));
process.chdir(path.resolve(__dirname, ".."));
lint.checkDir("lib");
lint.checkDir("mode");
lint.checkDir("addon");
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CodeMirror",
"version": "3.16.0",
"version": "3.17.0",
"main": ["lib/codemirror.js", "lib/codemirror.css"],
"ignore": [
"**/.*",
Expand Down
2 changes: 1 addition & 1 deletion demo/complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h2>Autocomplete Demo</h2>
<script>
CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.javascript);
}
};
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
extraKeys: {"Ctrl-Space": "autocomplete"}
Expand Down
70 changes: 70 additions & 0 deletions demo/lint.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
<link rel="stylesheet" href="../addon/lint/lint.css">
<script src="../lib/codemirror.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<script src="../mode/css/css.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js"></script>
<script src="https://rawgithub.com/zaach/jsonlint/79b553fb65c192add9066da64043458981b3972b/lib/jsonlint.js"></script>
<script src="https://rawgithub.com/stubbornella/csslint/master/release/csslint.js"></script>
<script src="../addon/lint/lint.js"></script>
<script src="../addon/lint/javascript-lint.js"></script>
<script src="../addon/lint/json-lint.js"></script>
<script src="../addon/lint/css-lint.js"></script>
<style type="text/css">
.CodeMirror {border: 1px solid black;}
</style>
Expand Down Expand Up @@ -82,6 +85,66 @@ <h2>Linter Demo</h2>
]
</textarea></p>

<p><textarea id="code-css">@charset "UTF-8";

@import url("booya.css") print, screen;
@import "whatup.css" screen;
@import "wicked.css";

/*Error*/
@charset "UTF-8";


@namespace "http://www.w3.org/1999/xhtml";
@namespace svg "http://www.w3.org/2000/svg";

/*Warning: empty ruleset */
.foo {
}

h1 {
font-weight: bold;
}

/*Warning: qualified heading */
.foo h1 {
font-weight: bold;
}

/*Warning: adjoining classes */
.foo.bar {
zoom: 1;
}

li.inline {
width: 100%; /*Warning: 100% can be problematic*/
}

li.last {
display: inline;
padding-left: 3px !important;
padding-right: 3px;
border-right: 0px;
}

@media print {
li.inline {
color: black;
}
}

@page {
margin: 10%;
counter-increment: page;

@top-center {
font-family: sans-serif;
font-weight: bold;
font-size: 2em;
content: counter(page);
}
}
</textarea></p>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code-js"), {
lineNumbers: true,
Expand All @@ -96,6 +159,13 @@ <h2>Linter Demo</h2>
gutters: ["CodeMirror-lint-markers"],
lint: true
});

var editor_css = CodeMirror.fromTextArea(document.getElementById("code-css"), {
lineNumbers: true,
mode: "css",
gutters: ["CodeMirror-lint-markers"],
lint: true
});
</script>

</article>
22 changes: 3 additions & 19 deletions demo/marker.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,19 @@ <h2>Breakpoint Demo</h2>
});
editor.on("gutterClick", function(cm, n) {
var info = cm.lineInfo(n);
cm.setGutterMarker(n, "breakpoints", info.markers ? null : makeMarker());
cm.setGutterMarker(n, "breakpoints", info.gutterMarkers ? null : makeMarker());
});

function makeMarker() {
var marker = document.createElement("div");
marker.style.color = "#822";
marker.innerHTML = "â—Ź";
marker.className = "breakpoint";
return marker;
}
</textarea></form>

<p>Click the line-number gutter to add or remove 'breakpoints'.</p>

<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
gutters: ["CodeMirror-linenumbers", "breakpoints"]
});
editor.on("gutterClick", function(cm, n) {
var info = cm.lineInfo(n);
cm.setGutterMarker(n, "breakpoints", info.gutterMarkers ? null : makeMarker());
});

function makeMarker() {
var marker = document.createElement("div");
marker.style.color = "#822";
marker.innerHTML = "â—Ź";
return marker;
}
</script>
<script>eval(document.getElementById("code").value);</script>

</article>
6 changes: 3 additions & 3 deletions demo/markselection.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>

<title>CodeMirror: Match Highlighter Demo</title>
<title>CodeMirror: Match Selection Demo</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../doc/docs.css">

Expand All @@ -22,12 +22,12 @@
<li><a href="https://github.com/marijnh/codemirror">Code</a>
</ul>
<ul>
<li><a class=active href="#">Match Highlighter</a>
<li><a class=active href="#">Match Selection</a>
</ul>
</div>

<article>
<h2>Match Highlighter Demo</h2>
<h2>Match Selection Demo</h2>
<form><textarea id="code" name="code">Select something from here.
You'll see that the selection's foreground color changes to white!
Since, by default, CodeMirror only puts an independent "marker" layer
Expand Down
2 changes: 1 addition & 1 deletion demo/matchtags.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2>Tag Matcher Demo</h2>
editor = CodeMirror(document.getElementById("editor"), {
value: "<html>\n " + document.documentElement.innerHTML + "\n</html>",
mode: "text/html",
matchTags: true,
matchTags: {bothTags: true},
extraKeys: {"Ctrl-J": "toMatchingTag"}
});
};
Expand Down
12 changes: 8 additions & 4 deletions demo/merge.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ <h2>merge view demo</h2>
either <span class=clicky onclick="initUI(2)">two-way</span>
or <span class=clicky onclick="initUI(3)">three-way</span>. The left
(or center) pane is editable, and the differences with the other
pane(s) are shown live as you edit it.</p>
pane(s) are <span class=clicky onclick="toggleDifferences()">optionally</span> shown live as you edit it.</p>

<p>This addon depends on
the <a href="https://code.google.com/p/google-diff-match-patch/">google-diff-match-patch</a>
library to compute the diffs.</p>

<script>
var value, orig1, orig2, dv;

var value, orig1, orig2, dv, hilight= true;
function initUI(panes) {
if (value == null) return;
var target = document.getElementById("view");
Expand All @@ -63,10 +62,15 @@ <h2>merge view demo</h2>
origLeft: panes == 3 ? orig1 : null,
orig: orig2,
lineNumbers: true,
mode: "text/html"
mode: "text/html",
highlightDifferences: hilight
});
}

function toggleDifferences() {
dv.setShowDifferences(hilight = !hilight);
}

window.onload = function() {
value = document.documentElement.innerHTML;
orig1 = value.replace(/\.\.\//g, "codemirror/").replace("yellow", "orange");
Expand Down
2 changes: 1 addition & 1 deletion demo/spanaffectswrapping_shim.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h2>Automatically derive odd wrapping behavior for your browser</h2>

<script id="script">
var a = document.getElementById("area"), bad = Object.create(null);
var chars = "a~`!@#$%^&*()-_=+}{[]\|'\"/?.>,<:;", l = chars.length;
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));
Expand Down
7 changes: 7 additions & 0 deletions doc/compress.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h2>Script compression helper</h2>
<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=3.17.0;f=">3.17</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=3.16.0;f=">3.16</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=3.15.0;f=">3.15</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=3.14.0;f=">3.14</option>
Expand Down Expand Up @@ -86,8 +87,10 @@ <h2>Script compression helper</h2>
<option value="http://codemirror.net/mode/css/css.js">css.js</option>
<option value="http://codemirror.net/mode/d/d.js">d.js</option>
<option value="http://codemirror.net/mode/diff/diff.js">diff.js</option>
<option value="http://codemirror.net/mode/dtd/dtd.js">dtd.js</option>
<option value="http://codemirror.net/mode/ecl/ecl.js">ecl.js</option>
<option value="http://codemirror.net/mode/erlang/erlang.js">erlang.js</option>
<option value="http://codemirror.net/mode/fortran/fortran.js">fortran.js</option>
<option value="http://codemirror.net/mode/gfm/gfm.js">gfm.js</option>
<option value="http://codemirror.net/mode/gas/gas.js">gas.js</option>
<option value="http://codemirror.net/mode/go/go.js">go.js</option>
Expand All @@ -109,6 +112,7 @@ <h2>Script compression helper</h2>
<option value="http://codemirror.net/mode/nginx/nginx.js">nginx.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/octave/octave.js">octave.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>
Expand Down Expand Up @@ -136,6 +140,7 @@ <h2>Script compression helper</h2>
<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/toml/toml.js">toml.js</option>
<option value="http://codemirror.net/mode/turtle/turtle.js">turtle.js</option>
<option value="http://codemirror.net/mode/vb/vb.js">vb.js</option>
<option value="http://codemirror.net/mode/vbscript/vbscript.js">vbscript.js</option>
Expand All @@ -156,8 +161,10 @@ <h2>Script compression helper</h2>
<option value="http://codemirror.net/addon/fold/comment-fold.js">comment-fold.js</option>
<option value="http://codemirror.net/addon/comment/continuecomment.js">continuecomment.js</option>
<option value="http://codemirror.net/addon/edit/continuelist.js">continuelist.js</option>
<option value="http://codemirror.net/addon/hint/css-hint.js">css-hint.js</option>
<option value="http://codemirror.net/addon/dialog/dialog.js">dialog.js</option>
<option value="http://codemirror.net/addon/fold/foldcode.js">foldcode.js</option>
<option value="http://codemirror.net/addon/fold/foldgutter.js">foldgutter.js</option>
<option value="http://codemirror.net/addon/display/fullscreen.js">fullscreen.js</option>
<option value="http://codemirror.net/addon/hint/html-hint.js">html-hint.js</option>
<option value="http://codemirror.net/addon/fold/indent-fold.js">indent-fold.js</option>
Expand Down
1 change: 1 addition & 0 deletions doc/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ article {
}

#logo {
border: 0;
margin-right: 7px;
margin-bottom: 25px;
}
Expand Down
28 changes: 27 additions & 1 deletion doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,21 @@ <h2>Configuration</h2>
<dd>When highlighting long lines, in order to stay responsive,
the editor will give up and simply style the rest of the line as
plain text when it reaches a certain position. The default is
10000. You can set this to <code>Infinity</code> to turn off
10 000. You can set this to <code>Infinity</code> to turn off
this behavior.</dd>

<dt id="option_crudeMeasuringFrom"><code><strong>crudeMeasuringFrom</strong>: number</code></dt>
<dd>When measuring the character positions in long lines, any
line longer than this number (default is 10 000),
when <a href="#option_lineWrapping">line wrapping</a>
is <strong>off</strong>, will simply be assumed to consist of
same-sized characters. This means that, on the one hand,
measuring will be inaccurate when characters of varying size,
right-to-left text, markers, or other irregular elements are
present. On the other hand, it means that having such a line
won't freeze the user interface because of the expensiveness of
the measurements.</dd>

<dt id="option_viewportMargin"><code><strong>viewportMargin</strong>: integer</code></dt>
<dd>Specifies the amount of lines that are rendered above and
below the part of the document that's currently scrolled into
Expand Down Expand Up @@ -502,6 +514,16 @@ <h2>Events</h2>
argument, and the raw <code>mousedown</code> event object as
fourth argument.</dd>

<dt id="event_gutterContextMenu"><code><strong>"gutterContextMenu"</strong> (instance: CodeMirror, line: integer, gutter: string, contextMenu: Event: Event)</code></dt>
<dd>Fires when the editor gutter (the line-number area)
receives a <code>contextmenu</code> event. Will pass the editor
instance as first argument, the (zero-based) number of the line
that was clicked as second argument, the CSS class of the
gutter that was clicked as third argument, and the raw
<code>contextmenu</code> mouse event object as fourth argument.
You can <code>preventDefault</code> the event, to signal that
CodeMirror should do no further handling.</dd>

<dt id="event_focus"><code><strong>"focus"</strong> (instance: CodeMirror)</code></dt>
<dd>Fires whenever the editor is focused.</dd>

Expand Down Expand Up @@ -2027,6 +2049,10 @@ <h2>Addons</h2>
schema data. See
the <a href="../demo/html5complete.html">demo</a>.</dd>

<dt id="addon_css-hint"><a href="../addon/hint/css-hint.js"><code>hint/css-hint.js</code></a></dt>
<dd>A minimal hinting function for CSS code.
Defines <code>CodeMirror.hint.css</code>.</dd>

<dt id="addon_python-hint"><a href="../addon/hint/python-hint.js"><code>hint/python-hint.js</code></a></dt>
<dd>A very simple hinting function for Python code.
Defines <code>CodeMirror.hint.python</code>.</dd>
Expand Down
3 changes: 3 additions & 0 deletions doc/realworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ <h2>CodeMirror real-world uses</h2>
<li><a href="http://mongo-mapreduce-webbrowser.opensagres.cloudbees.net/">Mongo MapReduce WebBrowser</a></li>
<li><a href="https://www.my2ndgeneration.com/">My2ndGeneration</a> (social coding)</li>
<li><a href="http://www.navigatecms.com">Navigate CMS</a></li>
<li><a href="https://github.com/soliton4/nodeMirror">nodeMirror</a> (IDE project)</li>
<li><a href="https://notex.ch">NoTex</a> (rST authoring)</li>
<li><a href="http://oakoutliner.com">Oak</a> (online outliner)</li>
<li><a href="http://clrhome.org/asm/">ORG</a> (z80 assembly IDE)</li>
Expand All @@ -104,10 +105,12 @@ <h2>CodeMirror real-world uses</h2>
<li><a href="http://www.solidshops.com/">SolidShops</a> (hosted e-commerce platform)</li>
<li><a href="http://sqlfiddle.com">SQLFiddle</a> (SQL playground)</li>
<li><a href="https://thefiletree.com">The File Tree</a> (collab editor)</li>
<li><a href="http://www.mapbox.com/tilemill/">TileMill</a> (map design tool)</li>
<li><a href="http://www.toolsverse.com/products/data-explorer/">Toolsverse Data Explorer</a> (database management)</li>
<li><a href="http://enjalot.com/tributary/2636296/sinwaves.js">Tributary</a> (augmented editing)</li>
<li><a href="http://blog.englard.net/post/39608000629/codeintumblr">Tumblr code highlighting shim</a></li>
<li><a href="http://turbopy.com/">TurboPY</a> (web publishing framework)</li>
<li><a href="http://uicod.com/">uiCod</a> (animation demo gallery and sharing)</li>
<li><a href="http://cruise.eecs.uottawa.ca/umpleonline/">UmpleOnline</a> (model-oriented programming tool)</li>
<li><a href="https://upsource.jetbrains.com/#idea/view/923f30395f2603cd9f42a32bcafd13b6c28de0ff/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ReplaceAbstractClassInstanceByMapIntention.java">Upsource</a> (code viewer)</li>
<li><a href="http://www.webglacademy.com/">WebGL academy</a> (learning WebGL)</li>
Expand Down
9 changes: 9 additions & 0 deletions doc/releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ <h2>Release notes and version history</h2>

<h2>Version 3.x</h2>

<p class="rel">23-09-2013: <a href="http://codemirror.net/codemirror-3.17.zip">Version 3.17</a>:</p>

<ul class="rel-note">
<li>New modes: <a href="../mode/fortran/index.html">Fortran</a>, <a href="../mode/octave/index.html">Octave</a> (Matlab), <a href="../mode/toml/index.html">TOML</a>, and <a href="../mode/dtd/index.html">DTD</a>.</li>
<li>New addons: <a href="../addon/lint/css-lint.js"><code>css-lint</code></a>, <a href="manual.html#addon_css-hint"><code>css-hint</code></a>.</li>
<li>Improve resilience to CSS 'frameworks' that globally mess up <code>box-sizing</code>.</li>
<li>Full <a href="https://github.com/marijnh/CodeMirror/compare/3.16.0...3.17.0">list of patches</a>.</li>
</ul>

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

<ul class="rel-note">
Expand Down
8 changes: 6 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ <h2>This is CodeMirror</h2>
<option value="mode/htmlmixed/index.html">Mixed language modes</option>
<option value="demo/bidi.html">Bi-directional text</option>
<option value="demo/variableheight.html">Variable font sizes</option>
<option value="demo/search.html">Search interface</option>
<option value="demo/vim.html">Vim bindings</option>
<option value="demo/emacs.html">Emacs bindings</option>
<option value="demo/tern.html">Tern integration</option>
<option value="demo/merge.html">Merge/diff interface</option>
<option value="demo/fullscreen.html">Full-screen editor</option>
</select></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("demotext"), {
Expand All @@ -80,7 +84,7 @@ <h2>This is CodeMirror</h2>
</script>
<div style="position: relative; margin: 1em 0;">
<a class="bigbutton left" href="http://codemirror.net/codemirror.zip">DOWNLOAD LATEST RELEASE</a>
<div><strong>version 3.15</strong> (<a href="doc/releases.html">Release notes</a>)</div>
<div><strong>version 3.17</strong> (<a href="doc/releases.html">Release notes</a>)</div>
<div>or use the <a href="doc/compress.html">minification helper</a></div>
<div style="position: absolute; top: 0; right: 0; text-align: right">
<span class="bigbutton right" onclick="document.getElementById('paypal').submit();">DONATE WITH PAYPAL</span>
Expand Down Expand Up @@ -125,7 +129,7 @@ <h2>Features</h2>
<li><a href="demo/variableheight.html">Mixing font sizes and styles</a>
<li><a href="demo/theme.html">Various themes</a>
<li>Able to <a href="demo/resize.html">resize to fit content</a>
<li><a href="doc/manual.html#mark_replacedWith">Inline</a> and <a href="doc/manual.html#setLineWidget">block</a> widgets
<li><a href="doc/manual.html#mark_replacedWith">Inline</a> and <a href="doc/manual.html#addLineWidget">block</a> widgets
<li>Programmable <a href="demo/marker.html">gutters</a>
<li>Making ranges of text <a href="doc/manual.html#markText">styled, read-only, or atomic</a>
<li><a href="demo/bidi.html">Bi-directional text</a> support
Expand Down
13 changes: 13 additions & 0 deletions keymap/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
* TODO: Implement the remaining special marks. They have more complex
* behavior.
*
* Events:
* 'vim-mode-change' - raised on the editor anytime the current mode changes,
* Event object: {mode: "visual", subMode: "linewise"}
*
* Code structure:
* 1. Default keymap
* 2. Variable declarations and short basic helpers
Expand Down Expand Up @@ -318,6 +322,7 @@
CodeMirror.defineOption('vimMode', false, function(cm, val) {
if (val) {
cm.setOption('keyMap', 'vim');
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
cm.on('beforeSelectionChange', beforeSelectionChange);
maybeInitVimState(cm);
} else if (cm.state.vim) {
Expand Down Expand Up @@ -579,6 +584,7 @@
!cursorEqual(cm.getCursor('head'), cm.getCursor('anchor'))) {
vim.visualMode = true;
vim.visualLine = false;
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual"});
cm.on('mousedown', exitVisualMode);
}
if (key != '0' || (key == '0' && vim.inputState.getRepeat() === 0)) {
Expand Down Expand Up @@ -1651,8 +1657,10 @@
// Handle Replace-mode as a special case of insert mode.
cm.toggleOverwrite(true);
cm.setOption('keyMap', 'vim-replace');
CodeMirror.signal(cm, "vim-mode-change", {mode: "replace"});
} else {
cm.setOption('keyMap', 'vim-insert');
CodeMirror.signal(cm, "vim-mode-change", {mode: "insert"});
}
if (!vimGlobalState.macroModeState.inReplay) {
// Only record if not replaying.
Expand Down Expand Up @@ -1694,6 +1702,7 @@
} else {
cm.setSelection(curStart, curEnd);
}
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual", subMode: vim.visualLine ? "linewise" : ""});
} else {
curStart = cm.getCursor('anchor');
curEnd = cm.getCursor('head');
Expand All @@ -1706,10 +1715,12 @@
curEnd.ch = cursorIsBefore(curStart, curEnd) ?
lineLength(cm, curEnd.line) : 0;
cm.setSelection(curStart, curEnd);
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual", subMode: "linewise"});
} else if (vim.visualLine && !actionArgs.linewise) {
// v pressed in linewise visual mode. Switch to characterwise visual
// mode instead of exiting visual mode.
vim.visualLine = false;
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual"});
} else {
exitVisualMode(cm);
}
Expand Down Expand Up @@ -2022,6 +2033,7 @@
// it's not supposed to be.
cm.setCursor(clipCursorToContent(cm, selectionEnd));
}
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
}

// Remove any trailing newlines from the selection. For
Expand Down Expand Up @@ -3444,6 +3456,7 @@
vim.insertMode = false;
cm.setOption('keyMap', 'vim');
cm.toggleOverwrite(false); // exit replace mode if we were in it.
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
}

CodeMirror.keyMap['vim-insert'] = {
Expand Down
10 changes: 7 additions & 3 deletions lib/codemirror.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
height: 100%;
outline: none; /* Prevent dragging from highlighting the element */
position: relative;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
.CodeMirror-sizer {
position: relative;
Expand Down Expand Up @@ -156,6 +158,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
.CodeMirror-gutter {
white-space: normal;
height: 100%;
-moz-box-sizing: content-box;
box-sizing: content-box;
padding-bottom: 30px;
margin-bottom: -32px;
display: inline-block;
Expand Down Expand Up @@ -215,16 +219,16 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
overflow: auto;
}

.CodeMirror-widget {
}
.CodeMirror-widget {}

.CodeMirror-wrap .CodeMirror-scroll {
overflow-x: hidden;
}

.CodeMirror-measure {
position: absolute;
width: 100%; height: 0px;
width: 100%;
height: 0;
overflow: hidden;
visibility: hidden;
}
Expand Down
150 changes: 104 additions & 46 deletions lib/codemirror.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mode/coffeescript/coffeescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ CodeMirror.defineMode('coffeescript', function(conf) {
if (current === '.') {
style = state.tokenize(stream, state);
current = stream.current();
if (style === 'variable') {
if (/^\.[\w$]+$/.test(current)) {
return 'variable';
} else {
return ERRORCLASS;
Expand Down
28 changes: 15 additions & 13 deletions mode/css/css.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
CodeMirror.defineMode("css", function(config) {
return CodeMirror.getMode(config, "text/css");
});

CodeMirror.defineMode("css-base", function(config, parserConfig) {
CodeMirror.defineMode("css", function(config, parserConfig) {
"use strict";

if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");

var indentUnit = config.indentUnit,
hooks = parserConfig.hooks || {},
atMediaTypes = parserConfig.atMediaTypes || {},
Expand Down Expand Up @@ -39,7 +37,7 @@ CodeMirror.defineMode("css-base", function(config, parserConfig) {
stream.match(/^\s*\w*/);
return ret("keyword", "important");
}
else if (/\d/.test(ch)) {
else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
}
Expand Down Expand Up @@ -277,16 +275,14 @@ CodeMirror.defineMode("css-base", function(config, parserConfig) {
state.stack[state.stack.length-1] = "@mediaType";
state.stack.push("@mediaType(");
}
else state.stack.push("(");
}
else if (type == ")") {
if (context == "propertyValue" && state.stack[state.stack.length-2] == "@mediaType(") {
if (context == "propertyValue") {
// In @mediaType( without closing ; after propertyValue
state.stack.pop();
state.stack.pop();
}
else if (context == "@mediaType(") {
state.stack.pop();
}
state.stack.pop();
}
else if (type == ":" && state.lastToken == "property") state.stack.push("propertyValue");
else if (context == "propertyValue" && type == ";") state.stack.pop();
Expand Down Expand Up @@ -582,7 +578,7 @@ CodeMirror.defineMode("css-base", function(config, parserConfig) {
return false;
}
},
name: "css-base"
name: "css"
});

CodeMirror.defineMIME("text/x-scss", {
Expand All @@ -593,6 +589,12 @@ CodeMirror.defineMode("css-base", function(config, parserConfig) {
valueKeywords: valueKeywords,
allowNested: true,
hooks: {
":": function(stream) {
if (stream.match(/\s*{/)) {
return [null, "{"];
}
return false;
},
"$": function(stream) {
stream.match(/^[\w-]+/);
if (stream.peek() == ":") {
Expand Down Expand Up @@ -620,6 +622,6 @@ CodeMirror.defineMode("css-base", function(config, parserConfig) {
}
}
},
name: "css-base"
name: "css"
});
})();
Empty file modified mode/d/d.js
100755 → 100644
Empty file.
Empty file modified mode/d/index.html
100755 → 100644
Empty file.
127 changes: 127 additions & 0 deletions mode/dtd/dtd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
DTD mode
Ported to CodeMirror by Peter Kroon <plakroon@gmail.com>
Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues
GitHub: @peterkroon
*/

CodeMirror.defineMode("dtd", function(config) {
var indentUnit = config.indentUnit, type;
function ret(style, tp) {type = tp; return style;}

function tokenBase(stream, state) {
var ch = stream.next();

if (ch == "<" && stream.eat("!") ) {
if (stream.eatWhile(/[\-]/)) {
state.tokenize = tokenSGMLComment;
return tokenSGMLComment(stream, state);
} else if (stream.eatWhile(/[\w]/)) return ret("keyword", "doindent");
} else if (ch == "<" && stream.eat("?")) { //xml declaration
state.tokenize = inBlock("meta", "?>");
return ret("meta", ch);
} else if (ch == "#" && stream.eatWhile(/[\w]/)) return ret("atom", "tag");
else if (ch == "|") return ret("keyword", "seperator");
else if (ch.match(/[\(\)\[\]\-\.,\+\?>]/)) return ret(null, ch);//if(ch === ">") return ret(null, "endtag"); else
else if (ch.match(/[\[\]]/)) return ret("rule", ch);
else if (ch == "\"" || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
} else if (stream.eatWhile(/[a-zA-Z\?\+\d]/)) {
var sc = stream.current();
if( sc.substr(sc.length-1,sc.length).match(/\?|\+/) !== null )stream.backUp(1);
return ret("tag", "tag");
} else if (ch == "%" || ch == "*" ) return ret("number", "number");
else {
stream.eatWhile(/[\w\\\-_%.{,]/);
return ret(null, null);
}
}

function tokenSGMLComment(stream, state) {
var dashes = 0, ch;
while ((ch = stream.next()) != null) {
if (dashes >= 2 && ch == ">") {
state.tokenize = tokenBase;
break;
}
dashes = (ch == "-") ? dashes + 1 : 0;
}
return ret("comment", "comment");
}

function tokenString(quote) {
return function(stream, state) {
var escaped = false, ch;
while ((ch = stream.next()) != null) {
if (ch == quote && !escaped) {
state.tokenize = tokenBase;
break;
}
escaped = !escaped && ch == "\\";
}
return ret("string", "tag");
};
}

function inBlock(style, terminator) {
return function(stream, state) {
while (!stream.eol()) {
if (stream.match(terminator)) {
state.tokenize = tokenBase;
break;
}
stream.next();
}
return style;
};
}

return {
startState: function(base) {
return {tokenize: tokenBase,
baseIndent: base || 0,
stack: []};
},

token: function(stream, state) {
if (stream.eatSpace()) return null;
var style = state.tokenize(stream, state);

var context = state.stack[state.stack.length-1];
if (stream.current() == "[" || type === "doindent" || type == "[") state.stack.push("rule");
else if (type === "endtag") state.stack[state.stack.length-1] = "endtag";
else if (stream.current() == "]" || type == "]" || (type == ">" && context == "rule")) state.stack.pop();
else if (type == "[") state.stack.push("[");
return style;
},

indent: function(state, textAfter) {
var n = state.stack.length;

if( textAfter.match(/\]\s+|\]/) )n=n-1;
else if(textAfter.substr(textAfter.length-1, textAfter.length) === ">"){
if(textAfter.substr(0,1) === "<")n;
else if( type == "doindent" && textAfter.length > 1 )n;
else if( type == "doindent")n--;
else if( type == ">" && textAfter.length > 1)n;
else if( type == "tag" && textAfter !== ">")n;
else if( type == "tag" && state.stack[state.stack.length-1] == "rule")n--;
else if( type == "tag")n++;
else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule" && type === ">")n--;
else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule")n;
else if( textAfter.substr(0,1) !== "<" && textAfter.substr(0,1) === ">" )n=n-1;
else if( textAfter === ">")n;
else n=n-1;
//over rule them all
if(type == null || type == "]")n--;
}

return state.baseIndent + n * indentUnit;
},

electricChars: "]>"
};
});

CodeMirror.defineMIME("application/xml-dtd", "dtd");
89 changes: 89 additions & 0 deletions mode/dtd/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!doctype html>

<title>CodeMirror: DTD mode</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../../doc/docs.css">

<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="dtd.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>

<ul>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a>
</ul>
<ul>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">DTD</a>
</ul>
</div>

<article>
<h2>DTD mode</h2>
<form><textarea id="code" name="code"><?xml version="1.0" encoding="UTF-8"?>

<!ATTLIST title
xmlns CDATA #FIXED "http://docbook.org/ns/docbook"
role CDATA #IMPLIED
%db.common.attributes;
%db.common.linking.attributes;
>

<!--
Try: http://docbook.org/xml/5.0/dtd/docbook.dtd
-->

<!DOCTYPE xsl:stylesheet
[
<!ENTITY nbsp "&amp;#160;">
<!ENTITY copy "&amp;#169;">
<!ENTITY reg "&amp;#174;">
<!ENTITY trade "&amp;#8482;">
<!ENTITY mdash "&amp;#8212;">
<!ENTITY ldquo "&amp;#8220;">
<!ENTITY rdquo "&amp;#8221;">
<!ENTITY pound "&amp;#163;">
<!ENTITY yen "&amp;#165;">
<!ENTITY euro "&amp;#8364;">
<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]
>

<!ELEMENT title (#PCDATA|inlinemediaobject|remark|superscript|subscript|xref|link|olink|anchor|biblioref|alt|annotation|indexterm|abbrev|acronym|date|emphasis|footnote|footnoteref|foreignphrase|phrase|quote|wordasword|firstterm|glossterm|coref|trademark|productnumber|productname|database|application|hardware|citation|citerefentry|citetitle|citebiblioid|author|person|personname|org|orgname|editor|jobtitle|replaceable|package|parameter|termdef|nonterminal|systemitem|option|optional|property|inlineequation|tag|markup|token|symbol|literal|code|constant|email|uri|guiicon|guibutton|guimenuitem|guimenu|guisubmenu|guilabel|menuchoice|mousebutton|keycombo|keycap|keycode|keysym|shortcut|accel|prompt|envar|filename|command|computeroutput|userinput|function|varname|returnvalue|type|classname|exceptionname|interfacename|methodname|modifier|initializer|ooclass|ooexception|oointerface|errorcode|errortext|errorname|errortype)*>

<!ENTITY % db.common.attributes "
xml:id ID #IMPLIED
version CDATA #IMPLIED
xml:lang CDATA #IMPLIED
xml:base CDATA #IMPLIED
remap CDATA #IMPLIED
xreflabel CDATA #IMPLIED
revisionflag (changed|added|deleted|off) #IMPLIED
dir (ltr|rtl|lro|rlo) #IMPLIED
arch CDATA #IMPLIED
audience CDATA #IMPLIED
condition CDATA #IMPLIED
conformance CDATA #IMPLIED
os CDATA #IMPLIED
revision CDATA #IMPLIED
security CDATA #IMPLIED
userlevel CDATA #IMPLIED
vendor CDATA #IMPLIED
wordsize CDATA #IMPLIED
annotations CDATA #IMPLIED

"></textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: {name: "dtd", alignCDATA: true},
lineNumbers: true,
lineWrapping: true
});
</script>

<p><strong>MIME types defined:</strong> <code>application/xml-dtd</code>.</p>
</article>
173 changes: 173 additions & 0 deletions mode/fortran/fortran.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
CodeMirror.defineMode("fortran", function() {
function words(array) {
var keys = {};
for (var i = 0; i < array.length; ++i) {
keys[array[i]] = true;
}
return keys;
}

var keywords = words([
"abstract", "accept", "allocatable", "allocate",
"array", "assign", "asynchronous", "backspace",
"bind", "block", "byte", "call", "case",
"class", "close", "common", "contains",
"continue", "cycle", "data", "deallocate",
"decode", "deferred", "dimension", "do",
"elemental", "else", "encode", "end",
"endif", "entry", "enumerator", "equivalence",
"exit", "external", "extrinsic", "final",
"forall", "format", "function", "generic",
"go", "goto", "if", "implicit", "import", "include",
"inquire", "intent", "interface", "intrinsic",
"module", "namelist", "non_intrinsic",
"non_overridable", "none", "nopass",
"nullify", "open", "optional", "options",
"parameter", "pass", "pause", "pointer",
"print", "private", "program", "protected",
"public", "pure", "read", "recursive", "result",
"return", "rewind", "save", "select", "sequence",
"stop", "subroutine", "target", "then", "to", "type",
"use", "value", "volatile", "where", "while",
"write"]);
var builtins = words(["abort", "abs", "access", "achar", "acos",
"adjustl", "adjustr", "aimag", "aint", "alarm",
"all", "allocated", "alog", "amax", "amin",
"amod", "and", "anint", "any", "asin",
"associated", "atan", "besj", "besjn", "besy",
"besyn", "bit_size", "btest", "cabs", "ccos",
"ceiling", "cexp", "char", "chdir", "chmod",
"clog", "cmplx", "command_argument_count",
"complex", "conjg", "cos", "cosh", "count",
"cpu_time", "cshift", "csin", "csqrt", "ctime",
"c_funloc", "c_loc", "c_associated", "c_null_ptr",
"c_null_funptr", "c_f_pointer", "c_null_char",
"c_alert", "c_backspace", "c_form_feed",
"c_new_line", "c_carriage_return",
"c_horizontal_tab", "c_vertical_tab", "dabs",
"dacos", "dasin", "datan", "date_and_time",
"dbesj", "dbesj", "dbesjn", "dbesy", "dbesy",
"dbesyn", "dble", "dcos", "dcosh", "ddim", "derf",
"derfc", "dexp", "digits", "dim", "dint", "dlog",
"dlog", "dmax", "dmin", "dmod", "dnint",
"dot_product", "dprod", "dsign", "dsinh",
"dsin", "dsqrt", "dtanh", "dtan", "dtime",
"eoshift", "epsilon", "erf", "erfc", "etime",
"exit", "exp", "exponent", "extends_type_of",
"fdate", "fget", "fgetc", "float", "floor",
"flush", "fnum", "fputc", "fput", "fraction",
"fseek", "fstat", "ftell", "gerror", "getarg",
"get_command", "get_command_argument",
"get_environment_variable", "getcwd",
"getenv", "getgid", "getlog", "getpid",
"getuid", "gmtime", "hostnm", "huge", "iabs",
"iachar", "iand", "iargc", "ibclr", "ibits",
"ibset", "ichar", "idate", "idim", "idint",
"idnint", "ieor", "ierrno", "ifix", "imag",
"imagpart", "index", "int", "ior", "irand",
"isatty", "ishft", "ishftc", "isign",
"iso_c_binding", "is_iostat_end", "is_iostat_eor",
"itime", "kill", "kind", "lbound", "len", "len_trim",
"lge", "lgt", "link", "lle", "llt", "lnblnk", "loc",
"log", "logical", "long", "lshift", "lstat", "ltime",
"matmul", "max", "maxexponent", "maxloc", "maxval",
"mclock", "merge", "move_alloc", "min", "minexponent",
"minloc", "minval", "mod", "modulo", "mvbits",
"nearest", "new_line", "nint", "not", "or", "pack",
"perror", "precision", "present", "product", "radix",
"rand", "random_number", "random_seed", "range",
"real", "realpart", "rename", "repeat", "reshape",
"rrspacing", "rshift", "same_type_as", "scale",
"scan", "second", "selected_int_kind",
"selected_real_kind", "set_exponent", "shape",
"short", "sign", "signal", "sinh", "sin", "sleep",
"sngl", "spacing", "spread", "sqrt", "srand", "stat",
"sum", "symlnk", "system", "system_clock", "tan",
"tanh", "time", "tiny", "transfer", "transpose",
"trim", "ttynam", "ubound", "umask", "unlink",
"unpack", "verify", "xor", "zabs", "zcos", "zexp",
"zlog", "zsin", "zsqrt"]);

var dataTypes = words(["c_bool", "c_char", "c_double", "c_double_complex",
"c_float", "c_float_complex", "c_funptr", "c_int",
"c_int16_t", "c_int32_t", "c_int64_t", "c_int8_t",
"c_int_fast16_t", "c_int_fast32_t", "c_int_fast64_t",
"c_int_fast8_t", "c_int_least16_t", "c_int_least32_t",
"c_int_least64_t", "c_int_least8_t", "c_intmax_t",
"c_intptr_t", "c_long", "c_long_double",
"c_long_double_complex", "c_long_long", "c_ptr",
"c_short", "c_signed_char", "c_size_t", "character",
"complex", "double", "integer", "logical", "real"]);
var isOperatorChar = /[+\-*&=<>\/\:]/;
var litOperator = new RegExp("(\.and\.|\.or\.|\.eq\.|\.lt\.|\.le\.|\.gt\.|\.ge\.|\.ne\.|\.not\.|\.eqv\.|\.neqv\.)", "i");

function tokenBase(stream, state) {

if (stream.match(litOperator)){
return 'operator';
}

var ch = stream.next();
if (ch == "!") {
stream.skipToEnd();
return "comment";
}
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
}
if (/[\[\]\(\),]/.test(ch)) {
return null;
}
if (/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
return "number";
}
if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return "operator";
}
stream.eatWhile(/[\w\$_]/);
var word = stream.current().toLowerCase();

if (keywords.hasOwnProperty(word)){
return 'keyword';
}
if (builtins.hasOwnProperty(word) || dataTypes.hasOwnProperty(word)) {
return 'builtin';
}
return "variable";
}

function tokenString(quote) {
return function(stream, state) {
var escaped = false, next, end = false;
while ((next = stream.next()) != null) {
if (next == quote && !escaped) {
end = true;
break;
}
escaped = !escaped && next == "\\";
}
if (end || !escaped) state.tokenize = null;
return "string";
};
}

// Interface

return {
startState: function() {
return {tokenize: null};
},

token: function(stream, state) {
if (stream.eatSpace()) return null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style == "comment" || style == "meta") return style;
return style;
}
};
});

CodeMirror.defineMIME("text/x-fortran", "fortran");
81 changes: 81 additions & 0 deletions mode/fortran/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!doctype html>

<title>CodeMirror: Fortran mode</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../../doc/docs.css">

<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="fortran.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>

<ul>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a>
</ul>
<ul>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">Fortran</a>
</ul>
</div>

<article>
<h2>Fortran mode</h2>


<div><textarea id="code" name="code">
! Example Fortran code
program average

! Read in some numbers and take the average
! As written, if there are no data points, an average of zero is returned
! While this may not be desired behavior, it keeps this example simple

implicit none

real, dimension(:), allocatable :: points
integer :: number_of_points
real :: average_points=0., positive_average=0., negative_average=0.

write (*,*) "Input number of points to average:"
read (*,*) number_of_points

allocate (points(number_of_points))

write (*,*) "Enter the points to average:"
read (*,*) points

! Take the average by summing points and dividing by number_of_points
if (number_of_points > 0) average_points = sum(points) / number_of_points

! Now form average over positive and negative points only
if (count(points > 0.) > 0) then
positive_average = sum(points, points > 0.) / count(points > 0.)
end if

if (count(points < 0.) > 0) then
negative_average = sum(points, points < 0.) / count(points < 0.)
end if

deallocate (points)

! Print result to terminal
write (*,'(a,g12.4)') 'Average = ', average_points
write (*,'(a,g12.4)') 'Average of positive points = ', positive_average
write (*,'(a,g12.4)') 'Average of negative points = ', negative_average
end program average
</textarea></div>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
mode: "text/x-fortran"
});
</script>
<p><strong>MIME types defined:</strong> <code>text/x-Fortran</code>.</p>
</article>
6 changes: 5 additions & 1 deletion mode/haskell/haskell.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CodeMirror.defineMode("haskell", function() {
CodeMirror.defineMode("haskell", function(_config, modeConfig) {

function switchState(source, setState, f) {
setState(f);
Expand Down Expand Up @@ -221,6 +221,10 @@ CodeMirror.defineMode("haskell", function() {
"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
"zip3", "zipWith", "zipWith3");

var override = modeConfig.overrideKeywords;
if (override) for (var word in override) if (override.hasOwnProperty(word))
wkw[word] = override[word];

return wkw;
})();

Expand Down
4 changes: 4 additions & 0 deletions mode/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ <h2>Language modes</h2>
<li><a href="python/index.html">Cython</a></li>
<li><a href="d/index.html">D</a></li>
<li><a href="diff/index.html">diff</a></li>
<li><a href="dtd/index.html">DTD</a></li>
<li><a href="ecl/index.html">ECL</a></li>
<li><a href="erlang/index.html">Erlang</a></li>
<li><a href="fortran/index.html">Fortran</a></li>
<li><a href="gas/index.html">Gas</a> (AT&amp;T-style assembly)</li>
<li><a href="go/index.html">Go</a></li>
<li><a href="groovy/index.html">Groovy</a></li>
Expand All @@ -64,6 +66,7 @@ <h2>Language modes</h2>
<li><a href="nginx/index.html">Nginx</a></li>
<li><a href="ntriples/index.html">NTriples</a></li>
<li><a href="ocaml/index.html">OCaml</a></li>
<li><a href="octave/index.html">Octave</a> (MATLAB)</li>
<li><a href="pascal/index.html">Pascal</a></li>
<li><a href="perl/index.html">Perl</a></li>
<li><a href="php/index.html">PHP</a></li>
Expand Down Expand Up @@ -91,6 +94,7 @@ <h2>Language modes</h2>
<li><a href="tcl/index.html">Tcl</a></li>
<li><a href="tiddlywiki/index.html">Tiddlywiki</a></li>
<li><a href="tiki/index.html">Tiki wiki</a></li>
<li><a href="toml/index.html">TOML</a></li>
<li><a href="turtle/index.html">Turtle</a></li>
<li><a href="vb/index.html">VB.NET</a></li>
<li><a href="vbscript/index.html">VBScript</a></li>
Expand Down
96 changes: 47 additions & 49 deletions mode/less/less.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
LESS mode - http://www.lesscss.org/
Ported to CodeMirror by Peter Kroon <plakroon@gmail.com>
Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues GitHub: @peterkroon
Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues
GitHub: @peterkroon
*/

CodeMirror.defineMode("less", function(config) {
Expand All @@ -17,68 +18,60 @@ CodeMirror.defineMode("less", function(config) {
else if (ch == "/" && stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
}
else if (ch == "<" && stream.eat("!")) {
} else if (ch == "<" && stream.eat("!")) {
state.tokenize = tokenSGMLComment;
return tokenSGMLComment(stream, state);
}
else if (ch == "=") ret(null, "compare");
} else if (ch == "=") ret(null, "compare");
else if (ch == "|" && stream.eat("=")) return ret(null, "compare");
else if (ch == "\"" || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
}
else if (ch == "/") { // e.g.: .png will not be parsed as a class
} else if (ch == "/") { // e.g.: .png will not be parsed as a class
if(stream.eat("/")){
state.tokenize = tokenSComment;
return tokenSComment(stream, state);
}else{
if(type == "string" || type == "(")return ret("string", "string");
if(state.stack[state.stack.length-1] != undefined)return ret(null, ch);
} else {
if(type == "string" || type == "(") return ret("string", "string");
if(state.stack[state.stack.length-1] != undefined) return ret(null, ch);
stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/);
if( /\/|\)|#/.test(stream.peek() || (stream.eatSpace() && stream.peek() == ")")) || stream.eol() )return ret("string", "string"); // let url(/images/logo.png) without quotes return as string
}
}
else if (ch == "!") {
} else if (ch == "!") {
stream.match(/^\s*\w*/);
return ret("keyword", "important");
}
else if (/\d/.test(ch)) {
} else if (/\d/.test(ch)) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
}
else if (/[,+<>*\/]/.test(ch)) {
} else if (/[,+<>*\/]/.test(ch)) {
if(stream.peek() == "=" || type == "a")return ret("string", "string");
if(ch === ",")return ret(null, ch);
return ret(null, "select-op");
}
else if (/[;{}:\[\]()~\|]/.test(ch)) {
} else if (/[;{}:\[\]()~\|]/.test(ch)) {
if(ch == ":"){
stream.eatWhile(/[a-z\\\-]/);
if( selectors.test(stream.current()) ){
return ret("tag", "tag");
}else if(stream.peek() == ":"){//::-webkit-search-decoration
} else if(stream.peek() == ":"){//::-webkit-search-decoration
stream.next();
stream.eatWhile(/[a-z\\\-]/);
if(stream.current().match(/\:\:\-(o|ms|moz|webkit)\-/))return ret("string", "string");
if( selectors.test(stream.current().substring(1)) )return ret("tag", "tag");
return ret(null, ch);
}else{
} else {
return ret(null, ch);
}
}else if(ch == "~"){
} else if(ch == "~"){
if(type == "r")return ret("string", "string");
}else{
} else {
return ret(null, ch);
}
}
else if (ch == ".") {
} else if (ch == ".") {
if(type == "(" || type == "string")return ret("string", "string"); // allow url(../image.png)
stream.eatWhile(/[\a-zA-Z0-9\-_]/);
if(stream.peek() == " ")stream.eatSpace();
if(stream.peek() == ")")return ret("number", "unit");//rgba(0,0,0,.25);
return ret("tag", "tag");
}
else if (ch == "#") {
} else if (ch == "#") {
//we don't eat white-space, we want the hex color and or id only
stream.eatWhile(/[A-Za-z0-9]/);
//check if there is a proper hex color length e.g. #eee || #eeeEEE
Expand All @@ -93,58 +86,57 @@ CodeMirror.defineMode("less", function(config) {
//#time { color: #aaa }
else if(stream.peek() == "}" )return ret("number", "unit");
//we have a valid hex color value, parse as id whenever an element/class is defined after the hex(id) value e.g. #eee aaa || #eee .aaa
else if( /[a-zA-Z\\]/.test(stream.peek()) )return ret("atom", "tag");
else if( /[a-zA-Z\\]/.test(stream.peek()) )return ret("atom", "tag");
//when a hex value is on the end of a line, parse as id
else if(stream.eol())return ret("atom", "tag");
else if(stream.eol())return ret("atom", "tag");
//default
else return ret("number", "unit");
}else{//when not a valid hexvalue in the current stream e.g. #footer
else return ret("number", "unit");
} else {//when not a valid hexvalue in the current stream e.g. #footer
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "tag");
}
}else{//when not a valid hexvalue length
} else {//when not a valid hexvalue length
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "tag");
}
}
else if (ch == "&") {
} else if (ch == "&") {
stream.eatWhile(/[\w\-]/);
return ret(null, ch);
}
else {
} else {
stream.eatWhile(/[\w\\\-_%.{]/);
if(type == "string"){
return ret("string", "string");
}else if(stream.current().match(/(^http$|^https$)/) != null){
} else if(stream.current().match(/(^http$|^https$)/) != null){
stream.eatWhile(/[\w\\\-_%.{:\/]/);
return ret("string", "string");
}else if(stream.peek() == "<" || stream.peek() == ">"){
} else if(stream.peek() == "<" || stream.peek() == ">" || stream.peek() == "+"){
return ret("tag", "tag");
}else if( /\(/.test(stream.peek()) ){
} else if( /\(/.test(stream.peek()) ){
return ret(null, ch);
}else if (stream.peek() == "/" && state.stack[state.stack.length-1] != undefined){ // url(dir/center/image.png)
} else if (stream.peek() == "/" && state.stack[state.stack.length-1] != undefined){ // url(dir/center/image.png)
return ret("string", "string");
}else if( stream.current().match(/\-\d|\-.\d/) ){ // match e.g.: -5px -0.4 etc... only colorize the minus sign
} else if( stream.current().match(/\-\d|\-.\d/) ){ // match e.g.: -5px -0.4 etc... only colorize the minus sign
//commment out these 2 comment if you want the minus sign to be parsed as null -500px
//stream.backUp(stream.current().length-1);
//return ret(null, ch); //console.log( stream.current() );
//return ret(null, ch);
return ret("number", "unit");
}else if( /\/|[\s\)]/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == "/")) && stream.current().indexOf(".") !== -1){
} else if( /\/|[\s\)]/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == "/")) && stream.current().indexOf(".") !== -1){
if(stream.current().substring(stream.current().length-1,stream.current().length) == "{"){
stream.backUp(1);
return ret("tag", "tag");
}//end if
stream.eatSpace();
if( /[{<>.a-zA-Z\/]/.test(stream.peek()) || stream.eol() )return ret("tag", "tag"); // e.g. button.icon-plus
return ret("string", "string"); // let url(/images/logo.png) without quotes return as string
}else if( stream.eol() || stream.peek() == "[" || stream.peek() == "#" || type == "tag" ){
} else if( stream.eol() || stream.peek() == "[" || stream.peek() == "#" || type == "tag" ){
if(stream.current().substring(stream.current().length-1,stream.current().length) == "{")stream.backUp(1);
return ret("tag", "tag");
}else if(type == "compare" || type == "a" || type == "("){
} else if(type == "compare" || type == "a" || type == "("){
return ret("string", "string");
}else if(type == "|" || stream.current() == "-" || type == "["){
} else if(type == "|" || stream.current() == "-" || type == "["){
if(type == "|" )return ret("tag", "tag");
return ret(null, ch);
}else if(stream.peek() == ":") {
} else if(stream.peek() == ":") {
stream.next();
var t_v = stream.peek() == ":" ? true : false;
if(!t_v){
Expand All @@ -156,11 +148,14 @@ CodeMirror.defineMode("less", function(config) {
stream.backUp(new_pos-(old_pos-1));
return ret("tag", "tag");
} else stream.backUp(new_pos-(old_pos-1));
}else{
} else {
stream.backUp(1);
}
if(t_v)return ret("tag", "tag"); else return ret("variable", "variable");
}else{
} else if(state.stack[state.stack.length-1] === "font-family"){
return ret(null, null);
} else {
if(state.stack[state.stack.length-1] === "{" || type === "select-op" || (state.stack[state.stack.length-1] === "rule" && type === ",") )return ret("tag", "tag");
return ret("variable", "variable");
}
}
Expand Down Expand Up @@ -238,12 +233,15 @@ CodeMirror.defineMode("less", function(config) {
}
else if (type == "}") state.stack.pop();
else if (type == "@media") state.stack.push("@media");
else if (context == "{" && type != "comment") state.stack.push("rule");
else if (stream.current() === "font-family") state.stack[state.stack.length-1] = "font-family";
else if (context == "{" && type != "comment" && type !== "tag") state.stack.push("rule");
else if (stream.peek() === ":" && stream.current().match(/@|#/) === null) style = type;
return style;
},

indent: function(state, textAfter) {
var n = state.stack.length;

if (/^\}/.test(textAfter))
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
return state.baseIndent + n * indentUnit;
Expand Down
6 changes: 6 additions & 0 deletions mode/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ CodeMirror.modeInfo = [
{name: 'CSS', mime: 'text/css', mode: 'css'},
{name: 'D', mime: 'text/x-d', mode: 'd'},
{name: 'diff', mime: 'text/x-diff', mode: 'diff'},
{name: 'DTD', mime: 'application/xml-dtd', mode: 'dtd'},
{name: 'ECL', mime: 'text/x-ecl', mode: 'ecl'},
{name: 'Erlang', mime: 'text/x-erlang', mode: 'erlang'},
{name: 'Fortran', mime: 'text/x-fortran', mode: 'fortran'},
{name: 'Gas', mime: 'text/x-gas', mode: 'gas'},
{name: 'GitHub Flavored Markdown', mime: 'text/x-gfm', mode: 'gfm'},
{name: 'GO', mime: 'text/x-go', mode: 'go'},
{name: 'Groovy', mime: 'text/x-groovy', mode: 'groovy'},
{name: 'HAML', mime: 'text/x-haml', mode: 'haml'},
{name: 'Haskell', mime: 'text/x-haskell', mode: 'haskell'},
{name: 'Haxe', mime: 'text/x-haxe', mode: 'haxe'},
{name: 'ASP.NET', mime: 'application/x-aspx', mode: 'htmlembedded'},
Expand All @@ -40,6 +43,7 @@ CodeMirror.modeInfo = [
{name: 'Nginx', mime: 'text/x-nginx-conf', mode: 'nginx'},
{name: 'NTriples', mime: 'text/n-triples', mode: 'ntriples'},
{name: 'OCaml', mime: 'text/x-ocaml', mode: 'ocaml'},
{name: 'Octave', mime: 'text/x-octave', mode: 'octave'},
{name: 'Pascal', mime: 'text/x-pascal', mode: 'pascal'},
{name: 'Perl', mime: 'text/x-perl', mode: 'perl'},
{name: 'PHP', mime: 'text/x-php', mode: 'php'},
Expand Down Expand Up @@ -69,6 +73,8 @@ CodeMirror.modeInfo = [
{name: 'Tcl', mime: 'text/x-tcl', mode: 'tcl'},
{name: 'TiddlyWiki ', mime: 'text/x-tiddlywiki', mode: 'tiddlywiki'},
{name: 'Tiki wiki', mime: 'text/tiki', mode: 'tiki'},
{name: 'TOML', mime: 'text/x-toml', mode: 'toml'},
{name: 'Turtle', mime: 'text/turtle', mode: 'turtle'},
{name: 'VB.NET', mime: 'text/x-vb', mode: 'vb'},
{name: 'VBScript', mime: 'text/vbscript', mode: 'vbscript'},
{name: 'Velocity', mime: 'text/velocity', mode: 'velocity'},
Expand Down
95 changes: 95 additions & 0 deletions mode/octave/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!doctype html>

<title>CodeMirror: Octave mode</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../../doc/docs.css">

<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="octave.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>

<ul>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a>
</ul>
<ul>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">Octave</a>
</ul>
</div>

<article>
<h2>Octave mode</h2>

<div><textarea id="code" name="code">
%numbers
1234
1234i
1234j
.234
.234j
2.23i
23e2
12E1j
123D-4
0x234

%strings
'asda''a'
"asda""a"

%identifiers
a
as123
__asd__

%operators
-
+
=
==
>
<
>=
<=
&
~
...
break zeros default margin round ones rand
ceil floor size clear zeros eye mean std cov
error eval function
abs acos atan asin cos cosh exp log prod sum
log10 max min sign sin sinh sqrt tan reshape
return
case switch
else elseif end if otherwise
do for while
try catch
classdef properties events methods
global persistent

%one line comment
...one line comment
%{ multi
line commment %}
1

</textarea></div>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: {name: "octave",
version: 2,
singleLineStringErrors: false},
lineNumbers: true,
indentUnit: 4,
tabMode: "shift",
matchBrackets: true
});
</script>

<p><strong>MIME types defined:</strong> <code>text/x-octave</code>.</p>
</article>
118 changes: 118 additions & 0 deletions mode/octave/octave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
CodeMirror.defineMode("octave", function() {
function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
}

var singleOperators = new RegExp("^[\\+\\-\\*/&|\\^~<>!@'\\\\]");
var singleDelimiters = new RegExp('^[\\(\\[\\{\\},:=;]');
var doubleOperators = new RegExp("^((==)|(~=)|(<=)|(>=)|(<<)|(>>)|(\\.[\\+\\-\\*/\\^\\\\]))");
var doubleDelimiters = new RegExp("^((!=)|(\\+=)|(\\-=)|(\\*=)|(/=)|(&=)|(\\|=)|(\\^=))");
var tripleDelimiters = new RegExp("^((>>=)|(<<=))");
var expressionEnd = new RegExp("^[\\]\\)]");
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");

var builtins = wordRegexp([
'error', 'eval', 'function', 'abs', 'acos', 'atan', 'asin', 'cos',
'cosh', 'exp', 'log', 'prod', 'log10', 'max', 'min', 'sign', 'sin', 'sinh',
'sqrt', 'tan', 'reshape', 'break', 'zeros', 'default', 'margin', 'round', 'ones',
'rand', 'syn', 'ceil', 'floor', 'size', 'clear', 'zeros', 'eye', 'mean', 'std', 'cov',
'det', 'eig', 'inv', 'norm', 'rank', 'trace', 'expm', 'logm', 'sqrtm', 'linspace', 'plot',
'title', 'xlabel', 'ylabel', 'legend', 'text', 'meshgrid', 'mesh', 'num2str'
]);

var keywords = wordRegexp([
'return', 'case', 'switch', 'else', 'elseif', 'end', 'endif', 'endfunction',
'if', 'otherwise', 'do', 'for', 'while', 'try', 'catch', 'classdef', 'properties', 'events',
'methods', 'global', 'persistent', 'endfor', 'endwhile', 'printf', 'disp', 'until', 'continue'
]);


// tokenizers
function tokenTranspose(stream, state) {
if (!stream.sol() && stream.peek() === '\'') {
stream.next();
state.tokenize = tokenBase;
return 'operator';
}
state.tokenize = tokenBase;
return tokenBase(stream, state);
}


function tokenComment(stream, state) {
if (stream.match(/^.*%}/)) {
state.tokenize = tokenBase;
return 'comment';
};
stream.skipToEnd();
return 'comment';
}

function tokenBase(stream, state) {
// whitespaces
if (stream.eatSpace()) return null;

// Handle one line Comments
if (stream.match('%{')){
state.tokenize = tokenComment;
stream.skipToEnd();
return 'comment';
}

if (stream.match(/^(%)|(\.\.\.)/)){
stream.skipToEnd();
return 'comment';
}

// Handle Number Literals
if (stream.match(/^[0-9\.+-]/, false)) {
if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) {
stream.tokenize = tokenBase;
return 'number'; };
if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };
if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };
}
if (stream.match(wordRegexp(['nan','NaN','inf','Inf']))) { return 'number'; };

// Handle Strings
if (stream.match(/^"([^"]|(""))*"/)) { return 'string'; } ;
if (stream.match(/^'([^']|(''))*'/)) { return 'string'; } ;

// Handle words
if (stream.match(keywords)) { return 'keyword'; } ;
if (stream.match(builtins)) { return 'builtin'; } ;
if (stream.match(identifiers)) { return 'variable'; } ;

if (stream.match(singleOperators) || stream.match(doubleOperators)) { return 'operator'; };
if (stream.match(singleDelimiters) || stream.match(doubleDelimiters) || stream.match(tripleDelimiters)) { return null; };

if (stream.match(expressionEnd)) {
state.tokenize = tokenTranspose;
return null;
};


// Handle non-detected items
stream.next();
return 'error';
};


return {
startState: function() {
return {
tokenize: tokenBase
};
},

token: function(stream, state) {
var style = state.tokenize(stream, state);
if (style === 'number' || style === 'variable'){
state.tokenize = tokenTranspose;
}
return style;
}
};
});

CodeMirror.defineMIME("text/x-octave", "octave");
13 changes: 8 additions & 5 deletions mode/sql/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
if (!cx) return CodeMirror.Pass;
if (cx.align) return cx.col + (textAfter.charAt(0) == cx.type ? 0 : 1);
else return cx.indent + config.indentUnit;
}
},

blockCommentStart: "/*",
blockCommentEnd: "*/",
lineComment: support.commentSlashSlash ? "//" : support.commentHash ? "#" : null
};
});

Expand Down Expand Up @@ -262,7 +266,7 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
name: "sql",
client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"),
keywords: set(sqlKeywords + "accessible action add after algorithm all analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general global grant grants group groupby_concat handler hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show signal slave slow smallint snapshot soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"),
builtin: set("bool boolean bit blob decimal double enum float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"),
builtin: set("bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"),
atoms: set("false true null unknown"),
operatorChars: /^[*+\-%<>!=&|^]/,
dateSQL: set("date time timestamp"),
Expand All @@ -278,7 +282,7 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
name: "sql",
client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"),
keywords: set(sqlKeywords + "accessible action add after algorithm all always analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general generated global grant grants group groupby_concat handler hard hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password persistent phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show signal slave slow smallint snapshot soft soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views virtual warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"),
builtin: set("bool boolean bit blob decimal double enum float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"),
builtin: set("bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"),
atoms: set("false true null unknown"),
operatorChars: /^[*+\-%<>!=&|^]/,
dateSQL: set("date time timestamp"),
Expand Down Expand Up @@ -309,8 +313,7 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
name: "sql",
client: set("appinfo arraysize autocommit autoprint autorecovery autotrace blockterminator break btitle cmdsep colsep compatibility compute concat copycommit copytypecheck define describe echo editfile embedded escape exec execute feedback flagger flush heading headsep instance linesize lno loboffset logsource long longchunksize markup native newpage numformat numwidth pagesize pause pno recsep recsepchar release repfooter repheader serveroutput shiftinout show showmode size spool sqlblanklines sqlcase sqlcode sqlcontinue sqlnumber sqlpluscompatibility sqlprefix sqlprompt sqlterminator suffix tab term termout time timing trimout trimspool ttitle underline verify version wrap"),
keywords: set("abort accept access add all alter and any array arraylen as asc assert assign at attributes audit authorization avg base_table begin between binary_integer body boolean by case cast char char_base check close cluster clusters colauth column comment commit compress connect connected constant constraint crash create current currval cursor data_base database date dba deallocate debugoff debugon decimal declare default definition delay delete desc digits dispose distinct do drop else elsif enable end entry escape exception exception_init exchange exclusive exists exit external fast fetch file for force form from function generic goto grant group having identified if immediate in increment index indexes indicator initial initrans insert interface intersect into is key level library like limited local lock log logging long loop master maxextents maxtrans member minextents minus mislabel mode modify multiset new next no noaudit nocompress nologging noparallel not nowait number_base object of off offline on online only open option or order out package parallel partition pctfree pctincrease pctused pls_integer positive positiven pragma primary prior private privileges procedure public raise range raw read rebuild record ref references refresh release rename replace resource restrict return returning reverse revoke rollback row rowid rowlabel rownum rows run savepoint schema segment select separate session set share snapshot some space split sql start statement storage subtype successful synonym tabauth table tables tablespace task terminate then to trigger truncate type union unique unlimited unrecoverable unusable update use using validate value values variable view views when whenever where while with work"),
functions: set("abs acos add_months ascii asin atan atan2 average bfilename ceil chartorowid chr concat convert cos cosh count decode deref dual dump dup_val_on_index empty error exp false floor found glb greatest hextoraw initcap instr instrb isopen last_day least lenght lenghtb ln lower lpad ltrim lub make_ref max min mod months_between new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower nls_sort nls_upper nlssort no_data_found notfound null nvl others power rawtohex reftohex round rowcount rowidtochar rpad rtrim sign sin sinh soundex sqlcode sqlerrm sqrt stddev substr substrb sum sysdate tan tanh to_char to_date to_label to_multi_byte to_number to_single_byte translate true trunc uid upper user userenv variance vsize"),
builtin: set("bfile blob character clob dec float int integer mlslabel natural naturaln nchar nclob number numeric nvarchar2 real rowtype signtype smallint string varchar varchar2"),
builtin: set("bfile blob character clob dec float int integer mlslabel natural naturaln nchar nclob number numeric nvarchar2 real rowtype signtype smallint string varchar varchar2 abs acos add_months ascii asin atan atan2 average bfilename ceil chartorowid chr concat convert cos cosh count decode deref dual dump dup_val_on_index empty error exp false floor found glb greatest hextoraw initcap instr instrb isopen last_day least lenght lenghtb ln lower lpad ltrim lub make_ref max min mod months_between new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower nls_sort nls_upper nlssort no_data_found notfound null nvl others power rawtohex reftohex round rowcount rowidtochar rpad rtrim sign sin sinh soundex sqlcode sqlerrm sqrt stddev substr substrb sum sysdate tan tanh to_char to_date to_label to_multi_byte to_number to_single_byte translate true trunc uid upper user userenv variance vsize"),
operatorChars: /^[*+\-%<>!=~]/,
dateSQL: set("date time timestamp"),
support: set("doubleQuote nCharCast zerolessFloat binaryNumber hexNumber")
Expand Down
73 changes: 73 additions & 0 deletions mode/toml/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!doctype html>

<title>CodeMirror: TOML Mode</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../../doc/docs.css">

<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="toml.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>

<ul>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a>
</ul>
<ul>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">TOML Mode</a>
</ul>
</div>

<article>
<h2>TOML Mode</h2>
<form><textarea id="code" name="code">
# This is a TOML document. Boom.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
organization = "GitHub"
bio = "GitHub Cofounder &amp; CEO\nLikes tater tots and beer."
dob = 1979-05-27T07:32:00Z # First class dates? Why not?

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

# You can indent as you please. Tabs or spaces. TOML don't care.
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"

[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"

[clients]
data = [ ["gamma", "delta"], [1, 2] ]

# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: {name: "toml"},
lineNumbers: true
});
</script>
<h3>The TOML Mode</h3>
<p> Created by Forbes Lindesay.</p>
<p><strong>MIME type defined:</strong> <code>text/x-toml</code>.</p>
</article>
71 changes: 71 additions & 0 deletions mode/toml/toml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
CodeMirror.defineMode("toml", function () {
return {
startState: function () {
return {
inString: false,
stringType: "",
lhs: true,
inArray: 0
};
},
token: function (stream, state) {
//check for state changes
if (!state.inString && ((stream.peek() == '"') || (stream.peek() == "'"))) {
state.stringType = stream.peek();
stream.next(); // Skip quote
state.inString = true; // Update state
}
if (stream.sol() && state.inArray === 0) {
state.lhs = true;
}
//return state
if (state.inString) {
while (state.inString && !stream.eol()) {
if (stream.peek() === state.stringType) {
stream.next(); // Skip quote
state.inString = false; // Clear flag
} else if (stream.peek() === '\\') {
stream.next();
stream.next();
} else {
stream.match(/^.[^\\\"\']*/);
}
}
return state.lhs ? "property string" : "string"; // Token style
} else if (state.inArray && stream.peek() === ']') {
stream.next();
state.inArray--;
return 'bracket';
} else if (state.lhs && stream.peek() === '[' && stream.skipTo(']')) {
stream.next();//skip closing ]
return "atom";
} else if (stream.peek() === "#") {
stream.skipToEnd();
return "comment";
} else if (stream.eatSpace()) {
return null;
} else if (state.lhs && stream.eatWhile(function (c) { return c != '=' && c != ' '; })) {
return "property";
} else if (state.lhs && stream.peek() === "=") {
stream.next();
state.lhs = false;
return null;
} else if (!state.lhs && stream.match(/^\d\d\d\d[\d\-\:\.T]*Z/)) {
return 'atom'; //date
} else if (!state.lhs && (stream.match('true') || stream.match('false'))) {
return 'atom';
} else if (!state.lhs && stream.peek() === '[') {
state.inArray++;
stream.next();
return 'bracket';
} else if (!state.lhs && stream.match(/^\-?\d+(?:\.\d+)?/)) {
return 'number';
} else if (!stream.eatSpace()) {
stream.next();
}
return null;
}
};
});

CodeMirror.defineMIME('text/x-toml', 'toml');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codemirror",
"version":"3.16.0",
"version":"3.17.0",
"main": "lib/codemirror.js",
"description": "In-browser code editing made bearable",
"licenses": [{"type": "MIT",
Expand Down
28 changes: 25 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var Pos = CodeMirror.Pos;

CodeMirror.defaults.rtlMoveVisually = true;

function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
Expand Down Expand Up @@ -529,10 +531,10 @@ testCM("multiBookmarkCursor", function(cm) {
}
var base1 = cm.cursorCoords(Pos(0, 1)).left, base4 = cm.cursorCoords(Pos(0, 4)).left;
add(true);
eq(base1, cm.cursorCoords(Pos(0, 1)).left);
is(Math.abs(base1 - cm.cursorCoords(Pos(0, 1)).left) < .1);
while (m = ms.pop()) m.clear();
add(false);
eq(base4, cm.cursorCoords(Pos(0, 1)).left);
is(Math.abs(base4 - cm.cursorCoords(Pos(0, 1)).left) < .1);
}, {value: "abcdefg"});

testCM("getAllMarks", function(cm) {
Expand Down Expand Up @@ -1159,7 +1161,7 @@ testCM("rtlMovement", function(cm) {
prevX = cursor.offsetLeft;
}
});
}, {rtlMoveVisually: true});
});

// Verify that updating a line clears its bidi ordering
testCM("bidiUpdate", function(cm) {
Expand Down Expand Up @@ -1340,6 +1342,7 @@ testCM("atomicMarker", function(cm) {
eqPos(cm.getCursor(), Pos(8, 3));
m.clear();
m = atom(1, 1, 3, 8);
cm.setCursor(Pos(0, 0));
cm.setCursor(Pos(2, 0));
eqPos(cm.getCursor(), Pos(3, 8));
cm.execCommand("goCharLeft");
Expand Down Expand Up @@ -1538,3 +1541,22 @@ testCM("change_removedText", function(cm) {
eq(removedText[0].join("\n"), "abc\nd");
eq(removedText[1].join("\n"), "");
});

testCM("lineStyleFromMode", function(cm) {
CodeMirror.defineMode("test_mode", function() {
return {token: function(stream) {
if (stream.match(/^\[[^\]]*\]/)) return "line-brackets";
if (stream.match(/^\([^\]]*\)/)) return "line-background-parens";
stream.match(/^\s+|^\S+/);
}};
});
cm.setOption("mode", "test_mode");
var bracketElts = byClassName(cm.getWrapperElement(), "brackets");
eq(bracketElts.length, 1);
eq(bracketElts[0].nodeName, "PRE");
is(!/brackets.*brackets/.test(bracketElts[0].className));
var parenElts = byClassName(cm.getWrapperElement(), "parens");
eq(parenElts.length, 1);
eq(parenElts[0].nodeName, "DIV");
is(!/parens.*parens/.test(parenElts[0].className));
}, {value: "line1: [br] [br]\nline2: (par) (par)\nline3: nothing"});
26 changes: 2 additions & 24 deletions theme/solarized.css