feat: improve treesitter

This commit is contained in:
Leon Schwarzäugl 2024-12-31 13:40:25 +01:00
parent 11eb077113
commit c8e5be731a
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
2 changed files with 90 additions and 60 deletions

View file

@ -12298,6 +12298,19 @@ This minor-mode adds functionality for doing better surround-commands; for examp
:config (evil-visual-mark-mode)) :config (evil-visual-mark-mode))
#+end_src #+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 *** ispell
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: h:e888d7a7-1755-4109-af11-5358b8cf140e :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 #+begin_src emacs-lisp
(use-package emacs ;; (use-package emacs
:ensure nil ;; :ensure nil
:init ;; :init
(setq treesit-language-source-alist ;; (setq treesit-language-source-alist
'((bash . ("https://github.com/tree-sitter/tree-sitter-bash")) ;; '((bash . ("https://github.com/tree-sitter/tree-sitter-bash"))
(c . ("https://github.com/tree-sitter/tree-sitter-c")) ;; (c . ("https://github.com/tree-sitter/tree-sitter-c"))
(cmake . ("https://github.com/uyha/tree-sitter-cmake")) ;; (cmake . ("https://github.com/uyha/tree-sitter-cmake"))
(cpp . ("https://github.com/tree-sitter/tree-sitter-cpp")) ;; (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp"))
(css . ("https://github.com/tree-sitter/tree-sitter-css")) ;; (css . ("https://github.com/tree-sitter/tree-sitter-css"))
(elisp . ("https://github.com/Wilfred/tree-sitter-elisp")) ;; (elisp . ("https://github.com/Wilfred/tree-sitter-elisp"))
(go . ("https://github.com/tree-sitter/tree-sitter-go")) ;; (go . ("https://github.com/tree-sitter/tree-sitter-go"))
(html . ("https://github.com/tree-sitter/tree-sitter-html")) ;; (html . ("https://github.com/tree-sitter/tree-sitter-html"))
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript")) ;; (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript"))
(json . ("https://github.com/tree-sitter/tree-sitter-json")) ;; (json . ("https://github.com/tree-sitter/tree-sitter-json"))
(julia . ("https://github.com/tree-sitter/tree-sitter-julia")) ;; (julia . ("https://github.com/tree-sitter/tree-sitter-julia"))
(latex . ("https://github.com/latex-lsp/tree-sitter-latex")) ;; (latex . ("https://github.com/latex-lsp/tree-sitter-latex"))
(make . ("https://github.com/alemuller/tree-sitter-make")) ;; (make . ("https://github.com/alemuller/tree-sitter-make"))
(markdown . ("https://github.com/ikatyang/tree-sitter-markdown")) ;; (markdown . ("https://github.com/ikatyang/tree-sitter-markdown"))
(nix . ("https://github.com/nix-community/tree-sitter-nix")) ;; (nix . ("https://github.com/nix-community/tree-sitter-nix"))
(R . ("https://github.com/r-lib/tree-sitter-r")) ;; (R . ("https://github.com/r-lib/tree-sitter-r"))
(python . ("https://github.com/tree-sitter/tree-sitter-python")) ;; (python . ("https://github.com/tree-sitter/tree-sitter-python"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript")) ;; (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript"))
(rust . ("https://github.com/tree-sitter/tree-sitter-rust")) ;; (rust . ("https://github.com/tree-sitter/tree-sitter-rust"))
(sql . ("https://github.com/m-novikov/tree-sitter-sql")) ;; (sql . ("https://github.com/m-novikov/tree-sitter-sql"))
(toml . ("https://github.com/tree-sitter/tree-sitter-toml")) ;; (toml . ("https://github.com/tree-sitter/tree-sitter-toml"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")) ;; (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src"))
(yaml . ("https://github.com/ikatyang/tree-sitter-yaml")))) ;; (yaml . ("https://github.com/ikatyang/tree-sitter-yaml"))))
) ;; )
(use-package treesit-auto (use-package treesit-auto
:custom
(setq treesit-auto-install t)
:config :config
(global-treesit-auto-mode) (treesit-auto-add-to-auto-mode-alist 'all)
(setq treesit-auto-install 'prompt)) (global-treesit-auto-mode))
#+end_src #+end_src
#+RESULTS:
: t
*** direnv (envrc) *** direnv (envrc)
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: h:82ddeef2-99f8-465b-ba36-07c3eaad717b :CUSTOM_ID: h:82ddeef2-99f8-465b-ba36-07c3eaad717b

View file

@ -590,6 +590,15 @@ create a new one."
(use-package evil-visual-mark-mode (use-package evil-visual-mark-mode
:config (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 ;; set the NixOS wordlist by hand
(setq ispell-alternate-dictionary (getenv "WORDLIST")) (setq ispell-alternate-dictionary (getenv "WORDLIST"))
@ -1118,39 +1127,42 @@ create a new one."
(use-package rg) (use-package rg)
(use-package emacs ;; (use-package emacs
:ensure nil ;; :ensure nil
:init ;; :init
(setq treesit-language-source-alist ;; (setq treesit-language-source-alist
'((bash . ("https://github.com/tree-sitter/tree-sitter-bash")) ;; '((bash . ("https://github.com/tree-sitter/tree-sitter-bash"))
(c . ("https://github.com/tree-sitter/tree-sitter-c")) ;; (c . ("https://github.com/tree-sitter/tree-sitter-c"))
(cmake . ("https://github.com/uyha/tree-sitter-cmake")) ;; (cmake . ("https://github.com/uyha/tree-sitter-cmake"))
(cpp . ("https://github.com/tree-sitter/tree-sitter-cpp")) ;; (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp"))
(css . ("https://github.com/tree-sitter/tree-sitter-css")) ;; (css . ("https://github.com/tree-sitter/tree-sitter-css"))
(elisp . ("https://github.com/Wilfred/tree-sitter-elisp")) ;; (elisp . ("https://github.com/Wilfred/tree-sitter-elisp"))
(go . ("https://github.com/tree-sitter/tree-sitter-go")) ;; (go . ("https://github.com/tree-sitter/tree-sitter-go"))
(html . ("https://github.com/tree-sitter/tree-sitter-html")) ;; (html . ("https://github.com/tree-sitter/tree-sitter-html"))
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript")) ;; (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript"))
(json . ("https://github.com/tree-sitter/tree-sitter-json")) ;; (json . ("https://github.com/tree-sitter/tree-sitter-json"))
(julia . ("https://github.com/tree-sitter/tree-sitter-julia")) ;; (julia . ("https://github.com/tree-sitter/tree-sitter-julia"))
(latex . ("https://github.com/latex-lsp/tree-sitter-latex")) ;; (latex . ("https://github.com/latex-lsp/tree-sitter-latex"))
(make . ("https://github.com/alemuller/tree-sitter-make")) ;; (make . ("https://github.com/alemuller/tree-sitter-make"))
(markdown . ("https://github.com/ikatyang/tree-sitter-markdown")) ;; (markdown . ("https://github.com/ikatyang/tree-sitter-markdown"))
(nix . ("https://github.com/nix-community/tree-sitter-nix")) ;; (nix . ("https://github.com/nix-community/tree-sitter-nix"))
(R . ("https://github.com/r-lib/tree-sitter-r")) ;; (R . ("https://github.com/r-lib/tree-sitter-r"))
(python . ("https://github.com/tree-sitter/tree-sitter-python")) ;; (python . ("https://github.com/tree-sitter/tree-sitter-python"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript")) ;; (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript"))
(rust . ("https://github.com/tree-sitter/tree-sitter-rust")) ;; (rust . ("https://github.com/tree-sitter/tree-sitter-rust"))
(sql . ("https://github.com/m-novikov/tree-sitter-sql")) ;; (sql . ("https://github.com/m-novikov/tree-sitter-sql"))
(toml . ("https://github.com/tree-sitter/tree-sitter-toml")) ;; (toml . ("https://github.com/tree-sitter/tree-sitter-toml"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")) ;; (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src"))
(yaml . ("https://github.com/ikatyang/tree-sitter-yaml")))) ;; (yaml . ("https://github.com/ikatyang/tree-sitter-yaml"))))
) ;; )
(use-package treesit-auto (use-package treesit-auto
:custom
(setq treesit-auto-install t)
:config :config
(global-treesit-auto-mode) (treesit-auto-add-to-auto-mode-alist 'all)
(setq treesit-auto-install 'prompt)) (global-treesit-auto-mode))
;; (use-package direnv ;; (use-package direnv
;; :custom (direnv-always-show-summary nil) ;; :custom (direnv-always-show-summary nil)
;; :config (direnv-mode)) ;; :config (direnv-mode))