From ce8cbcd6828e3e806ca4e12972d26f5f61f5e654 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Fri, 17 Oct 2025 06:25:27 +0300 Subject: emacs: Move treesit configuration to a new file, fix the versions --- emacs/.config/emacs/arkta/arkta-treesit.el | 93 ++++++++++++++++++++++++++++++ emacs/.config/emacs/init.el | 33 +---------- 2 files changed, 94 insertions(+), 32 deletions(-) create mode 100644 emacs/.config/emacs/arkta/arkta-treesit.el 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 @@ +;; -*- lexical-binding: t -*- +;; Copyright © 2018-2025 Uko Koknevics + +(use-package treesit + :straight '(treesit :type built-in) + :config + (defvar *arkta/treesit-current* nil) + + (defun arkta/treesit-current-file () + (expand-file-name "treesit/current.el" local-config-dir)) + + (defun arkta/treesit-init-current () + (let ((file (arkta/treesit-current-file))) + (when (file-exists-p file) + (let ((current (with-temp-buffer + (insert-file-contents-literally file) + (read (current-buffer))))) + (unless (listp current) + (error "Malformed treesit current status: not a list")) + (mapc (lambda (spec) + (unless (consp spec) + (error "Malformed treesit current status: not an alist")) + (unless (symbolp (car spec)) + (error "Malformed treesit current status: not a symbol-indexed alist"))) + current) + (setq *arkta/treesit-current* current) + current)))) + + (defun arkta/treesit-save-current () + (let ((file (arkta/treesit-current-file))) + (make-directory (file-name-directory file) 'parents) + (with-temp-file file + (print *arkta/treesit-current* (current-buffer))))) + + (defun arkta/treesit-current () + (or *arkta/treesit-current* + (arkta/treesit-init-current))) + + (defun arkta/treesit-append-current (spec) + (let ((current (arkta/treesit-current))) + (assq-delete-all (car spec) current) + (setq *arkta/treesit-current* (cons spec current)) + (arkta/treesit-save-current))) + + (defun arkta/$after-treesit-install-language-grammar (lang &optional out-dir) + (declare (ignore out-dir)) + (let ((spec (assq lang treesit-language-source-alist))) + (arkta/treesit-append-current spec))) + (advice-add 'treesit-install-language-grammar :after #'arkta/$after-treesit-install-language-grammar) + + (defun arkta/treesit-newest-p (spec) + (when-let* ((current-treesits (arkta/treesit-current)) + (current-this (assq (car spec) current-treesits))) + (equal current-this spec))) + + (defun arkta/treesit-ensure-language (spec) + (let ((name (car spec))) + (unless (and (treesit-language-available-p name) + (arkta/treesit-newest-p spec)) + (message "Treesit: Ensuring %s...\n" (car spec)) + (treesit-install-language-grammar name)))) + + (defun arkta/treesit-ensure-languages () + (mapc #'arkta/treesit-ensure-language treesit-language-source-alist)) + + (setq treesit-extra-load-path + (list (expand-file-name "tree-sitter" local-config-dir))) + + (setq treesit-language-source-alist + '((c "https://github.com/tree-sitter/tree-sitter-c.git" "v0.24.1") + (cmake "https://github.com/uyha/tree-sitter-cmake.git" "v0.7.1") + (cpp "https://github.com/tree-sitter/tree-sitter-cpp.git" "v0.23.4") + (c-sharp "https://github.com/tree-sitter/tree-sitter-c-sharp.git" "v0.23.1") + (css "https://github.com/tree-sitter/tree-sitter-css.git" "v0.25.0") + (dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile.git" "v0.2.0") + (go "https://github.com/tree-sitter/tree-sitter-go.git" "v0.25.0") + (gomod "https://github.com/camdencheek/tree-sitter-go-mod.git" "v1.1.0") + (java "https://github.com/tree-sitter/tree-sitter-java.git" "v0.23.5") + (javascript "https://github.com/tree-sitter/tree-sitter-javascript.git" "v0.25.0") + (json "https://github.com/tree-sitter/tree-sitter-json.git" "v0.24.8") + (kotlin "https://github.com/fwcd/tree-sitter-kotlin.git" "0.3.8") + (python "https://github.com/tree-sitter/tree-sitter-python.git" "v0.25.0") + (ruby "https://github.com/tree-sitter/tree-sitter-ruby.git" "v0.23.1") + (rust "https://github.com/tree-sitter/tree-sitter-rust.git" "v0.24.0") + (toml "https://github.com/ikatyang/tree-sitter-toml.git" "v0.5.1") + (tsx "https://github.com/tree-sitter/tree-sitter-typescript.git" "v0.23.2" "tsx/src") + (typescript "https://github.com/tree-sitter/tree-sitter-typescript.git" "v0.23.2" "typescript/src") + (typst "https://github.com/uben0/tree-sitter-typst.git" "v0.11.0") + (yaml "https://github.com/ikatyang/tree-sitter-yaml.git" "v0.5.0"))) + + (arkta/treesit-ensure-languages)) + +(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 @@ (require 'arkta-cosmetic) (require 'arkta-progmodes) (require 'arkta-project) +(require 'arkta-treesit) (use-package ace-window :straight t @@ -407,35 +408,3 @@ (treemacs-select-when-already-in-treemacs 'next-or-back) :bind (("C-c SPC" . treemacs-select-window) ("C-c C-SPC" . treemacs-select-window))) - -(use-package treesit - :straight '(treesit :type built-in) - :config - (setq treesit-extra-load-path - (list (expand-file-name "tree-sitter" local-config-dir))) - (setq treesit-language-source-alist - '((c "https://github.com/tree-sitter/tree-sitter-c.git") - (cmake "https://github.com/uyha/tree-sitter-cmake.git") - (cpp "https://github.com/tree-sitter/tree-sitter-cpp.git") - (c-sharp "https://github.com/tree-sitter/tree-sitter-c-sharp.git") - (css "https://github.com/tree-sitter/tree-sitter-css.git") - (dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile.git") - (go "https://github.com/tree-sitter/tree-sitter-go.git") - (gomod "https://github.com/camdencheek/tree-sitter-go-mod.git") - (java "https://github.com/tree-sitter/tree-sitter-java.git") - (javascript "https://github.com/tree-sitter/tree-sitter-javascript.git") - (json "https://github.com/tree-sitter/tree-sitter-json.git") - (kotlin "https://github.com/fwcd/tree-sitter-kotlin") - (python "https://github.com/tree-sitter/tree-sitter-python.git") - (ruby "https://github.com/tree-sitter/tree-sitter-ruby.git") - (rust "https://github.com/tree-sitter/tree-sitter-rust.git") - (toml "https://github.com/ikatyang/tree-sitter-toml.git") - (tsx "https://github.com/tree-sitter/tree-sitter-typescript.git" nil "tsx/src") - (typescript "https://github.com/tree-sitter/tree-sitter-typescript.git" nil "typescript/src") - (typst "https://github.com/uben0/tree-sitter-typst") - (yaml "https://github.com/ikatyang/tree-sitter-yaml.git"))) - (mapc (lambda (spec) - (let ((name (car spec))) - (unless (treesit-language-available-p name) - (treesit-install-language-grammar name)))) - treesit-language-source-alist)) -- cgit v1.2.3