here's a demo of emacs-tree-sitter highlighting part of clojure.core
here is the corresponding highlights.scm: https://gist.github.com/sogaiu/a2a51cd58e5276a4676f3195897bf7c9
highlights.scm has definitions for highlighting the following:
* keywords
* strings
* numbers
* booleans and nil
* comments
* discard expressions
* the ^
for metadata
* dynamic variables (ear-muffed things)
* symbols starting with &
(like &form
, &env
, &
)
* gensym-ish things (symbols ending with #
)
* some macro calls (just the head)
* some built-in function calls (just the head)
* other function calls (just the head)
* some interop-ish things (i.e. symbol in head position that starts with .
)
* symbols that contain dots (e.g. clojure.lang.Numbers
)
* things that are quoted or syntax quoted may have their highlighting affected
Sweet!
I don’t see discards in the gist, though you mention them here. What gives?
thanks for taking a look! yes, you are right that there are no discards in the image. such sharp eyes! sorry about that. i think the image may be missing gensym stuff and possibly other stuff too. i'll make a few more images 🙂
this is what discard expressions look like if you give them the highest priority (i.e. you put a rule for it at the top of the highlights.scm file)
i don't really find that to my taste, so i tend to go for the following sort of arrangement
here discard expressions have a lower priority
the following demos gensym-ish symbol highlighting along with syntax-quoted forms having somewhat different coloring
in the very first image, if you look closely, you may be able to see that there is actually a difference between macro calls (boldish pinkish) and "built-in" functions (e.g. cast
is not bold and is sort of redish)
i think the bold light blue in the first image is roughly non-built-in calls -- where "non-built-in" basically means highlights.scm hasn't been taught about such symbols. the point is to be able to distinguish between: * macro / special form calls (only the known ones) * built-in function calls (only the known ones) * other calls
Nice!
I wasn’t referring to the image really. It was the gist. But I only read it very quickly. (Super happy with having some images to look at for more examples, though).
oh my bad.
here is the line in the gist regarding discard expressions: https://gist.github.com/sogaiu/a2a51cd58e5276a4676f3195897bf7c9#file-highlights-scm-L11
i made an attempt at getting things to work with nvim-treesitter: https://github.com/sogaiu/nvim-treesitter/tree/clojure
@aleh_atsman it's a bit rough, but how does this look?