Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax highlighting for c++ removes font-lock-variable-name-face #53

Closed
jstaursky opened this issue Aug 2, 2020 · 6 comments
Closed

Comments

@jstaursky
Copy link

jstaursky commented Aug 2, 2020

currently syntax highlighting in c++ is too much. When everything is highlighted on the page nothing becomes discernible. Currently I need to set tree-sitter-hl-face:variable to inherit from default just to regain some sanity. But then I lose variable name highlighting (during a variables declaration that is). How can I retain some features from the default font lock (such as font-lock-variable-name-face) without turning off tree-sitter?

@ubolonton
Copy link
Collaborator

tree-sitter-hl supports customization, as documented here. Adding this function to the major mode's hook would disable tree-sitter-hl-face:variable, and treat the font-lock-keywords-based highlighting set by the major mode as the fallback for unhighlighted texts:

(lambda ()
  (setq-local tree-sitter-hl-use-font-lock-keywords t)
  (add-function :filter-return (local 'tree-sitter-hl-face-mapping-function)
                (lambda (face)
                  (unless (memq face '(tree-sitter-hl-face:variable))
                    face))))

However, c++-mode's variable highlighting doesn't rely on font-lock-keywords alone, so the above would not work.

When everything is highlighted on the page nothing becomes discernible.

Yeah, this is a general issue with the default highlighting queries included in most grammar repositories, which seem to be geared more towards GitHub's use cases. tree-sitter-langs attempts to provide its own queries that fit Emacs better. For C/C++, they are WIP in the highlight-queries branch.

As a temporary workaround, you can override the C/C++ query files (highlights.scm) in your local installation with the WIP copies from https://github.com/ubolonton/emacs-tree-sitter/tree/highlight-queries/langs/queries.

@jstaursky
Copy link
Author

I see. I tried the suggested WIP and still had no luck :/ to be clear I would like to go from
screenshot-2020-08-04T2020=H1617
to
screenshot-2020-08-04T2020=H1704
I'll try and get around to fixing this eventually and send you a pull request.

@ubolonton
Copy link
Collaborator

Did you copy both c/highlights.scm and cpp/highlights.scm? C++ highlighting uses both.

@jstaursky
Copy link
Author

jstaursky commented Aug 5, 2020

That did the trick! thank you, awesome project btw. Wish I knew rust so I could be helpful.

@jstaursky
Copy link
Author

jstaursky commented Aug 5, 2020

btw your missing >= and <= in your operator highlights
https://github.com/ubolonton/emacs-tree-sitter/blob/327bdec10af9600e3108d1b52d546a65d2e32c9a/langs/queries/c/highlights.scm#L40-L55

might also want to consider adding scope operator ::

@ubolonton
Copy link
Collaborator

That did the trick! thank you, awesome project btw. Wish I knew rust so I could be helpful.

The Rust part is actually more or less done. You can help with the Lisp part as well :)

btw your missing >= and <= in your operator highlights
might also want to consider adding scope operator ::

Yeah, I'll add those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants