Hello everyone,
On browsing the source of TimL¹, I noticed that Tim Pope's syntax file
dynamically generated its core syntax matches from buffer variables in
order to quickly highlight local vars after evaluation.
This is such an awesome and obvious way of highlighting keywords that
I've changed vim-clojure-static to do the same. The README² has the
details, but here is a quick summary:
g:clojure_syntax_keywords
b:clojure_syntax_keywords
A dictionary of syntax-group to a list of symbol names. Symbols
listed here will be added to a syntax group when the syntax for
the file is reloaded.
The global version can contain symbols you always want
highlighted:
e.g.
let g:clojure_syntax_keywords = {
\ 'clojureMacro': ['defproject']
\ }
b:clojure_syntax_without_core_keywords
This is a boolean flag that causes the syntax script to skip
highlighting vars from clojure.core. Special forms and constants
remain highlighted.
The primary motivation behind these variables is to give plugins more
control over the syntax highlighting of a buffer. In particular:
a. Highlighting ClojureScript and other Clojure derivatives can now
be done (mostly) without forking the syntax script.
b. Namespaces that use :refer-clojure to create DSLs that clash
with clojure.core can be accurately highlighted. core.matrix,
core.logic, and David Greenberg's piplin come to mind.
The latter point is now a feature of vim-clojure-highlight³, so if
you have ever felt bothered by extraneous highlighting of vars you
specifically excluded, give it a try!
Unfortunately, there is no easy way to hook into Fireplace's eval
to change the highlighting after eval like in TimL. There are two
solutions:
1. Send a patch to fireplace.vim that adds a custom EvalPost event
that we can hook into.
2. Define your own mappings with :ClojureHighlightReferences. For
instance, if you use `cpr` to re-evaluate a buffer:
augroup my_clojure_autocmds
autocmd!
autocmd FileType clojure
\ nnoremap <silent><buffer> cpr :Require \| ClojureHighlightReferences<CR>
augroup END
Thanks to everyone who's contributed to vim-clojure-static¹, and thanks
to Tim Pope for providing the inspiration for these changes.
Happy hacking,
guns
¹
https://github.com/tpope/timl
²
https://github.com/guns/vim-clojure-static#syntax-options
³
https://github.com/guns/vim-clojure-highlight
⁴ There have been a steady stream of improvements over the past year:
https://github.com/guns/vim-clojure-static/issues?state=closed