Skip to content

Instantly share code, notes, and snippets.

@ananthakumaran
Last active October 14, 2021 00:01
Show Gist options
  • Select an option

  • Save ananthakumaran/ed91ef5a7bbf679cdf13e8a65ea54abe to your computer and use it in GitHub Desktop.

Select an option

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)
@jsmestad
Copy link
Copy Markdown

I'd love to help test this out, but I am using doom. Given Doom has very specific loading requirements, would it be possible to make a version that works for doom? 🤞

@ananthakumaran
Copy link
Copy Markdown
Author

I'd love to help test this out, but I am using doom. Given Doom has very specific loading requirements, would it be possible to make a version that works for doom? 🤞

I don't personally use doom, but if you can get tree-sitter working for any language, then adding support for elixir should be straightforward.

@dsdshcym
Copy link
Copy Markdown

@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
Copy Markdown

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