|
1 | 1 | ;; Authors: Sung Pae <self@sungpae.com> |
2 | 2 |
|
3 | 3 | (ns vim-clojure-static.update |
4 | | - (:require [clojure.java.shell :refer [sh]] |
| 4 | + (:require [clojure.java.io :as io] |
| 5 | + [clojure.java.shell :refer [sh]] |
5 | 6 | [clojure.string :as string]) |
6 | 7 | (:import (java.text SimpleDateFormat) |
7 | 8 | (java.util Date))) |
8 | 9 |
|
| 10 | +(defn fjoin [& args] |
| 11 | + (string/join \/ args)) |
| 12 | + |
| 13 | +(def clojure-section |
| 14 | + #"(?ms)^CLOJURE.*?(?=^[\p{Lu} ]+\t*\*)") |
| 15 | + |
| 16 | +(defn update-doc! [first-line-pattern src-file dst-file] |
| 17 | + (let [sbuf (->> src-file |
| 18 | + io/reader |
| 19 | + line-seq |
| 20 | + (drop-while #(not (re-find first-line-pattern %))) |
| 21 | + (string/join \newline)) |
| 22 | + dbuf (slurp dst-file) |
| 23 | + dmatch (re-find clojure-section dbuf) |
| 24 | + hunk (re-find clojure-section sbuf)] |
| 25 | + (spit dst-file (string/replace-first dbuf dmatch hunk)))) |
| 26 | + |
| 27 | +(defn copy-runtime-files! [src dst & opts] |
| 28 | + (let [{:keys [tag date paths]} (apply hash-map opts)] |
| 29 | + (doseq [path paths |
| 30 | + :let [buf (-> (fjoin src path) |
| 31 | + slurp |
| 32 | + (string/replace "%%RELEASE_TAG%%" tag) |
| 33 | + (string/replace "%%RELEASE_DATE%%" date))]] |
| 34 | + (spit (fjoin dst "runtime" path) buf)))) |
| 35 | + |
9 | 36 | (defn update-vim! |
10 | 37 | "Update Vim repository runtime files in dst/runtime" |
11 | 38 | [src dst] |
12 | | - (let [join (fn [& args] (string/join \/ args)) |
13 | | - indent-file (join dst "runtime/doc/indent.txt") |
14 | | - indent-buf (slurp indent-file) |
15 | | - indent-match (re-find #"(?ms)^CLOJURE.*?(?=^[ \p{Lu}]+\t*\*)" indent-buf) |
16 | | - indent-doc (re-find #"(?ms)^CLOJURE.*(?=^ABOUT)" (slurp (join src "doc/clojure.txt"))) |
17 | | - current-date (.format (SimpleDateFormat. "dd MMMM YYYY") (Date.)) |
18 | | - current-tag (string/trim-newline (:out (sh "git" "tag" "--points-at" "HEAD")))] |
| 39 | + (let [current-tag (string/trim-newline (:out (sh "git" "tag" "--points-at" "HEAD"))) |
| 40 | + current-date (.format (SimpleDateFormat. "dd MMMM YYYY") (Date.))] |
19 | 41 | (assert (seq current-tag) "Git HEAD is not tagged!") |
20 | | - ;; Insert indentation documentation |
21 | | - (spit indent-file (string/replace-first indent-buf |
22 | | - indent-match |
23 | | - (str indent-doc \newline))) |
24 | | - ;; Copy runtime files |
25 | | - (doseq [file ["autoload/clojurecomplete.vim" |
26 | | - "ftplugin/clojure.vim" |
27 | | - "indent/clojure.vim" |
28 | | - "syntax/clojure.vim"] |
29 | | - :let [buf (-> (join src file) |
30 | | - slurp |
31 | | - (string/replace "%%RELEASE_DATE%%" current-date) |
32 | | - (string/replace "%%RELEASE_TAG%%" current-tag))]] |
33 | | - (spit (join dst "runtime" file) buf)))) |
| 42 | + (update-doc! #"CLOJURE\t*\*ft-clojure-indent\*" |
| 43 | + (fjoin src "doc/clojure.txt") |
| 44 | + (fjoin dst "runtime/doc/indent.txt")) |
| 45 | + (update-doc! #"CLOJURE\t*\*ft-clojure-syntax\*" |
| 46 | + (fjoin src "doc/clojure.txt") |
| 47 | + (fjoin dst "runtime/doc/syntax.txt")) |
| 48 | + (copy-runtime-files! src dst |
| 49 | + :tag current-tag |
| 50 | + :date current-date |
| 51 | + :paths ["autoload/clojurecomplete.vim" |
| 52 | + "ftplugin/clojure.vim" |
| 53 | + "indent/clojure.vim" |
| 54 | + "syntax/clojure.vim"]))) |
34 | 55 |
|
35 | 56 | (comment |
36 | 57 | (update-vim! "/home/guns/src/vim-clojure-static" "/home/guns/src/vim")) |
0 commit comments