Skip to content

Commit 98408fa

Browse files
committed
Add update-project! fn to automate generate && replace
1 parent c7ef615 commit 98408fa

6 files changed

Lines changed: 65 additions & 37 deletions

File tree

autoload/clojurecomplete.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
" License: Same as Vim
66
" Last Change: %%RELEASE_DATE%%
77

8-
" Special forms and public vars in clojure.core
8+
" -*- COMPLETION WORDS -*-
99
" Generated from https://github.com/guns/vim-clojure-static/blob/%%RELEASE_TAG%%/clj/src/vim_clojure_static/generate.clj
10-
" Clojure version 1.6.0-RC3
10+
" Clojure version 1.6.0-RC4
1111
let s:words = ["*","*'","*1","*2","*3","*agent*","*allow-unresolved-vars*","*assert*","*clojure-version*","*command-line-args*","*compile-files*","*compile-path*","*compiler-options*","*data-readers*","*default-data-reader-fn*","*e","*err*","*file*","*flush-on-newline*","*fn-loader*","*in*","*math-context*","*ns*","*out*","*print-dup*","*print-length*","*print-level*","*print-meta*","*print-readably*","*read-eval*","*source-path*","*unchecked-math*","*use-context-classloader*","*verbose-defrecords*","*warn-on-reflection*","+","+'","-","-'","->","->>","->ArrayChunk","->Vec","->VecNode","->VecSeq","-cache-protocol-fn","-reset-methods",".","..","/","<","<=","=","==",">",">=","EMPTY-NODE","accessor","aclone","add-classpath","add-watch","agent","agent-error","agent-errors","aget","alength","alias","all-ns","alter","alter-meta!","alter-var-root","amap","ancestors","and","apply","areduce","array-map","as->","aset","aset-boolean","aset-byte","aset-char","aset-double","aset-float","aset-int","aset-long","aset-short","assert","assoc!","assoc","assoc-in","associative?","atom","await","await-for","await1","bases","bean","bigdec","bigint","biginteger","binding","bit-and","bit-and-not","bit-clear","bit-flip","bit-not","bit-or","bit-set","bit-shift-left","bit-shift-right","bit-test","bit-xor","boolean","boolean-array","booleans","bound-fn","bound-fn*","bound?","butlast","byte","byte-array","bytes","case","cast","catch","char","char-array","char-escape-string","char-name-string","char?","chars","chunk","chunk-append","chunk-buffer","chunk-cons","chunk-first","chunk-next","chunk-rest","chunked-seq?","class","class?","clear-agent-errors","clojure-version","coll?","comment","commute","comp","comparator","compare","compare-and-set!","compile","complement","concat","cond","cond->","cond->>","condp","conj!","conj","cons","constantly","construct-proxy","contains?","count","counted?","create-ns","create-struct","cycle","dec","dec'","decimal?","declare","def","default-data-readers","definline","definterface","defmacro","defmethod","defmulti","defn","defn-","defonce","defprotocol","defrecord","defstruct","deftype","delay","delay?","deliver","denominator","deref","derive","descendants","destructure","disj!","disj","dissoc!","dissoc","distinct","distinct?","do","doall","dorun","doseq","dosync","dotimes","doto","double","double-array","doubles","drop","drop-last","drop-while","empty","empty?","ensure","enumeration-seq","error-handler","error-mode","eval","even?","every-pred","every?","ex-data","ex-info","extend","extend-protocol","extend-type","extenders","extends?","false?","ffirst","file-seq","filter","filterv","finally","find","find-keyword","find-ns","find-protocol-impl","find-protocol-method","find-var","first","flatten","float","float-array","float?","floats","flush","fn","fn","fn?","fnext","fnil","for","force","format","frequencies","future","future-call","future-cancel","future-cancelled?","future-done?","future?","gen-class","gen-interface","gensym","get","get-in","get-method","get-proxy-class","get-thread-bindings","get-validator","group-by","hash","hash-combine","hash-map","hash-ordered-coll","hash-set","hash-unordered-coll","identical?","identity","if","if-let","if-not","if-some","ifn?","import","in-ns","inc","inc'","init-proxy","instance?","int","int-array","integer?","interleave","intern","interpose","into","into-array","ints","io!","isa?","iterate","iterator-seq","juxt","keep","keep-indexed","key","keys","keyword","keyword?","last","lazy-cat","lazy-seq","let","let","letfn","line-seq","list","list*","list?","load","load-file","load-reader","load-string","loaded-libs","locking","long","long-array","longs","loop","loop","macroexpand","macroexpand-1","make-array","make-hierarchy","map","map-indexed","map?","mapcat","mapv","max","max-key","memfn","memoize","merge","merge-with","meta","method-sig","methods","min","min-key","mix-collection-hash","mod","monitor-enter","monitor-exit","munge","name","namespace","namespace-munge","neg?","new","newline","next","nfirst","nil?","nnext","not","not-any?","not-empty","not-every?","not=","ns","ns-aliases","ns-imports","ns-interns","ns-map","ns-name","ns-publics","ns-refers","ns-resolve","ns-unalias","ns-unmap","nth","nthnext","nthrest","num","number?","numerator","object-array","odd?","or","parents","partial","partition","partition-all","partition-by","pcalls","peek","persistent!","pmap","pop!","pop","pop-thread-bindings","pos?","pr","pr-str","prefer-method","prefers","primitives-classnames","print","print-ctor","print-dup","print-method","print-simple","print-str","printf","println","println-str","prn","prn-str","promise","proxy","proxy-call-with-super","proxy-mappings","proxy-name","proxy-super","push-thread-bindings","pvalues","quot","quote","rand","rand-int","rand-nth","range","ratio?","rational?","rationalize","re-find","re-groups","re-matcher","re-matches","re-pattern","re-seq","read","read-line","read-string","realized?","record?","recur","reduce","reduce-kv","reduced","reduced?","reductions","ref","ref-history-count","ref-max-history","ref-min-history","ref-set","refer","refer-clojure","reify","release-pending-sends","rem","remove","remove-all-methods","remove-method","remove-ns","remove-watch","repeat","repeatedly","replace","replicate","require","reset!","reset-meta!","resolve","rest","restart-agent","resultset-seq","reverse","reversible?","rseq","rsubseq","satisfies?","second","select-keys","send","send-off","send-via","seq","seq?","seque","sequence","sequential?","set!","set","set-agent-send-executor!","set-agent-send-off-executor!","set-error-handler!","set-error-mode!","set-validator!","set?","short","short-array","shorts","shuffle","shutdown-agents","slurp","some","some->","some->>","some-fn","some?","sort","sort-by","sorted-map","sorted-map-by","sorted-set","sorted-set-by","sorted?","special-symbol?","spit","split-at","split-with","str","string?","struct","struct-map","subs","subseq","subvec","supers","swap!","symbol","symbol?","sync","take","take-last","take-nth","take-while","test","the-ns","thread-bound?","throw","time","to-array","to-array-2d","trampoline","transient","tree-seq","true?","try","type","unchecked-add","unchecked-add-int","unchecked-byte","unchecked-char","unchecked-dec","unchecked-dec-int","unchecked-divide-int","unchecked-double","unchecked-float","unchecked-inc","unchecked-inc-int","unchecked-int","unchecked-long","unchecked-multiply","unchecked-multiply-int","unchecked-negate","unchecked-negate-int","unchecked-remainder-int","unchecked-short","unchecked-subtract","unchecked-subtract-int","underive","unquote","unquote-splicing","unsigned-bit-shift-right","update-in","update-proxy","use","val","vals","var","var-get","var-set","var?","vary-meta","vec","vector","vector-of","vector?","when","when-first","when-let","when-not","when-some","while","with-bindings","with-bindings*","with-in-str","with-loading-context","with-local-vars","with-meta","with-open","with-out-str","with-precision","with-redefs","with-redefs-fn","xml-seq","zero?","zipmap"]
1212

13-
" Simple word completion omnifunc
13+
" Simple word completion for special forms and public vars in clojure.core
1414
function! clojurecomplete#Complete(findstart, base)
1515
if a:findstart
1616
return searchpos('\<', 'bnW', line('.'))[1] - 1

clj/project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
:license {:name "Vim License"
55
:url "http://vimdoc.sourceforge.net/htmldoc/uganda.html#license"
66
:comments ":help license"}
7-
:dependencies [[org.clojure/clojure "1.6.0-RC3"]
7+
:dependencies [[org.clojure/clojure "1.6.0-RC4"]
88
[frak "0.1.6"]])

clj/src/vim_clojure_static/generate.clj

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -286,31 +286,6 @@
286286
(str "setlocal lispwords=" (string/join \, (sort lispwords)) "\n"))
287287

288288
(comment
289-
;; Generate the vim literal definitions for pasting into the runtime files.
290-
(spit "tmp/clojure-defs.vim"
291-
(str generation-comment
292-
clojure-version-comment
293-
vim-keywords
294-
\newline
295-
generation-comment
296-
java-version-comment
297-
vim-posix-char-classes
298-
vim-java-char-classes
299-
vim-unicode-binary-char-classes
300-
vim-unicode-category-char-classes
301-
vim-unicode-script-char-classes
302-
vim-unicode-block-char-classes
303-
\newline
304-
generation-comment
305-
(vim-top-cluster (slurp "../syntax/clojure.vim"))
306-
\newline
307-
generation-comment
308-
vim-lispwords
309-
\newline
310-
generation-comment
311-
clojure-version-comment
312-
vim-completion-words))
313-
314289
;; Generate an example file with all possible character property literals.
315290
(spit "tmp/all-char-props.clj"
316291
comprehensive-clojure-character-property-regexps)

clj/src/vim_clojure_static/update.clj

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
(ns vim-clojure-static.update
44
(:require [clojure.java.io :as io]
55
[clojure.java.shell :refer [sh]]
6-
[clojure.string :as string])
6+
[clojure.string :as string]
7+
[vim-clojure-static.generate :as g])
78
(:import (java.text SimpleDateFormat)
8-
(java.util Date)))
9+
(java.util Date)
10+
(java.util.regex Pattern)))
11+
12+
(def CLOJURE-SECTION
13+
#"(?ms)^CLOJURE.*?(?=^[\p{Lu} ]+\t*\*)")
914

1015
(defn fjoin [& args]
1116
(string/join \/ args))
1217

13-
(def clojure-section
14-
#"(?ms)^CLOJURE.*?(?=^[\p{Lu} ]+\t*\*)")
18+
(defn qstr [& xs]
19+
(string/replace (apply str xs) "\\" "\\\\"))
1520

1621
(defn update-doc! [first-line-pattern src-file dst-file]
1722
(let [sbuf (->> src-file
@@ -20,8 +25,8 @@
2025
(drop-while #(not (re-find first-line-pattern %)))
2126
(string/join \newline))
2227
dbuf (slurp dst-file)
23-
dmatch (re-find clojure-section dbuf)
24-
hunk (re-find clojure-section sbuf)]
28+
dmatch (re-find CLOJURE-SECTION dbuf)
29+
hunk (re-find CLOJURE-SECTION sbuf)]
2530
(spit dst-file (string/replace-first dbuf dmatch hunk))))
2631

2732
(defn copy-runtime-files! [src dst & opts]
@@ -33,6 +38,50 @@
3338
(string/replace "%%RELEASE_DATE%%" date))]]
3439
(spit (fjoin dst "runtime" path) buf))))
3540

41+
(defn project-replacements [dir]
42+
{(fjoin dir "syntax/clojure.vim")
43+
{"-*- KEYWORDS -*-"
44+
(qstr g/generation-comment
45+
g/clojure-version-comment
46+
g/vim-keywords)
47+
"-*- CHARACTER PROPERTY CLASSES -*-"
48+
(qstr g/generation-comment
49+
g/java-version-comment
50+
g/vim-posix-char-classes
51+
g/vim-java-char-classes
52+
g/vim-unicode-binary-char-classes
53+
g/vim-unicode-category-char-classes
54+
g/vim-unicode-script-char-classes
55+
g/vim-unicode-block-char-classes)
56+
"-*- TOP CLUSTER -*-"
57+
(qstr g/generation-comment
58+
(g/vim-top-cluster (slurp (fjoin dir "syntax/clojure.vim"))))}
59+
60+
(fjoin dir "ftplugin/clojure.vim")
61+
{"-*- LISPWORDS -*-"
62+
(qstr g/generation-comment
63+
g/vim-lispwords)}
64+
65+
(fjoin dir "autoload/clojurecomplete.vim")
66+
{"-*- COMPLETION WORDS -*-"
67+
(qstr g/generation-comment
68+
g/clojure-version-comment
69+
g/vim-completion-words)}})
70+
71+
(defn update-project!
72+
"Update project runtime files in the given directory."
73+
[dir]
74+
(doseq [[file replacements] (project-replacements dir)]
75+
(doseq [[magic-comment replacement] replacements]
76+
(let [buf (slurp file)
77+
pat (Pattern/compile (str "(?s)\\Q" magic-comment "\\E\\n.*?\\n\\n"))
78+
rep (str magic-comment "\n" replacement "\n")
79+
buf' (string/replace buf pat rep)]
80+
(if (= buf buf')
81+
(printf "No changes: %s\n" magic-comment)
82+
(do (printf "Updating %s\n" magic-comment)
83+
(spit file buf')))))))
84+
3685
(defn update-vim!
3786
"Update Vim repository runtime files in dst/runtime"
3887
[src dst]
@@ -54,4 +103,5 @@
54103
"syntax/clojure.vim"])))
55104

56105
(comment
106+
(update-project! "..")
57107
(update-vim! "/home/guns/src/vim-clojure-static" "/home/guns/src/vim"))

ftplugin/clojure.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ setlocal commentstring=;\ %s
4242
" Functions that accept a flat list of forms do not treat the first argument
4343
" specially and hence are not indented specially.
4444
"
45+
" -*- LISPWORDS -*-
4546
" Generated from https://github.com/guns/vim-clojure-static/blob/%%RELEASE_TAG%%/clj/src/vim_clojure_static/generate.clj
4647
setlocal lispwords=as->,binding,bound-fn,case,catch,cond->,cond->>,condp,def,definline,definterface,defmacro,defmethod,defmulti,defn,defn-,defonce,defprotocol,defrecord,defstruct,deftest,deftest-,deftype,doall,dorun,doseq,dotimes,doto,extend,extend-protocol,extend-type,fn,for,if,if-let,if-not,if-some,let,letfn,locking,loop,ns,proxy,reify,set-test,testing,when,when-first,when-let,when-not,when-some,while,with-bindings,with-in-str,with-local-vars,with-open,with-precision,with-redefs,with-redefs-fn,with-test
4748

syntax/clojure.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ if has("folding") && exists("g:clojure_fold") && g:clojure_fold > 0
1919
setlocal foldmethod=syntax
2020
endif
2121

22+
" -*- KEYWORDS -*-
2223
" Generated from https://github.com/guns/vim-clojure-static/blob/%%RELEASE_TAG%%/clj/src/vim_clojure_static/generate.clj
23-
" Clojure version 1.6.0-RC3
24+
" Clojure version 1.6.0-RC4
2425
syntax keyword clojureConstant nil
2526
syntax keyword clojureBoolean false true
2627
syntax keyword clojureSpecial . catch clojure.core/fn clojure.core/let clojure.core/loop def do finally fn if let loop monitor-enter monitor-exit new quote recur set! throw try var
@@ -83,7 +84,7 @@ syntax match clojureRegexpEscape "\v\\%([\\tnrfae.()\[\]{}^$*?+]|c\u|0[0-3]?\o{
8384
syntax region clojureRegexpQuoted start=/\\Q/ms=e+1 skip=/\\\\\|\\"/ end=/\\E/me=s-1 end=/"/me=s-1 contained
8485
syntax region clojureRegexpQuote start=/\\Q/ skip=/\\\\\|\\"/ end=/\\E/ end=/"/me=s-1 contains=clojureRegexpQuoted keepend contained
8586

86-
" Character property classes
87+
" -*- CHARACTER PROPERTY CLASSES -*-
8788
" Generated from https://github.com/guns/vim-clojure-static/blob/%%RELEASE_TAG%%/clj/src/vim_clojure_static/generate.clj
8889
" Java version 1.7.0_45
8990
syntax match clojureRegexpPosixCharClass "\v\\[pP]\{%(Blank|P%(unct|rint)|Digit|Graph|A%(l%(pha|num)|SCII)|XDigit|Space|Upper|Lower|Cntrl)\}" contained display
@@ -121,6 +122,7 @@ syntax keyword clojureCommentTodo contained FIXME XXX TODO FIXME: XXX: TODO:
121122
syntax match clojureComment ";.*$" contains=clojureCommentTodo,@Spell
122123
syntax match clojureComment "#!.*$"
123124

125+
" -*- TOP CLUSTER -*-
124126
" Generated from https://github.com/guns/vim-clojure-static/blob/%%RELEASE_TAG%%/clj/src/vim_clojure_static/generate.clj
125127
syntax cluster clojureTop contains=@Spell,clojureAnonArg,clojureBoolean,clojureCharacter,clojureComment,clojureCond,clojureConstant,clojureDefine,clojureDeref,clojureDispatch,clojureError,clojureException,clojureFunc,clojureKeyword,clojureMacro,clojureMap,clojureMeta,clojureNumber,clojureQuote,clojureRegexp,clojureRepeat,clojureSexp,clojureSpecial,clojureString,clojureSymbol,clojureUnquote,clojureVarArg,clojureVariable,clojureVector
126128

0 commit comments

Comments
 (0)