17
17
"use strict" ;
18
18
19
19
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" ;
22
24
var INDENT_WORD_SKIP = options . indentUnit || 2 ;
23
25
var NORMAL_INDENT_UNIT = options . indentUnit || 2 ;
24
26
@@ -28,16 +30,10 @@ CodeMirror.defineMode("clojure", function (options) {
28
30
return obj ;
29
31
}
30
32
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*" ,
41
37
"*clojure-version*" , "*command-line-args*" , "*compile-files*" , "*compile-path*" , "*compiler-options*" ,
42
38
"*data-readers*" , "*default-data-reader-fn*" , "*e" , "*err*" , "*file*" , "*flush-on-newline*" , "*fn-loader*" ,
43
39
"*in*" , "*math-context*" , "*ns*" , "*out*" , "*print-dup*" , "*print-length*" , "*print-level*" , "*print-meta*" ,
@@ -113,7 +109,7 @@ CodeMirror.defineMode("clojure", function (options) {
113
109
"when-some" , "while" , "with-bindings" , "with-bindings*" , "with-in-str" , "with-loading-context" , "with-local-vars" ,
114
110
"with-meta" , "with-open" , "with-out-str" , "with-precision" , "with-redefs" , "with-redefs-fn" , "xml-seq" , "zero?" ,
115
111
"zipmap" ] ;
116
- var commonIndentKeys = [
112
+ var commonIndentSymbols = [
117
113
// Built-ins
118
114
"ns" , "fn" , "def" , "defn" , "defmethod" , "bound-fn" , "if" , "if-not" , "case" , "condp" , "when" , "while" , "when-not" , "when-first" , "when-some" , "do" , "future" , "comment" , "doto" ,
119
115
"locking" , "proxy" , "with-open" , "with-precision" , "reify" , "deftype" , "defrecord" , "defprotocol" , "extend" , "extend-protocol" , "extend-type" ,
@@ -127,12 +123,13 @@ CodeMirror.defineMode("clojure", function (options) {
127
123
// contrib
128
124
"handler-case" , "handle" , "dotrace" , "deftrace" ] ;
129
125
130
- CodeMirror . registerHelper ( "hintWords" , "clojure" , commonAtoms . concat ( commonBuiltins ) ) ;
126
+ CodeMirror . registerHelper ( "hintWords" , "clojure" ,
127
+ commonAtoms . concat ( commonSpecialForms , commonCoreSymbols ) ) ;
131
128
132
129
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 ) ;
136
133
137
134
var tests = {
138
135
digit : / \d / ,
@@ -271,7 +268,7 @@ CodeMirror.defineMode("clojure", function (options) {
271
268
keyWord += letter ;
272
269
}
273
270
274
- if ( keyWord . length > 0 && ( indentKeys . propertyIsEnumerable ( keyWord ) ||
271
+ if ( keyWord . length > 0 && ( indentSymbols . propertyIsEnumerable ( keyWord ) ||
275
272
tests . block_indent . test ( keyWord ) ) ) { // indent-word
276
273
pushStack ( state , indentTemp + INDENT_WORD_SKIP , ch ) ;
277
274
} else { // non-indent word
@@ -295,14 +292,14 @@ CodeMirror.defineMode("clojure", function (options) {
295
292
}
296
293
} else if ( ch == ":" ) {
297
294
stream . eatWhile ( tests . symbol ) ;
298
- return ATOM ;
295
+ return KEYWORD ;
299
296
} else {
300
297
stream . eatWhile ( tests . symbol ) ;
301
298
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 ;
306
303
} else if ( atoms && atoms . propertyIsEnumerable ( stream . current ( ) ) ) {
307
304
returnType = ATOM ;
308
305
} else {
0 commit comments