1
0
Fork 0

feat(emacs): use tree sitter for web languages

This commit is contained in:
Lucas Sta Maria 2025-02-11 22:24:38 -05:00
parent 096ec810e4
commit 1877195d40
No known key found for this signature in database
GPG key ID: F07FB16A826E3B47

View file

@ -113,6 +113,43 @@
(use-package cdlatex :straight t)
(use-package yaml-mode :straight t)
;; From https://www.ovistoica.com/blog/2024-7-05-modern-emacs-typescript-web-tsx-config
(use-package treesit
:mode (("\\.tsx\\'" . tsx-ts-mode)
("\\.js\\'" . typescript-ts-mode)
("\\.mjs\\'" . typescript-ts-mode)
("\\.mts\\'" . typescript-ts-mode)
("\\.cjs\\'" . typescript-ts-mode)
("\\.ts\\'" . typescript-ts-mode)
("\\.jsx\\'" . tsx-ts-mode)
("\\.json\\'" . json-ts-mode))
:preface
(defun os/setup-install-grammars ()
"Install Tree-sitter grammars if they are absent."
(interactive)
(dolist (grammar
'((css . ("https://github.com/tree-sitter/tree-sitter-css" "v0.23.2"))
(html . ("https://github.com/tree-sitter/tree-sitter-html" "v0.23.2"))
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.1" "src"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.23.2" "tsx/src"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.23.2" "typescript/src"))))
(add-to-list 'treesit-language-source-alist grammar)
(unless (treesit-language-available-p (car grammar))
(treesit-install-language-grammar (car grammar)))))
(dolist (mapping
'(
(css-mode . css-ts-mode)
(typescript-mode . typescript-ts-mode)
(js-mode . typescript-ts-mode)
(js2-mode . typescript-ts-mode)
(css-mode . css-ts-mode)
(json-mode . json-ts-mode)
(js-json-mode . json-ts-mode)))
(add-to-list 'major-mode-remap-alist mapping))
:config
(os/setup-install-grammars))
(provide 'priime-languages)
;;; priime-languages.el ends here