Skip to content

Instantly share code, notes, and snippets.

@ananthakumaran
Last active October 14, 2021 00:01
Show Gist options
  • Save ananthakumaran/ed91ef5a7bbf679cdf13e8a65ea54abe to your computer and use it in GitHub Desktop.
Save ananthakumaran/ed91ef5a7bbf679cdf13e8a65ea54abe to your computer and use it in GitHub Desktop.
(defface tree-sitter-hl-face:warning
'((default :inherit font-lock-warning-face))
"Face for parser errors"
:group 'tree-sitter-hl-faces)
(defun hook/tree-sitter-common ()
(unless font-lock-defaults
(setq font-lock-defaults '(nil)))
(setq tree-sitter-hl-use-font-lock-keywords nil)
(tree-sitter-mode +1)
(tree-sitter-hl-mode +1))
(defun hook/elixir-tree-sitter ()
(setq
tree-sitter-hl-default-patterns
(read
(concat
"["
(s-replace "#match?" ".match?"
(f-read-text (expand-file-name "~/work/repos/tree-sitter-elixir/queries/highlights.scm")))
"]")))
(hook/tree-sitter-common))
(use-package tree-sitter
:ensure t
:hook ((elixir-mode . hook/elixir-tree-sitter))
:custom-face
(tree-sitter-hl-face:operator ((t)))
(tree-sitter-hl-face:variable ((t)))
(tree-sitter-hl-face:function.method.call ((t)))
(tree-sitter-hl-face:property ((t)))
:config
(setq tree-sitter-debug-highlight-jump-region t)
(setq tree-sitter-debug-jump-buttons t))
(use-package tree-sitter-langs
:ensure t
:after tree-sitter
:config
(add-to-list 'tree-sitter-major-mode-language-alist '(elixir-mode . elixir)))
(provide 'init-tree-sitter)
@dsdshcym
Copy link

@jsmestad
Here is my tree-sitter config with doom emacs:

(use-package! tree-sitter
  :init
  (defface tree-sitter-hl-face:warning
    '((default :inherit font-lock-warning-face))
    "Face for parser errors"
    :group 'tree-sitter-hl-faces)

  (defun hook/tree-sitter-common ()
    (unless font-lock-defaults
      (setq font-lock-defaults '(nil)))
    (setq tree-sitter-hl-use-font-lock-keywords nil)
    (tree-sitter-mode +1)
    (tree-sitter-hl-mode +1))

  (defun hook/elixir-tree-sitter ()
    (require 'f)
    (require 's)

    (setq tree-sitter-hl-default-patterns
     (read
      (concat
       "["
       (s-replace "#match?" ".match?"
                  (f-read-text (expand-file-name "~/Projects/ananthakumaran/tree-sitter-elixir/queries/highlights.scm")))
       "]")))
    (hook/tree-sitter-common))

  :hook ((elixir-mode . hook/elixir-tree-sitter))
  :custom-face
  (tree-sitter-hl-face:operator ((t)))
  (tree-sitter-hl-face:variable ((t)))
  (tree-sitter-hl-face:function.method.call ((t)))
  (tree-sitter-hl-face:property ((t))))

(use-package! tree-sitter-langs
  :after tree-sitter
  :config
  (add-to-list 'tree-sitter-major-mode-language-alist '(elixir-mode . elixir)))

From my quick testing, everything works well

@jsmestad
Copy link

jsmestad commented Jun 3, 2021

Thanks that worked perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment