Fork me on GitHub
#tree-sitter
<
2023-10-31
lilactown18:10:20

in emacs, I have the following config:

(use-package tree-sitter
  :config
  ;; activate tree-sitter on any buffer containing code for which it has a parser available
  (global-tree-sitter-mode)
  ;; you can easily see the difference tree-sitter-hl-mode makes for python, ts or tsx
  ;; by switching on and off
  (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
this ends up overriding clojure-mode buffers to look almost unhighlighted. Turning off tree-sitter-hl-mode in the buffer uses the default font-lock settings, which look great. So three questions: 1. Is there a way I can get the tree-sitter-hl-mode highlighting to look good? 2. How should I disable that mode in Clojure buffers, if I can't make it look good? 3. I'm guessing that clojure-ts-mode handles more things like indentation, code navigation? anything else?

lilactown18:10:10

for (2) I found https://shivjm.blog/tree-sitter-hl-mode-lsp-modes-semantic-highlighting-and-rust-analyzer/ which had this snippet:

(setf tree-sitter-major-mode-language-alist
        (cl-remove 'rustic-mode tree-sitter-major-mode-language-alist :key #'car))
which I adapted for clojure-mode:
(use-package tree-sitter
  :config
  ;; activate tree-sitter on any buffer containing code for which it has a parser available
  (global-tree-sitter-mode)
  (setf tree-sitter-major-mode-language-alist
        (cl-remove 'clojure-mode
                   tree-sitter-major-mode-language-alist :key #'car))
  ;; you can easily see the difference tree-sitter-hl-mode makes for python, ts or tsx
  ;; by switching on and off
  (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))

lispers-anonymous22:11:06

> I'm guessing that clojure-ts-mode handles more things like indentation, code navigation? anything else? fwiw, clojure-ts-mode is not related to tree-sitter mode in any way. tree-sitter is a package that was written before the emacs builtin treesit package. clojure-ts-mode uses the builtin. If you want to try it then you don't need to setup tree-sitter at all. Just clojure-ts-mode

lispers-anonymous22:11:34

And clojure-ts-mode handles syntax highlighting and indentation. It does not handle code navigation. That is better left to eglot/lsp-mode/cider