Skip to content

Commit f5f7b16

Browse files
finalfantasiamarijnh
authored andcommitted
[clojure mode] Highlight special forms and core symbols as keyword.
The Common Lisp mode uses `keyword` for both special forms and the forms that assume the body parameter; the Scheme mode uses `builtin` for its special forms and core symbols. Both of these modes don't distinguish keyword-ish symbols from built-in symbols as the other modes for the languages that have real keywords do, such as Ruby. Since Clojure is a Lisp, the Clojure mode should also follow the same Lisp-y convention (it's neither idiomatic nor practically useful to distinguish symbols such as `let` and `map`, for example).
1 parent 39f543f commit f5f7b16

File tree

2 files changed

+149
-175
lines changed

2 files changed

+149
-175
lines changed

mode/clojure/clojure.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
"use strict";
1818

1919
CodeMirror.defineMode("clojure", function (options) {
20-
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", CHARACTER = "string-2",
21-
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword", VAR = "variable";
20+
var ATOM = "atom", BRACKET = "bracket", CHARACTER = "string-2",
21+
COMMENT = "comment", CORE_SYMBOL = "keyword", KEYWORD="atom",
22+
NUMBER = "number", SPECIAL_FORM = "keyword", STRING = "string",
23+
VAR = "variable";
2224
var INDENT_WORD_SKIP = options.indentUnit || 2;
2325
var NORMAL_INDENT_UNIT = options.indentUnit || 2;
2426

@@ -28,16 +30,10 @@ CodeMirror.defineMode("clojure", function (options) {
2830
return obj;
2931
}
3032

31-
var commonAtoms = ["true", "false", "nil"];
32-
var commonKeywords = ["defn", "defn-", "def", "def-", "defonce", "defmulti", "defmethod", "defmacro",
33-
"defstruct", "deftype", "defprotocol", "defrecord", "defproject", "deftest", "slice", "defalias",
34-
"defhinted", "defmacro-", "defn-memo", "defnk", "defonce-", "defunbound", "defunbound-",
35-
"defvar", "defvar-", "let", "letfn", "do", "case", "cond", "condp", "for", "loop", "recur", "when",
36-
"when-not", "when-let", "when-first", "when-some", "if", "if-let", "if-not", ".", "..", "->", "->>", "doto",
37-
"and", "or", "dosync", "doseq", "dotimes", "dorun", "doall", "load", "import", "unimport", "ns",
38-
"in-ns", "refer", "try", "catch", "finally", "throw", "with-open", "with-local-vars", "binding",
39-
"gen-class", "gen-and-load-class", "gen-and-save-class", "handler-case", "handle", "new"];
40-
var commonBuiltins = ["*", "*'", "*1", "*2", "*3", "*agent*", "*allow-unresolved-vars*", "*assert*",
33+
var commonAtoms = ["false", "nil", "true"];
34+
var commonSpecialForms = [".", "catch", "def", "do", "if", "monitor-enter",
35+
"monitor-exit", "new", "quote", "recur", "set!", "throw", "try", "var"];
36+
var commonCoreSymbols = ["*", "*'", "*1", "*2", "*3", "*agent*", "*allow-unresolved-vars*", "*assert*",
4137
"*clojure-version*", "*command-line-args*", "*compile-files*", "*compile-path*", "*compiler-options*",
4238
"*data-readers*", "*default-data-reader-fn*", "*e", "*err*", "*file*", "*flush-on-newline*", "*fn-loader*",
4339
"*in*", "*math-context*", "*ns*", "*out*", "*print-dup*", "*print-length*", "*print-level*", "*print-meta*",
@@ -113,7 +109,7 @@ CodeMirror.defineMode("clojure", function (options) {
113109
"when-some", "while", "with-bindings", "with-bindings*", "with-in-str", "with-loading-context", "with-local-vars",
114110
"with-meta", "with-open", "with-out-str", "with-precision", "with-redefs", "with-redefs-fn", "xml-seq", "zero?",
115111
"zipmap"];
116-
var commonIndentKeys = [
112+
var commonIndentSymbols = [
117113
// Built-ins
118114
"ns", "fn", "def", "defn", "defmethod", "bound-fn", "if", "if-not", "case", "condp", "when", "while", "when-not", "when-first", "when-some", "do", "future", "comment", "doto",
119115
"locking", "proxy", "with-open", "with-precision", "reify", "deftype", "defrecord", "defprotocol", "extend", "extend-protocol", "extend-type",
@@ -127,12 +123,13 @@ CodeMirror.defineMode("clojure", function (options) {
127123
// contrib
128124
"handler-case", "handle", "dotrace", "deftrace"];
129125

130-
CodeMirror.registerHelper("hintWords", "clojure", commonAtoms.concat(commonBuiltins));
126+
CodeMirror.registerHelper("hintWords", "clojure",
127+
commonAtoms.concat(commonSpecialForms, commonCoreSymbols));
131128

132129
var atoms = makeKeywords(commonAtoms);
133-
var keywords = makeKeywords(commonKeywords);
134-
var builtins = makeKeywords(commonBuiltins);
135-
var indentKeys = makeKeywords(commonIndentKeys);
130+
var specialForms = makeKeywords(commonSpecialForms);
131+
var coreSymbols = makeKeywords(commonCoreSymbols);
132+
var indentSymbols = makeKeywords(commonIndentSymbols);
136133

137134
var tests = {
138135
digit: /\d/,
@@ -271,7 +268,7 @@ CodeMirror.defineMode("clojure", function (options) {
271268
keyWord += letter;
272269
}
273270

274-
if (keyWord.length > 0 && (indentKeys.propertyIsEnumerable(keyWord) ||
271+
if (keyWord.length > 0 && (indentSymbols.propertyIsEnumerable(keyWord) ||
275272
tests.block_indent.test(keyWord))) { // indent-word
276273
pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
277274
} else { // non-indent word
@@ -295,14 +292,14 @@ CodeMirror.defineMode("clojure", function (options) {
295292
}
296293
} else if ( ch == ":" ) {
297294
stream.eatWhile(tests.symbol);
298-
return ATOM;
295+
return KEYWORD;
299296
} else {
300297
stream.eatWhile(tests.symbol);
301298

302-
if (keywords && keywords.propertyIsEnumerable(stream.current())) {
303-
returnType = KEYWORD;
304-
} else if (builtins && builtins.propertyIsEnumerable(stream.current())) {
305-
returnType = BUILTIN;
299+
if (specialForms && specialForms.propertyIsEnumerable(stream.current())) {
300+
returnType = SPECIAL_FORM;
301+
} else if (coreSymbols && coreSymbols.propertyIsEnumerable(stream.current())) {
302+
returnType = CORE_SYMBOL;
306303
} else if (atoms && atoms.propertyIsEnumerable(stream.current())) {
307304
returnType = ATOM;
308305
} else {

0 commit comments

Comments
 (0)