16 changes: 14 additions & 2 deletions doc/oldrelease.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>CodeMirror</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>
<link rel="stylesheet" type="text/css" href="docs.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="alternate" href="http://twitter.com/statuses/user_timeline/242283288.rss" type="application/rss+xml"/>
</head>
<body>
Expand All @@ -16,6 +16,18 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi

</pre>

<p class="rel">27-10-2011: <a href="http://codemirror.net/codemirror-2.16.zip">Version 2.16</a>:</p>
<ul class="rel-note">
<li>Add <a href="../mode/perl/index.html">Perl</a>, <a href="../mode/rust/index.html">Rust</a>, <a href="../mode/tiddlywiki/index.html">TiddlyWiki</a>, and <a href="../mode/groovy/index.html">Groovy</a> modes.</li>
<li>Dragging text inside the editor now moves, rather than copies.</li>
<li>Add a <a href="manual.html#coordsFromIndex"><code>coordsFromIndex</code></a> method.</li>
<li><strong>API change</strong>: <code>setValue</code> now no longer clears history. Use <a href="manual.html#clearHistory"><code>clearHistory</code></a> for that.</li>
<li><strong>API change</strong>: <a href="manual.html#markText"><code>markText</code></a> now
returns an object with <code>clear</code> and <code>find</code>
methods. Marked text is now more robust when edited.</li>
<li>Fix editing code with tabs in Internet Explorer.</li>
</ul>

<p class="rel">26-09-2011: <a href="http://codemirror.net/codemirror-2.15.zip">Version 2.15</a>:</p>
<p class="rel-note">Fix bug that snuck into 2.14: Clicking the
character that currently has the cursor didn't re-focus the
Expand Down Expand Up @@ -119,7 +131,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<li>Fix some issues with JavaScript indentation.</li>
</ul>

<p class="rel">22-02-2011: <a href="https://github.com/marijnh/codemirror2/tree/beta2">Version 2.0 beta 2</a>:</p>
<p class="rel">22-02-2011: <a href="https://github.com/marijnh/codemirror/tree/beta2">Version 2.0 beta 2</a>:</p>
<p class="rel-note">Somewhat more mature API, lots of bugs shaken out.</a>

<p class="rel">17-02-2011: <a href="http://codemirror.net/codemirror-0.94.zip">Version 0.94</a>:</p>
Expand Down
2 changes: 1 addition & 1 deletion doc/reporting.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>CodeMirror: Reporting Bugs</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>
<link rel="stylesheet" type="text/css" href="docs.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>li { margin-top: 1em; }</style>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion doc/upgrade_v2.2.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>CodeMirror: Upgrading to v2.2</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>
<link rel="stylesheet" type="text/css" href="docs.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>

Expand Down
91 changes: 50 additions & 41 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>CodeMirror</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>
<link rel="stylesheet" type="text/css" href="doc/docs.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="alternate" href="http://twitter.com/statuses/user_timeline/242283288.rss" type="application/rss+xml"/>
</head>
<body style="margin-top: 9em">

<div style="background: #eee; border-bottom: 2px solid #df0019; position: absolute; left: 0; top: 0; right: 0; padding: 18px 0;">
<div style="max-width: 64.3em; margin: 0 auto;">
<a href="http://www.pledgie.com/campaigns/17784">
<img style="width: 149px; height: 37px; vertical-align: bottom" alt='Click here to lend your support to: Fund CodeMirror development and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/17784.png?skin_name=chrome' border=0/>
</a> &nbsp; <span style="font-size: 1.23em; font-weight: bold;">Please check out our development fundraiser.
</div>
</div>
<body>

<h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMirror</a></h1>

Expand Down Expand Up @@ -77,6 +69,7 @@ <h2 style="margin-top: 0">Supported modes:</h2>
<li><a href="mode/clike/scala.html">Scala</a></li>
<li><a href="mode/scheme/index.html">Scheme</a></li>
<li><a href="mode/shell/index.html">Shell</a></li>
<li><a href="mode/sieve/index.html">Sieve</a></li>
<li><a href="mode/smalltalk/index.html">Smalltalk</a></li>
<li><a href="mode/smarty/index.html">Smarty</a></li>
<li><a href="mode/sparql/index.html">SPARQL</a></li>
Expand Down Expand Up @@ -127,10 +120,12 @@ <h2>Real-world uses:</h2>
<li><a href="http://brackets.io">Adobe Brackets</a> (code editor)</li>
<li><a href="http://www.mergely.com/">Mergely</a> (interactive diffing)</li>
<li><a href="https://script.google.com/">Google Apps Script</a></li>
<li><a href="https://github.com/github/android">GitHub's Android app</a></li>
<li><a href="http://eloquentjavascript.net/chapter1.html">Eloquent JavaScript</a> (book)</li>
<li><a href="http://media.chikuyonok.ru/codemirror2/">Zen Coding</a> (fast XML editing)</li>
<li><a href="http://paperjs.org/">Paper.js</a> (graphics scripting)</li>
<li><a href="http://tour.golang.org">Go language tour</a></li>
<li><a href="http://codev.it/">Codev</a> (collaborative IDE)</li>
<li><a href="http://enjalot.com/tributary/2636296/sinwaves.js">Tributary</a> (augmented editing)</li>
<li><a href="http://prose.io/">Prose.io</a> (github content editor)</li>
<li><a href="http://www.wescheme.org/">WeScheme</a> (learning tool)</li>
Expand All @@ -156,17 +151,17 @@ <h2 id="code">Getting the code</h2>
href="LICENSE">MIT-style</a> license. To get it, you can download
the <a href="http://codemirror.net/codemirror.zip">latest
release</a> or the current <a
href="http://codemirror.net/codemirror2-latest.zip">development
href="http://codemirror.net/codemirror-latest.zip">development
snapshot</a> as zip files. To create a custom minified script file,
you can use the <a href="doc/compress.html">compression API</a>.</p>

<p>We use <a href="http://git-scm.com/">git</a> for version control.
The main repository can be fetched in this way:</p>

<pre class="code">git clone http://marijnhaverbeke.nl/git/codemirror2</pre>
<pre class="code">git clone http://marijnhaverbeke.nl/git/codemirror</pre>

<p>CodeMirror can also be found on GitHub at <a
href="http://github.com/marijnh/CodeMirror2">marijnh/CodeMirror2</a>.
href="http://github.com/marijnh/CodeMirror">marijnh/CodeMirror</a>.
If you plan to hack on the code and contribute patches, the best way
to do it is to create a GitHub fork, and send pull requests.</p>

Expand All @@ -178,26 +173,34 @@ <h2 id="documention">Documentation</h2>

<p>For those who want to learn more about the code, there is
an <a href="doc/internals.html">overview of the internals</a> available.
The <a href="http://github.com/marijnh/CodeMirror2">source code</a>
The <a href="http://github.com/marijnh/CodeMirror">source code</a>
itself is, for the most part, also well commented.</p>

<h2 id="support">Support and bug reports</h2>

<p>There is
a <a href="http://groups.google.com/group/codemirror">Google
group</a> (a sort of mailing list/newsgroup thing) for discussion
and news related to CodeMirror. When reporting a bug,
<a href="doc/reporting.html">read this first</a>. If you have
a <a href="http://github.com">github</a> account,
simply <a href="http://github.com/marijnh/CodeMirror2/issues">open
an issue there</a>. Otherwise, post something to
the <a href="http://groups.google.com/group/codemirror">group</a>,
or e-mail me directly: <a href="mailto:marijnh@gmail.com">Marijn
Haverbeke</a>.</p>
<p>Community discussion, questions, and informal bug reporting is
done on
the <a href="http://groups.google.com/group/codemirror">CodeMirror
Google group</a>. There is a separate
group, <a href="http://groups.google.com/group/codemirror-announce">CodeMirror-announce</a>,
which is lower-volume, and is only used for major announcements—new
versions and such. These will be cross-posted to both groups, so you
don't need to subscribe to both.</p>

<p>Though bug reports through e-mail are responded to, the preferred
way to report bugs is to use
the <a href="http://github.com/marijnh/CodeMirror/issues">Github
issue tracker</a>. Before reporting a
bug, <a href="doc/reporting.html">read these pointers</a>. Also,
the issue tracker is for <em>bugs</em>, not requests for help.</p>

<p>When none of these seem fitting, you can
simply <a href="mailto:marijnh@gmail.com">e-mail the maintainer</a>
directly.</p>

<h2 id="supported">Supported browsers</h2>

<p>The following browsers are able to run CodeMirror:</p>
<p>The following <em>desktop</em> browsers are able to run CodeMirror:</p>

<ul>
<li>Firefox 2 or higher</li>
Expand All @@ -216,6 +219,10 @@ <h2 id="supported">Supported browsers</h2>
See <a href="#support">here</a> for information on how to contact
me.</p>

<p>Mobile browsers mostly kind of work, but, because of limitations
and their fundamentally different UI assumptions, show a lot of
quirks that are hard to work around.</p>

<h2 id="commercial">Commercial support</h2>

<p>CodeMirror is developed and maintained by me, Marijn Haverbeke,
Expand Down Expand Up @@ -264,11 +271,25 @@ <h2>Reading material</h2>

<ul>
<li><a href="doc/manual.html">User manual</a></li>
<li><a href="http://github.com/marijnh/CodeMirror2">Browse the code</a></li>
<li><a href="http://github.com/marijnh/CodeMirror">Browse the code</a></li>
</ul>

<h2 id=releases>Releases</h2>

<p class="rel">23-08-2012: <a href="http://codemirror.net/codemirror-2.33.zip">Version 2.33</a>:</p>

<ul class="rel-note">
<li>New mode: <a href="mode/sieve/">Sieve</a>.</li>
<li>New <a href="doc/manual.html#getViewport"><code>getViewPort</code></a> and <a href="doc/manual.html#option_onViewportChange"><code>onViewportChange</code></a> API.</li>
<li><a href="doc/manual.html#option_cursorBlinkRate">Configurable</a> cursor blink rate.</li>
<li>Make binding a key to <code>false</code> disabling handling (again).</li>
<li>Show non-printing characters as red dots.</li>
<li>More tweaks to the scrolling model.</li>
<li>Expanded testsuite. Basic linter added.</li>
<li>Remove most uses of <code>innerHTML</code>. Remove <code>CodeMirror.htmlEscape</code>.</li>
<li><a href="https://github.com/marijnh/CodeMirror/compare/v2.32...v2.33">Full list</a> of patches.</li>
</ul>

<p class="rel">23-07-2012: <a href="http://codemirror.net/codemirror-2.32.zip">Version 2.32</a>:</p>

<p class="rel-note">Emergency fix for a bug where an editor with
Expand All @@ -284,7 +305,7 @@ <h2 id=releases>Releases</h2>
<li>Add <a href="doc/manual.html#getHistory"><code>getHistory</code></a> and <a href="doc/manual.html#setHistory"><code>setHistory</code></a> methods.</li>
<li>Allow custom line separator string in <a href="doc/manual.html#getValue"><code>getValue</code></a> and <a href="doc/manual.html#getRange"><code>getRange</code></a>.</li>
<li>Support double- and triple-click drag, double-clicking whitespace.</li>
<li>And more... <a href="https://github.com/marijnh/CodeMirror2/compare/v2.3...v2.31">(all patches)</a></li>
<li>And more... <a href="https://github.com/marijnh/CodeMirror/compare/v2.3...v2.31">(all patches)</a></li>
</ul>

<p class="rel">22-06-2012: <a href="http://codemirror.net/codemirror-2.3.zip">Version 2.3</a>:</p>
Expand All @@ -296,7 +317,7 @@ <h2 id=releases>Releases</h2>
<li>Add <a href="demo/multiplex.html">mode-multiplexing</a> utility script.</li>
<li>Fix bug where right-click paste works in read-only mode.</li>
<li>Add a <a href="doc/manual.html#getScrollInfo"><code>getScrollInfo</code></a> method.</li>
<li>Lots of other <a href="https://github.com/marijnh/CodeMirror2/compare/v2.25...v2.3">fixes</a>.</li>
<li>Lots of other <a href="https://github.com/marijnh/CodeMirror/compare/v2.25...v2.3">fixes</a>.</li>
</ul>

<p class="rel">23-05-2012: <a href="http://codemirror.net/codemirror-2.25.zip">Version 2.25</a>:</p>
Expand Down Expand Up @@ -426,18 +447,6 @@ <h2 id=releases>Releases</h2>
<li>Various fixes to modes.</li>
</ul>

<p class="rel">27-10-2011: <a href="http://codemirror.net/codemirror-2.16.zip">Version 2.16</a>:</p>
<ul class="rel-note">
<li>Add <a href="mode/perl/index.html">Perl</a>, <a href="mode/rust/index.html">Rust</a>, <a href="mode/tiddlywiki/index.html">TiddlyWiki</a>, and <a href="mode/groovy/index.html">Groovy</a> modes.</li>
<li>Dragging text inside the editor now moves, rather than copies.</li>
<li>Add a <a href="doc/manual.html#coordsFromIndex"><code>coordsFromIndex</code></a> method.</li>
<li><strong>API change</strong>: <code>setValue</code> now no longer clears history. Use <a href="doc/manual.html#clearHistory"><code>clearHistory</code></a> for that.</li>
<li><strong>API change</strong>: <a href="doc/manual.html#markText"><code>markText</code></a> now
returns an object with <code>clear</code> and <code>find</code>
methods. Marked text is now more robust when edited.</li>
<li>Fix editing code with tabs in Internet Explorer.</li>
</ul>

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

</div></div>
Expand Down
11 changes: 6 additions & 5 deletions keymap/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
for (var prop in o) if (o.hasOwnProperty(prop)) f(prop, o[prop]);
}
function iterList(l, f) {
for (var i in l) f(l[i]);
for (var i = 0; i < l.length; ++i) f(l[i]);
}
function toLetter(ch) {
// T -> t, Shift-T -> T, '*' -> *, "Space" -> " "
Expand Down Expand Up @@ -229,7 +229,8 @@
else f(prompt(shortText, ""));
}
function showAlert(cm, text) {
if (cm.openDialog) cm.openDialog(CodeMirror.htmlEscape(text) + " <button type=button>OK</button>");
var esc = text.replace(/[<&]/, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
if (cm.openDialog) cm.openDialog(esc + " <button type=button>OK</button>");
else alert(text);
}

Expand Down Expand Up @@ -502,9 +503,9 @@
setupPrefixBindingForKey(toCombo(ch));
setupPrefixBindingForKey(toCombo(ch.toLowerCase()));
}
iterList(SPECIAL_SYMBOLS, function (ch) {
setupPrefixBindingForKey(toCombo(ch));
});
for (var i = 0; i < SPECIAL_SYMBOLS.length; ++i) {
setupPrefixBindingForKey(toCombo(SPECIAL_SYMBOLS.charAt(i)));
}
setupPrefixBindingForKey("Space");

CodeMirror.keyMap["vim-prefix-y"] = {
Expand Down
26 changes: 15 additions & 11 deletions lib/codemirror.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
}

.CodeMirror-scroll {
overflow-x: auto;
overflow-y: hidden;
overflow: auto;
height: 300px;
/* This is needed to prevent an IE[67] bug where the scrolled content
is visible outside of the scrolling box. */
Expand All @@ -20,13 +19,11 @@

/* Vertical scrollbar */
.CodeMirror-scrollbar {
float: right;
position: absolute;
right: 0; top: 0;
overflow-x: hidden;
overflow-y: scroll;

/* This corrects for the 1px gap introduced to the left of the scrollbar
by the rule for .CodeMirror-scrollbar-inner. */
margin-left: -1px;
z-index: 5;
}
.CodeMirror-scrollbar-inner {
/* This needs to have a nonzero width in order for the scrollbar to appear
Expand Down Expand Up @@ -69,10 +66,6 @@
white-space: pre;
cursor: text;
}
.CodeMirror-lines * {
/* Necessary for throw-scrolling to decelerate properly on Safari. */
pointer-events: none;
}

.CodeMirror pre {
-moz-border-radius: 0;
Expand Down Expand Up @@ -165,5 +158,16 @@ span.cm-em {font-style: italic;}
span.cm-emstrong {font-style: italic; font-weight: bold;}
span.cm-link {text-decoration: underline;}

span.cm-invalidchar {color: #f00;}

div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}

@media print {

/* Hide the cursor when printing */
.CodeMirror pre.CodeMirror-cursor {
visibility: hidden;
}

}
702 changes: 354 additions & 348 deletions lib/codemirror.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lib/util/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
inp.focus();
CodeMirror.connect(inp, "blur", close);
} else if (button = dialog.getElementsByTagName("button")[0]) {
CodeMirror.connect(button, "click", close);
CodeMirror.connect(button, "click", function() {
close();
me.focus();
});
button.focus();
CodeMirror.connect(button, "blur", close);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ CodeMirror.modeExtensions["javascript"] = {
autoFormatLineBreaks: function (text, startPos, endPos) {
text = text.substring(startPos, endPos);
var curPos = 0;
var reLinesSplitter = new RegExp("(;|\\{|\\})([^\r\n])", "g");
var reLinesSplitter = new RegExp("(;|\\{|\\})([^\r\n;])", "g");
var nonBreakableBlocks = this.getNonBreakableBlocks(text);
if (nonBreakableBlocks != null) {
var res = "";
Expand Down
6 changes: 3 additions & 3 deletions lib/util/javascript-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
case '(': level--; break;
default: break;
}
} while (level > 0)
} while (level > 0);
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
if (tprop.className == 'variable')
tprop.className = 'function';
Expand All @@ -55,7 +55,7 @@
CodeMirror.javascriptHint = function(editor) {
return scriptHint(editor, javascriptKeywords,
function (e, cur) {return e.getTokenAt(cur);});
}
};

function getCoffeeScriptToken(editor, cur) {
// This getToken, it is for coffeescript, imitates the behavior of
Expand All @@ -77,7 +77,7 @@

CodeMirror.coffeescriptHint = function(editor) {
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken);
}
};

var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
"toUpperCase toLowerCase split concat match replace search").split(" ");
Expand Down
2 changes: 1 addition & 1 deletion lib/util/loadmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var loading = {};
function splitCallback(cont, n) {
var countDown = n;
return function() { if (--countDown == 0) cont(); }
return function() { if (--countDown == 0) cont(); };
}
function ensureDeps(mode, cont) {
var deps = CodeMirror.modes[mode].dependencies;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/multiplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
if (found == stream.pos) {
stream.match(other.open);
state.innerActive = other;
state.inner = CodeMirror.startState(other.mode, outer.indent(state.outer, ""));
state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);
return other.delimStyle;
} else if (found != -1 && found < cutOff) {
cutOff = found;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/pig-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

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

function toTitleCase(str) {
return str.replace(/(?:^|\s)\w/g, function(match) {
Expand Down
12 changes: 8 additions & 4 deletions lib/util/runmode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
CodeMirror.runMode = function(string, modespec, callback, options) {
function esc(str) {
return str.replace(/[<&]/, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
}

var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
var isNode = callback.nodeType == 1;
var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
Expand All @@ -15,12 +19,12 @@ CodeMirror.runMode = function(string, modespec, callback, options) {
for (var pos = 0;;) {
var idx = text.indexOf("\t", pos);
if (idx == -1) {
escaped += CodeMirror.htmlEscape(text.slice(pos));
escaped += esc(text.slice(pos));
col += text.length - pos;
break;
} else {
col += idx - pos;
escaped += CodeMirror.htmlEscape(text.slice(pos, idx));
escaped += esc(text.slice(pos, idx));
var size = tabSize - col % tabSize;
col += size;
for (var i = 0; i < size; ++i) escaped += " ";
Expand All @@ -29,10 +33,10 @@ CodeMirror.runMode = function(string, modespec, callback, options) {
}

if (style)
accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + escaped + "</span>");
accum.push("<span class=\"cm-" + esc(style) + "\">" + escaped + "</span>");
else
accum.push(escaped);
}
};
}
var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
for (var i = 0, e = lines.length; i < e; ++i) {
Expand Down
8 changes: 4 additions & 4 deletions lib/util/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
if (!query || state.query) return;
state.query = parseQuery(query);
if (cm.lineCount() < 2000) { // This is too expensive on big documents.
for (var cursor = getSearchCursor(cm, query); cursor.findNext();)
for (var cursor = getSearchCursor(cm, state.query); cursor.findNext();)
state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching"));
}
state.posFrom = state.posTo = cm.getCursor();
Expand All @@ -57,14 +57,14 @@
}
cm.setSelection(cursor.from(), cursor.to());
state.posFrom = cursor.from(); state.posTo = cursor.to();
})}
});}
function clearSearch(cm) {cm.operation(function() {
var state = getSearchState(cm);
if (!state.query) return;
state.query = null;
for (var i = 0; i < state.marked.length; ++i) state.marked[i].clear();
state.marked.length = 0;
})}
});}

var replaceQueryDialog =
'Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
Expand All @@ -83,7 +83,7 @@
cursor.replace(text.replace(/\$(\d)/, function(w, i) {return match[i];}));
} else cursor.replace(text);
}
})});
});});
} else {
clearSearch(cm);
var cursor = getSearchCursor(cm, query, cm.getCursor());
Expand Down
24 changes: 13 additions & 11 deletions lib/util/searchcursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@
// It takes a position and a direction, and returns an object
// describing the next occurrence of the query, or null if no
// more matches were found.
if (typeof query != "string") // Regexp match
if (typeof query != "string") { // Regexp match
if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
this.matches = function(reverse, pos) {
if (reverse) {
var line = cm.getLine(pos.line).slice(0, pos.ch), match = line.match(query), start = 0;
query.lastIndex = 0;
var line = cm.getLine(pos.line).slice(0, pos.ch), match = query.exec(line), start = 0;
while (match) {
var ind = line.indexOf(match[0]);
start += ind;
line = line.slice(ind + 1);
var newmatch = line.match(query);
start += match.index;
line = line.slice(match.index);
query.lastIndex = 0;
var newmatch = query.exec(line);
if (newmatch) match = newmatch;
else break;
start++;
}
}
else {
var line = cm.getLine(pos.line).slice(pos.ch), match = line.match(query),
start = match && pos.ch + line.indexOf(match[0]);
} else {
query.lastIndex = pos.ch;
var line = cm.getLine(pos.line), match = query.exec(line),
start = match && match.index;
}
if (match)
return {from: {line: pos.line, ch: start},
to: {line: pos.line, ch: start + match[0].length},
match: match};
};
else { // String query
} else { // String query
if (caseFold) query = query.toLowerCase();
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
var target = query.split("\n");
Expand Down
157 changes: 89 additions & 68 deletions lib/util/simple-hint.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,97 @@
(function() {
CodeMirror.simpleHint = function(editor, getHints) {
// We want a single cursor position.
if (editor.somethingSelected()) return;
//don't show completion if the token is empty
var tempToken = editor.getTokenAt(editor.getCursor());
if(!(/[\S]/gi.test(tempToken.string))) return;
CodeMirror.simpleHint = function(editor, getHints, givenOptions) {
// Determine effective options based on given values and defaults.
var options = {}, defaults = CodeMirror.simpleHint.defaults;
for (var opt in defaults)
if (defaults.hasOwnProperty(opt))
options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];

function collectHints(previousToken) {
// We want a single cursor position.
if (editor.somethingSelected()) return;

var result = getHints(editor);
if (!result || !result.list.length) return;
var completions = result.list;
function insert(str) {
editor.replaceRange(str, result.from, result.to);
}
// When there is only one completion, use it directly.
if (completions.length == 1) {insert(completions[0]); return true;}
var tempToken = editor.getTokenAt(editor.getCursor());

// Build the select widget
var complete = document.createElement("div");
complete.className = "CodeMirror-completions";
var sel = complete.appendChild(document.createElement("select"));
// Opera doesn't move the selection when pressing up/down in a
// multi-select, but it does properly support the size property on
// single-selects, so no multi-select is necessary.
if (!window.opera) sel.multiple = true;
for (var i = 0; i < completions.length; ++i) {
var opt = sel.appendChild(document.createElement("option"));
opt.appendChild(document.createTextNode(completions[i]));
}
sel.firstChild.selected = true;
sel.size = Math.min(10, completions.length);
var pos = editor.cursorCoords();
complete.style.left = pos.x + "px";
complete.style.top = pos.yBot + "px";
document.body.appendChild(complete);
// 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);
if(winW - pos.x < sel.clientWidth)
complete.style.left = (pos.x - sel.clientWidth) + "px";
// Hack to hide the scrollbar.
if (completions.length <= 10)
complete.style.width = (sel.clientWidth - 1) + "px";
// Don't show completions if token has changed and the option is set.
if (options.closeOnTokenChange && previousToken != null &&
(tempToken.start != previousToken.start || tempToken.className != previousToken.className)) {
return;
}

var done = false;
function close() {
if (done) return;
done = true;
complete.parentNode.removeChild(complete);
}
function pick() {
insert(completions[sel.selectedIndex]);
close();
setTimeout(function(){editor.focus();}, 50);
}
CodeMirror.connect(sel, "blur", close);
CodeMirror.connect(sel, "keydown", function(event) {
var code = event.keyCode;
// Enter
if (code == 13) {CodeMirror.e_stop(event); pick();}
// Escape
else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();}
else if (code != 38 && code != 40) {
close(); editor.focus();
// Pass the event to the CodeMirror instance so that it can handle things like backspace properly.
editor.triggerOnKeyDown(event);
setTimeout(function(){CodeMirror.simpleHint(editor, getHints);}, 50);
var result = getHints(editor);
if (!result || !result.list.length) return;
var completions = result.list;
function insert(str) {
editor.replaceRange(str, result.from, result.to);
}
// When there is only one completion, use it directly.
if (completions.length == 1) {insert(completions[0]); return true;}

// Build the select widget
var complete = document.createElement("div");
complete.className = "CodeMirror-completions";
var sel = complete.appendChild(document.createElement("select"));
// Opera doesn't move the selection when pressing up/down in a
// multi-select, but it does properly support the size property on
// single-selects, so no multi-select is necessary.
if (!window.opera) sel.multiple = true;
for (var i = 0; i < completions.length; ++i) {
var opt = sel.appendChild(document.createElement("option"));
opt.appendChild(document.createTextNode(completions[i]));
}
sel.firstChild.selected = true;
sel.size = Math.min(10, completions.length);
var pos = editor.cursorCoords();
complete.style.left = pos.x + "px";
complete.style.top = pos.yBot + "px";
document.body.appendChild(complete);
// 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);
if(winW - pos.x < sel.clientWidth)
complete.style.left = (pos.x - sel.clientWidth) + "px";
// Hack to hide the scrollbar.
if (completions.length <= 10)
complete.style.width = (sel.clientWidth - 1) + "px";

var done = false;
function close() {
if (done) return;
done = true;
complete.parentNode.removeChild(complete);
}
});
CodeMirror.connect(sel, "dblclick", pick);
function pick() {
insert(completions[sel.selectedIndex]);
close();
setTimeout(function(){editor.focus();}, 50);
}
CodeMirror.connect(sel, "blur", close);
CodeMirror.connect(sel, "keydown", function(event) {
var code = event.keyCode;
// Enter
if (code == 13) {CodeMirror.e_stop(event); pick();}
// Escape
else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();}
else if (code != 38 && code != 40) {
close(); editor.focus();
// Pass the event to the CodeMirror instance so that it can handle things like backspace properly.
editor.triggerOnKeyDown(event);
// Don't show completions if the code is backspace and the option is set.
if (!options.closeOnBackspace || code != 8) {
setTimeout(function(){collectHints(tempToken);}, 50);
}
}
});
CodeMirror.connect(sel, "dblclick", pick);

sel.focus();
// Opera sometimes ignores focusing a freshly created node
if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
return true;
sel.focus();
// Opera sometimes ignores focusing a freshly created node
if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
return true;
}
return collectHints();
};
CodeMirror.simpleHint.defaults = {
closeOnBackspace: true,
closeOnTokenChange: false
};
})();
16 changes: 8 additions & 8 deletions lib/util/xml-hint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


(function() {

CodeMirror.xmlHints = [];
Expand All @@ -15,7 +15,7 @@
// dirty hack for simple-hint to receive getHint event on space
var getTokenAt = editor.getTokenAt;

editor.getTokenAt = function() { return 'disabled'; }
editor.getTokenAt = function() { return 'disabled'; };
CodeMirror.simpleHint(cm, getHint);

editor.getTokenAt = getTokenAt;
Expand All @@ -40,7 +40,7 @@
}
}

text = text.substr(0, text.length - typed.length);
text = text.slice(0, text.length - typed.length);

var path = getActiveElement(cm, text) + simbol;
var hints = CodeMirror.xmlHints[path];
Expand All @@ -58,10 +58,10 @@
return {
list: hints,
from: { line: cursor.line, ch: cursor.ch - typed.length },
to: cursor,
to: cursor
};
};
}
};

var getActiveElement = function(codeMirror, text) {

Expand All @@ -76,7 +76,7 @@
while ((match = regex.exec(text)) != null) {
matches.push({
tag: match[1],
selfclose: (match[0].substr(-1) === '/>')
selfclose: (match[0].slice(match[0].length - 2) === '/>')
});
}

Expand Down Expand Up @@ -114,7 +114,7 @@

if (close < open)
{
text = text.substr(open);
text = text.slice(open);

if(text != '<') {

Expand All @@ -127,7 +127,7 @@
if (space < 0)
space = text.length;

return text.substr(0, space);
return text.slice(0, space);
}
}

Expand Down
8 changes: 6 additions & 2 deletions mode/clike/clike.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,18 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
return "string";
}

CodeMirror.defineMIME("text/x-csrc", {
function mimes(ms, mode) {
for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode);
}

mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], {
name: "clike",
keywords: words(cKeywords),
blockKeywords: words("case do else for if switch while struct"),
atoms: words("null"),
hooks: {"#": cppHook}
});
CodeMirror.defineMIME("text/x-c++src", {
mimes(["text/x-c++src", "text/x-c++hdr"], {
name: "clike",
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
"static_cast typeid catch operator template typename class friend private " +
Expand Down
1 change: 1 addition & 0 deletions mode/clike/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: C-like mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/clike/scala.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: C-like mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<link rel="stylesheet" href="../../theme/ambiance.css">
Expand Down
2 changes: 1 addition & 1 deletion mode/clojure/clojure.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ CodeMirror.defineMode("clojure", function (config, mode) {
} else if (isNumber(ch,stream)){
returnType = NUMBER;
} else if (ch == "(" || ch == "[") {
var keyWord = ''; var indentTemp = stream.column();
var keyWord = '', indentTemp = stream.column(), letter;
/**
Either
(indent-word ..
Expand Down
1 change: 1 addition & 0 deletions mode/clojure/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Clojure mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions mode/coffeescript/coffeescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ CodeMirror.defineMode('coffeescript', function(conf) {
}
if (singleline) {
if (conf.mode.singleLineStringErrors) {
outclass = ERRORCLASS
outclass = ERRORCLASS;
} else {
state.tokenize = tokenBase;
}
Expand All @@ -205,7 +205,7 @@ CodeMirror.defineMode('coffeescript', function(conf) {
}
stream.eatWhile("#");
}
return "comment"
return "comment";
}

function indent(stream, state, type) {
Expand Down Expand Up @@ -244,7 +244,7 @@ CodeMirror.defineMode('coffeescript', function(conf) {
while (state.scopes[0].offset !== _indent) {
state.scopes.shift();
}
return false
return false;
} else {
state.scopes.shift();
return false;
Expand Down
1 change: 1 addition & 0 deletions mode/coffeescript/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: CoffeeScript mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
54 changes: 52 additions & 2 deletions mode/css/css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
CodeMirror.defineMode("css", function(config) {
var indentUnit = config.indentUnit, type;

var keywords = keySet(["above", "absolute", "activeborder", "activecaption", "afar", "after-white-space", "ahead", "alias", "all", "all-scroll",
"alternate", "always", "amharic", "amharic-abegede", "antialiased", "appworkspace", "arabic-indic", "armenian", "asterisks",
"auto", "avoid", "background", "backwards", "baseline", "below", "bidi-override", "binary", "bengali", "blink",
"block", "block-axis", "bold", "bolder", "border", "border-box", "both", "bottom", "break-all", "break-word", "button",
"button-bevel", "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian", "capitalize", "caps-lock-indicator",
"caption", "captiontext", "caret", "cell", "center", "checkbox", "circle", "cjk-earthly-branch", "cjk-heavenly-stem", "cjk-ideographic",
"clear", "clip", "close-quote", "col-resize", "collapse", "compact", "condensed", "contain", "content", "content-box", "context-menu",
"continuous", "copy", "cover", "crop", "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal", "decimal-leading-zero", "default",
"default-button", "destination-atop", "destination-in", "destination-out", "destination-over", "devanagari", "disc", "discard", "document",
"dot-dash", "dot-dot-dash", "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", "element",
"ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede", "ethiopic-abegede-am-et", "ethiopic-abegede-gez",
"ethiopic-abegede-ti-er", "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er", "ethiopic-halehame-aa-et",
"ethiopic-halehame-am-et", "ethiopic-halehame-gez", "ethiopic-halehame-om-et", "ethiopic-halehame-sid-et",
"ethiopic-halehame-so-et", "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig", "ew-resize", "expanded",
"extra-condensed", "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes", "forwards", "from", "geometricPrecision",
"georgian", "graytext", "groove", "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew", "help",
"hidden", "hide", "higher", "highlight", "highlighttext", "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", "infobackground", "infotext", "inherit", "initial", "inline",
"inline-axis", "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert", "italic", "justify", "kannada", "katakana",
"katakana-iroha", "khmer", "landscape", "lao", "large", "larger", "left", "level", "lighter", "line-through", "linear", "lines",
"list-item", "listbox", "listitem", "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", "lower-greek",
"lower-hexadecimal", "lower-latin", "lower-norwegian", "lower-roman", "lowercase", "ltr", "malayalam", "match", "media-controls-background",
"media-current-time-display", "media-fullscreen-button", "media-mute-button", "media-play-button", "media-return-to-realtime-button",
"media-rewind-button", "media-seek-back-button", "media-seek-forward-button", "media-slider", "media-sliderthumb", "media-time-remaining-display",
"media-volume-slider", "media-volume-slider-container", "media-volume-sliderthumb", "medium", "menu", "menulist", "menulist-button",
"menulist-text", "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", "mix", "mongolian", "monospace", "move", "multiple",
"myanmar", "n-resize", "narrower", "navy", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", "no-open-quote", "no-repeat", "none",
"normal", "not-allowed", "nowrap", "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote", "optimizeLegibility",
"optimizeSpeed", "oriya", "oromo", "outset", "outside", "overlay", "overline", "padding", "padding-box", "painted", "paused",
"persian", "plus-darker", "plus-lighter", "pointer", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress",
"push-button", "radio", "read-only", "read-write", "read-write-plaintext-only", "relative", "repeat", "repeat-x",
"repeat-y", "reset", "reverse", "rgb", "rgba", "ridge", "right", "round", "row-resize", "rtl", "run-in", "running", "s-resize", "sans-serif",
"scroll", "scrollbar", "se-resize", "searchfield", "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
"searchfield-results-decoration", "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama", "single",
"skip-white-space", "slide", "slider-horizontal", "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
"small", "small-caps", "small-caption", "smaller", "solid", "somali", "source-atop", "source-in", "source-out", "source-over",
"space", "square", "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub", "subpixel-antialiased", "super",
"sw-resize", "table", "table-caption", "table-cell", "table-column", "table-column-group", "table-footer-group", "table-header-group",
"table-row", "table-row-group", "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", "thick", "thin",
"threeddarkshadow", "threedface", "threedhighlight", "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", "tigrinya-er-abegede",
"tigrinya-et", "tigrinya-et-abegede", "to", "top", "transparent", "ultra-condensed", "ultra-expanded", "underline", "up", "upper-alpha", "upper-armenian",
"upper-greek", "upper-hexadecimal", "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", "vertical", "vertical-text", "visible",
"visibleFill", "visiblePainted", "visibleStroke", "visual", "w-resize", "wait", "wave", "white", "wider", "window", "windowframe", "windowtext",
"x-large", "x-small", "xor", "xx-large", "xx-small", "yellow", "-wap-marquee", "-webkit-activelink", "-webkit-auto", "-webkit-baseline-middle",
"-webkit-body", "-webkit-box", "-webkit-center", "-webkit-control", "-webkit-focus-ring-color", "-webkit-grab", "-webkit-grabbing",
"-webkit-gradient", "-webkit-inline-box", "-webkit-left", "-webkit-link", "-webkit-marquee", "-webkit-mini-control", "-webkit-nowrap", "-webkit-pictograph",
"-webkit-right", "-webkit-small-control", "-webkit-text", "-webkit-xxx-large", "-webkit-zoom-in", "-webkit-zoom-out"]);

function keySet(array) { var keys = {}; for (var i = 0; i < array.length; ++i) keys[array[i]] = true; return keys; }
function ret(style, tp) {type = tp; return style;}

function tokenBase(stream, state) {
Expand Down Expand Up @@ -34,7 +84,7 @@ CodeMirror.defineMode("css", function(config) {
else if (/[,.+>*\/]/.test(ch)) {
return ret(null, "select-op");
}
else if (/[;{}:\[\]]/.test(ch)) {
else if (/[;{}:\[\]\(\)]/.test(ch)) {
return ret(null, ch);
}
else {
Expand Down Expand Up @@ -94,7 +144,7 @@ CodeMirror.defineMode("css", function(config) {
var context = state.stack[state.stack.length-1];
if (type == "hash" && context != "rule") style = "string-2";
else if (style == "variable") {
if (context == "rule") style = "number";
if (context == "rule") style = keywords[stream.current()] ? "keyword" : "number";
else if (!context || context == "@media{") style = "tag";
}

Expand Down
1 change: 1 addition & 0 deletions mode/css/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: CSS mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/diff/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Diff mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion mode/ecl/ecl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CodeMirror.defineMode("ecl", function(config) {
}
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
curPunc = ch;
return null
return null;
}
if (/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
Expand Down
1 change: 1 addition & 0 deletions mode/erlang/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Erlang mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
7 changes: 4 additions & 3 deletions mode/gfm/gfm.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {

return function (lang) {
return modes[lang] ? CodeMirror.getMode(config, modes[lang]) : null;
}
};
}());

function markdown(stream, state) {
// intercept fenced code blocks
if (stream.sol() && stream.match(/^```([\w+#]*)/)) {
// try switching mode
state.localMode = getMode(RegExp.$1)
state.localMode = getMode(RegExp.$1);
if (state.localMode)
state.localState = state.localMode.startState();

Expand Down Expand Up @@ -103,6 +103,7 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {

token: function(stream, state) {
/* Parse GFM double bracket links */
var ch;
if ((ch = stream.peek()) != undefined && ch == '[') {
stream.next(); // Advance the stream

Expand Down Expand Up @@ -140,5 +141,5 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {

return state.token(stream, state);
}
}
};
}, "markdown");
1 change: 1 addition & 0 deletions mode/gfm/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: GFM mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions mode/go/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
}
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
curPunc = ch;
return null
return null;
}
if (ch == "/") {
if (stream.eat("*")) {
Expand Down Expand Up @@ -144,7 +144,7 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
if (curPunc == "{") pushContext(state, stream.column(), "}");
else if (curPunc == "[") pushContext(state, stream.column(), "]");
else if (curPunc == "(") pushContext(state, stream.column(), ")");
else if (curPunc == "case") ctx.type = "case"
else if (curPunc == "case") ctx.type = "case";
else if (curPunc == "}" && ctx.type == "}") ctx = popContext(state);
else if (curPunc == ctx.type) popContext(state);
state.startOfLine = false;
Expand Down
1 change: 1 addition & 0 deletions mode/go/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Go mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<link rel="stylesheet" href="../../theme/elegant.css">
Expand Down
2 changes: 1 addition & 1 deletion mode/groovy/groovy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CodeMirror.defineMode("groovy", function(config, parserConfig) {
}
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
curPunc = ch;
return null
return null;
}
if (/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
Expand Down
1 change: 1 addition & 0 deletions mode/groovy/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Groovy mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions mode/haskell/haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
}
setState(ncomment(type, currNest));
return type;
}
};
}

function stringLiteral(source, setState) {
Expand Down Expand Up @@ -170,7 +170,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
return function () {
for (var i = 0; i < arguments.length; i++)
wkw[arguments[i]] = t;
}
};
}

setType("keyword")(
Expand Down
1 change: 1 addition & 0 deletions mode/haskell/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Haskell mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions mode/haxe/haxe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
var keywords = function(){
function kw(type) {return {type: type, style: "keyword"};}
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
var operator = kw("operator"), atom = {type: "atom", style: "atom"}, attribute = {type:"attribute", style: "attribute"}
var operator = kw("operator"), atom = {type: "atom", style: "atom"}, attribute = {type:"attribute", style: "attribute"};
var type = kw("typedef");
return {
"if": A, "while": A, "else": B, "do": B, "try": B,
Expand Down Expand Up @@ -219,7 +219,7 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
function pushlex(type, info) {
var result = function() {
var state = cx.state;
state.lexical = new HaxeLexical(state.indented, cx.stream.column(), type, null, state.lexical, info)
state.lexical = new HaxeLexical(state.indented, cx.stream.column(), type, null, state.lexical, info);
};
result.lex = true;
return result;
Expand All @@ -243,7 +243,7 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
}

function statement(type) {
if (type == "@") return cont(metadef)
if (type == "@") return cont(metadef);
if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex);
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
Expand Down Expand Up @@ -297,7 +297,7 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
function metadef(type, value) {
if(type == ":") return cont(metadef);
if(type == "variable") return cont(metadef);
if(type == "(") return cont(pushlex(")"), comasep(metaargs, ")"), poplex, statement)
if(type == "(") return cont(pushlex(")"), comasep(metaargs, ")"), poplex, statement);
}
function metaargs(type, value) {
if(typ == "variable") return cont();
Expand Down
1 change: 1 addition & 0 deletions mode/haxe/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Haxe mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions mode/htmlembedded/htmlembedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
htmlState : htmlMixedMode.startState(),
scriptState : scriptingMode.startState()
}
};
},

token: function(stream, state) {
Expand All @@ -55,12 +55,12 @@ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
token : state.token,
htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
}
};
},


electricChars: "/{}:"
}
};
}, "htmlmixed");

CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
Expand Down
1 change: 1 addition & 0 deletions mode/htmlembedded/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Html Embedded Scripts mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion mode/htmlmixed/htmlmixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
},

electricChars: "/{}:"
}
};
}, "xml", "javascript", "css");

CodeMirror.defineMIME("text/html", "htmlmixed");
1 change: 1 addition & 0 deletions mode/htmlmixed/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: HTML mixed mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/javascript/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: JavaScript mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions mode/javascript/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
function pushlex(type, info) {
var result = function() {
var state = cx.state;
state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info)
state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info);
};
result.lex = true;
return result;
Expand Down Expand Up @@ -243,7 +243,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {

function maybeoperator(type, value) {
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
if (type == "operator" || type == ":") return cont(expression);
if (type == "operator" && value == "?") return cont(expression, expect(":"), expression);
if (type == ";") return;
if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
if (type == ".") return cont(property, maybeoperator);
Expand Down
1 change: 1 addition & 0 deletions mode/jinja2/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Jinja2 mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
126 changes: 124 additions & 2 deletions mode/less/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,140 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: LESS mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="less.js"></script>
<style>.CodeMirror {background: #f8f8f8; border: 1px solid #ddd; font-size:12px} .CodeMirror-scroll {height: 400px}</style>
<link rel="stylesheet" href="../../doc/docs.css">
<link rel="stylesheet" href="../../theme/lesser-dark.css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>CodeMirror: LESS mode</h1>
<form><textarea id="code" name="code">/* Some LESS code */
<form><textarea id="code" name="code">@media screen and (device-aspect-ratio: 16/9) { … }
@media screen and (device-aspect-ratio: 32/18) { … }
@media screen and (device-aspect-ratio: 1280/720) { … }
@media screen and (device-aspect-ratio: 2560/1440) { … }

html:lang(fr-be)
html:lang(de)
:lang(fr-be) > q
:lang(de) > q

tr:nth-child(2n+1) /* represents every odd row of an HTML table */
tr:nth-child(odd) /* same */
tr:nth-child(2n+0) /* represents every even row of an HTML table */
tr:nth-child(even) /* same */

/* Alternate paragraph colours in CSS */
p:nth-child(4n+1) { color: navy; }
p:nth-child(4n+2) { color: green; }
p:nth-child(4n+3) { color: maroon; }
p:nth-child(4n+4) { color: purple; }

:nth-child(10n-1) /* represents the 9th, 19th, 29th, etc, element */
:nth-child(10n+9) /* Same */
:nth-child(10n+-1) /* Syntactically invalid, and would be ignored */

:nth-child( 3n + 1 )
:nth-child( +3n - 2 )
:nth-child( -n+ 6)
:nth-child( +6 )

html|tr:nth-child(-n+6) /* represents the 6 first rows of XHTML tables */

img:nth-of-type(2n+1) { float: right; }
img:nth-of-type(2n) { float: left; }

body > h2:nth-of-type(n+2):nth-last-of-type(n+2)
body > h2:not(:first-of-type):not(:last-of-type)

html|*:not(:link):not(:visited)
*|*:not(:hover)
p::first-line { text-transform: uppercase }

p { color: red; font-size: 12pt }
p::first-letter { color: green; font-size: 200% }
p::first-line { color: blue }

p { line-height: 1.1 }
p::first-letter { font-size: 3em; font-weight: normal }
span { font-weight: bold }

* /* a=0 b=0 c=0 -> specificity = 0 */
LI /* a=0 b=0 c=1 -> specificity = 1 */
UL LI /* a=0 b=0 c=2 -> specificity = 2 */
UL OL+LI /* a=0 b=0 c=3 -> specificity = 3 */
H1 + *[REL=up] /* a=0 b=1 c=1 -> specificity = 11 */
UL OL LI.red /* a=0 b=1 c=3 -> specificity = 13 */
LI.red.level /* a=0 b=2 c=1 -> specificity = 21 */
#x34y /* a=1 b=0 c=0 -> specificity = 100 */
#s12:not(FOO) /* a=1 b=0 c=1 -> specificity = 101 */

@namespace foo url(http://www.example.com);
foo|h1 { color: blue } /* first rule */
foo|* { color: yellow } /* second rule */
|h1 { color: red } /* ...*/
*|h1 { color: green }
h1 { color: green }

span[hello="Ocean"][goodbye="Land"]

a[rel~="copyright"] { ... }
a[href="http://www.w3.org/"] { ... }

DIALOGUE[character=romeo]
DIALOGUE[character=juliet]

[att^=val]
[att$=val]
[att*=val]

@namespace foo "http://www.example.com";
[foo|att=val] { color: blue }
[*|att] { color: yellow }
[|att] { color: green }
[att] { color: green }


*:target { color : red }
*:target::before { content : url(target.png) }

E[foo]{
padding:65px;
}
E[foo] ~ F{
padding:65px;
}
E#myid{
padding:65px;
}
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
-webkit-appearance: none; // Inner-padding issues in Chrome OSX, Safari 5
}
button::-moz-focus-inner,
input::-moz-focus-inner { // Inner padding and border oddities in FF3/4
padding: 0;
border: 0;
}
.btn {
// reset here as of 2.0.3 due to Recess property order
border-color: #ccc;
border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);
}
fieldset span button, fieldset span input[type="file"] {
font-size:12px;
font-family:Arial, Helvetica, sans-serif;
}
.el tr:nth-child(even):last-child td:first-child{
-moz-border-radius-bottomleft:3px;
-webkit-border-bottom-left-radius:3px;
border-bottom-left-radius:3px;
}

/* Some LESS code */

button {
width: 32px;
Expand Down
154 changes: 94 additions & 60 deletions mode/less/less.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
/*
LESS mode - http://www.lesscss.org/
Ported to CodeMirror by Peter Kroon
Ported to CodeMirror by Peter Kroon <plakroon@gmail.com>
Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues GitHub: @peterkroon
*/

CodeMirror.defineMode("less", function(config) {
var indentUnit = config.indentUnit, type;
function ret(style, tp) {type = tp; return style;}
//html5 tags
var tags = ["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","command","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","keygen","kbd","label","legend","li","link","map","mark","menu","meta","meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr"];
//html tags
var tags = "a abbr acronym address applet area article aside audio b base basefont bdi bdo big blockquote body br button canvas caption cite code col colgroup command datalist dd del details dfn dir div dl dt em embed fieldset figcaption figure font footer form frame frameset h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins keygen kbd label legend li link map mark menu meta meter nav noframes noscript object ol optgroup option output p param pre progress q rp rt ruby s samp script section select small source span strike strong style sub summary sup table tbody td textarea tfoot th thead time title tr track tt u ul var video wbr".split(' ');

function inTagsArray(val){
for(var i=0; i<tags.length; i++){
if(val === tags[i]){
return true;
}
}
for(var i=0; i<tags.length; i++)if(val === tags[i])return true;
}


var selectors = /(^\:root$|^\:nth\-child$|^\:nth\-last\-child$|^\:nth\-of\-type$|^\:nth\-last\-of\-type$|^\:first\-child$|^\:last\-child$|^\:first\-of\-type$|^\:last\-of\-type$|^\:only\-child$|^\:only\-of\-type$|^\:empty$|^\:link|^\:visited$|^\:active$|^\:hover$|^\:focus$|^\:target$|^\:lang$|^\:enabled^\:disabled$|^\:checked$|^\:first\-line$|^\:first\-letter$|^\:before$|^\:after$|^\:not$|^\:required$|^\:invalid$)/;

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

if (ch == "@") {stream.eatWhile(/[\w\-]/); return ret("meta", stream.current());}
else if (ch == "/" && stream.eat("*")) {
state.tokenize = tokenCComment;
Expand All @@ -30,19 +29,20 @@ CodeMirror.defineMode("less", function(config) {
return tokenSGMLComment(stream, state);
}
else if (ch == "=") ret(null, "compare");
else if ((ch == "~" || ch == "|") && stream.eat("=")) return 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 == "/") { // lesscss 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{
stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/);
if(/\/|\)|#/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")))return ret("string", "string");//let url(/images/logo.png) without quotes return as string
return ret("number", "unit");
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 == "!") {
Expand All @@ -53,30 +53,42 @@ CodeMirror.defineMode("less", function(config) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
}
else if (/[,+<>*\/]/.test(ch)) {//removed . dot character original was [,.+>*\/]
else if (/[,+<>*\/]/.test(ch)) {
if(stream.peek() == "=" || type == "a")return ret("string", "string");
return ret(null, "select-op");
}
else if (/[;{}:\[\]()]/.test(ch)) { //added () char for lesscss original was [;{}:\[\]]
if(ch == ":"){
stream.eatWhile(/[active|hover|link|visited]/);
if( stream.current().match(/active|hover|link|visited/)){
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
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{
return ret(null, ch);
}
}else if(ch == "~"){
if(type == "r")return ret("string", "string");
}else{
return ret(null, ch);
}
}
else if (ch == ".") { // lesscss
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 == "#") { // lesscss
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
if(stream.current().length ===4 || stream.current().length ===7){
if(stream.current().length == 4 || stream.current().length == 7){
if(stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false) != null){//is there a valid hex color value present in the current stream
//when not a valid hex value, parse as id
if(stream.current().substring(1) != stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false))return ret("atom", "tag");
Expand All @@ -96,8 +108,8 @@ CodeMirror.defineMode("less", function(config) {
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "tag");
}
}else{
stream.eatWhile(/[\w\\\-]/);
}else{//when not a valid hexvalue length
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "tag");
}
}
Expand All @@ -107,39 +119,62 @@ CodeMirror.defineMode("less", function(config) {
}
else {
stream.eatWhile(/[\w\\\-_%.{]/);
if(stream.current().match(/http|https/) != null){
if(type == "string"){
return ret("string", "string");
}else if(stream.current().match(/(^http$|^https$)/) != null){
stream.eatWhile(/[\w\\\-_%.{:\/]/);
return ret("string", "string");
}else if(stream.peek() == "<" || stream.peek() == ">"){
return ret("tag", "tag");
}else if( stream.peek().match(/\(/) != null ){// lessc
}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)
return ret("string", "string");
}else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc... only colorize the minus sign
//stream.backUp(stream.current().length-1); //commment out these 2 comment if you want the minus sign to be parsed as null -500px
//return ret(null, ch);
}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("number", "unit");
}else if( inTagsArray(stream.current()) ){ // lesscss match html tags
}else if( inTagsArray(stream.current().toLowerCase()) ){ // match html tags
return ret("tag", "tag");
}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
if( (stream.eatSpace() && stream.peek().match(/[{<>.a-zA-Z]/) != null) || 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() ){
if(stream.current().substring(stream.current().length-1,stream.current().length) == "{")stream.backUp(1);
return ret("tag", "tag");
}else{
return ret("variable", "variable");
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" ){
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 == "("){
return ret("string", "string");
}else if(type == "|" || stream.current() == "-" || type == "["){
return ret(null, ch);
}else if(stream.peek() == ":") {
stream.next();
var t_v = stream.peek() == ":" ? true : false;
if(!t_v){
var old_pos = stream.pos;
var sc = stream.current().length;
stream.eatWhile(/[a-z\\\-]/);
var new_pos = stream.pos;
if(stream.current().substring(sc-1).match(selectors) != null){
stream.backUp(new_pos-(old_pos-1));
return ret("tag", "tag");
} else stream.backUp(new_pos-(old_pos-1));
}else{
stream.backUp(1);
}
if(t_v)return ret("tag", "tag"); else return ret("variable", "variable");
}else{
return ret("variable", "variable");
}
}

}
}

function tokenSComment(stream, state) {// SComment = Slash comment
function tokenSComment(stream, state) { // SComment = Slash comment
stream.skipToEnd();
state.tokenize = tokenBase;
return ret("comment", "comment");
Expand All @@ -156,7 +191,7 @@ CodeMirror.defineMode("less", function(config) {
}
return ret("comment", "comment");
}

function tokenSGMLComment(stream, state) {
var dashes = 0, ch;
while ((ch = stream.next()) != null) {
Expand All @@ -168,7 +203,7 @@ CodeMirror.defineMode("less", function(config) {
}
return ret("comment", "comment");
}

function tokenString(quote) {
return function(stream, state) {
var escaped = false, ch;
Expand All @@ -181,29 +216,28 @@ CodeMirror.defineMode("less", function(config) {
return ret("string", "string");
};
}

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 (type == "hash" && context == "rule") style = "atom";
else if (style == "variable") {
if (context == "rule") style = null; //"tag"
else if (!context || context == "@media{"){
style = stream.current() == "when" ? "variable" :
stream.string.match(/#/g) != undefined ? null :
/[\s,|\s\)]/.test(stream.peek()) ? "tag" : null;
}
else if (!context || context == "@media{") {
style = stream.current() == "when" ? "variable" :
/[\s,|\s\)|\s]/.test(stream.peek()) ? "tag" : type;
}
}

if (context == "rule" && /^[\{\};]$/.test(type))
state.stack.pop();
if (type == "{") {
Expand All @@ -215,18 +249,18 @@ CodeMirror.defineMode("less", function(config) {
else if (context == "{" && type != "comment") state.stack.push("rule");
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;
},

electricChars: "}"
};
});

CodeMirror.defineMIME("text/x-less", "less");
if (!CodeMirror.mimeModes.hasOwnProperty("text/css"))
CodeMirror.defineMIME("text/css", "less");
CodeMirror.defineMIME("text/css", "less");
1 change: 1 addition & 0 deletions mode/lua/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Lua mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/markdown/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Markdown mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions mode/markdown/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.em = false;
// Reset STRONG state
state.strong = false;
// Reset state.quote
state.quote = false;
if (!htmlFound && state.f == htmlBlock) {
state.f = inlineNormal;
state.block = blockNormal;
Expand Down Expand Up @@ -106,7 +108,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
}

function inlineNormal(stream, state) {
var style = state.text(stream, state)
var style = state.text(stream, state);
if (typeof style !== 'undefined')
return style;

Expand All @@ -119,7 +121,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (ch === '`') {
return switchInline(stream, state, inlineElement(code, '`'));
}
if (ch === '[') {
if (ch === '[' && stream.match(/.*\](?:\(|\[)/, false)) {
return switchInline(stream, state, linkText);
}
if (ch === '<' && stream.match(/^\w/, false)) {
Expand Down Expand Up @@ -246,8 +248,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {

// Reset state.header
state.header = false;
// Reset state.quote
state.quote = false;

state.f = state.block;
var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length;
Expand Down
1 change: 1 addition & 0 deletions mode/mysql/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: MySQL mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/ntriples/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: NTriples mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions mode/ntriples/ntriples.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
CodeMirror.defineMode("ntriples", function() {

Location = {
var Location = {
PRE_SUBJECT : 0,
WRITING_SUB_URI : 1,
WRITING_BNODE_URI : 2,
Expand Down Expand Up @@ -87,8 +87,8 @@ CodeMirror.defineMode("ntriples", function() {
currState.location=ret;
}

untilSpace = function(c) { return c != ' '; };
untilEndURI = function(c) { return c != '>'; };
var untilSpace = function(c) { return c != ' '; };
var untilEndURI = function(c) { return c != '>'; };
return {
startState: function() {
return {
Expand All @@ -114,7 +114,7 @@ CodeMirror.defineMode("ntriples", function() {
}
if(ch == '#') {
var parsedAnchor = '';
stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false});
stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false;});
state.anchors.push(parsedAnchor);
return 'variable-2';
}
Expand Down
2 changes: 1 addition & 1 deletion mode/ocaml/ocaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CodeMirror.defineMode('ocaml', function(config) {
}

return {
startState: function() {return {tokenize: tokenBase, commentLevel: 0}},
startState: function() {return {tokenize: tokenBase, commentLevel: 0};},
token: function(stream, state) {
if (stream.eatSpace()) return null;
return state.tokenize(stream, state);
Expand Down
1 change: 1 addition & 0 deletions mode/pascal/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Pascal mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion mode/pascal/pascal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CodeMirror.defineMode("pascal", function(config) {
return tokenComment(stream, state);
}
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
return null
return null;
}
if (/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
Expand Down
1 change: 1 addition & 0 deletions mode/perl/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Perl mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
142 changes: 71 additions & 71 deletions mode/perl/perl.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,22 +477,22 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
if(chain[++i]!==undefined){
state.chain=chain[i];
state.style=style;
state.tail=tail}
state.tail=tail;}
else if(tail)
stream.eatWhile(tail);
state.tokenize=tokenPerl;
return style}
e=!e&&c=="\\"}
return style};
return state.tokenize(stream,state)}
return style;}
e=!e&&c=="\\";}
return style;};
return state.tokenize(stream,state);}

function tokenSOMETHING(stream,state,string){
state.tokenize=function(stream,state){
if(stream.string==string)
state.tokenize=tokenPerl;
stream.skipToEnd();
return "string"};
return state.tokenize(stream,state)}
return "string";};
return state.tokenize(stream,state);}

function tokenPerl(stream,state){
if(stream.eatSpace())
Expand All @@ -504,9 +504,9 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
return 'number';
if(stream.match(/^<<(?=\w)/)){ // NOTE: <<SOMETHING\n...\nSOMETHING\n
stream.eatWhile(/\w/);
return tokenSOMETHING(stream,state,stream.current().substr(2))}
return tokenSOMETHING(stream,state,stream.current().substr(2));}
if(stream.sol()&&stream.match(/^\=item(?!\w)/)){// NOTE: \n=item...\n=cut\n
return tokenSOMETHING(stream,state,'=cut')}
return tokenSOMETHING(stream,state,'=cut');}
var ch=stream.next();
if(ch=='"'||ch=="'"){ // NOTE: ' or " or <<'SOMETHING'\n...\nSOMETHING\n or <<"SOMETHING"\n...\nSOMETHING\n
if(stream.prefix(3)=="<<"+ch){
Expand All @@ -515,8 +515,8 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
var n=stream.current().substr(1);
if(n&&stream.eat(ch))
return tokenSOMETHING(stream,state,n);
stream.pos=p}
return tokenChain(stream,state,[ch],"string")}
stream.pos=p;}
return tokenChain(stream,state,[ch],"string");}
if(ch=="q"){
var c=stream.look(-2);
if(!(c&&/\w/.test(c))){
Expand All @@ -525,100 +525,100 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
c=stream.look(1);
if(c=="("){
stream.eatSuffix(2);
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
if(c=="["){
stream.eatSuffix(2);
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
if(c=="{"){
stream.eatSuffix(2);
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
if(c=="<"){
stream.eatSuffix(2);
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}
if(/[\^'"!~\/]/.test(c)){
stream.eatSuffix(1);
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers)}}
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers);}}
else if(c=="q"){
c=stream.look(1);
if(c=="("){
stream.eatSuffix(2);
return tokenChain(stream,state,[")"],"string")}
return tokenChain(stream,state,[")"],"string");}
if(c=="["){
stream.eatSuffix(2);
return tokenChain(stream,state,["]"],"string")}
return tokenChain(stream,state,["]"],"string");}
if(c=="{"){
stream.eatSuffix(2);
return tokenChain(stream,state,["}"],"string")}
return tokenChain(stream,state,["}"],"string");}
if(c=="<"){
stream.eatSuffix(2);
return tokenChain(stream,state,[">"],"string")}
return tokenChain(stream,state,[">"],"string");}
if(/[\^'"!~\/]/.test(c)){
stream.eatSuffix(1);
return tokenChain(stream,state,[stream.eat(c)],"string")}}
return tokenChain(stream,state,[stream.eat(c)],"string");}}
else if(c=="w"){
c=stream.look(1);
if(c=="("){
stream.eatSuffix(2);
return tokenChain(stream,state,[")"],"bracket")}
return tokenChain(stream,state,[")"],"bracket");}
if(c=="["){
stream.eatSuffix(2);
return tokenChain(stream,state,["]"],"bracket")}
return tokenChain(stream,state,["]"],"bracket");}
if(c=="{"){
stream.eatSuffix(2);
return tokenChain(stream,state,["}"],"bracket")}
return tokenChain(stream,state,["}"],"bracket");}
if(c=="<"){
stream.eatSuffix(2);
return tokenChain(stream,state,[">"],"bracket")}
return tokenChain(stream,state,[">"],"bracket");}
if(/[\^'"!~\/]/.test(c)){
stream.eatSuffix(1);
return tokenChain(stream,state,[stream.eat(c)],"bracket")}}
return tokenChain(stream,state,[stream.eat(c)],"bracket");}}
else if(c=="r"){
c=stream.look(1);
if(c=="("){
stream.eatSuffix(2);
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
if(c=="["){
stream.eatSuffix(2);
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
if(c=="{"){
stream.eatSuffix(2);
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
if(c=="<"){
stream.eatSuffix(2);
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}
if(/[\^'"!~\/]/.test(c)){
stream.eatSuffix(1);
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers)}}
return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers);}}
else if(/[\^'"!~\/(\[{<]/.test(c)){
if(c=="("){
stream.eatSuffix(1);
return tokenChain(stream,state,[")"],"string")}
return tokenChain(stream,state,[")"],"string");}
if(c=="["){
stream.eatSuffix(1);
return tokenChain(stream,state,["]"],"string")}
return tokenChain(stream,state,["]"],"string");}
if(c=="{"){
stream.eatSuffix(1);
return tokenChain(stream,state,["}"],"string")}
return tokenChain(stream,state,["}"],"string");}
if(c=="<"){
stream.eatSuffix(1);
return tokenChain(stream,state,[">"],"string")}
return tokenChain(stream,state,[">"],"string");}
if(/[\^'"!~\/]/.test(c)){
return tokenChain(stream,state,[stream.eat(c)],"string")}}}}
return tokenChain(stream,state,[stream.eat(c)],"string");}}}}
if(ch=="m"){
var c=stream.look(-2);
if(!(c&&/\w/.test(c))){
c=stream.eat(/[(\[{<\^'"!~\/]/);
if(c){
if(/[\^'"!~\/]/.test(c)){
return tokenChain(stream,state,[c],RXstyle,RXmodifiers)}
return tokenChain(stream,state,[c],RXstyle,RXmodifiers);}
if(c=="("){
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
if(c=="["){
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
if(c=="{"){
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers)}
return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
if(c=="<"){
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers)}}}}
return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}}}}
if(ch=="s"){
var c=/[\/>\]})\w]/.test(stream.look(-2));
if(!c){
Expand All @@ -632,7 +632,7 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
if(c=="(")
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers)}}}
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}
if(ch=="y"){
var c=/[\/>\]})\w]/.test(stream.look(-2));
if(!c){
Expand All @@ -646,7 +646,7 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
if(c=="(")
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers)}}}
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}
if(ch=="t"){
var c=/[\/>\]})\w]/.test(stream.look(-2));
if(!c){
Expand All @@ -661,65 +661,65 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
if(c=="(")
return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers)}}}}
return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}}
if(ch=="`"){
return tokenChain(stream,state,[ch],"variable-2")}
return tokenChain(stream,state,[ch],"variable-2");}
if(ch=="/"){
if(!/~\s*$/.test(stream.prefix()))
return "operator";
else
return tokenChain(stream,state,[ch],RXstyle,RXmodifiers)}
return tokenChain(stream,state,[ch],RXstyle,RXmodifiers);}
if(ch=="$"){
var p=stream.pos;
if(stream.eatWhile(/\d/)||stream.eat("{")&&stream.eatWhile(/\d/)&&stream.eat("}"))
return "variable-2";
else
stream.pos=p}
stream.pos=p;}
if(/[$@%]/.test(ch)){
var p=stream.pos;
if(stream.eat("^")&&stream.eat(/[A-Z]/)||!/[@$%&]/.test(stream.look(-2))&&stream.eat(/[=|\\\-#?@;:&`~\^!\[\]*'"$+.,\/<>()]/)){
var c=stream.current();
if(PERL[c])
return "variable-2"}
stream.pos=p}
return "variable-2";}
stream.pos=p;}
if(/[$@%&]/.test(ch)){
if(stream.eatWhile(/[\w$\[\]]/)||stream.eat("{")&&stream.eatWhile(/[\w$\[\]]/)&&stream.eat("}")){
var c=stream.current();
if(PERL[c])
return "variable-2";
else
return "variable"}}
return "variable";}}
if(ch=="#"){
if(stream.look(-2)!="$"){
stream.skipToEnd();
return "comment"}}
return "comment";}}
if(/[:+\-\^*$&%@=<>!?|\/~\.]/.test(ch)){
var p=stream.pos;
stream.eatWhile(/[:+\-\^*$&%@=<>!?|\/~\.]/);
if(PERL[stream.current()])
return "operator";
else
stream.pos=p}
stream.pos=p;}
if(ch=="_"){
if(stream.pos==1){
if(stream.suffix(6)=="_END__"){
return tokenChain(stream,state,['\0'],"comment")}
return tokenChain(stream,state,['\0'],"comment");}
else if(stream.suffix(7)=="_DATA__"){
return tokenChain(stream,state,['\0'],"variable-2")}
return tokenChain(stream,state,['\0'],"variable-2");}
else if(stream.suffix(7)=="_C__"){
return tokenChain(stream,state,['\0'],"string")}}}
return tokenChain(stream,state,['\0'],"string");}}}
if(/\w/.test(ch)){
var p=stream.pos;
if(stream.look(-2)=="{"&&(stream.look(0)=="}"||stream.eatWhile(/\w/)&&stream.look(0)=="}"))
return "string";
else
stream.pos=p}
stream.pos=p;}
if(/[A-Z]/.test(ch)){
var l=stream.look(-2);
var p=stream.pos;
stream.eatWhile(/[A-Z_]/);
if(/[\da-z]/.test(stream.look(0))){
stream.pos=p}
stream.pos=p;}
else{
var c=PERL[stream.current()];
if(!c)
Expand All @@ -738,9 +738,9 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
else if(c==5)
return "variable-2";
else
return "meta"}
return "meta";}
else
return "meta"}}
return "meta";}}
if(/[a-zA-Z_]/.test(ch)){
var l=stream.look(-2);
stream.eatWhile(/\w/);
Expand All @@ -761,48 +761,48 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
else if(c==5)
return "variable-2";
else
return "meta"}
return "meta";}
else
return "meta"}
return null}
return "meta";}
return null;}

return{
startState:function(){
return{
tokenize:tokenPerl,
chain:null,
style:null,
tail:null}},
tail:null};},
token:function(stream,state){
return (state.tokenize||tokenPerl)(stream,state)},
electricChars:"{}"}});
return (state.tokenize||tokenPerl)(stream,state);},
electricChars:"{}"};});

CodeMirror.defineMIME("text/x-perl", "perl");

// it's like "peek", but need for look-ahead or look-behind if index < 0
CodeMirror.StringStream.prototype.look=function(c){
return this.string.charAt(this.pos+(c||0))};
return this.string.charAt(this.pos+(c||0));};

// return a part of prefix of current stream from current position
CodeMirror.StringStream.prototype.prefix=function(c){
if(c){
var x=this.pos-c;
return this.string.substr((x>=0?x:0),c)}
return this.string.substr((x>=0?x:0),c);}
else{
return this.string.substr(0,this.pos-1)}};
return this.string.substr(0,this.pos-1);}};

// return a part of suffix of current stream from current position
CodeMirror.StringStream.prototype.suffix=function(c){
var y=this.string.length;
var x=y-this.pos+1;
return this.string.substr(this.pos,(c&&c<y?c:x))};
return this.string.substr(this.pos,(c&&c<y?c:x));};

// return a part of suffix of current stream from current position and change current position
CodeMirror.StringStream.prototype.nsuffix=function(c){
var p=this.pos;
var l=c||(this.string.length-this.pos+1);
this.pos+=l;
return this.string.substr(p,l)};
return this.string.substr(p,l);};

// eating and vomiting a part of stream from current position
CodeMirror.StringStream.prototype.eatSuffix=function(c){
Expand All @@ -813,4 +813,4 @@ CodeMirror.StringStream.prototype.eatSuffix=function(c){
else if(x>=(y=this.string.length-1))
this.pos=y;
else
this.pos=x};
this.pos=x;};
1 change: 1 addition & 0 deletions mode/php/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: PHP mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions mode/php/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if (stream.match(delim)) state.tokenize = null;
else stream.skipToEnd();
return "string";
}
};
}
var phpConfig = {
name: "clike",
Expand Down Expand Up @@ -118,7 +118,7 @@
curState: parserConfig.startOpen ? phpMode.startState() : html,
curClose: parserConfig.startOpen ? /^\?>/ : null,
mode: parserConfig.startOpen ? "php" : "html",
pending: null}
pending: null};
},

copyState: function(state) {
Expand All @@ -142,7 +142,7 @@
},

electricChars: "/{}:"
}
};
}, "xml", "clike", "javascript", "css");
CodeMirror.defineMIME("application/x-httpd-php", "php");
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
Expand Down
1 change: 1 addition & 0 deletions mode/pig/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Pig Latin mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions mode/pig/pig.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ CodeMirror.defineMode("pig", function(config, parserConfig) {
// is it one of the builtin functions?
if (builtins && builtins.propertyIsEnumerable(stream.current().toUpperCase()))
{
return ("keyword", "variable-2")
return ("keyword", "variable-2");
}
// is it one of the listed types?
if (types && types.propertyIsEnumerable(stream.current().toUpperCase()))
return ("keyword", "variable-3")
return ("keyword", "variable-3");
// default is a 'variable'
return ret("variable", "pig-word");
}
Expand Down Expand Up @@ -161,7 +161,7 @@ CodeMirror.defineMode("pig", function(config, parserConfig) {
+ "NEQ MATCHES TRUE FALSE ";

// data types
var pTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP "
var pTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP ";

CodeMirror.defineMIME("text/x-pig", {
name: "pig",
Expand Down
1 change: 1 addition & 0 deletions mode/plsql/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Oracle PL/SQL mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/properties/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Properties files mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/python/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Python mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion mode/python/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
while (state.scopes[0].offset !== _indent) {
state.scopes.shift();
}
return false
return false;
} else {
if (type === 'py') {
state.scopes[0].offset = stream.indentation();
Expand Down
1 change: 1 addition & 0 deletions mode/r/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: R mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/rpm/changes/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: RPM changes mode</title>
<link rel="stylesheet" href="../../../lib/codemirror.css">
<script src="../../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/rpm/spec/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: RPM spec mode</title>
<link rel="stylesheet" href="../../../lib/codemirror.css">
<script src="../../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/rst/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: reStructuredText mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/ruby/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Ruby mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/rust/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Rust mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
1 change: 1 addition & 0 deletions mode/scheme/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Scheme mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion mode/scheme/scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ CodeMirror.defineMode("scheme", function (config, mode) {
stream.skipToEnd(); // rest of the line is a comment
returnType = COMMENT;
} else if (ch == "(" || ch == "[") {
var keyWord = ''; var indentTemp = stream.column();
var keyWord = ''; var indentTemp = stream.column(), letter;
/**
Either
(indent-word ..
Expand Down
2 changes: 1 addition & 1 deletion mode/shell/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ CodeMirror.defineMode('shell', function(config) {
};

return {
startState: function() {return {tokens:[]}},
startState: function() {return {tokens:[]};},
token: function(stream, state) {
if (stream.eatSpace()) return null;
return tokenize(stream, state);
Expand Down
23 changes: 23 additions & 0 deletions mode/sieve/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (C) 2012 Thomas Schmid <schmid-thomas@gmx.net>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Please note that some subdirectories of the CodeMirror distribution
include their own LICENSE files, and are released under different
licences.
81 changes: 81 additions & 0 deletions mode/sieve/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Sieve (RFC5228) mode</title>
<link rel="stylesheet" href="../../doc/docs.css">
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="sieve.js"></script>
<style>.CodeMirror {background: #f8f8f8;}</style>
</head>
<body>
<h1>CodeMirror: Sieve (RFC5228) mode</h1>
<form><textarea id="code" name="code">
#
# Example Sieve Filter
# Declare any optional features or extension used by the script
#

require ["fileinto", "reject"];

#
# Reject any large messages (note that the four leading dots get
# "stuffed" to three)
#
if size :over 1M
{
reject text:
Please do not send me large attachments.
Put your file on a server and send me the URL.
Thank you.
.... Fred
.
;
stop;
}

#
# Handle messages from known mailing lists
# Move messages from IETF filter discussion list to filter folder
#
if header :is "Sender" "owner-ietf-mta-filters@imc.org"
{
fileinto "filter"; # move to "filter" folder
}
#
# Keep all messages to or from people in my company
#
elsif address :domain :is ["From", "To"] "example.com"
{
keep; # keep in "In" folder
}

#
# Try and catch unsolicited email. If a message is not to me,
# or it contains a subject known to be spam, file it away.
#
elsif anyof (not address :all :contains
["To", "Cc", "Bcc"] "me@example.com",
header :matches "subject"
["*make*money*fast*", "*university*dipl*mas*"])
{
# If message header does not contain my address,
# it's from a list.
fileinto "spam"; # move to "spam" folder
}
else
{
# Move all other (non-company) mail to "personal"
# folder.
fileinto "personal";
}
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
</script>

<p><strong>MIME types defined:</strong> <code>application/sieve</code>.</p>

</body>
</html>
Loading