Fork me on GitHub
#tree-sitter
<
2020-10-29
>
sogaiu08:10:19

here's a demo of emacs-tree-sitter highlighting part of clojure.core

sogaiu08:10:55

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

pez08:10:09

I don’t see discards in the gist, though you mention them here. What gives?

sogaiu08:10:44

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 🙂

sogaiu08:10:29

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)

sogaiu08:10:05

i don't really find that to my taste, so i tend to go for the following sort of arrangement

sogaiu08:10:19

here discard expressions have a lower priority

sogaiu08:10:30

the following demos gensym-ish symbol highlighting along with syntax-quoted forms having somewhat different coloring

sogaiu08:10:30

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)

sogaiu08:10:04

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

pez09:10:56

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).

sogaiu09:10:36

oh my bad.

sogaiu14:10:11

i made an attempt at getting things to work with nvim-treesitter: https://github.com/sogaiu/nvim-treesitter/tree/clojure

sogaiu14:10:02

@aleh_atsman it's a bit rough, but how does this look?

aw_yeah 3