emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
816 stars 73 forks source link

More specific faces for a fine grained control in themes #217

Open pkryger opened 2 years ago

pkryger commented 2 years ago

I've asked @protesilaos to add tree-sitter support to his modus-themes. In the discussion below, he mentioned that:

My intent was to reduce the overall colouration produced by the default tree-sitter faces. These tweaks give us good results, though there still are some cases where tree-sitter exaggerates the styles it uses, such as by combining types with constants to produce ad-hoc (anonymous) faces. We cannot do anything about anonymous faces at the theme level. As such, we may get an extra bold weight[1] when we would rather not have it and/or a different colour than the one desired. [...] What we want is for each construct to get its own face. If some combined result is desired, and if the existing faces are not suitable, then new faces need to be defined.

Please see more in a discussion in the GitLab issue.

Please note, that I'm by any means expert on theming nor AST parsing. Is that something that could be addressed? Or perhaps a different approach should be considered?

protesilaos commented 2 years ago

Hello there!

Please note, that I'm by any means expert on theming nor AST parsing. Is that something that could be addressed? Or perhaps a different approach should be considered?

I am not familiar with the inner workings of tree-sitter. So please consider the following a general remark on using Emacs faces.

Basically, when we have a construct that gets its attributes with something like :inherit (face-1 face-2) we get an implicit face-1+2 which the user/theme cannot customise. Sometimes this is okay, though it generally is better to avoid that practice: either not blend faces or define a face-3 and use it instead.

While using tree-sitter, I encountered this issue in a few scenaria, such as a type+constant combination. I can share specific snippets if you need them.