All Projects → meain → evil-textobj-tree-sitter

meain / evil-textobj-tree-sitter

Licence: Apache-2.0 license
Tree-sitter powered textobjects for evil mode in Emacs

Programming Languages

scheme
763 projects
emacs lisp
2029 projects
go
31211 projects - #10 most used programming language
Makefile
30231 projects
shell
77523 projects

Projects that are alternatives of or similar to evil-textobj-tree-sitter

Dotfiles
Ninrod's sharpened dotfiles for emacs, vim, zsh, tmux. Since '15.
Stars: ✭ 208 (+136.36%)
Mutual labels:  evil
nightfox.nvim
🦊A highly customizable theme for vim and neovim with support for lsp, treesitter and a variety of plugins.
Stars: ✭ 1,489 (+1592.05%)
Mutual labels:  treesitter
material.nvim
🔱 Material colorscheme for NeoVim written in Lua with built-in support for native LSP, TreeSitter and many more plugins
Stars: ✭ 574 (+552.27%)
Mutual labels:  treesitter
nvim-treesitter-lua
Tree-sitter Lua parser integration for nvim-treesitter.
Stars: ✭ 12 (-86.36%)
Mutual labels:  treesitter
R3ditor
An open-source project created to reverse-engineering some Resident Evil 3 files
Stars: ✭ 19 (-78.41%)
Mutual labels:  evil
neon
Customizable coloscheme with dark and light options, vivid colors and easy on the eye.
Stars: ✭ 100 (+13.64%)
Mutual labels:  treesitter
Evil Multiedit
Multiple cursors for evil-mode, based on iedit
Stars: ✭ 200 (+127.27%)
Mutual labels:  evil
evil.R
Evil tricks for R
Stars: ✭ 38 (-56.82%)
Mutual labels:  evil
awesome-neovim
Awesome Configurations for C/C++,Zig,Web and Lua development in NeoVim
Stars: ✭ 54 (-38.64%)
Mutual labels:  treesitter
evil-textobj-syntax
This package is a port of vim-textobj-syntax for emacs. It provides evil text objects for consecutive items with same syntax highlight.
Stars: ✭ 19 (-78.41%)
Mutual labels:  evil
vscode.nvim
Neovim/Vim color scheme inspired by Dark+ and Light+ theme in Visual Studio Code
Stars: ✭ 362 (+311.36%)
Mutual labels:  treesitter
kosmikoa.nvim
A dark color scheme for Neovim with support for LSP, Treesitter. This mirror is deprecated. Use the repo at https://sr.ht/~novakane/kosmikoa.nvim/
Stars: ✭ 23 (-73.86%)
Mutual labels:  treesitter
Dotfiles
Well documented awesome dotfiles 😍 Many neovim lua configs, handy zsh/bash functions, fzf functions + more
Stars: ✭ 64 (-27.27%)
Mutual labels:  treesitter
Evil Org Mode
Supplemental evil-mode keybindings to emacs org-mode
Stars: ✭ 241 (+173.86%)
Mutual labels:  evil
onedark.nvim
One dark and light colorscheme for neovim >= 0.5.0 written in lua based on Atom's One Dark and Light theme. Additionally, it comes with 5 color variant styles
Stars: ✭ 425 (+382.95%)
Mutual labels:  treesitter
Philosophy
A list of philosophy books and resources.
Stars: ✭ 206 (+134.09%)
Mutual labels:  evil
nvim-highlite
A colorscheme template that is "lite" on logic for the developer.
Stars: ✭ 163 (+85.23%)
Mutual labels:  treesitter
nvim
No description or website provided.
Stars: ✭ 28 (-68.18%)
Mutual labels:  treesitter
evil-briefcase
Change cases quickly with vim motions in emacs
Stars: ✭ 20 (-77.27%)
Mutual labels:  evil
navigator.lua
Source code analysis & navigation plugin for Neovim. Navigate codes like a breeze🎐. Exploring LSP and 🌲Treesitter symbols a piece of 🍰. Take control like a boss 🦍.
Stars: ✭ 781 (+787.5%)
Mutual labels:  treesitter

evil-textobj-tree-sitter

MELPA test

Tree-sitter powered textobjects for evil mode in Emacs.

gif

This is an Emacs port of nvim-treesitter/nvim-treesitter-textobjects.

This package will let you create evil textobjects using tree-sitter grammars. You can easily create function,class,comment etc textobjects in multiple languages.

Installation & Usage

You can install evil-textobj-tree-sitter from melpa. Here is how you would do it using use-package and package.el:

(use-package evil-textobj-tree-sitter :ensure t)

Or you can use straight.el:

(use-package evil-textobj-tree-sitter :straight t)

Or using straight.el and el-get to pull from source:

(use-package evil-textobj-tree-sitter
  :straight (evil-textobj-tree-sitter :type git
                      :host github
                      :repo "meain/evil-textobj-tree-sitter"
                      :files (:defaults "queries")))

You will also have to setup tree-sitter.

Mapping textobjects

By default, the library does not provide any keybindings, but it should be relatively easy to add them.

;; 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")))

We support quite a few textobjects. You can find a list of available textobjects at nvim-treesitter/nvim-treesitter-textobjects. We might not have support for all of them as emacs-tree-sitter does not yet support all the languages as of now. As for the list of languages that we support you can check the value of evil-textobj-tree-sitter-major-mode-language-alist.

Custom textobjects

If you are not able to find the text object that you are looking for in the builtin list, you can create custom text objects by passing the a custom query with captures.

For example if you want to create text object to select import statements, you can write something like below. You will have to provide the tree-sitter queries for all the languages that you want it to work for

;; The first arguemnt to `evil-textobj-tree-sitter-get-textobj' will be the capture group to use
;; and the second arg will be an alist mapping major-mode to the corresponding query to use.
(define-key evil-outer-text-objects-map "m" (evil-textobj-tree-sitter-get-textobj "import"
                                              '((python-mode . [(import_statement) @import])
                                                (rust-mode . [(use_declaration) @import]))))

Goto

We have also added support for for a fancier version of goto-char. You can use this to go to the next function, previous class or do any motions like that.

You can use the evil-textobj-tree-sitter-goto-textobj function to invoke goto. You can either use this in other function or just bound to a key. The first argument is the textobj that you want to use, the second one specifies if you want to search forward or backward and the last one is for specifying wheather to go to the start or end of the textobj.

Below are some sample binding that you can do. You can use any textobj that is available here.

;; Goto start of next function
(define-key evil-normal-state-map (kbd "]f") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer")))
;; Goto start of previous function
(define-key evil-normal-state-map (kbd "[f") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" t)))
;; Goto end of next function
(define-key evil-normal-state-map (kbd "]F") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" nil t)))
;; Goto end of previous function
(define-key evil-normal-state-map (kbd "[F") (lambda ()
                                                  (interactive)
                                                  (evil-textobj-tree-sitter-goto-textobj "function.outer" t t)))

Contributing new textobjects

As I have already mentioned, I pull the text objects from nvim-treesitter/nvim-treesitter-textobjects project. This right now automatically happens every friday using a Github Action which will create a new PR on the repo. So if you would like to update/add the builtin tree-sitter objects, feel free to update them in the neovim project repository. Unless there is something Emacs specific I recommend everyone to just submit the new queries to that project.

If you are adding a completely new language, there is two other things that you will have to do to make sure everything will work well.

  1. Make sure the lang is available in emacs-tree-sitter/tree-sitter-langs
  2. Make sure we have a major-mode mapping in evil-textobj-tree-sitter-major-mode-language-alist

License

The primary codebase is licensed under Apache-2.0. The queries have be taken from nvim-treesitter/nvim-treesitter-textobjects which is also licensed under the same license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].