|
18 | 18 | ;; Helpers |
19 | 19 | ;; |
20 | 20 |
|
21 | | -(defn vim-frak-pattern |
| 21 | +(defn- vim-frak-pattern |
22 | 22 | "Create a non-capturing regular expression pattern compatible with Vim." |
23 | 23 | [strs] |
24 | 24 | (-> (f/string-pattern strs {:escape-chars :vim}) |
25 | 25 | (string/replace #"\(\?:" "\\%\\("))) |
26 | 26 |
|
27 | | -(defn property-pattern |
| 27 | +(defn- property-pattern |
28 | 28 | "Vimscript very magic pattern for a character property class." |
29 | 29 | ([s] (property-pattern s true)) |
30 | 30 | ([s braces?] |
31 | 31 | (if braces? |
32 | 32 | (format "\\v\\\\[pP]\\{%s\\}" s) |
33 | 33 | (format "\\v\\\\[pP]%s" s)))) |
34 | 34 |
|
35 | | -(defn syntax-match-properties |
| 35 | +(defn- syntax-match-properties |
36 | 36 | "Vimscript literal `syntax match` for a character property class." |
37 | 37 | ([group fmt props] (syntax-match-properties group fmt props true)) |
38 | 38 | ([group fmt props braces?] |
39 | 39 | (format "syntax match %s \"%s\" contained display\n" |
40 | 40 | (name group) |
41 | 41 | (property-pattern (format fmt (vim-frak-pattern props)) braces?)))) |
42 | 42 |
|
43 | | -(defn get-private-field |
| 43 | +(defn- get-private-field |
44 | 44 | "Violate encapsulation and get the value of a private field." |
45 | 45 | [^Class cls fieldname] |
46 | 46 | (let [^Field field (first (filter #(= fieldname (.getName ^Field %)) |
47 | 47 | (.getDeclaredFields cls)))] |
48 | 48 | (.setAccessible field true) |
49 | 49 | (.get field field))) |
50 | 50 |
|
51 | | -(defn fn-var? [v] |
| 51 | +(defn- fn-var? [v] |
52 | 52 | (let [f @v] |
53 | 53 | (or (contains? (meta v) :arglists) |
54 | 54 | (fn? f) |
55 | 55 | (instance? MultiFn f)))) |
56 | 56 |
|
57 | | -(defn inner-class-name [^Class cls] |
| 57 | +(defn- inner-class-name [^Class cls] |
58 | 58 | (string/replace (.getName cls) #".*\$(.+)" "$1")) |
59 | 59 |
|
60 | | -(defn map-keyword-names [coll] |
| 60 | +(defn- map-keyword-names [coll] |
61 | 61 | (reduce |
62 | 62 | (fn [v x] |
63 | 63 | ;; Include fully qualified versions of core vars for matching vars in |
|
71 | 71 | :else (conj v (str x)))) |
72 | 72 | [] coll)) |
73 | 73 |
|
74 | | -(defn vim-top-cluster |
| 74 | +(defn- vim-top-cluster |
75 | 75 | "Generate a Vimscript literal `syntax cluster` statement for `groups` and |
76 | 76 | all top-level syntax groups in the given syntax buffer." |
77 | 77 | [groups syntax-buf] |
|
275 | 275 | "\\c%%(In|blk\\=|block\\=)%s" |
276 | 276 | (map string/lower-case (:block character-properties)))) |
277 | 277 |
|
278 | | -(def comprehensive-clojure-character-property-regexps |
| 278 | +(def vim-lispwords |
| 279 | + "Vimscript literal `setlocal lispwords=` statement." |
| 280 | + (str "setlocal lispwords=" (string/join \, (sort lispwords)) "\n")) |
| 281 | + |
| 282 | +(defn- comprehensive-clojure-character-property-regexps [] |
279 | 283 | "A string representing a Clojure literal vector of regular expressions |
280 | 284 | containing all possible property character classes. For testing Vimscript |
281 | 285 | syntax matching optimizations." |
|
290 | 294 | (fmt "script=" :script) |
291 | 295 | (fmt "block=" :block)]))) |
292 | 296 |
|
293 | | -(def vim-lispwords |
294 | | - "Vimscript literal `setlocal lispwords=` statement." |
295 | | - (str "setlocal lispwords=" (string/join \, (sort lispwords)) "\n")) |
296 | | - |
297 | 297 | ;; |
298 | 298 | ;; Update functions |
299 | 299 | ;; |
300 | 300 |
|
301 | | -(def CLOJURE-SECTION |
| 301 | +(def ^:private CLOJURE-SECTION |
302 | 302 | #"(?ms)^CLOJURE.*?(?=^[\p{Lu} ]+\t*\*)") |
303 | 303 |
|
304 | | -(defn fjoin [& args] |
| 304 | +(defn- fjoin [& args] |
305 | 305 | (string/join \/ args)) |
306 | 306 |
|
307 | | -(defn qstr [& xs] |
| 307 | +(defn- qstr [& xs] |
308 | 308 | (string/replace (apply str xs) "\\" "\\\\")) |
309 | 309 |
|
310 | | -(defn update-doc! [first-line-pattern src-file dst-file] |
| 310 | +(defn- update-doc! [first-line-pattern src-file dst-file] |
311 | 311 | (let [sbuf (->> src-file |
312 | 312 | io/reader |
313 | 313 | line-seq |
|
318 | 318 | hunk (re-find CLOJURE-SECTION sbuf)] |
319 | 319 | (spit dst-file (string/replace-first dbuf dmatch hunk)))) |
320 | 320 |
|
321 | | -(defn copy-runtime-files! [src dst & opts] |
| 321 | +(defn- copy-runtime-files! [src dst & opts] |
322 | 322 | (let [{:keys [tag date paths]} (apply hash-map opts)] |
323 | 323 | (doseq [path paths |
324 | 324 | :let [buf (-> (fjoin src path) |
|
327 | 327 | (string/replace "%%RELEASE_DATE%%" date))]] |
328 | 328 | (spit (fjoin dst "runtime" path) buf)))) |
329 | 329 |
|
330 | | -(defn project-replacements [dir] |
| 330 | +(defn- project-replacements [dir] |
331 | 331 | {(fjoin dir "syntax/clojure.vim") |
332 | 332 | {"-*- KEYWORDS -*-" |
333 | 333 | (qstr generation-comment |
|
345 | 345 | "-*- TOP CLUSTER -*-" |
346 | 346 | (qstr generation-comment |
347 | 347 | (vim-top-cluster (mapv first keyword-groups) |
348 | | - (slurp (fjoin dir "syntax/clojure.vim"))))} |
| 348 | + (slurp (fjoin dir "syntax/clojure.vim"))))} |
349 | 349 |
|
350 | 350 | (fjoin dir "ftplugin/clojure.vim") |
351 | 351 | {"-*- LISPWORDS -*-" |
|
358 | 358 | clojure-version-comment |
359 | 359 | vim-completion-words)}}) |
360 | 360 |
|
361 | | -(defn update-project! |
| 361 | +(defn- update-project! |
362 | 362 | "Update project runtime files in the given directory." |
363 | 363 | [dir] |
364 | 364 | (doseq [[file replacements] (project-replacements dir)] |
|
372 | 372 | (do (printf "Updating %s\n" magic-comment) |
373 | 373 | (spit file buf'))))))) |
374 | 374 |
|
375 | | -(defn update-vim! |
| 375 | +(defn- update-vim! |
376 | 376 | "Update Vim repository runtime files in dst/runtime" |
377 | 377 | [src dst] |
378 | 378 | (let [current-tag (string/trim-newline (:out (sh "git" "tag" "--points-at" "HEAD"))) |
|
398 | 398 |
|
399 | 399 | ;; Generate an example file with all possible character property literals. |
400 | 400 | (spit "tmp/all-char-props.clj" |
401 | | - comprehensive-clojure-character-property-regexps) |
| 401 | + (comprehensive-clojure-character-property-regexps)) |
402 | 402 |
|
403 | 403 | ;; Performance test: `syntax keyword` vs `syntax match` |
404 | 404 | (vim-clojure-static.test/benchmark |
|
0 commit comments