citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

clojure.vim (14232B)


      1 " Vim syntax file
      2 " Language:    Clojure
      3 " Maintainer:  Toralf Wittner <toralf.wittner@gmail.com>
      4 "              modified by Meikel Brandmeyer <mb@kotka.de>
      5 " URL:         http://kotka.de/projects/clojure/vimclojure.html
      6 
      7 if version < 600
      8     syntax clear
      9 elseif exists("b:current_syntax")
     10     finish
     11 endif
     12 
     13 " Highlight superfluous closing parens, brackets and braces.
     14 syn match clojureError "]\|}\|)"
     15 
     16 if (exists("g:clj_highlight_builtins") && g:clj_highlight_builtins != 0)
     17 			\ || (exists("g:clj_want_gorilla") && g:clj_want_gorilla != 0)
     18 	" Special case for Windows.
     19 	call vimclojure#InitBuffer()
     20 
     21 	let s:builtins_map = {
     22 		\ "Constant":  "nil",
     23 		\ "Boolean":   "true false",
     24 		\ "Cond":      "if if-not if-let when when-not when-let "
     25 		\            . "when-first cond condp",
     26 		\ "Exception": "try catch finally throw",
     27 		\ "Repeat":    "recur map mapcat reduce filter for doseq dorun "
     28 		\            . "doall dotimes",
     29 		\ "Special":   ". def do fn if let new quote var loop",
     30 		\ "Variable":  "*warn-on-reflection* this "
     31 		\            . "*agent* *ns* *in* *out* *err* *command-line-args* "
     32 		\            . "*print-meta* *print-readably* *print-length* "
     33 		\            . "*allow-unresolved-args* *compile-files* "
     34 		\            . "*compile-path* *file* *flush-on-newline* "
     35 		\            . "*macro-meta* *math-context* *print-dup* "
     36 		\            . "*print-level* *use-context-classloader* "
     37 		\            . "*source-path* *clojure-version* *read-eval*"
     38 		\            . "*1 *2 *3 *e",
     39 		\ "Define":    "def- defn defn- defmacro defmulti defmethod "
     40 		\            . "defstruct defonce declare definline ",
     41 		\ "Macro":     "and or -> assert with-out-str with-in-str with-open "
     42 		\            . "locking destructure ns dosync binding delay "
     43 		\            . "lazy-cons lazy-cat time assert doc with-precision "
     44 		\            . "with-local-vars .. doto memfn proxy amap areduce "
     45 		\            . "refer-clojure future lazy-seq letfn",
     46 		\ "Func":      "= not= not nil? false? true? complement identical? "
     47 		\            . "string? symbol? map? seq? vector? keyword? var? "
     48 		\            . "special-symbol? apply partial comp constantly "
     49 		\            . "identity comparator fn? re-matcher re-find re-matches "
     50 		\            . "re-groups re-seq re-pattern str pr prn print "
     51 		\            . "println pr-str prn-str print-str println-str newline "
     52 		\            . "macroexpand macroexpand-1 monitor-enter monitor-exit "
     53 		\            . "eval find-doc file-seq flush hash load load-file "
     54 		\            . "print-doc read read-line scan slurp subs sync test "
     55 		\            . "format printf loaded-libs use require load-reader "
     56 		\            . "load-string + - * / < <= == >= > dec inc min max neg? "
     57 		\            . "pos? quot rem zero? rand rand-int decimal? even? odd? "
     58 		\            . "float? integer? number? ratio? rational? "
     59 		\            . "bit-and bit-or bit-xor bit-not bit-shift-left "
     60 		\            . "bit-shift-right symbol keyword gensym count conj seq "
     61 		\            . "first rest ffirst fnext nfirst nnext second every? "
     62 		\            . "not-every? some not-any? concat reverse cycle "
     63 		\            . "interleave interpose split-at split-with take "
     64 		\            . "take-nth take-while drop drop-while repeat replicate "
     65 		\            . "iterate range into distinct sort sort-by zipmap "
     66 		\            . "line-seq butlast last nth nthnext next "
     67 		\            . "repeatedly tree-seq enumeration-seq iterator-seq "
     68 		\            . "coll? associative? empty? list? reversible? "
     69 		\            . "sequential? sorted? list list* cons peek pop vec "
     70 		\            . "vector peek pop rseq subvec array-map hash-map "
     71 		\            . "sorted-map sorted-map-by assoc assoc-in dissoc get "
     72 		\            . "get-in contains? find select-keys update-in key val "
     73 		\            . "keys vals merge merge-with max-key min-key "
     74 		\            . "create-struct struct-map struct accessor "
     75 		\            . "remove-method meta with-meta in-ns refer create-ns "
     76 		\            . "find-ns all-ns remove-ns import ns-name ns-map "
     77 		\            . "ns-interns ns-publics ns-imports ns-refers ns-resolve "
     78 		\            . "resolve ns-unmap name namespace require use "
     79 		\            . "set! find-var var-get var-set ref deref "
     80 		\            . "ensure alter ref-set commute agent send send-off "
     81 		\            . "agent-errors clear-agent-errors await await-for "
     82 		\            . "instance? bean alength aget aset aset-boolean "
     83 		\            . "aset-byte aset-char aset-double aset-float "
     84 		\            . "aset-int aset-long aset-short make-array "
     85 		\            . "to-array to-array-2d into-array int long float "
     86 		\            . "double char boolean short byte parse add-classpath "
     87 		\            . "cast class get-proxy-class proxy-mappings "
     88 		\            . "update-proxy hash-set sorted-set set disj set? "
     89 		\            . "aclone add-watch alias alter-var-root "
     90 		\            . "ancestors await1 bases bigdec bigint bit-and-not "
     91 		\            . "bit-clear bit-flip bit-set bit-test counted?"
     92 		\            . "char-escape-string char-name-string class? "
     93 		\            . "compare compile construct-proxy delay? "
     94 		\            . "derive descendants distinct? double-array "
     95 		\            . "doubles drop-last empty float-array floats "
     96 		\            . "force gen-class get-validator int-array ints "
     97 		\            . "isa? long-array longs make-hierarchy method-sig "
     98 		\            . "not-empty ns-aliases ns-unalias num partition "
     99 		\            . "parents pmap prefer-method primitives-classnames "
    100 		\            . "print-ctor print-dup print-method print-simple "
    101 		\            . "print-special-doc proxy-call-with-super "
    102 		\            . "proxy-super rationalize read-string remove "
    103 		\            . "remove-watch replace resultset-seq rsubseq "
    104 		\            . "seque set-validator! shutdown-agents subseq "
    105 		\            . "special-form-anchor syntax-symbol-anchor supers "
    106 		\            . "unchecked-add unchecked-dec unchecked-divide "
    107 		\            . "unchecked-inc unchecked-multiply unchecked-negate "
    108 		\            . "unchecked-subtract underive xml-seq trampoline "
    109 		\            . "atom compare-and-set! ifn? gen-interface "
    110 		\            . "intern init-proxy io! memoize proxy-name swap! "
    111 		\            . "release-pending-sends the-ns unquote while "
    112 		\            . "unchecked-remainder add-watcher alter-meta! "
    113 		\            . "future-call methods mod pcalls prefers pvalues "
    114 		\            . "print-namespace-doc remove-watcher reset! "
    115 		\            . "reset-meta! type vary-meta unquote-splicing "
    116 		\            . "sequence clojure-version counted? stream?"
    117 		\ }
    118 
    119 	for category in keys(s:builtins_map)
    120 		let words = split(s:builtins_map[category], " ")
    121 		let words = map(copy(words), '"clojure.core/" . v:val') + words
    122 		let s:builtins_map[category] = words
    123 	endfor
    124 
    125 	call vimclojure#ColorNamespace(s:builtins_map)
    126 endif
    127 
    128 if exists("b:vimclojure_namespace")
    129 	let s:result = vimclojure#ExecuteNailWithInput("DynamicHighlighting",
    130 				\ b:vimclojure_namespace)
    131 	execute "let s:highlights = " . s:result
    132 	call vimclojure#ColorNamespace(s:highlights)
    133 	unlet s:result s:highlights
    134 endif
    135 
    136 syn cluster clojureAtomCluster   contains=clojureError,clojureFunc,clojureMacro,clojureCond,clojureDefine,clojureRepeat,clojureException,clojureConstant,clojureVariable,clojureSpecial,clojureKeyword,clojureString,clojureCharacter,clojureNumber,clojureRational,clojureFloat,clojureBoolean,clojureQuote,clojureUnquote,clojureDispatch,clojurePattern
    137 syn cluster clojureTopCluster    contains=@clojureAtomCluster,clojureComment,clojureSexp,clojureAnonFn,clojureVector,clojureMap,clojureSet
    138 
    139 syn keyword clojureTodo contained FIXME XXX
    140 syn match   clojureComment contains=clojureTodo ";.*$"
    141 
    142 syn match   clojureKeyword "\c:\{1,2}[a-z?!\-_+*./=<>][a-z0-9?!\-_+*\./=<>]*"
    143 
    144 syn region  clojureString start=/L\="/ skip=/\\\\\|\\"/ end=/"/
    145 
    146 syn match   clojureCharacter "\\."
    147 syn match   clojureCharacter "\\[0-7]\{3\}"
    148 syn match   clojureCharacter "\\u[0-9]\{4\}"
    149 syn match   clojureCharacter "\\space"
    150 syn match   clojureCharacter "\\tab"
    151 syn match   clojureCharacter "\\newline"
    152 syn match   clojureCharacter "\\return"
    153 syn match   clojureCharacter "\\backspace"
    154 syn match   clojureCharacter "\\formfeed"
    155 
    156 let radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
    157 for radix in range(2, 36)
    158 	execute 'syn match clojureNumber "\c\<-\?' . radix . 'r['
    159 				\ . strpart(radixChars, 0, radix)
    160 				\ . ']\+\>"'
    161 endfor
    162 
    163 syn match   clojureNumber "\<-\?[0-9]\+M\?\>"
    164 syn match   clojureRational "\<-\?[0-9]\+/[0-9]\+\>"
    165 syn match   clojureFloat "\<-\?[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"
    166 
    167 syn match   clojureQuote "\('\|`\)"
    168 syn match   clojureUnquote "\(\~@\|\~\)"
    169 syn match   clojureDispatch "\(#^\|#'\)"
    170 
    171 syn match   clojureAnonArg contained "%\(\d\|&\)\?"
    172 syn match   clojureVarArg contained "&"
    173 
    174 if exists("g:clj_paren_rainbow") && g:clj_paren_rainbow != 0
    175 	syn region clojureSexpLevel0 matchgroup=clojureParen0 start="(" matchgroup=clojureParen0 end=")"           contains=@clojureTopCluster,clojureSexpLevel1
    176 	syn region clojureSexpLevel1 matchgroup=clojureParen1 start="(" matchgroup=clojureParen1 end=")" contained contains=@clojureTopCluster,clojureSexpLevel2
    177 	syn region clojureSexpLevel2 matchgroup=clojureParen2 start="(" matchgroup=clojureParen2 end=")" contained contains=@clojureTopCluster,clojureSexpLevel3
    178 	syn region clojureSexpLevel3 matchgroup=clojureParen3 start="(" matchgroup=clojureParen3 end=")" contained contains=@clojureTopCluster,clojureSexpLevel4
    179 	syn region clojureSexpLevel4 matchgroup=clojureParen4 start="(" matchgroup=clojureParen4 end=")" contained contains=@clojureTopCluster,clojureSexpLevel5
    180 	syn region clojureSexpLevel5 matchgroup=clojureParen5 start="(" matchgroup=clojureParen5 end=")" contained contains=@clojureTopCluster,clojureSexpLevel6
    181 	syn region clojureSexpLevel6 matchgroup=clojureParen6 start="(" matchgroup=clojureParen6 end=")" contained contains=@clojureTopCluster,clojureSexpLevel7
    182 	syn region clojureSexpLevel7 matchgroup=clojureParen7 start="(" matchgroup=clojureParen7 end=")" contained contains=@clojureTopCluster,clojureSexpLevel8
    183 	syn region clojureSexpLevel8 matchgroup=clojureParen8 start="(" matchgroup=clojureParen8 end=")" contained contains=@clojureTopCluster,clojureSexpLevel9
    184 	syn region clojureSexpLevel9 matchgroup=clojureParen9 start="(" matchgroup=clojureParen9 end=")" contained contains=@clojureTopCluster,clojureSexpLevel0
    185 else
    186 	syn region clojureSexp       matchgroup=clojureParen0 start="(" matchgroup=clojureParen0 end=")"           contains=@clojureTopCluster
    187 endif
    188 
    189 syn region  clojureAnonFn  matchgroup=clojureParen0 start="#(" matchgroup=clojureParen0 end=")"  contains=@clojureTopCluster,clojureAnonArg,clojureSexpLevel0
    190 syn region  clojureVector  matchgroup=clojureParen0 start="\[" matchgroup=clojureParen0 end="\]" contains=@clojureTopCluster,clojureVarArg,clojureSexpLevel0
    191 syn region  clojureMap     matchgroup=clojureParen0 start="{"  matchgroup=clojureParen0 end="}"  contains=@clojureTopCluster,clojureSexpLevel0
    192 syn region  clojureSet     matchgroup=clojureParen0 start="#{" matchgroup=clojureParen0 end="}"  contains=@clojureTopCluster,clojureSexpLevel0
    193 syn region  clojurePattern                          start=/#"/                          end=/"/  skip=/\\"/
    194 
    195 syn region  clojureCommentSexp                          start="("                                       end=")" transparent contained contains=clojureCommentSexp
    196 syn region  clojureComment     matchgroup=clojureParen0 start="(comment"rs=s+1 matchgroup=clojureParen0 end=")"                       contains=clojureCommentSexp
    197 syn region  clojureComment                              start="#!" end="\n"
    198 syn match   clojureComment "#_"
    199 
    200 syn sync match matchPlace grouphere NONE "^[^ \t]"
    201 
    202 if version >= 600
    203 	command -nargs=+ HiLink highlight default link <args>
    204 else
    205 	command -nargs=+ HiLink highlight         link <args>
    206 endif
    207 
    208 HiLink clojureConstant  Constant
    209 HiLink clojureBoolean   Boolean
    210 HiLink clojureCharacter Character
    211 HiLink clojureKeyword   Operator
    212 HiLink clojureNumber    Number
    213 HiLink clojureRational  Number
    214 HiLink clojureFloat     Float
    215 HiLink clojureString    String
    216 HiLink clojurePattern   Constant
    217 
    218 HiLink clojureVariable  Identifier
    219 HiLink clojureCond      Conditional
    220 HiLink clojureDefine    Define
    221 HiLink clojureException Exception
    222 HiLink clojureFunc      Function
    223 HiLink clojureMacro     Macro
    224 HiLink clojureRepeat    Repeat
    225 
    226 HiLink clojureQuote     Special
    227 HiLink clojureUnquote   Special
    228 HiLink clojureDispatch  Special
    229 HiLink clojureAnonArg   Special
    230 HiLink clojureVarArg    Special
    231 HiLink clojureSpecial   Special
    232 
    233 HiLink clojureComment   Comment
    234 HiLink clojureTodo      Todo
    235 
    236 HiLink clojureError     Error
    237 
    238 HiLink clojureParen0    Delimiter
    239 
    240 if exists("g:clj_paren_rainbow") && g:clj_paren_rainbow != 0
    241 	if &background == "dark"
    242 		highlight default clojureParen1 ctermfg=yellow      guifg=orange1
    243 		highlight default clojureParen2 ctermfg=green       guifg=yellow1
    244 		highlight default clojureParen3 ctermfg=cyan        guifg=greenyellow
    245 		highlight default clojureParen4 ctermfg=magenta     guifg=green1
    246 		highlight default clojureParen5 ctermfg=red         guifg=springgreen1
    247 		highlight default clojureParen6 ctermfg=yellow      guifg=cyan1
    248 		highlight default clojureParen7 ctermfg=green       guifg=slateblue1
    249 		highlight default clojureParen8 ctermfg=cyan        guifg=magenta1
    250 		highlight default clojureParen9 ctermfg=magenta     guifg=purple1
    251 	else
    252 		highlight default clojureParen1 ctermfg=darkyellow  guifg=orangered3
    253 		highlight default clojureParen2 ctermfg=darkgreen   guifg=orange2
    254 		highlight default clojureParen3 ctermfg=blue        guifg=yellow3
    255 		highlight default clojureParen4 ctermfg=darkmagenta guifg=olivedrab4
    256 		highlight default clojureParen5 ctermfg=red         guifg=green4
    257 		highlight default clojureParen6 ctermfg=darkyellow  guifg=paleturquoise3
    258 		highlight default clojureParen7 ctermfg=darkgreen   guifg=deepskyblue4
    259 		highlight default clojureParen8 ctermfg=blue        guifg=darkslateblue
    260 		highlight default clojureParen9 ctermfg=darkmagenta guifg=darkviolet
    261 	endif
    262 endif
    263 
    264 delcommand HiLink
    265 
    266 let b:current_syntax = "clojure"