;; -*- lexical-binding: t; -*- (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) ("\\.php\\'" . php-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.20.0")) (php "https://github.com/tree-sitter/tree-sitter-php" "v0.23.12" "php/src") (bash "https://github.com/tree-sitter/tree-sitter-bash") (html . ("https://github.com/tree-sitter/tree-sitter-html" "v0.20.1")) (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.21.2" "src")) (json . ("https://github.com/tree-sitter/tree-sitter-json" "v0.20.2")) (python . ("https://github.com/tree-sitter/tree-sitter-python" "v0.20.4")) ;; (go "https://github.com/tree-sitter/tree-sitter-go" "v0.20.0") (markdown "https://github.com/ikatyang/tree-sitter-markdown") (make "https://github.com/alemuller/tree-sitter-make") (elisp "https://github.com/Wilfred/tree-sitter-elisp") (cmake "https://github.com/uyha/tree-sitter-cmake") (c "https://github.com/tree-sitter/tree-sitter-c") (cpp "https://github.com/tree-sitter/tree-sitter-cpp") ;; (toml "https://github.com/tree-sitter/tree-sitter-toml") (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "tsx/src")) (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "typescript/src")) (yaml . ("https://github.com/ikatyang/tree-sitter-yaml" "v0.5.0")) ;; (prisma "https://github.com/victorhqc/tree-sitter-prisma") )) (add-to-list 'treesit-language-source-alist grammar) ;; Only install `grammar' if we don't already have it ;; installed. However, if you want to *update* a grammar then ;; this obviously prevents that from happening. (unless (treesit-language-available-p (car grammar)) (treesit-install-language-grammar (car grammar))))) ;; Optional, but recommended. Tree-sitter enabled major modes are ;; distinct from their ordinary counterparts. ;; ;; You can remap major modes with `major-mode-remap-alist'. Note ;; that this does *not* extend to hooks! Make sure you migrate them ;; also (dolist (mapping '((python-mode . python-ts-mode) (css-mode . css-ts-mode) (typescript-mode . typescript-ts-mode) (js-mode . typescript-ts-mode) (js2-mode . typescript-ts-mode) (c-mode . c-ts-mode) (c++-mode . c++-ts-mode) (c-or-c++-mode . c-or-c++-ts-mode) (bash-mode . bash-ts-mode) (css-mode . css-ts-mode) (json-mode . json-ts-mode) (js-json-mode . json-ts-mode) (sh-mode . bash-ts-mode) (sh-base-mode . bash-ts-mode) (php-mode . php-ts-mode) )) (add-to-list 'major-mode-remap-alist mapping)) :config (os/setup-install-grammars))