From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Fri, 27 Jan 2012 12:05:17 -0800
Subject: Merged old FileIO
---
imports/codemirror/mode/clike/clike.js | 249 +++++++
imports/codemirror/mode/clike/index.html | 101 +++
imports/codemirror/mode/clojure/clojure.js | 207 ++++++
imports/codemirror/mode/clojure/index.html | 66 ++
imports/codemirror/mode/coffeescript/LICENSE | 22 +
.../codemirror/mode/coffeescript/coffeescript.js | 325 ++++++++
imports/codemirror/mode/coffeescript/index.html | 721 ++++++++++++++++++
imports/codemirror/mode/css/css.js | 124 ++++
imports/codemirror/mode/css/index.html | 55 ++
imports/codemirror/mode/diff/diff.css | 3 +
imports/codemirror/mode/diff/diff.js | 13 +
imports/codemirror/mode/diff/index.html | 99 +++
imports/codemirror/mode/gfm/gfm.js | 108 +++
imports/codemirror/mode/gfm/index.html | 47 ++
imports/codemirror/mode/groovy/groovy.js | 210 ++++++
imports/codemirror/mode/groovy/index.html | 71 ++
imports/codemirror/mode/haskell/haskell.js | 242 ++++++
imports/codemirror/mode/haskell/index.html | 60 ++
.../codemirror/mode/htmlembedded/htmlembedded.js | 68 ++
imports/codemirror/mode/htmlembedded/index.html | 49 ++
imports/codemirror/mode/htmlmixed/htmlmixed.js | 83 +++
imports/codemirror/mode/htmlmixed/index.html | 51 ++
imports/codemirror/mode/javascript/index.html | 77 ++
imports/codemirror/mode/javascript/javascript.js | 360 +++++++++
imports/codemirror/mode/jinja2/index.html | 37 +
imports/codemirror/mode/jinja2/jinja2.js | 42 ++
imports/codemirror/mode/lua/index.html | 72 ++
imports/codemirror/mode/lua/lua.js | 140 ++++
imports/codemirror/mode/markdown/index.html | 339 +++++++++
imports/codemirror/mode/markdown/markdown.js | 242 ++++++
imports/codemirror/mode/ntriples/index.html | 32 +
imports/codemirror/mode/ntriples/ntriples.js | 172 +++++
imports/codemirror/mode/pascal/LICENSE | 7 +
imports/codemirror/mode/pascal/index.html | 48 ++
imports/codemirror/mode/pascal/pascal.js | 138 ++++
imports/codemirror/mode/perl/LICENSE | 19 +
imports/codemirror/mode/perl/index.html | 62 ++
imports/codemirror/mode/perl/perl.js | 816 +++++++++++++++++++++
imports/codemirror/mode/php/index.html | 48 ++
imports/codemirror/mode/php/php.js | 120 +++
imports/codemirror/mode/plsql/index.html | 62 ++
imports/codemirror/mode/plsql/plsql.js | 217 ++++++
imports/codemirror/mode/python/LICENSE.txt | 21 +
imports/codemirror/mode/python/index.html | 122 +++
imports/codemirror/mode/python/python.js | 333 +++++++++
imports/codemirror/mode/r/LICENSE | 24 +
imports/codemirror/mode/r/index.html | 73 ++
imports/codemirror/mode/r/r.js | 141 ++++
imports/codemirror/mode/rpm/changes/changes.js | 19 +
imports/codemirror/mode/rpm/changes/index.html | 53 ++
imports/codemirror/mode/rpm/spec/index.html | 99 +++
imports/codemirror/mode/rpm/spec/spec.css | 5 +
imports/codemirror/mode/rpm/spec/spec.js | 66 ++
imports/codemirror/mode/rst/index.html | 525 +++++++++++++
imports/codemirror/mode/rst/rst.js | 326 ++++++++
imports/codemirror/mode/ruby/LICENSE | 24 +
imports/codemirror/mode/ruby/index.html | 171 +++++
imports/codemirror/mode/ruby/ruby.js | 195 +++++
imports/codemirror/mode/rust/index.html | 48 ++
imports/codemirror/mode/rust/rust.js | 411 +++++++++++
imports/codemirror/mode/scheme/index.html | 64 ++
imports/codemirror/mode/scheme/scheme.js | 202 +++++
imports/codemirror/mode/smalltalk/index.html | 55 ++
imports/codemirror/mode/smalltalk/smalltalk.js | 139 ++++
imports/codemirror/mode/sparql/index.html | 40 +
imports/codemirror/mode/sparql/sparql.js | 143 ++++
imports/codemirror/mode/stex/index.html | 95 +++
imports/codemirror/mode/stex/stex.js | 167 +++++
imports/codemirror/mode/tiddlywiki/index.html | 183 +++++
imports/codemirror/mode/tiddlywiki/tiddlywiki.css | 21 +
imports/codemirror/mode/tiddlywiki/tiddlywiki.js | 374 ++++++++++
imports/codemirror/mode/velocity/index.html | 103 +++
imports/codemirror/mode/velocity/velocity.js | 146 ++++
imports/codemirror/mode/xml/index.html | 44 ++
imports/codemirror/mode/xml/xml.js | 252 +++++++
imports/codemirror/mode/xmlpure/index.html | 59 ++
imports/codemirror/mode/xmlpure/xmlpure.js | 485 ++++++++++++
imports/codemirror/mode/yaml/index.html | 67 ++
imports/codemirror/mode/yaml/yaml.js | 95 +++
79 files changed, 11414 insertions(+)
create mode 100755 imports/codemirror/mode/clike/clike.js
create mode 100755 imports/codemirror/mode/clike/index.html
create mode 100755 imports/codemirror/mode/clojure/clojure.js
create mode 100755 imports/codemirror/mode/clojure/index.html
create mode 100755 imports/codemirror/mode/coffeescript/LICENSE
create mode 100755 imports/codemirror/mode/coffeescript/coffeescript.js
create mode 100755 imports/codemirror/mode/coffeescript/index.html
create mode 100755 imports/codemirror/mode/css/css.js
create mode 100755 imports/codemirror/mode/css/index.html
create mode 100755 imports/codemirror/mode/diff/diff.css
create mode 100755 imports/codemirror/mode/diff/diff.js
create mode 100755 imports/codemirror/mode/diff/index.html
create mode 100755 imports/codemirror/mode/gfm/gfm.js
create mode 100755 imports/codemirror/mode/gfm/index.html
create mode 100755 imports/codemirror/mode/groovy/groovy.js
create mode 100755 imports/codemirror/mode/groovy/index.html
create mode 100755 imports/codemirror/mode/haskell/haskell.js
create mode 100755 imports/codemirror/mode/haskell/index.html
create mode 100755 imports/codemirror/mode/htmlembedded/htmlembedded.js
create mode 100755 imports/codemirror/mode/htmlembedded/index.html
create mode 100755 imports/codemirror/mode/htmlmixed/htmlmixed.js
create mode 100755 imports/codemirror/mode/htmlmixed/index.html
create mode 100755 imports/codemirror/mode/javascript/index.html
create mode 100755 imports/codemirror/mode/javascript/javascript.js
create mode 100755 imports/codemirror/mode/jinja2/index.html
create mode 100755 imports/codemirror/mode/jinja2/jinja2.js
create mode 100755 imports/codemirror/mode/lua/index.html
create mode 100755 imports/codemirror/mode/lua/lua.js
create mode 100755 imports/codemirror/mode/markdown/index.html
create mode 100755 imports/codemirror/mode/markdown/markdown.js
create mode 100755 imports/codemirror/mode/ntriples/index.html
create mode 100755 imports/codemirror/mode/ntriples/ntriples.js
create mode 100755 imports/codemirror/mode/pascal/LICENSE
create mode 100755 imports/codemirror/mode/pascal/index.html
create mode 100755 imports/codemirror/mode/pascal/pascal.js
create mode 100755 imports/codemirror/mode/perl/LICENSE
create mode 100755 imports/codemirror/mode/perl/index.html
create mode 100755 imports/codemirror/mode/perl/perl.js
create mode 100755 imports/codemirror/mode/php/index.html
create mode 100755 imports/codemirror/mode/php/php.js
create mode 100755 imports/codemirror/mode/plsql/index.html
create mode 100755 imports/codemirror/mode/plsql/plsql.js
create mode 100755 imports/codemirror/mode/python/LICENSE.txt
create mode 100755 imports/codemirror/mode/python/index.html
create mode 100755 imports/codemirror/mode/python/python.js
create mode 100755 imports/codemirror/mode/r/LICENSE
create mode 100755 imports/codemirror/mode/r/index.html
create mode 100755 imports/codemirror/mode/r/r.js
create mode 100755 imports/codemirror/mode/rpm/changes/changes.js
create mode 100755 imports/codemirror/mode/rpm/changes/index.html
create mode 100755 imports/codemirror/mode/rpm/spec/index.html
create mode 100755 imports/codemirror/mode/rpm/spec/spec.css
create mode 100755 imports/codemirror/mode/rpm/spec/spec.js
create mode 100755 imports/codemirror/mode/rst/index.html
create mode 100755 imports/codemirror/mode/rst/rst.js
create mode 100755 imports/codemirror/mode/ruby/LICENSE
create mode 100755 imports/codemirror/mode/ruby/index.html
create mode 100755 imports/codemirror/mode/ruby/ruby.js
create mode 100755 imports/codemirror/mode/rust/index.html
create mode 100755 imports/codemirror/mode/rust/rust.js
create mode 100755 imports/codemirror/mode/scheme/index.html
create mode 100755 imports/codemirror/mode/scheme/scheme.js
create mode 100755 imports/codemirror/mode/smalltalk/index.html
create mode 100755 imports/codemirror/mode/smalltalk/smalltalk.js
create mode 100755 imports/codemirror/mode/sparql/index.html
create mode 100755 imports/codemirror/mode/sparql/sparql.js
create mode 100755 imports/codemirror/mode/stex/index.html
create mode 100755 imports/codemirror/mode/stex/stex.js
create mode 100755 imports/codemirror/mode/tiddlywiki/index.html
create mode 100755 imports/codemirror/mode/tiddlywiki/tiddlywiki.css
create mode 100755 imports/codemirror/mode/tiddlywiki/tiddlywiki.js
create mode 100755 imports/codemirror/mode/velocity/index.html
create mode 100755 imports/codemirror/mode/velocity/velocity.js
create mode 100755 imports/codemirror/mode/xml/index.html
create mode 100755 imports/codemirror/mode/xml/xml.js
create mode 100755 imports/codemirror/mode/xmlpure/index.html
create mode 100755 imports/codemirror/mode/xmlpure/xmlpure.js
create mode 100755 imports/codemirror/mode/yaml/index.html
create mode 100755 imports/codemirror/mode/yaml/yaml.js
(limited to 'imports/codemirror/mode')
diff --git a/imports/codemirror/mode/clike/clike.js b/imports/codemirror/mode/clike/clike.js
new file mode 100755
index 00000000..69877efd
--- /dev/null
+++ b/imports/codemirror/mode/clike/clike.js
@@ -0,0 +1,249 @@
+CodeMirror.defineMode("clike", function(config, parserConfig) {
+ var indentUnit = config.indentUnit,
+ keywords = parserConfig.keywords || {},
+ blockKeywords = parserConfig.blockKeywords || {},
+ atoms = parserConfig.atoms || {},
+ hooks = parserConfig.hooks || {},
+ multiLineStrings = parserConfig.multiLineStrings;
+ var isOperatorChar = /[+\-*&%=<>!?|\/]/;
+
+ var curPunc;
+
+ function tokenBase(stream, state) {
+ var ch = stream.next();
+ if (hooks[ch]) {
+ var result = hooks[ch](stream, state);
+ if (result !== false) return result;
+ }
+ if (ch == '"' || ch == "'") {
+ state.tokenize = tokenString(ch);
+ return state.tokenize(stream, state);
+ }
+ if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
+ curPunc = ch;
+ return null
+ }
+ if (/\d/.test(ch)) {
+ stream.eatWhile(/[\w\.]/);
+ return "number";
+ }
+ if (ch == "/") {
+ if (stream.eat("*")) {
+ state.tokenize = tokenComment;
+ return tokenComment(stream, state);
+ }
+ if (stream.eat("/")) {
+ stream.skipToEnd();
+ return "comment";
+ }
+ }
+ if (isOperatorChar.test(ch)) {
+ stream.eatWhile(isOperatorChar);
+ return "operator";
+ }
+ stream.eatWhile(/[\w\$_]/);
+ var cur = stream.current();
+ if (keywords.propertyIsEnumerable(cur)) {
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
+ return "keyword";
+ }
+ if (atoms.propertyIsEnumerable(cur)) return "atom";
+ return "word";
+ }
+
+ function tokenString(quote) {
+ return function(stream, state) {
+ var escaped = false, next, end = false;
+ while ((next = stream.next()) != null) {
+ if (next == quote && !escaped) {end = true; break;}
+ escaped = !escaped && next == "\\";
+ }
+ if (end || !(escaped || multiLineStrings))
+ state.tokenize = tokenBase;
+ return "string";
+ };
+ }
+
+ function tokenComment(stream, state) {
+ var maybeEnd = false, ch;
+ while (ch = stream.next()) {
+ if (ch == "/" && maybeEnd) {
+ state.tokenize = tokenBase;
+ break;
+ }
+ maybeEnd = (ch == "*");
+ }
+ return "comment";
+ }
+
+ function Context(indented, column, type, align, prev) {
+ this.indented = indented;
+ this.column = column;
+ this.type = type;
+ this.align = align;
+ this.prev = prev;
+ }
+ function pushContext(state, col, type) {
+ return state.context = new Context(state.indented, col, type, null, state.context);
+ }
+ function popContext(state) {
+ var t = state.context.type;
+ if (t == ")" || t == "]" || t == "}")
+ state.indented = state.context.indented;
+ return state.context = state.context.prev;
+ }
+
+ // Interface
+
+ return {
+ startState: function(basecolumn) {
+ return {
+ tokenize: null,
+ context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
+ indented: 0,
+ startOfLine: true
+ };
+ },
+
+ token: function(stream, state) {
+ var ctx = state.context;
+ if (stream.sol()) {
+ if (ctx.align == null) ctx.align = false;
+ state.indented = stream.indentation();
+ state.startOfLine = true;
+ }
+ if (stream.eatSpace()) return null;
+ curPunc = null;
+ var style = (state.tokenize || tokenBase)(stream, state);
+ if (style == "comment" || style == "meta") return style;
+ if (ctx.align == null) ctx.align = true;
+
+ if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
+ else if (curPunc == "{") pushContext(state, stream.column(), "}");
+ else if (curPunc == "[") pushContext(state, stream.column(), "]");
+ else if (curPunc == "(") pushContext(state, stream.column(), ")");
+ else if (curPunc == "}") {
+ while (ctx.type == "statement") ctx = popContext(state);
+ if (ctx.type == "}") ctx = popContext(state);
+ while (ctx.type == "statement") ctx = popContext(state);
+ }
+ else if (curPunc == ctx.type) popContext(state);
+ else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
+ pushContext(state, stream.column(), "statement");
+ state.startOfLine = false;
+ return style;
+ },
+
+ indent: function(state, textAfter) {
+ if (state.tokenize != tokenBase && state.tokenize != null) return 0;
+ var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
+ if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
+ var closing = firstChar == ctx.type;
+ if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
+ else if (ctx.align) return ctx.column + (closing ? 0 : 1);
+ else return ctx.indented + (closing ? 0 : indentUnit);
+ },
+
+ electricChars: "{}"
+ };
+});
+
+(function() {
+ function words(str) {
+ var obj = {}, words = str.split(" ");
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
+ return obj;
+ }
+ var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
+ "double static else struct entry switch extern typedef float union for unsigned " +
+ "goto while enum void const signed volatile";
+
+ function cppHook(stream, state) {
+ if (!state.startOfLine) return false;
+ stream.skipToEnd();
+ return "meta";
+ }
+
+ // C#-style strings where "" escapes a quote.
+ function tokenAtString(stream, state) {
+ var next;
+ while ((next = stream.next()) != null) {
+ if (next == '"' && !stream.eat('"')) {
+ state.tokenize = null;
+ break;
+ }
+ }
+ return "string";
+ }
+
+ CodeMirror.defineMIME("text/x-csrc", {
+ name: "clike",
+ keywords: words(cKeywords),
+ blockKeywords: words("case do else for if switch while struct"),
+ atoms: words("null"),
+ hooks: {"#": cppHook}
+ });
+ CodeMirror.defineMIME("text/x-c++src", {
+ name: "clike",
+ keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
+ "static_cast typeid catch operator template typename class friend private " +
+ "this using const_cast inline public throw virtual delete mutable protected " +
+ "wchar_t"),
+ blockKeywords: words("catch class do else finally for if struct switch try while"),
+ atoms: words("true false null"),
+ hooks: {"#": cppHook}
+ });
+ CodeMirror.defineMIME("text/x-java", {
+ name: "clike",
+ keywords: words("abstract assert boolean break byte case catch char class const continue default " +
+ "do double else enum extends final finally float for goto if implements import " +
+ "instanceof int interface long native new package private protected public " +
+ "return short static strictfp super switch synchronized this throw throws transient " +
+ "try void volatile while"),
+ blockKeywords: words("catch class do else finally for if switch try while"),
+ atoms: words("true false null"),
+ hooks: {
+ "@": function(stream, state) {
+ stream.eatWhile(/[\w\$_]/);
+ return "meta";
+ }
+ }
+ });
+ CodeMirror.defineMIME("text/x-csharp", {
+ name: "clike",
+ keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
+ " default delegate do double else enum event explicit extern finally fixed float for" +
+ " foreach goto if implicit in int interface internal is lock long namespace new object" +
+ " operator out override params private protected public readonly ref return sbyte sealed short" +
+ " sizeof stackalloc static string struct switch this throw try typeof uint ulong unchecked" +
+ " unsafe ushort using virtual void volatile while add alias ascending descending dynamic from get" +
+ " global group into join let orderby partial remove select set value var yield"),
+ blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
+ atoms: words("true false null"),
+ hooks: {
+ "@": function(stream, state) {
+ if (stream.eat('"')) {
+ state.tokenize = tokenAtString;
+ return tokenAtString(stream, state);
+ }
+ stream.eatWhile(/[\w\$_]/);
+ return "meta";
+ }
+ }
+ });
+ CodeMirror.defineMIME("text/x-groovy", {
+ name: "clike",
+ keywords: words("abstract as assert boolean break byte case catch char class const continue def default " +
+ "do double else enum extends final finally float for goto if implements import " +
+ "in instanceof int interface long native new package property private protected public " +
+ "return short static strictfp super switch synchronized this throw throws transient " +
+ "try void volatile while"),
+ atoms: words("true false null"),
+ hooks: {
+ "@": function(stream, state) {
+ stream.eatWhile(/[\w\$_]/);
+ return "meta";
+ }
+ }
+ });
+}());
diff --git a/imports/codemirror/mode/clike/index.html b/imports/codemirror/mode/clike/index.html
new file mode 100755
index 00000000..5e375ef4
--- /dev/null
+++ b/imports/codemirror/mode/clike/index.html
@@ -0,0 +1,101 @@
+
+
+
+ CodeMirror: C-like mode
+
+
+
+
+
+
+
+ CodeMirror: C-like mode
+
+
+
+
+
+ Simple mode that tries to handle C-like languages as well as it
+ can. Takes two configuration parameters: keywords
, an
+ object whose property names are the keywords in the language,
+ and useCPP
, which determines whether C preprocessor
+ directives are recognized.
+
+ MIME types defined: text/x-csrc
+ (C code), text/x-c++src
(C++
+ code), text/x-java
(Java
+ code), text/x-groovy
(Groovy code).
+
+
diff --git a/imports/codemirror/mode/clojure/clojure.js b/imports/codemirror/mode/clojure/clojure.js
new file mode 100755
index 00000000..a951589e
--- /dev/null
+++ b/imports/codemirror/mode/clojure/clojure.js
@@ -0,0 +1,207 @@
+/**
+ * Author: Hans Engel
+ * Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementation by Koh Zi Chun)
+ */
+CodeMirror.defineMode("clojure", function (config, mode) {
+ var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", TAG = "tag",
+ ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword";
+ var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
+
+ function makeKeywords(str) {
+ var obj = {}, words = str.split(" ");
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
+ return obj;
+ }
+
+ var atoms = makeKeywords("true false nil");
+
+ var keywords = makeKeywords(
+ // Control structures
+ "defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype defprotocol defrecord deftest slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do case cond condp for loop recur when when-not when-let when-first if if-let if-not . .. -> ->> doto and or dosync doseq dotimes dorun doall load import unimport ns in-ns refer try catch finally throw with-open with-local-vars binding gen-class gen-and-load-class gen-and-save-class handler-case handle" +
+
+ // Built-ins
+ "* *1 *2 *3 *agent* *allow-unresolved-vars* *assert *clojure-version* *command-line-args* *compile-files* *compile-path* *e *err* *file* *flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *read-eval* *source-path* *use-context-classloader* *warn-on-reflection* + - / < <= = == > >= accessor aclone agent agent-errors aget alength alias all-ns alter alter-meta! alter-var-root amap ancestors and apply areduce array-map aset aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in associative? atom await await-for await1 bases bean bigdec bigint binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array booleans bound-fn bound-fn* butlast byte byte-array bytes case cast char char-array char-escape-string char-name-string char? chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? class class? clear-agent-errors clojure-version coll? comment commute comp comparator compare compare-and-set! compile complement concat cond condp conj conj! cons constantly construct-proxy contains? count counted? create-ns create-struct cycle dec decimal? declare definline defmacro defmethod defmulti defn defn- defonce defstruct delay delay? deliver deref derive descendants destructure disj disj! dissoc dissoc! distinct distinct? doall doc dorun doseq dosync dotimes doto double double-array doubles drop drop-last drop-while empty empty? ensure enumeration-seq eval even? every? extend extend-protocol extend-type extends? extenders false? ffirst file-seq filter find find-doc find-ns find-var first float float-array float? floats flush fn fn? fnext for force format future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface gensym get get-in get-method get-proxy-class get-thread-bindings get-validator hash hash-map hash-set identical? identity if-let if-not ifn? import in-ns inc init-proxy instance? int int-array integer? interleave intern interpose into into-array ints io! isa? iterate iterator-seq juxt key keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list* list? load load-file load-reader load-string loaded-libs locking long long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy map map? mapcat max max-key memfn memoize merge merge-with meta method-sig methods min min-key mod name namespace neg? newline next nfirst nil? nnext not not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? or parents partial partition pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str prefer-method prefers primitives-classnames print print-ctor print-doc print-dup print-method print-namespace-doc print-simple print-special-doc print-str printf println println-str prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot rand rand-int range ratio? rational? rationalize re-find re-groups re-matcher re-matches re-pattern re-seq read read-line read-string reify reduce ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure release-pending-sends rem remove remove-method remove-ns repeat repeatedly replace replicate require reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq rsubseq satisfies? second select-keys send send-off seq seq? seque sequence sequential? set set-validator! set? short short-array shorts shutdown-agents slurp some sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-form-anchor special-symbol? split-at split-with str stream? string? struct struct-map subs subseq subvec supers swap! symbol symbol? sync syntax-symbol-anchor take take-last take-nth take-while test the-ns time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-dec unchecked-divide unchecked-inc unchecked-multiply unchecked-negate unchecked-remainder unchecked-subtract underive unquote unquote-splicing update-in update-proxy use val vals var-get var-set var? vary-meta vec vector vector? when when-first when-let when-not while with-bindings with-bindings* with-in-str with-loading-context with-local-vars with-meta with-open with-out-str with-precision xml-seq");
+
+ var indentKeys = makeKeywords(
+ // Built-ins
+ "ns fn def defn defmethod bound-fn if if-not case condp when while when-not when-first do future comment doto locking proxy with-open with-precision reify deftype defrecord defprotocol extend extend-protocol extend-type try catch" +
+
+ // Binding forms
+ "let letfn binding loop for doseq dotimes when-let if-let" +
+
+ // Data structures
+ "defstruct struct-map assoc" +
+
+ // clojure.test
+ "testing deftest" +
+
+ // contrib
+ "handler-case handle dotrace deftrace");
+
+ var tests = {
+ digit: /\d/,
+ digit_or_colon: /[\d:]/,
+ hex: /[0-9a-fA-F]/,
+ sign: /[+-]/,
+ exponent: /[eE]/,
+ keyword_char: /[^\s\(\[\;\)\]]/,
+ basic: /[\w\$_\-]/,
+ lang_keyword: /[\w*+!\-_?:\/]/
+ };
+
+ function stateStack(indent, type, prev) { // represents a state stack object
+ this.indent = indent;
+ this.type = type;
+ this.prev = prev;
+ }
+
+ function pushStack(state, indent, type) {
+ state.indentStack = new stateStack(indent, type, state.indentStack);
+ }
+
+ function popStack(state) {
+ state.indentStack = state.indentStack.prev;
+ }
+
+ function isNumber(ch, stream){
+ // hex
+ if ( ch === '0' && 'x' == stream.peek().toLowerCase() ) {
+ stream.eat('x');
+ stream.eatWhile(tests.hex);
+ return true;
+ }
+
+ // leading sign
+ if ( ch == '+' || ch == '-' ) {
+ stream.eat(tests.sign);
+ ch = stream.next();
+ }
+
+ if ( tests.digit.test(ch) ) {
+ stream.eat(ch);
+ stream.eatWhile(tests.digit);
+
+ if ( '.' == stream.peek() ) {
+ stream.eat('.');
+ stream.eatWhile(tests.digit);
+ }
+
+ if ( 'e' == stream.peek().toLowerCase() ) {
+ stream.eat(tests.exponent);
+ stream.eat(tests.sign);
+ stream.eatWhile(tests.digit);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ return {
+ startState: function () {
+ return {
+ indentStack: null,
+ indentation: 0,
+ mode: false,
+ };
+ },
+
+ token: function (stream, state) {
+ if (state.indentStack == null && stream.sol()) {
+ // update indentation, but only if indentStack is empty
+ state.indentation = stream.indentation();
+ }
+
+ // skip spaces
+ if (stream.eatSpace()) {
+ return null;
+ }
+ var returnType = null;
+
+ switch(state.mode){
+ case "string": // multi-line string parsing mode
+ var next, escaped = false;
+ while ((next = stream.next()) != null) {
+ if (next == "\"" && !escaped) {
+
+ state.mode = false;
+ break;
+ }
+ escaped = !escaped && next == "\\";
+ }
+ returnType = STRING; // continue on in string mode
+ break;
+ default: // default parsing mode
+ var ch = stream.next();
+
+ if (ch == "\"") {
+ state.mode = "string";
+ returnType = STRING;
+ } else if (ch == "'" && !( tests.digit_or_colon.test(stream.peek()) )) {
+ returnType = ATOM;
+ } else if (ch == ";") { // comment
+ stream.skipToEnd(); // rest of the line is a comment
+ returnType = COMMENT;
+ } else if (isNumber(ch,stream)){
+ returnType = NUMBER;
+ } else if (ch == "(" || ch == "[") {
+ var keyWord = ''; var indentTemp = stream.column();
+ /**
+ Either
+ (indent-word ..
+ (non-indent-word ..
+ (;something else, bracket, etc.
+ */
+
+ while ((letter = stream.eat(tests.keyword_char)) != null) {
+ keyWord += letter;
+ }
+
+ if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
+
+ pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
+ } else { // non-indent word
+ // we continue eating the spaces
+ stream.eatSpace();
+ if (stream.eol() || stream.peek() == ";") {
+ // nothing significant after
+ // we restart indentation 1 space after
+ pushStack(state, indentTemp + 1, ch);
+ } else {
+ pushStack(state, indentTemp + stream.current().length, ch); // else we match
+ }
+ }
+ stream.backUp(stream.current().length - 1); // undo all the eating
+
+ returnType = BRACKET;
+ } else if (ch == ")" || ch == "]") {
+ returnType = BRACKET;
+ if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
+ popStack(state);
+ }
+ } else if ( ch == ":" ) {
+ stream.eatWhile(tests.lang_keyword);
+ return TAG;
+ } else {
+ stream.eatWhile(tests.basic);
+
+ if (keywords && keywords.propertyIsEnumerable(stream.current())) {
+ returnType = BUILTIN;
+ } else if ( atoms && atoms.propertyIsEnumerable(stream.current()) ) {
+ returnType = ATOM;
+ } else returnType = null;
+ }
+ }
+
+ return returnType;
+ },
+
+ indent: function (state, textAfter) {
+ if (state.indentStack == null) return state.indentation;
+ return state.indentStack.indent;
+ }
+ };
+});
+
+CodeMirror.defineMIME("text/x-clojure", "clojure");
diff --git a/imports/codemirror/mode/clojure/index.html b/imports/codemirror/mode/clojure/index.html
new file mode 100755
index 00000000..9762d589
--- /dev/null
+++ b/imports/codemirror/mode/clojure/index.html
@@ -0,0 +1,66 @@
+
+
+
+ CodeMirror: Clojure mode
+
+
+
+
+
+
+
+ CodeMirror: Clojure mode
+
+; Conway's Game of Life, based on the work of:
+;; Laurent Petit https://gist.github.com/1200343
+;; Christophe Grand http://clj-me.cgrand.net/2011/08/19/conways-game-of-life
+
+(ns ^{:doc "Conway's Game of Life."}
+ game-of-life)
+
+;; Core game of life's algorithm functions
+
+(defn neighbours
+ "Given a cell's coordinates, returns the coordinates of its neighbours."
+ [[x y]]
+ (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
+ [(+ dx x) (+ dy y)]))
+
+(defn step
+ "Given a set of living cells, computes the new set of living cells."
+ [cells]
+ (set (for [[cell n] (frequencies (mapcat neighbours cells))
+ :when (or (= n 3) (and (= n 2) (cells cell)))]
+ cell)))
+
+;; Utility methods for displaying game on a text terminal
+
+(defn print-board
+ "Prints a board on *out*, representing a step in the game."
+ [board w h]
+ (doseq [x (range (inc w)) y (range (inc h))]
+ (if (= y 0) (print "\n"))
+ (print (if (board [x y]) "[X]" " . "))))
+
+(defn display-grids
+ "Prints a squence of boards on *out*, representing several steps."
+ [grids w h]
+ (doseq [board grids]
+ (print-board board w h)
+ (print "\n")))
+
+;; Launches an example board
+
+(def
+ ^{:doc "board represents the initial set of living cells"}
+ board #{[2 1] [2 2] [2 3]})
+
+(display-grids (take 3 (iterate step board)) 5 5)
+
+
+ MIME types defined: text/x-clojure
.
+
+
+
diff --git a/imports/codemirror/mode/coffeescript/LICENSE b/imports/codemirror/mode/coffeescript/LICENSE
new file mode 100755
index 00000000..977e284e
--- /dev/null
+++ b/imports/codemirror/mode/coffeescript/LICENSE
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) 2011 Jeff Pickhardt
+Modified from the Python CodeMirror mode, Copyright (c) 2010 Timothy Farrell
+
+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.
\ No newline at end of file
diff --git a/imports/codemirror/mode/coffeescript/coffeescript.js b/imports/codemirror/mode/coffeescript/coffeescript.js
new file mode 100755
index 00000000..d4d57239
--- /dev/null
+++ b/imports/codemirror/mode/coffeescript/coffeescript.js
@@ -0,0 +1,325 @@
+/**
+ * Link to the project's GitHub page:
+ * https://github.com/pickhardt/coffeescript-codemirror-mode
+ */
+CodeMirror.defineMode('coffeescript', function(conf) {
+ var ERRORCLASS = 'error';
+
+ function wordRegexp(words) {
+ return new RegExp("^((" + words.join(")|(") + "))\\b");
+ }
+
+ var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]");
+ var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
+ var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))");
+ var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
+ var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))");
+ var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
+
+ var wordOperators = wordRegexp(['and', 'or', 'not',
+ 'is', 'isnt', 'in',
+ 'instanceof', 'typeof']);
+ var indentKeywords = ['for', 'while', 'loop', 'if', 'unless', 'else',
+ 'switch', 'try', 'catch', 'finally', 'class'];
+ var commonKeywords = ['break', 'by', 'continue', 'debugger', 'delete',
+ 'do', 'in', 'of', 'new', 'return', 'then',
+ 'this', 'throw', 'when', 'until'];
+
+ var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
+
+ indentKeywords = wordRegexp(indentKeywords);
+
+
+ var stringPrefixes = new RegExp("^('{3}|\"{3}|['\"])");
+ var regexPrefixes = new RegExp("^(/{3}|/)");
+ var commonConstants = ['Infinity', 'NaN', 'undefined', 'null', 'true', 'false', 'on', 'off', 'yes', 'no'];
+ var constants = wordRegexp(commonConstants);
+
+ // Tokenizers
+ function tokenBase(stream, state) {
+ // Handle scope changes
+ if (stream.sol()) {
+ var scopeOffset = state.scopes[0].offset;
+ if (stream.eatSpace()) {
+ var lineOffset = stream.indentation();
+ if (lineOffset > scopeOffset) {
+ return 'indent';
+ } else if (lineOffset < scopeOffset) {
+ return 'dedent';
+ }
+ return null;
+ } else {
+ if (scopeOffset > 0) {
+ dedent(stream, state);
+ }
+ }
+ }
+ if (stream.eatSpace()) {
+ return null;
+ }
+
+ var ch = stream.peek();
+
+ // Handle comments
+ if (ch === '#') {
+ stream.skipToEnd();
+ return 'comment';
+ }
+
+ // Handle number literals
+ if (stream.match(/^-?[0-9\.]/, false)) {
+ var floatLiteral = false;
+ // Floats
+ if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) {
+ floatLiteral = true;
+ }
+ if (stream.match(/^-?\d+\.\d*/)) {
+ floatLiteral = true;
+ }
+ if (stream.match(/^-?\.\d+/)) {
+ floatLiteral = true;
+ }
+ if (floatLiteral) {
+ return 'number';
+ }
+ // Integers
+ var intLiteral = false;
+ // Hex
+ if (stream.match(/^-?0x[0-9a-f]+/i)) {
+ intLiteral = true;
+ }
+ // Decimal
+ if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) {
+ intLiteral = true;
+ }
+ // Zero by itself with no other piece of number.
+ if (stream.match(/^-?0(?![\dx])/i)) {
+ intLiteral = true;
+ }
+ if (intLiteral) {
+ return 'number';
+ }
+ }
+
+ // Handle strings
+ if (stream.match(stringPrefixes)) {
+ state.tokenize = tokenFactory(stream.current(), 'string');
+ return state.tokenize(stream, state);
+ }
+ // Handle regex literals
+ if (stream.match(regexPrefixes)) {
+ if (stream.current() != '/' || stream.match(/^.*\//, false)) { // prevent highlight of division
+ state.tokenize = tokenFactory(stream.current(), 'string-2');
+ return state.tokenize(stream, state);
+ } else {
+ stream.backUp(1);
+ }
+ }
+
+ // Handle operators and delimiters
+ if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
+ return 'punctuation';
+ }
+ if (stream.match(doubleOperators)
+ || stream.match(singleOperators)
+ || stream.match(wordOperators)) {
+ return 'operator';
+ }
+ if (stream.match(singleDelimiters)) {
+ return 'punctuation';
+ }
+
+ if (stream.match(constants)) {
+ return 'atom';
+ }
+
+ if (stream.match(keywords)) {
+ return 'keyword';
+ }
+
+ if (stream.match(identifiers)) {
+ return 'variable';
+ }
+
+ // Handle non-detected items
+ stream.next();
+ return ERRORCLASS;
+ }
+
+ function tokenFactory(delimiter, outclass) {
+ var delim_re = new RegExp(delimiter);
+ var singleline = delimiter.length == 1;
+
+ return function tokenString(stream, state) {
+ while (!stream.eol()) {
+ stream.eatWhile(/[^'"\/\\]/);
+ if (stream.eat('\\')) {
+ stream.next();
+ if (singleline && stream.eol()) {
+ return outclass;
+ }
+ } else if (stream.match(delim_re)) {
+ state.tokenize = tokenBase;
+ return outclass;
+ } else {
+ stream.eat(/['"\/]/);
+ }
+ }
+ if (singleline) {
+ if (conf.mode.singleLineStringErrors) {
+ outclass = ERRORCLASS
+ } else {
+ state.tokenize = tokenBase;
+ }
+ }
+ return outclass;
+ };
+ }
+
+ function indent(stream, state, type) {
+ type = type || 'coffee';
+ var indentUnit = 0;
+ if (type === 'coffee') {
+ for (var i = 0; i < state.scopes.length; i++) {
+ if (state.scopes[i].type === 'coffee') {
+ indentUnit = state.scopes[i].offset + conf.indentUnit;
+ break;
+ }
+ }
+ } else {
+ indentUnit = stream.column() + stream.current().length;
+ }
+ state.scopes.unshift({
+ offset: indentUnit,
+ type: type
+ });
+ }
+
+ function dedent(stream, state) {
+ if (state.scopes.length == 1) return;
+ if (state.scopes[0].type === 'coffee') {
+ var _indent = stream.indentation();
+ var _indent_index = -1;
+ for (var i = 0; i < state.scopes.length; ++i) {
+ if (_indent === state.scopes[i].offset) {
+ _indent_index = i;
+ break;
+ }
+ }
+ if (_indent_index === -1) {
+ return true;
+ }
+ while (state.scopes[0].offset !== _indent) {
+ state.scopes.shift();
+ }
+ return false
+ } else {
+ state.scopes.shift();
+ return false;
+ }
+ }
+
+ function tokenLexer(stream, state) {
+ var style = state.tokenize(stream, state);
+ var current = stream.current();
+
+ // Handle '.' connected identifiers
+ if (current === '.') {
+ style = state.tokenize(stream, state);
+ current = stream.current();
+ if (style === 'variable') {
+ return 'variable';
+ } else {
+ return ERRORCLASS;
+ }
+ }
+
+ // Handle properties
+ if (current === '@') {
+ style = state.tokenize(stream, state);
+ current = stream.current();
+ if (style === 'variable') {
+ return 'variable-2';
+ } else {
+ return ERRORCLASS;
+ }
+ }
+
+ // Handle scope changes.
+ if (current === 'return') {
+ state.dedent += 1;
+ }
+ if (((current === '->' || current === '=>') &&
+ !state.lambda &&
+ state.scopes[0].type == 'coffee' &&
+ stream.peek() === '')
+ || style === 'indent') {
+ indent(stream, state);
+ }
+ var delimiter_index = '[({'.indexOf(current);
+ if (delimiter_index !== -1) {
+ indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
+ }
+ if (indentKeywords.exec(current)){
+ indent(stream, state);
+ }
+ if (current == 'then'){
+ dedent(stream, state);
+ }
+
+
+ if (style === 'dedent') {
+ if (dedent(stream, state)) {
+ return ERRORCLASS;
+ }
+ }
+ delimiter_index = '])}'.indexOf(current);
+ if (delimiter_index !== -1) {
+ if (dedent(stream, state)) {
+ return ERRORCLASS;
+ }
+ }
+ if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'coffee') {
+ if (state.scopes.length > 1) state.scopes.shift();
+ state.dedent -= 1;
+ }
+
+ return style;
+ }
+
+ var external = {
+ startState: function(basecolumn) {
+ return {
+ tokenize: tokenBase,
+ scopes: [{offset:basecolumn || 0, type:'coffee'}],
+ lastToken: null,
+ lambda: false,
+ dedent: 0
+ };
+ },
+
+ token: function(stream, state) {
+ var style = tokenLexer(stream, state);
+
+ state.lastToken = {style:style, content: stream.current()};
+
+ if (stream.eol() && stream.lambda) {
+ state.lambda = false;
+ }
+
+ return style;
+ },
+
+ indent: function(state, textAfter) {
+ if (state.tokenize != tokenBase) {
+ return 0;
+ }
+
+ return state.scopes[0].offset;
+ }
+
+ };
+ return external;
+});
+
+CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript');
diff --git a/imports/codemirror/mode/coffeescript/index.html b/imports/codemirror/mode/coffeescript/index.html
new file mode 100755
index 00000000..127c4bf9
--- /dev/null
+++ b/imports/codemirror/mode/coffeescript/index.html
@@ -0,0 +1,721 @@
+
+
+
+ CodeMirror: CoffeeScript mode
+
+
+
+
+
+
+
+ CodeMirror: CoffeeScript mode
+
+# CoffeeScript mode for CodeMirror
+# Copyright (c) 2011 Jeff Pickhardt, released under
+# the MIT License.
+#
+# Modified from the Python CodeMirror mode, which also is
+# under the MIT License Copyright (c) 2010 Timothy Farrell.
+#
+# The following script, Underscore.coffee, is used to
+# demonstrate CoffeeScript mode for CodeMirror.
+#
+# To download CoffeeScript mode for CodeMirror, go to:
+# https://github.com/pickhardt/coffeescript-codemirror-mode
+
+# **Underscore.coffee
+# (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.**
+# Underscore is freely distributable under the terms of the
+# [MIT license](http://en.wikipedia.org/wiki/MIT_License).
+# Portions of Underscore are inspired by or borrowed from
+# [Prototype.js](http://prototypejs.org/api), Oliver Steele's
+# [Functional](http://osteele.com), and John Resig's
+# [Micro-Templating](http://ejohn.org).
+# For all details and documentation:
+# http://documentcloud.github.com/underscore/
+
+
+# Baseline setup
+# --------------
+
+# Establish the root object, `window` in the browser, or `global` on the server.
+root = this
+
+
+# Save the previous value of the `_` variable.
+previousUnderscore = root._
+
+
+# Establish the object that gets thrown to break out of a loop iteration.
+# `StopIteration` is SOP on Mozilla.
+breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration
+
+
+# Helper function to escape **RegExp** contents, because JS doesn't have one.
+escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1')
+
+
+# Save bytes in the minified (but not gzipped) version:
+ArrayProto = Array.prototype
+ObjProto = Object.prototype
+
+
+# Create quick reference variables for speed access to core prototypes.
+slice = ArrayProto.slice
+unshift = ArrayProto.unshift
+toString = ObjProto.toString
+hasOwnProperty = ObjProto.hasOwnProperty
+propertyIsEnumerable = ObjProto.propertyIsEnumerable
+
+
+# All **ECMA5** native implementations we hope to use are declared here.
+nativeForEach = ArrayProto.forEach
+nativeMap = ArrayProto.map
+nativeReduce = ArrayProto.reduce
+nativeReduceRight = ArrayProto.reduceRight
+nativeFilter = ArrayProto.filter
+nativeEvery = ArrayProto.every
+nativeSome = ArrayProto.some
+nativeIndexOf = ArrayProto.indexOf
+nativeLastIndexOf = ArrayProto.lastIndexOf
+nativeIsArray = Array.isArray
+nativeKeys = Object.keys
+
+
+# Create a safe reference to the Underscore object for use below.
+_ = (obj) -> new wrapper(obj)
+
+
+# Export the Underscore object for **CommonJS**.
+if typeof(exports) != 'undefined' then exports._ = _
+
+
+# Export Underscore to global scope.
+root._ = _
+
+
+# Current version.
+_.VERSION = '1.1.0'
+
+
+# Collection Functions
+# --------------------
+
+# The cornerstone, an **each** implementation.
+# Handles objects implementing **forEach**, arrays, and raw objects.
+_.each = (obj, iterator, context) ->
+ try
+ if nativeForEach and obj.forEach is nativeForEach
+ obj.forEach iterator, context
+ else if _.isNumber obj.length
+ iterator.call context, obj[i], i, obj for i in [0...obj.length]
+ else
+ iterator.call context, val, key, obj for own key, val of obj
+ catch e
+ throw e if e isnt breaker
+ obj
+
+
+# Return the results of applying the iterator to each element. Use JavaScript
+# 1.6's version of **map**, if possible.
+_.map = (obj, iterator, context) ->
+ return obj.map(iterator, context) if nativeMap and obj.map is nativeMap
+ results = []
+ _.each obj, (value, index, list) ->
+ results.push iterator.call context, value, index, list
+ results
+
+
+# **Reduce** builds up a single result from a list of values. Also known as
+# **inject**, or **foldl**. Uses JavaScript 1.8's version of **reduce**, if possible.
+_.reduce = (obj, iterator, memo, context) ->
+ if nativeReduce and obj.reduce is nativeReduce
+ iterator = _.bind iterator, context if context
+ return obj.reduce iterator, memo
+ _.each obj, (value, index, list) ->
+ memo = iterator.call context, memo, value, index, list
+ memo
+
+
+# The right-associative version of **reduce**, also known as **foldr**. Uses
+# JavaScript 1.8's version of **reduceRight**, if available.
+_.reduceRight = (obj, iterator, memo, context) ->
+ if nativeReduceRight and obj.reduceRight is nativeReduceRight
+ iterator = _.bind iterator, context if context
+ return obj.reduceRight iterator, memo
+ reversed = _.clone(_.toArray(obj)).reverse()
+ _.reduce reversed, iterator, memo, context
+
+
+# Return the first value which passes a truth test.
+_.detect = (obj, iterator, context) ->
+ result = null
+ _.each obj, (value, index, list) ->
+ if iterator.call context, value, index, list
+ result = value
+ _.breakLoop()
+ result
+
+
+# Return all the elements that pass a truth test. Use JavaScript 1.6's
+# **filter**, if it exists.
+_.filter = (obj, iterator, context) ->
+ return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter
+ results = []
+ _.each obj, (value, index, list) ->
+ results.push value if iterator.call context, value, index, list
+ results
+
+
+# Return all the elements for which a truth test fails.
+_.reject = (obj, iterator, context) ->
+ results = []
+ _.each obj, (value, index, list) ->
+ results.push value if not iterator.call context, value, index, list
+ results
+
+
+# Determine whether all of the elements match a truth test. Delegate to
+# JavaScript 1.6's **every**, if it is present.
+_.every = (obj, iterator, context) ->
+ iterator ||= _.identity
+ return obj.every iterator, context if nativeEvery and obj.every is nativeEvery
+ result = true
+ _.each obj, (value, index, list) ->
+ _.breakLoop() unless (result = result and iterator.call(context, value, index, list))
+ result
+
+
+# Determine if at least one element in the object matches a truth test. Use
+# JavaScript 1.6's **some**, if it exists.
+_.some = (obj, iterator, context) ->
+ iterator ||= _.identity
+ return obj.some iterator, context if nativeSome and obj.some is nativeSome
+ result = false
+ _.each obj, (value, index, list) ->
+ _.breakLoop() if (result = iterator.call(context, value, index, list))
+ result
+
+
+# Determine if a given value is included in the array or object,
+# based on `===`.
+_.include = (obj, target) ->
+ return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
+ return true for own key, val of obj when val is target
+ false
+
+
+# Invoke a method with arguments on every item in a collection.
+_.invoke = (obj, method) ->
+ args = _.rest arguments, 2
+ (if method then val[method] else val).apply(val, args) for val in obj
+
+
+# Convenience version of a common use case of **map**: fetching a property.
+_.pluck = (obj, key) ->
+ _.map(obj, (val) -> val[key])
+
+
+# Return the maximum item or (item-based computation).
+_.max = (obj, iterator, context) ->
+ return Math.max.apply(Math, obj) if not iterator and _.isArray(obj)
+ result = computed: -Infinity
+ _.each obj, (value, index, list) ->
+ computed = if iterator then iterator.call(context, value, index, list) else value
+ computed >= result.computed and (result = {value: value, computed: computed})
+ result.value
+
+
+# Return the minimum element (or element-based computation).
+_.min = (obj, iterator, context) ->
+ return Math.min.apply(Math, obj) if not iterator and _.isArray(obj)
+ result = computed: Infinity
+ _.each obj, (value, index, list) ->
+ computed = if iterator then iterator.call(context, value, index, list) else value
+ computed < result.computed and (result = {value: value, computed: computed})
+ result.value
+
+
+# Sort the object's values by a criterion produced by an iterator.
+_.sortBy = (obj, iterator, context) ->
+ _.pluck(((_.map obj, (value, index, list) ->
+ {value: value, criteria: iterator.call(context, value, index, list)}
+ ).sort((left, right) ->
+ a = left.criteria; b = right.criteria
+ if a < b then -1 else if a > b then 1 else 0
+ )), 'value')
+
+
+# Use a comparator function to figure out at what index an object should
+# be inserted so as to maintain order. Uses binary search.
+_.sortedIndex = (array, obj, iterator) ->
+ iterator ||= _.identity
+ low = 0
+ high = array.length
+ while low < high
+ mid = (low + high) >> 1
+ if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid
+ low
+
+
+# Convert anything iterable into a real, live array.
+_.toArray = (iterable) ->
+ return [] if (!iterable)
+ return iterable.toArray() if (iterable.toArray)
+ return iterable if (_.isArray(iterable))
+ return slice.call(iterable) if (_.isArguments(iterable))
+ _.values(iterable)
+
+
+# Return the number of elements in an object.
+_.size = (obj) -> _.toArray(obj).length
+
+
+# Array Functions
+# ---------------
+
+# Get the first element of an array. Passing `n` will return the first N
+# values in the array. Aliased as **head**. The `guard` check allows it to work
+# with **map**.
+_.first = (array, n, guard) ->
+ if n and not guard then slice.call(array, 0, n) else array[0]
+
+
+# Returns everything but the first entry of the array. Aliased as **tail**.
+# Especially useful on the arguments object. Passing an `index` will return
+# the rest of the values in the array from that index onward. The `guard`
+# check allows it to work with **map**.
+_.rest = (array, index, guard) ->
+ slice.call(array, if _.isUndefined(index) or guard then 1 else index)
+
+
+# Get the last element of an array.
+_.last = (array) -> array[array.length - 1]
+
+
+# Trim out all falsy values from an array.
+_.compact = (array) -> item for item in array when item
+
+
+# Return a completely flattened version of an array.
+_.flatten = (array) ->
+ _.reduce array, (memo, value) ->
+ return memo.concat(_.flatten(value)) if _.isArray value
+ memo.push value
+ memo
+ , []
+
+
+# Return a version of the array that does not contain the specified value(s).
+_.without = (array) ->
+ values = _.rest arguments
+ val for val in _.toArray(array) when not _.include values, val
+
+
+# Produce a duplicate-free version of the array. If the array has already
+# been sorted, you have the option of using a faster algorithm.
+_.uniq = (array, isSorted) ->
+ memo = []
+ for el, i in _.toArray array
+ memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el))
+ memo
+
+
+# Produce an array that contains every item shared between all the
+# passed-in arrays.
+_.intersect = (array) ->
+ rest = _.rest arguments
+ _.select _.uniq(array), (item) ->
+ _.all rest, (other) ->
+ _.indexOf(other, item) >= 0
+
+
+# Zip together multiple lists into a single array -- elements that share
+# an index go together.
+_.zip = ->
+ length = _.max _.pluck arguments, 'length'
+ results = new Array length
+ for i in [0...length]
+ results[i] = _.pluck arguments, String i
+ results
+
+
+# If the browser doesn't supply us with **indexOf** (I'm looking at you, MSIE),
+# we need this function. Return the position of the first occurrence of an
+# item in an array, or -1 if the item is not included in the array.
+_.indexOf = (array, item) ->
+ return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf
+ i = 0; l = array.length
+ while l - i
+ if array[i] is item then return i else i++
+ -1
+
+
+# Provide JavaScript 1.6's **lastIndexOf**, delegating to the native function,
+# if possible.
+_.lastIndexOf = (array, item) ->
+ return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf
+ i = array.length
+ while i
+ if array[i] is item then return i else i--
+ -1
+
+
+# Generate an integer Array containing an arithmetic progression. A port of
+# [the native Python **range** function](http://docs.python.org/library/functions.html#range).
+_.range = (start, stop, step) ->
+ a = arguments
+ solo = a.length <= 1
+ i = start = if solo then 0 else a[0]
+ stop = if solo then a[0] else a[1]
+ step = a[2] or 1
+ len = Math.ceil((stop - start) / step)
+ return [] if len <= 0
+ range = new Array len
+ idx = 0
+ loop
+ return range if (if step > 0 then i - stop else stop - i) >= 0
+ range[idx] = i
+ idx++
+ i+= step
+
+
+# Function Functions
+# ------------------
+
+# Create a function bound to a given object (assigning `this`, and arguments,
+# optionally). Binding with arguments is also known as **curry**.
+_.bind = (func, obj) ->
+ args = _.rest arguments, 2
+ -> func.apply obj or root, args.concat arguments
+
+
+# Bind all of an object's methods to that object. Useful for ensuring that
+# all callbacks defined on an object belong to it.
+_.bindAll = (obj) ->
+ funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj)
+ _.each funcs, (f) -> obj[f] = _.bind obj[f], obj
+ obj
+
+
+# Delays a function for the given number of milliseconds, and then calls
+# it with the arguments supplied.
+_.delay = (func, wait) ->
+ args = _.rest arguments, 2
+ setTimeout((-> func.apply(func, args)), wait)
+
+
+# Memoize an expensive function by storing its results.
+_.memoize = (func, hasher) ->
+ memo = {}
+ hasher or= _.identity
+ ->
+ key = hasher.apply this, arguments
+ return memo[key] if key of memo
+ memo[key] = func.apply this, arguments
+
+
+# Defers a function, scheduling it to run after the current call stack has
+# cleared.
+_.defer = (func) ->
+ _.delay.apply _, [func, 1].concat _.rest arguments
+
+
+# Returns the first function passed as an argument to the second,
+# allowing you to adjust arguments, run code before and after, and
+# conditionally execute the original function.
+_.wrap = (func, wrapper) ->
+ -> wrapper.apply wrapper, [func].concat arguments
+
+
+# Returns a function that is the composition of a list of functions, each
+# consuming the return value of the function that follows.
+_.compose = ->