Skip to content

Commit a8ae0da

Browse files
committed
Merge branch 'noprompt-regexp' of git://github.com/guns/vim-clojure-static into noprompt-regexp
Conflicts: syntax/clojure.vim
2 parents 8062e98 + e20ed10 commit a8ae0da

8 files changed

Lines changed: 389 additions & 38 deletions

File tree

clj/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/target
2+
/lib
3+
/classes
4+
/checkouts
5+
pom.xml
6+
pom.xml.asc
7+
*.jar
8+
*.class
9+
.lein-deps-sum
10+
.lein-failures
11+
.lein-plugins
12+
.lein-repl-history
13+
/tmp

clj/project.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(defproject vim-clojure-static "0.1.0"
2+
:url "https://github.com/guns/vim-clojure-static"
3+
:license {:name "Vim License" :url ":help license"}
4+
:dependencies [[org.clojure/clojure "1.5.0"]])
Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
;; Copyright (c) 2012 Sung Pae <self@sungpae.com>
1+
;; Copyright (c) 2013 Sung Pae <self@sungpae.com>
22
;; Distributed under the MIT license.
33
;; http://www.opensource.org/licenses/mit-license.php
4-
;;
5-
;; Copy this file to a project running the latest Clojure release and generate
6-
;; updated Vimscript definitions.
74

8-
(ns vim-clojure-static
9-
(:require clojure.string clojure.set clojure.java.shell))
5+
(ns vim-clojure-static.generate
6+
(:require [clojure.string :as string]
7+
[clojure.set :as set]))
108

119
(def generation-message
12-
(str "\" Generated from https://github.com/guns/vim-clojure-static/blob/vim-release-004/vim_clojure_static.clj"
10+
(str "\" Generated from https://github.com/guns/vim-clojure-static/blob/vim-release-004/clj/src/vim_clojure_static/generate.clj"
1311
\newline
1412
"\" Clojure " (clojure-version)
1513
\newline))
@@ -34,7 +32,7 @@
3432
declared (atom (set (filter symbol? (mapcat peek builtins))))
3533
coresyms (keys (ns-publics `clojure.core))
3634
select! (fn [pred]
37-
(let [xs (clojure.set/difference (set (filter pred coresyms)) @declared)]
35+
(let [xs (set/difference (set (filter pred coresyms)) @declared)]
3836
(swap! declared into xs)
3937
xs))
4038
builtins (conj builtins
@@ -54,9 +52,9 @@
5452
[] coll))
5553
definitions (map (fn [[group keywords]]
5654
(str "syntax keyword clojure" group \space
57-
(clojure.string/join \space (sort (names keywords)))))
55+
(string/join \space (sort (names keywords)))))
5856
builtins)]
59-
(str generation-message (clojure.string/join \newline definitions))))
57+
(str generation-message (string/join \newline definitions))))
6058

6159
(def completion-words
6260
"Vimscript literal list of special forms and public vars in clojure.core."
@@ -68,24 +66,7 @@
6866
(concat special-forms)
6967
(map #(str \" % \"))
7068
sort
71-
(clojure.string/join \,)))))
72-
73-
(defn update-vim!
74-
"Update runtime files in dir/runtime"
75-
[src dst]
76-
(let [join (fn [& args] (clojure.string/join \/ args))
77-
indent-file (join dst "runtime/doc/indent.txt")
78-
indent-buf (slurp indent-file)
79-
indent-match (re-find #"(?ms)^CLOJURE.*?(?=^[ \p{Lu}]+\t*\*)" indent-buf)
80-
indent-doc (re-find #"(?ms)^CLOJURE.*(?=^ABOUT)" (slurp (join src "doc/clojure.txt")))]
81-
;; Insert indentation documentation
82-
(spit indent-file (clojure.string/replace-first indent-buf
83-
indent-match
84-
(str indent-doc \newline)))
85-
;; Copy runtime files
86-
(doseq [file ["autoload/clojurecomplete.vim" "ftplugin/clojure.vim" "indent/clojure.vim" "syntax/clojure.vim"]]
87-
(println (clojure.java.shell/sh "cp" (join src file) (join dst "runtime" file))))))
69+
(string/join \,)))))
8870

8971
(comment
90-
(spit "/tmp/clojure-defs.vim" (str syntax-keywords "\n\n" completion-words))
91-
(update-vim! "/home/guns/src/vim-clojure-static" "/home/guns/src/vim"))
72+
(spit "/tmp/clojure-defs.vim" (str syntax-keywords "\n\n" completion-words)))
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
;; Copyright (c) 2013 Sung Pae <self@sungpae.com>
2+
;; Distributed under the MIT license.
3+
;; http://www.opensource.org/licenses/mit-license.php
4+
5+
(ns vim-clojure-static.test
6+
(:require [clojure.java.io :as io]
7+
[clojure.java.shell :as shell]
8+
[clojure.edn :as edn]
9+
[clojure.string :as string]
10+
[clojure.test :as test]))
11+
12+
(defn syn-id-names
13+
"Map lines of clojure text to vim synID names at each column as keywords:
14+
15+
(syn-id-names \"foo\" …) -> {\"foo\" [:clojureString :clojureString :clojureString] …}
16+
17+
First parameter is the file that is used to communicate with Vim. The file
18+
is not deleted to allow manual inspection."
19+
[file & lines]
20+
(io/make-parents file)
21+
(spit file (string/join \newline lines))
22+
(shell/sh "vim" "-u" "NONE" "-N" "-S" "vim/syn-id-names.vim" file)
23+
;; The last line of the file will contain valid EDN
24+
(into {} (map (fn [l ids] [l (mapv keyword ids)])
25+
lines
26+
(edn/read-string (peek (string/split-lines (slurp file)))))))
27+
28+
(defn subfmt
29+
"Extract a subsequence of seq s corresponding to the character positions of
30+
%s in format spec fmt"
31+
[fmt s]
32+
(let [f (seq (format fmt \o001))
33+
i (.indexOf f \o001)]
34+
(->> s
35+
(drop i)
36+
(drop-last (- (count f) i 1)))))
37+
38+
(defmacro defsyntaxtest
39+
"Create a new testing var with tests in the format:
40+
41+
(defsyntaxtest example
42+
(with-format \"#\\\"%s\\\"\"
43+
\"123\" #(every? (partial = :clojureRegexp) %)
44+
…)
45+
(with-format …))
46+
47+
At runtime the syn-id-names of the strings (which are placed in the format
48+
spec) are passed to their associated predicates. The format spec should
49+
contain a single `%s`."
50+
[name & body]
51+
(assert (every? #(= 'with-format (first %)) body))
52+
(assert (every? #(string? (second %)) body))
53+
(assert (every? #(even? (count %)) body))
54+
(let [[strings contexts] (reduce (fn [[strings contexts] [_ fmt & forms]]
55+
(let [[ss λs] (apply map list (partition 2 forms))
56+
ss (map #(format fmt %) ss)]
57+
[(concat strings ss)
58+
(conj contexts {:fmt fmt :ss ss :λs λs})]))
59+
[[] []] body)]
60+
`(test/deftest ~name
61+
;; Shellout to vim should happen at runtime
62+
(let [~'synids (syn-id-names (str "tmp/" ~(str name) ".clj") ~@strings)]
63+
~@(map (fn [{:keys [fmt ss λs]}]
64+
`(test/testing ~fmt
65+
~@(map (fn [s λ] `(test/is ( (subfmt ~fmt (get ~'synids ~s)))))
66+
ss λs)))
67+
contexts)))))
68+
69+
(comment
70+
71+
(macroexpand-1
72+
'(defsyntaxtest number-literals-test
73+
(with-format "%s"
74+
"123" #(every? (partial = :clojureNumber) %)
75+
"456" #(every? (partial = :clojureNumber) %))
76+
(with-format "#\"%s\""
77+
"^" #(= % [:clojureRegexpBoundary]))))
78+
(test #'number-literals-test)
79+
80+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
;; Copyright (c) 2013 Sung Pae <self@sungpae.com>
2+
;; Distributed under the MIT license.
3+
;; http://www.opensource.org/licenses/mit-license.php
4+
5+
(ns vim-clojure-static.update
6+
(:require [clojure.string :as string]
7+
[clojure.java.shell :as shell]))
8+
9+
(defn update-vim!
10+
"Update Vim repository runtime files in dst/runtime"
11+
[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+
;; Insert indentation documentation
18+
(spit indent-file (string/replace-first indent-buf
19+
indent-match
20+
(str indent-doc \newline)))
21+
;; Copy runtime files
22+
(doseq [file ["autoload/clojurecomplete.vim"
23+
"ftplugin/clojure.vim"
24+
"indent/clojure.vim"
25+
"syntax/clojure.vim"]]
26+
(shell/sh "cp" (join src file) (join dst "runtime" file)))))
27+
28+
(comment
29+
(update-vim! "/home/guns/src/vim-clojure-static" "/home/guns/src/vim"))

0 commit comments

Comments
 (0)