From c8e5be731abd55e2696d8bf79daf28f5c6dd5654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Schwarz=C3=A4ugl?= Date: Tue, 31 Dec 2024 13:40:25 +0100 Subject: [PATCH] feat: improve treesitter --- SwarselSystems.org | 78 ++++++++++++++++++++++++++---------------- programs/emacs/init.el | 72 ++++++++++++++++++++++---------------- 2 files changed, 90 insertions(+), 60 deletions(-) diff --git a/SwarselSystems.org b/SwarselSystems.org index c2839fb..e4470a3 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -12298,6 +12298,19 @@ This minor-mode adds functionality for doing better surround-commands; for examp :config (evil-visual-mark-mode)) #+end_src +**** evil-textobj-tree-sitter + +#+begin_src emacs-lisp + + (use-package evil-textobj-tree-sitter) + ;; bind `function.outer`(entire function block) to `f` for use in things like `vaf`, `yaf` + (define-key evil-outer-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.outer")) + ;; bind `function.inner`(function block without name and args) to `f` for use in things like `vif`, `yif` + (define-key evil-inner-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.inner")) + + ;; You can also bind multiple items and we will match the first one we can find + (define-key evil-outer-text-objects-map "a" (evil-textobj-tree-sitter-get-textobj ("conditional.outer" "loop.outer"))) +#+end_src *** ispell :PROPERTIES: :CUSTOM_ID: h:e888d7a7-1755-4109-af11-5358b8cf140e @@ -13343,43 +13356,48 @@ In order to update the language grammars, run the next command below. #+begin_src emacs-lisp - (use-package emacs - :ensure nil - :init - (setq treesit-language-source-alist - '((bash . ("https://github.com/tree-sitter/tree-sitter-bash")) - (c . ("https://github.com/tree-sitter/tree-sitter-c")) - (cmake . ("https://github.com/uyha/tree-sitter-cmake")) - (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp")) - (css . ("https://github.com/tree-sitter/tree-sitter-css")) - (elisp . ("https://github.com/Wilfred/tree-sitter-elisp")) - (go . ("https://github.com/tree-sitter/tree-sitter-go")) - (html . ("https://github.com/tree-sitter/tree-sitter-html")) - (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript")) - (json . ("https://github.com/tree-sitter/tree-sitter-json")) - (julia . ("https://github.com/tree-sitter/tree-sitter-julia")) - (latex . ("https://github.com/latex-lsp/tree-sitter-latex")) - (make . ("https://github.com/alemuller/tree-sitter-make")) - (markdown . ("https://github.com/ikatyang/tree-sitter-markdown")) - (nix . ("https://github.com/nix-community/tree-sitter-nix")) - (R . ("https://github.com/r-lib/tree-sitter-r")) - (python . ("https://github.com/tree-sitter/tree-sitter-python")) - (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript")) - (rust . ("https://github.com/tree-sitter/tree-sitter-rust")) - (sql . ("https://github.com/m-novikov/tree-sitter-sql")) - (toml . ("https://github.com/tree-sitter/tree-sitter-toml")) - (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")) - (yaml . ("https://github.com/ikatyang/tree-sitter-yaml")))) - ) + ;; (use-package emacs + ;; :ensure nil + ;; :init + ;; (setq treesit-language-source-alist + ;; '((bash . ("https://github.com/tree-sitter/tree-sitter-bash")) + ;; (c . ("https://github.com/tree-sitter/tree-sitter-c")) + ;; (cmake . ("https://github.com/uyha/tree-sitter-cmake")) + ;; (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp")) + ;; (css . ("https://github.com/tree-sitter/tree-sitter-css")) + ;; (elisp . ("https://github.com/Wilfred/tree-sitter-elisp")) + ;; (go . ("https://github.com/tree-sitter/tree-sitter-go")) + ;; (html . ("https://github.com/tree-sitter/tree-sitter-html")) + ;; (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript")) + ;; (json . ("https://github.com/tree-sitter/tree-sitter-json")) + ;; (julia . ("https://github.com/tree-sitter/tree-sitter-julia")) + ;; (latex . ("https://github.com/latex-lsp/tree-sitter-latex")) + ;; (make . ("https://github.com/alemuller/tree-sitter-make")) + ;; (markdown . ("https://github.com/ikatyang/tree-sitter-markdown")) + ;; (nix . ("https://github.com/nix-community/tree-sitter-nix")) + ;; (R . ("https://github.com/r-lib/tree-sitter-r")) + ;; (python . ("https://github.com/tree-sitter/tree-sitter-python")) + ;; (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript")) + ;; (rust . ("https://github.com/tree-sitter/tree-sitter-rust")) + ;; (sql . ("https://github.com/m-novikov/tree-sitter-sql")) + ;; (toml . ("https://github.com/tree-sitter/tree-sitter-toml")) + ;; (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")) + ;; (yaml . ("https://github.com/ikatyang/tree-sitter-yaml")))) + ;; ) (use-package treesit-auto + :custom + (setq treesit-auto-install t) :config - (global-treesit-auto-mode) - (setq treesit-auto-install 'prompt)) + (treesit-auto-add-to-auto-mode-alist 'all) + (global-treesit-auto-mode)) #+end_src +#+RESULTS: +: t + *** direnv (envrc) :PROPERTIES: :CUSTOM_ID: h:82ddeef2-99f8-465b-ba36-07c3eaad717b diff --git a/programs/emacs/init.el b/programs/emacs/init.el index 41f6e76..951ea76 100644 --- a/programs/emacs/init.el +++ b/programs/emacs/init.el @@ -590,6 +590,15 @@ create a new one." (use-package evil-visual-mark-mode :config (evil-visual-mark-mode)) +(use-package evil-textobj-tree-sitter) +;; bind `function.outer`(entire function block) to `f` for use in things like `vaf`, `yaf` +(define-key evil-outer-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.outer")) +;; bind `function.inner`(function block without name and args) to `f` for use in things like `vif`, `yif` +(define-key evil-inner-text-objects-map "f" (evil-textobj-tree-sitter-get-textobj "function.inner")) + +;; You can also bind multiple items and we will match the first one we can find +(define-key evil-outer-text-objects-map "a" (evil-textobj-tree-sitter-get-textobj ("conditional.outer" "loop.outer"))) + ;; set the NixOS wordlist by hand (setq ispell-alternate-dictionary (getenv "WORDLIST")) @@ -1118,39 +1127,42 @@ create a new one." (use-package rg) -(use-package emacs - :ensure nil - :init - (setq treesit-language-source-alist - '((bash . ("https://github.com/tree-sitter/tree-sitter-bash")) - (c . ("https://github.com/tree-sitter/tree-sitter-c")) - (cmake . ("https://github.com/uyha/tree-sitter-cmake")) - (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp")) - (css . ("https://github.com/tree-sitter/tree-sitter-css")) - (elisp . ("https://github.com/Wilfred/tree-sitter-elisp")) - (go . ("https://github.com/tree-sitter/tree-sitter-go")) - (html . ("https://github.com/tree-sitter/tree-sitter-html")) - (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript")) - (json . ("https://github.com/tree-sitter/tree-sitter-json")) - (julia . ("https://github.com/tree-sitter/tree-sitter-julia")) - (latex . ("https://github.com/latex-lsp/tree-sitter-latex")) - (make . ("https://github.com/alemuller/tree-sitter-make")) - (markdown . ("https://github.com/ikatyang/tree-sitter-markdown")) - (nix . ("https://github.com/nix-community/tree-sitter-nix")) - (R . ("https://github.com/r-lib/tree-sitter-r")) - (python . ("https://github.com/tree-sitter/tree-sitter-python")) - (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript")) - (rust . ("https://github.com/tree-sitter/tree-sitter-rust")) - (sql . ("https://github.com/m-novikov/tree-sitter-sql")) - (toml . ("https://github.com/tree-sitter/tree-sitter-toml")) - (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")) - (yaml . ("https://github.com/ikatyang/tree-sitter-yaml")))) - ) +;; (use-package emacs +;; :ensure nil +;; :init +;; (setq treesit-language-source-alist +;; '((bash . ("https://github.com/tree-sitter/tree-sitter-bash")) +;; (c . ("https://github.com/tree-sitter/tree-sitter-c")) +;; (cmake . ("https://github.com/uyha/tree-sitter-cmake")) +;; (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp")) +;; (css . ("https://github.com/tree-sitter/tree-sitter-css")) +;; (elisp . ("https://github.com/Wilfred/tree-sitter-elisp")) +;; (go . ("https://github.com/tree-sitter/tree-sitter-go")) +;; (html . ("https://github.com/tree-sitter/tree-sitter-html")) +;; (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript")) +;; (json . ("https://github.com/tree-sitter/tree-sitter-json")) +;; (julia . ("https://github.com/tree-sitter/tree-sitter-julia")) +;; (latex . ("https://github.com/latex-lsp/tree-sitter-latex")) +;; (make . ("https://github.com/alemuller/tree-sitter-make")) +;; (markdown . ("https://github.com/ikatyang/tree-sitter-markdown")) +;; (nix . ("https://github.com/nix-community/tree-sitter-nix")) +;; (R . ("https://github.com/r-lib/tree-sitter-r")) +;; (python . ("https://github.com/tree-sitter/tree-sitter-python")) +;; (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript")) +;; (rust . ("https://github.com/tree-sitter/tree-sitter-rust")) +;; (sql . ("https://github.com/m-novikov/tree-sitter-sql")) +;; (toml . ("https://github.com/tree-sitter/tree-sitter-toml")) +;; (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")) +;; (yaml . ("https://github.com/ikatyang/tree-sitter-yaml")))) +;; ) (use-package treesit-auto + :custom + (setq treesit-auto-install t) :config - (global-treesit-auto-mode) - (setq treesit-auto-install 'prompt)) + (treesit-auto-add-to-auto-mode-alist 'all) + (global-treesit-auto-mode)) + ;; (use-package direnv ;; :custom (direnv-always-show-summary nil) ;; :config (direnv-mode))