diff options
| author | 2025-10-17 08:06:36 +0300 | |
|---|---|---|
| committer | 2025-10-17 08:06:36 +0300 | |
| commit | 87b55c036365e502610e9a0b98518075f3cfae76 (patch) | |
| tree | ffc2f27d7422e0887d386b99601c74a5e27c068c | |
| parent | emacs: Move treesit configuration to a new file, fix the versions (diff) | |
| download | dotfiles-87b55c036365e502610e9a0b98518075f3cfae76.tar.gz dotfiles-87b55c036365e502610e9a0b98518075f3cfae76.tar.xz dotfiles-87b55c036365e502610e9a0b98518075f3cfae76.zip | |
emacs: Improve the treesit config by a lot
| -rw-r--r-- | emacs/.config/emacs/arkta/arkta-progmodes.el | 3 | ||||
| -rw-r--r-- | emacs/.config/emacs/arkta/arkta-treesit.el | 152 |
2 files changed, 132 insertions, 23 deletions
diff --git a/emacs/.config/emacs/arkta/arkta-progmodes.el b/emacs/.config/emacs/arkta/arkta-progmodes.el index 98cf58e..eddc4aa 100644 --- a/emacs/.config/emacs/arkta/arkta-progmodes.el +++ b/emacs/.config/emacs/arkta/arkta-progmodes.el | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | ;; -*- lexical-binding: t -*- | 1 | ;; -*- lexical-binding: t -*- |
| 2 | ;; Copyright © 2018-2025 Uko Koknevics | 2 | ;; Copyright © 2018-2025 Uko Koknevics |
| 3 | 3 | ||
| 4 | (require 'arkta-treesit) | ||
| 5 | |||
| 4 | (use-package adoc-mode | 6 | (use-package adoc-mode |
| 5 | :straight t | 7 | :straight t |
| 6 | :mode "\\.adoc\\'") | 8 | :mode "\\.adoc\\'") |
| @@ -299,6 +301,7 @@ | |||
| 299 | 301 | ||
| 300 | (use-package typst-ts-mode | 302 | (use-package typst-ts-mode |
| 301 | :after treesit | 303 | :after treesit |
| 304 | :when (arkta/treesit-supports 14) | ||
| 302 | :straight t | 305 | :straight t |
| 303 | :mode "\\.typ\\'") | 306 | :mode "\\.typ\\'") |
| 304 | 307 | ||
diff --git a/emacs/.config/emacs/arkta/arkta-treesit.el b/emacs/.config/emacs/arkta/arkta-treesit.el index e6fede7..9375245 100644 --- a/emacs/.config/emacs/arkta/arkta-treesit.el +++ b/emacs/.config/emacs/arkta/arkta-treesit.el | |||
| @@ -4,6 +4,28 @@ | |||
| 4 | (use-package treesit | 4 | (use-package treesit |
| 5 | :straight '(treesit :type built-in) | 5 | :straight '(treesit :type built-in) |
| 6 | :config | 6 | :config |
| 7 | (use-package dash | ||
| 8 | :straight t) | ||
| 9 | |||
| 10 | (defun arkta/treesit-supports-single (wanted-version) | ||
| 11 | (and (>= wanted-version (treesit-library-abi-version t)) | ||
| 12 | (<= wanted-version (treesit-library-abi-version)))) | ||
| 13 | |||
| 14 | (defun arkta/treesit-supports (&rest wanted-versions) | ||
| 15 | (-any? #'arkta/treesit-supports-single wanted-versions)) | ||
| 16 | |||
| 17 | (unless (arkta/treesit-supports 13) | ||
| 18 | (error "Your treesitter library does not support ABI version 13!")) | ||
| 19 | |||
| 20 | (defmacro arkta/treesit-cond (&rest body) | ||
| 21 | (declare (indent 0)) | ||
| 22 | `(cond ,@(cl-loop for (version . clause-body) in body | ||
| 23 | collect (let ((check (if (consp version) | ||
| 24 | `(arkta/treesit-supports ,@version) | ||
| 25 | `(arkta/treesit-supports-single ,version)))) | ||
| 26 | `(,check ,@clause-body))) | ||
| 27 | (t (error "Unsupported treesit version [%s;%s]!!" (treesit-library-abi-version t) (treesit-library-abi-version))))) | ||
| 28 | |||
| 7 | (defvar *arkta/treesit-current* nil) | 29 | (defvar *arkta/treesit-current* nil) |
| 8 | 30 | ||
| 9 | (defun arkta/treesit-current-file () | 31 | (defun arkta/treesit-current-file () |
| @@ -43,7 +65,6 @@ | |||
| 43 | (arkta/treesit-save-current))) | 65 | (arkta/treesit-save-current))) |
| 44 | 66 | ||
| 45 | (defun arkta/$after-treesit-install-language-grammar (lang &optional out-dir) | 67 | (defun arkta/$after-treesit-install-language-grammar (lang &optional out-dir) |
| 46 | (declare (ignore out-dir)) | ||
| 47 | (let ((spec (assq lang treesit-language-source-alist))) | 68 | (let ((spec (assq lang treesit-language-source-alist))) |
| 48 | (arkta/treesit-append-current spec))) | 69 | (arkta/treesit-append-current spec))) |
| 49 | (advice-add 'treesit-install-language-grammar :after #'arkta/$after-treesit-install-language-grammar) | 70 | (advice-add 'treesit-install-language-grammar :after #'arkta/$after-treesit-install-language-grammar) |
| @@ -57,8 +78,9 @@ | |||
| 57 | (let ((name (car spec))) | 78 | (let ((name (car spec))) |
| 58 | (unless (and (treesit-language-available-p name) | 79 | (unless (and (treesit-language-available-p name) |
| 59 | (arkta/treesit-newest-p spec)) | 80 | (arkta/treesit-newest-p spec)) |
| 60 | (message "Treesit: Ensuring %s...\n" (car spec)) | 81 | (message "Treesit: Ensuring %s..." name) |
| 61 | (treesit-install-language-grammar name)))) | 82 | (treesit-install-language-grammar name)) |
| 83 | (message "Treesit: We have %s with ABI version %s" name (treesit-language-abi-version name)))) | ||
| 62 | 84 | ||
| 63 | (defun arkta/treesit-ensure-languages () | 85 | (defun arkta/treesit-ensure-languages () |
| 64 | (mapc #'arkta/treesit-ensure-language treesit-language-source-alist)) | 86 | (mapc #'arkta/treesit-ensure-language treesit-language-source-alist)) |
| @@ -67,26 +89,110 @@ | |||
| 67 | (list (expand-file-name "tree-sitter" local-config-dir))) | 89 | (list (expand-file-name "tree-sitter" local-config-dir))) |
| 68 | 90 | ||
| 69 | (setq treesit-language-source-alist | 91 | (setq treesit-language-source-alist |
| 70 | '((c "https://github.com/tree-sitter/tree-sitter-c.git" "v0.24.1") | 92 | `((c "https://github.com/tree-sitter/tree-sitter-c.git" |
| 71 | (cmake "https://github.com/uyha/tree-sitter-cmake.git" "v0.7.1") | 93 | ,(arkta/treesit-cond |
| 72 | (cpp "https://github.com/tree-sitter/tree-sitter-cpp.git" "v0.23.4") | 94 | (15 "v0.24.1") |
| 73 | (c-sharp "https://github.com/tree-sitter/tree-sitter-c-sharp.git" "v0.23.1") | 95 | (14 "v0.23.6") |
| 74 | (css "https://github.com/tree-sitter/tree-sitter-css.git" "v0.25.0") | 96 | (13 "v0.19.0"))) |
| 75 | (dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile.git" "v0.2.0") | 97 | |
| 76 | (go "https://github.com/tree-sitter/tree-sitter-go.git" "v0.25.0") | 98 | (cmake "https://github.com/uyha/tree-sitter-cmake.git" |
| 77 | (gomod "https://github.com/camdencheek/tree-sitter-go-mod.git" "v1.1.0") | 99 | ,(arkta/treesit-cond |
| 78 | (java "https://github.com/tree-sitter/tree-sitter-java.git" "v0.23.5") | 100 | (14 "v0.7.1") |
| 79 | (javascript "https://github.com/tree-sitter/tree-sitter-javascript.git" "v0.25.0") | 101 | (13 "0.1.0"))) |
| 80 | (json "https://github.com/tree-sitter/tree-sitter-json.git" "v0.24.8") | 102 | |
| 81 | (kotlin "https://github.com/fwcd/tree-sitter-kotlin.git" "0.3.8") | 103 | (cpp "https://github.com/tree-sitter/tree-sitter-cpp.git" |
| 82 | (python "https://github.com/tree-sitter/tree-sitter-python.git" "v0.25.0") | 104 | ,(arkta/treesit-cond |
| 83 | (ruby "https://github.com/tree-sitter/tree-sitter-ruby.git" "v0.23.1") | 105 | (14 "v0.23.4") |
| 84 | (rust "https://github.com/tree-sitter/tree-sitter-rust.git" "v0.24.0") | 106 | (13 "v0.19.0"))) |
| 85 | (toml "https://github.com/ikatyang/tree-sitter-toml.git" "v0.5.1") | 107 | |
| 86 | (tsx "https://github.com/tree-sitter/tree-sitter-typescript.git" "v0.23.2" "tsx/src") | 108 | (c-sharp "https://github.com/tree-sitter/tree-sitter-c-sharp.git" |
| 87 | (typescript "https://github.com/tree-sitter/tree-sitter-typescript.git" "v0.23.2" "typescript/src") | 109 | ,(arkta/treesit-cond |
| 88 | (typst "https://github.com/uben0/tree-sitter-typst.git" "v0.11.0") | 110 | (14 "v0.23.1") |
| 89 | (yaml "https://github.com/ikatyang/tree-sitter-yaml.git" "v0.5.0"))) | 111 | (13 "v0.20.0"))) |
| 112 | |||
| 113 | (css "https://github.com/tree-sitter/tree-sitter-css.git" | ||
| 114 | ,(arkta/treesit-cond | ||
| 115 | (15 "v0.25.0") | ||
| 116 | (14 "v0.23.2") | ||
| 117 | (13 "v0.19.0"))) | ||
| 118 | |||
| 119 | (dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile.git" | ||
| 120 | ,(arkta/treesit-cond | ||
| 121 | (14 "v0.2.0") | ||
| 122 | (13 "v0.1.2"))) | ||
| 123 | |||
| 124 | (go "https://github.com/tree-sitter/tree-sitter-go.git" | ||
| 125 | ,(arkta/treesit-cond | ||
| 126 | (15 "v0.25.0") | ||
| 127 | (14 "v0.23.4") | ||
| 128 | (13 "v0.19.1"))) | ||
| 129 | |||
| 130 | (gomod "https://github.com/camdencheek/tree-sitter-go-mod.git" | ||
| 131 | ,(arkta/treesit-cond | ||
| 132 | (14 "v1.1.0") | ||
| 133 | (13 "v1.0.0"))) | ||
| 134 | |||
| 135 | (java "https://github.com/tree-sitter/tree-sitter-java.git" | ||
| 136 | ,(arkta/treesit-cond | ||
| 137 | (14 "v0.23.5") | ||
| 138 | (13 "v0.19.1"))) | ||
| 139 | |||
| 140 | (javascript "https://github.com/tree-sitter/tree-sitter-javascript.git" | ||
| 141 | ,(arkta/treesit-cond | ||
| 142 | (15 "v0.25.0") | ||
| 143 | (14 "v0.23.1") | ||
| 144 | (13 "v0.19.0"))) | ||
| 145 | |||
| 146 | (json "https://github.com/tree-sitter/tree-sitter-json.git" | ||
| 147 | ,(arkta/treesit-cond | ||
| 148 | (14 "v0.24.8") | ||
| 149 | (13 "v0.19.0"))) | ||
| 150 | |||
| 151 | (kotlin "https://github.com/fwcd/tree-sitter-kotlin.git" | ||
| 152 | ,(arkta/treesit-cond | ||
| 153 | (14 "0.3.8") | ||
| 154 | (13 "0.2.11"))) | ||
| 155 | |||
| 156 | (python "https://github.com/tree-sitter/tree-sitter-python.git" | ||
| 157 | ,(arkta/treesit-cond | ||
| 158 | (15 "v0.25.0") | ||
| 159 | (14 "v0.23.6") | ||
| 160 | (13 "v0.19.0"))) | ||
| 161 | |||
| 162 | (ruby "https://github.com/tree-sitter/tree-sitter-ruby.git" | ||
| 163 | ,(arkta/treesit-cond | ||
| 164 | (14 "v0.23.1") | ||
| 165 | (13 "v0.19.0"))) | ||
| 166 | |||
| 167 | (rust "https://github.com/tree-sitter/tree-sitter-rust.git" | ||
| 168 | ,(arkta/treesit-cond | ||
| 169 | (15 "v0.24.0") | ||
| 170 | (14 "v0.23.3") | ||
| 171 | (13 "v0.19.1"))) | ||
| 172 | |||
| 173 | (toml "https://github.com/ikatyang/tree-sitter-toml.git" | ||
| 174 | ,(arkta/treesit-cond | ||
| 175 | (13 "v0.5.1"))) | ||
| 176 | |||
| 177 | (tsx "https://github.com/tree-sitter/tree-sitter-typescript.git" | ||
| 178 | ,(arkta/treesit-cond | ||
| 179 | (14 "v0.23.2") | ||
| 180 | (13 "v0.19.0")) | ||
| 181 | "tsx/src") | ||
| 182 | (typescript "https://github.com/tree-sitter/tree-sitter-typescript.git" | ||
| 183 | ,(arkta/treesit-cond | ||
| 184 | (14 "v0.23.2") | ||
| 185 | (13 "v0.19.0")) | ||
| 186 | "typescript/src") | ||
| 187 | |||
| 188 | (yaml "https://github.com/ikatyang/tree-sitter-yaml.git" | ||
| 189 | ,(arkta/treesit-cond | ||
| 190 | (13 "v0.5.0"))) | ||
| 191 | |||
| 192 | ,@(when (arkta/treesit-supports 14) | ||
| 193 | `((typst "https://github.com/uben0/tree-sitter-typst.git" | ||
| 194 | ,(arkta/treesit-cond | ||
| 195 | (14 "v0.11.0"))))))) | ||
| 90 | 196 | ||
| 91 | (arkta/treesit-ensure-languages)) | 197 | (arkta/treesit-ensure-languages)) |
| 92 | 198 | ||