Jump around your source code in emacs using treesit and avy
APACHE-2.0 License
[[https://github.com/dmille56/treesit-jump/actions/workflows/main.yml/badge.svg]]
About :PROPERTIES: :CUSTOM_ID: about :END: Jump around your source code in emacs using treesit and avy.
Demos :PROPERTIES: :CUSTOM_ID: demos :END:
treesit-jump-jump (used to jump to match) [[https://i.imgur.com/bYeCHwd.gif]]
treesit-jump-select (used to select the region of a match) [[https://i.imgur.com/Ge5g7pb.gif]]
treesit-jump-delete (used to delete the region of a match) [[https://i.imgur.com/ofIUGTj.gif]]
treesit-jump-parent-jump (used to jump to a parent of the current node under the cursor) [[https://i.imgur.com/2222Jun.gif]]
treesit-jump-gptel-describe (used to describe the selected region using gptel (chatgpt/ollama/etc.))
** Config :PROPERTIES: :CUSTOM_ID: config :END: #+BEGIN_SRC emacs-lisp (use-package treesit-jump :straight (:host github :repo "dmille56/treesit-jump" :files ("*.el" "treesit-queries")) :config ;; Optional: add some queries to filter out of results (since they can be too cluttered sometimes) (setq treesit-jump-queries-filter-list '("inner" "test" "param"))) #+END_SRC
** Extra config options :PROPERTIES: :CUSTOM_ID: extra-config-options :END:
Transient for all the functions: treesit-jump-transient
How to add extra treesit queries per mode: #+BEGIN_SRC emacs-lisp (add-to-list 'treesit-jump-queries-extra-alist (cons 'powershell-ts-mode '("(flow_control_statement ()) @flow"))) (add-to-list 'treesit-jump-queries-extra-alist (cons 'python-ts-mode '("(return_statement ()) @return"))) #+END_SRC
How to add queries to filter out of results per mode: #+BEGIN_SRC emacs-lisp (add-to-list 'treesit-jump-queries-filter-mode-alist (cons 'python-ts-mode '("class"))) #+END_SRC
Function to clear cache (useful if you've added to treesit-queries per node after running treesit-jump functions): #+BEGIN_SRC emacs-lisp treesit-jump-queries-clear-cache #+END_SRC
See [[https://github.com/karthink/gptel]] for help configuring gptel queries (in order to configure backend between chatgpt/ollama/etc.)
Queries are defined in treesit-queries directory. Queries must be defined separately for each language. List of the query capture types are defined here: [[https://github.com/nvim-treesitter/nvim-treesitter-textobjects?tab=readme-ov-file#built-in-textobjects]].
For help defining your own queries refer to: [[https://github.com/emacs-mirror/emacs/blob/master/admin/notes/tree-sitter/starter-guide#query-syntax]]. Also recommend the following package for debugging your queries: https://git.sr.ht/~meow_king/ts-query-highlight.
Notes :PROPERTIES: :CUSTOM_ID: notes :END: I've tested that the queries compile for the following languages: Python, C, C++, Java, C#, JavaScript, TypeScript, Go, Rust.
Special Thanks :PROPERTIES: :CUSTOM_ID: special-thanks :END: This package takes inspiration from [[https://github.com/abo-abo/avy][avy]], and [[https://github.com/meain/evil-textobj-tree-sitter][evil-textobj-tree-sitter]]. Queries (and a bit of code to process them) were taken originally from evil-textobj-tree-sitter. The code here is licensed under the same license (Apache-2.0).