diff options
author | Sam Light <samlight1994@gmail.com> | 2025-05-18 00:57:23 +0100 |
---|---|---|
committer | Sam Light <samlight1994@gmail.com> | 2025-05-18 00:57:23 +0100 |
commit | 4a9ae23c86324b2ccd4eb6b9f8e7a5538f2943cc (patch) | |
tree | d75e48dd1fd7221f030eafeecb86aef1294307be /config/tree-sitter.el | |
parent | 14ecb1716764cb0580af6eb7ea6dde08169e565a (diff) |
Treesitter config
Diffstat (limited to 'config/tree-sitter.el')
-rw-r--r-- | config/tree-sitter.el | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/config/tree-sitter.el b/config/tree-sitter.el new file mode 100644 index 0000000..0e95c81 --- /dev/null +++ b/config/tree-sitter.el @@ -0,0 +1,75 @@ +;; -*- 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)) |