treesit-jump-jump (used to jump to match)
treesit-jump-select (used to select the region of a match)
treesit-jump-delete (used to delete the region of a match)
treesit-jump-parent-jump (used to jump to a parent of the current node under the cursor)
treesit-jump-gptel-describe (used to describe the selected region using gptel (chatgpt/ollama/etc.))
- Emacs compiled with treesit support (version 29+)
- Installed treesitter grammar (for the language you want to use)
- You can use treesit-auto to install grammars and auto load treesitter language modes.
- Avy
- Transient
- Gptel
(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")))
- Transient for all the functions: treesit-jump-transient
- How to add extra treesit queries per mode:
(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")))
- How to add queries to filter out of results per mode:
(add-to-list 'treesit-jump-queries-filter-mode-alist (cons 'python-ts-mode '("class")))
- Function to clear cache (useful if you’ve added to treesit-queries per node after running treesit-jump functions):
treesit-jump-queries-clear-cache
- 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.
I’ve tested that the queries compile for the following languages: Python, C, C++, Java, C#, JavaScript, TypeScript, Go, Rust. This package takes inspiration from avy, and 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).