Skip to content

Instantly share code, notes, and snippets.

@tpope
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpope/9927381 to your computer and use it in GitHub Desktop.
Save tpope/9927381 to your computer and use it in GitHub Desktop.
Autocmd DSL
(def ^:private autocmds (dict))
(defmacro augroup [name & body]
`(try
(execute "augroup" ~(str name))
(execute "autocmd!")
~@body
(finally (execute "augroup END"))))
(defmacro autocmd [type pattern & body]
(let [sym (gensym "autocmd")]
`(do
(set! (. autocmds ~sym) (fn ~'[<amatch> <afile> <abuf>] ~@body))
(execute
"autocmd"
~(str type)
~pattern
(str "call timl#call(g:user.autocmds." '~sym ", [expand('<amatch>'), expand('<afile>'), expand('<abuf>')])")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment