emacs-tree-sitter / elisp-tree-sitter

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

Use tree-sitter only for types and fallback to emacs for the rest #148

Closed pushqrdx closed 3 years ago

pushqrdx commented 3 years ago

I only want tree-sitter to highlight c++ types, all the rest should be highlighted using emacs font-lock, i tried something like this but it everything other than types lose highlights (white/default)

 (add-function :before-while tree-sitter-hl-face-mapping-function
    (lambda (face)
        (unless (not (string= face "type")) face)))
shackra commented 3 years ago

IIRC emacs-tree-sitter de-activates font-lock on purpose and takes care of the highlighting. What's your reasoning for wanting to keep font-lock and emacs-tree-sitter co-existing?

pushqrdx commented 3 years ago

@shackra having the best of both worlds, for instance tree-sitter screws up c++ macros (no highlighting at all), also there are some issues with operator overloads, namespace highlighting, but on of the solid things that tree-sitter does is highlighting types so i wanted to augment emac's font-lock with tree-sitter

ubolonton commented 3 years ago

If you want to use the coloring provided by font-lock-keywords, you need to set tree-sitter-hl-use-font-lock-keywords as well, like this:

(add-hook 'c++-mode-hook
  (lambda ()
    (setq-local tree-sitter-hl-use-font-lock-keywords t)
    (add-function :before-while (local 'tree-sitter-hl-face-mapping-function)
                  (lambda (capture-name)
                    (string= capture-name "type")))))