feat(emacs): use tree sitter for web languages
This commit is contained in:
parent
096ec810e4
commit
1877195d40
1 changed files with 37 additions and 0 deletions
|
@ -113,6 +113,43 @@
|
||||||
(use-package cdlatex :straight t)
|
(use-package cdlatex :straight t)
|
||||||
(use-package yaml-mode :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)
|
(provide 'priime-languages)
|
||||||
|
|
||||||
;;; priime-languages.el ends here
|
;;; priime-languages.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue