summaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-10-17 06:25:27 +0300
committerGravatar Uko Kokņevičs2025-10-17 06:25:27 +0300
commitce8cbcd6828e3e806ca4e12972d26f5f61f5e654 (patch)
tree37f236f877b41cc46569e0b2fea7faf338d7ff54 /emacs
parentemacs: Move warnings configuration higher up (diff)
downloaddotfiles-ce8cbcd6828e3e806ca4e12972d26f5f61f5e654.tar.gz
dotfiles-ce8cbcd6828e3e806ca4e12972d26f5f61f5e654.tar.xz
dotfiles-ce8cbcd6828e3e806ca4e12972d26f5f61f5e654.zip
emacs: Move treesit configuration to a new file, fix the versions
Diffstat (limited to 'emacs')
-rw-r--r--emacs/.config/emacs/arkta/arkta-treesit.el93
-rw-r--r--emacs/.config/emacs/init.el33
2 files changed, 94 insertions, 32 deletions
diff --git a/emacs/.config/emacs/arkta/arkta-treesit.el b/emacs/.config/emacs/arkta/arkta-treesit.el
new file mode 100644
index 0000000..e6fede7
--- /dev/null
+++ b/emacs/.config/emacs/arkta/arkta-treesit.el
@@ -0,0 +1,93 @@
1;; -*- lexical-binding: t -*-
2;; Copyright © 2018-2025 Uko Koknevics
3
4(use-package treesit
5 :straight '(treesit :type built-in)
6 :config
7 (defvar *arkta/treesit-current* nil)
8
9 (defun arkta/treesit-current-file ()
10 (expand-file-name "treesit/current.el" local-config-dir))
11
12 (defun arkta/treesit-init-current ()
13 (let ((file (arkta/treesit-current-file)))
14 (when (file-exists-p file)
15 (let ((current (with-temp-buffer
16 (insert-file-contents-literally file)
17 (read (current-buffer)))))
18 (unless (listp current)
19 (error "Malformed treesit current status: not a list"))
20 (mapc (lambda (spec)
21 (unless (consp spec)
22 (error "Malformed treesit current status: not an alist"))
23 (unless (symbolp (car spec))
24 (error "Malformed treesit current status: not a symbol-indexed alist")))
25 current)
26 (setq *arkta/treesit-current* current)
27 current))))
28
29 (defun arkta/treesit-save-current ()
30 (let ((file (arkta/treesit-current-file)))
31 (make-directory (file-name-directory file) 'parents)
32 (with-temp-file file
33 (print *arkta/treesit-current* (current-buffer)))))
34
35 (defun arkta/treesit-current ()
36 (or *arkta/treesit-current*
37 (arkta/treesit-init-current)))
38
39 (defun arkta/treesit-append-current (spec)
40 (let ((current (arkta/treesit-current)))
41 (assq-delete-all (car spec) current)
42 (setq *arkta/treesit-current* (cons spec current))
43 (arkta/treesit-save-current)))
44
45 (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)))
48 (arkta/treesit-append-current spec)))
49 (advice-add 'treesit-install-language-grammar :after #'arkta/$after-treesit-install-language-grammar)
50
51 (defun arkta/treesit-newest-p (spec)
52 (when-let* ((current-treesits (arkta/treesit-current))
53 (current-this (assq (car spec) current-treesits)))
54 (equal current-this spec)))
55
56 (defun arkta/treesit-ensure-language (spec)
57 (let ((name (car spec)))
58 (unless (and (treesit-language-available-p name)
59 (arkta/treesit-newest-p spec))
60 (message "Treesit: Ensuring %s...\n" (car spec))
61 (treesit-install-language-grammar name))))
62
63 (defun arkta/treesit-ensure-languages ()
64 (mapc #'arkta/treesit-ensure-language treesit-language-source-alist))
65
66 (setq treesit-extra-load-path
67 (list (expand-file-name "tree-sitter" local-config-dir)))
68
69 (setq treesit-language-source-alist
70 '((c "https://github.com/tree-sitter/tree-sitter-c.git" "v0.24.1")
71 (cmake "https://github.com/uyha/tree-sitter-cmake.git" "v0.7.1")
72 (cpp "https://github.com/tree-sitter/tree-sitter-cpp.git" "v0.23.4")
73 (c-sharp "https://github.com/tree-sitter/tree-sitter-c-sharp.git" "v0.23.1")
74 (css "https://github.com/tree-sitter/tree-sitter-css.git" "v0.25.0")
75 (dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile.git" "v0.2.0")
76 (go "https://github.com/tree-sitter/tree-sitter-go.git" "v0.25.0")
77 (gomod "https://github.com/camdencheek/tree-sitter-go-mod.git" "v1.1.0")
78 (java "https://github.com/tree-sitter/tree-sitter-java.git" "v0.23.5")
79 (javascript "https://github.com/tree-sitter/tree-sitter-javascript.git" "v0.25.0")
80 (json "https://github.com/tree-sitter/tree-sitter-json.git" "v0.24.8")
81 (kotlin "https://github.com/fwcd/tree-sitter-kotlin.git" "0.3.8")
82 (python "https://github.com/tree-sitter/tree-sitter-python.git" "v0.25.0")
83 (ruby "https://github.com/tree-sitter/tree-sitter-ruby.git" "v0.23.1")
84 (rust "https://github.com/tree-sitter/tree-sitter-rust.git" "v0.24.0")
85 (toml "https://github.com/ikatyang/tree-sitter-toml.git" "v0.5.1")
86 (tsx "https://github.com/tree-sitter/tree-sitter-typescript.git" "v0.23.2" "tsx/src")
87 (typescript "https://github.com/tree-sitter/tree-sitter-typescript.git" "v0.23.2" "typescript/src")
88 (typst "https://github.com/uben0/tree-sitter-typst.git" "v0.11.0")
89 (yaml "https://github.com/ikatyang/tree-sitter-yaml.git" "v0.5.0")))
90
91 (arkta/treesit-ensure-languages))
92
93(provide 'arkta-treesit)
diff --git a/emacs/.config/emacs/init.el b/emacs/.config/emacs/init.el
index 0b64c06..70a7d18 100644
--- a/emacs/.config/emacs/init.el
+++ b/emacs/.config/emacs/init.el
@@ -224,6 +224,7 @@
224(require 'arkta-cosmetic) 224(require 'arkta-cosmetic)
225(require 'arkta-progmodes) 225(require 'arkta-progmodes)
226(require 'arkta-project) 226(require 'arkta-project)
227(require 'arkta-treesit)
227 228
228(use-package ace-window 229(use-package ace-window
229 :straight t 230 :straight t
@@ -407,35 +408,3 @@
407 (treemacs-select-when-already-in-treemacs 'next-or-back) 408 (treemacs-select-when-already-in-treemacs 'next-or-back)
408 :bind (("C-c SPC" . treemacs-select-window) 409 :bind (("C-c SPC" . treemacs-select-window)
409 ("C-c C-SPC" . treemacs-select-window))) 410 ("C-c C-SPC" . treemacs-select-window)))
410
411(use-package treesit
412 :straight '(treesit :type built-in)
413 :config
414 (setq treesit-extra-load-path
415 (list (expand-file-name "tree-sitter" local-config-dir)))
416 (setq treesit-language-source-alist
417 '((c "https://github.com/tree-sitter/tree-sitter-c.git")
418 (cmake "https://github.com/uyha/tree-sitter-cmake.git")
419 (cpp "https://github.com/tree-sitter/tree-sitter-cpp.git")
420 (c-sharp "https://github.com/tree-sitter/tree-sitter-c-sharp.git")
421 (css "https://github.com/tree-sitter/tree-sitter-css.git")
422 (dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile.git")
423 (go "https://github.com/tree-sitter/tree-sitter-go.git")
424 (gomod "https://github.com/camdencheek/tree-sitter-go-mod.git")
425 (java "https://github.com/tree-sitter/tree-sitter-java.git")
426 (javascript "https://github.com/tree-sitter/tree-sitter-javascript.git")
427 (json "https://github.com/tree-sitter/tree-sitter-json.git")
428 (kotlin "https://github.com/fwcd/tree-sitter-kotlin")
429 (python "https://github.com/tree-sitter/tree-sitter-python.git")
430 (ruby "https://github.com/tree-sitter/tree-sitter-ruby.git")
431 (rust "https://github.com/tree-sitter/tree-sitter-rust.git")
432 (toml "https://github.com/ikatyang/tree-sitter-toml.git")
433 (tsx "https://github.com/tree-sitter/tree-sitter-typescript.git" nil "tsx/src")
434 (typescript "https://github.com/tree-sitter/tree-sitter-typescript.git" nil "typescript/src")
435 (typst "https://github.com/uben0/tree-sitter-typst")
436 (yaml "https://github.com/ikatyang/tree-sitter-yaml.git")))
437 (mapc (lambda (spec)
438 (let ((name (car spec)))
439 (unless (treesit-language-available-p name)
440 (treesit-install-language-grammar name))))
441 treesit-language-source-alist))