Skip to content

Commit d776eca

Browse files
committed
Execute core syntax keyword statements from a dictionary
Users can define their own simple syntax items by adding a 'clojure*' entry in g:clojure_syntax_keywords or b:clojure_syntax_keywords. The motivation behind this is to allow plugins to augment syntax definitions and then reload them by resetting the syntax via: let &syntax = &syntax This was inspired by TimL's dynamic highlighting feature.
1 parent 5ccae65 commit d776eca

2 files changed

Lines changed: 54 additions & 29 deletions

File tree

clj/src/vim_clojure_static/generate.clj

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
(->> syntax-buf
7575
(re-seq #"syntax\s+(?:keyword|match|region)\s+(\S+)(?!.*\bcontained\b)")
7676
(map peek)
77+
(concat (map first keyword-groups))
7778
sort
7879
distinct
7980
(string/join \,)
@@ -100,22 +101,22 @@
100101
(def keyword-groups
101102
"Special forms, constants, and every public var in clojure.core listed by
102103
syntax group suffix."
103-
(let [builtins [["Constant" '#{nil}]
104-
["Boolean" '#{true false}]
105-
["Special" special-forms]
104+
(let [builtins [["clojureConstant" '#{nil}]
105+
["clojureBoolean" '#{true false}]
106+
["clojureSpecial" special-forms]
106107
;; These are duplicates from special-forms
107-
["Exception" '#{throw try catch finally}]
108-
["Cond" '#{case cond cond-> cond->> condp if-let if-not
109-
if-some when when-first when-let when-not
110-
when-some}]
108+
["clojureException" '#{throw try catch finally}]
109+
["clojureCond" '#{case cond cond-> cond->> condp if-let
110+
if-not if-some when when-first when-let
111+
when-not when-some}]
111112
;; Imperative looping constructs (not sequence functions)
112-
["Repeat" '#{doseq dotimes while}]]
113+
["clojureRepeat" '#{doseq dotimes while}]]
113114
coresyms (set/difference (set (keys (ns-publics 'clojure.core)))
114115
(set (mapcat peek builtins)))
115-
group-preds [["Define" #(re-seq #"\Adef(?!ault)" (str %))]
116-
["Macro" #(:macro (meta (ns-resolve 'clojure.core %)))]
117-
["Func" #(fn-var? (ns-resolve 'clojure.core %))]
118-
["Variable" identity]]]
116+
group-preds [["clojureDefine" #(re-seq #"\Adef(?!ault)" (str %))]
117+
["clojureMacro" #(:macro (meta (ns-resolve 'clojure.core %)))]
118+
["clojureFunc" #(fn-var? (ns-resolve 'clojure.core %))]
119+
["clojureVariable" identity]]]
119120
(first
120121
(reduce
121122
(fn [[v syms] [group pred]]
@@ -176,21 +177,25 @@
176177
;;
177178

178179
(def vim-keywords
179-
"Vimscript literal `syntax keyword` for important identifiers."
180+
"Vimscript literal dictionary of important identifiers."
180181
(->> keyword-groups
181182
(map (fn [[group keywords]]
182-
(format "syntax keyword clojure%s %s\n"
183-
group
184-
(string/join \space (sort (map-keyword-names keywords))))))
185-
string/join))
183+
(->> keywords
184+
map-keyword-names
185+
sort
186+
(map pr-str)
187+
(string/join \,)
188+
(format "'%s': [%s]" group))))
189+
(string/join "\n \\ , ")
190+
(format "let s:clojure_syntax_keywords = {\n \\ %s\n \\ }\n")))
186191

187192
(def vim-completion-words
188193
"Vimscript literal list of words for omnifunc completion."
189194
(->> 'clojure.core
190195
ns-publics
191196
keys
192197
(concat special-forms)
193-
(map #(str \" % \"))
198+
(map (comp pr-str str))
194199
sort
195200
(string/join \,)
196201
(format "let s:words = [%s]\n")))

0 commit comments

Comments
 (0)