Skip to content

Commit 0a16fae

Browse files
committed
Update Vim patching functions
1 parent 5dea5ab commit 0a16fae

2 files changed

Lines changed: 46 additions & 27 deletions

File tree

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,57 @@
11
;; Authors: Sung Pae <self@sungpae.com>
22

33
(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]]
56
[clojure.string :as string])
67
(:import (java.text SimpleDateFormat)
78
(java.util Date)))
89

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+
936
(defn update-vim!
1037
"Update Vim repository runtime files in dst/runtime"
1138
[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.))]
1941
(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"])))
3455

3556
(comment
3657
(update-vim! "/home/guns/src/vim-clojure-static" "/home/guns/src/vim"))

doc/clojure.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ This option is off by default.
126126

127127
CLOJURE *ft-clojure-syntax*
128128

129-
*g:clojure_fold*
130-
131-
Setting this option enables folding Clojure code via the syntax engine. Any
132-
list, vector, or map that extends over more than one line can be folded using
133-
the standard Vim |fold-commands|.
129+
Setting *g:clojure_fold* enables folding Clojure code via the syntax engine.
130+
Any list, vector, or map that extends over more than one line can be folded
131+
using the standard Vim |fold-commands|.
134132

135133
Please note that this option does not work with scripts that redefine the
136134
bracket syntax regions, such as rainbow-parentheses plugins.

0 commit comments

Comments
 (0)