Add treesitter based navigation

Also add rustic
This commit is contained in:
outfoxxed 2022-11-30 01:08:28 -08:00
parent 2baadca418
commit 4ef985d7e6
No known key found for this signature in database
GPG key ID: 5775F651AC84FFE6

45
init.el
View file

@ -79,6 +79,18 @@
;; Rainbow-Mode (show hex strings in color)
(use-package rainbow-mode)
;; Treesitter
(use-package tree-sitter
:config
(use-package tree-sitter-langs
:config
(tree-sitter-require 'rust)
(tree-sitter-require 'java))
(global-tree-sitter-mode +1))
;; Rust support
(use-package rustic)
;; Evil (Vim Emulation)
(use-package evil
:init
@ -88,3 +100,36 @@
:config
(evil-set-initial-state 'prog-mode 'normal)
(evil-mode +1))
;; Treesitter based navigation
(use-package evil-textobj-tree-sitter
:config
(let ((define-scope (lambda (key outer inner)
(define-key evil-outer-text-objects-map key outer)
(define-key evil-inner-text-objects-map key inner)))
(define-jumps (lambda (key name)
(let ((key key) (name name))
(define-key evil-normal-state-map (kbd (concat "]" key))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer"))))
(define-key evil-normal-state-map (kbd (concat "[" key))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer") t)))
(define-key evil-normal-state-map (kbd (concat "]" (upcase key)))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer") nil t)))
(define-key evil-normal-state-map (kbd (concat "[" (upcase key)))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer") t t)))))
))
;; Define new scope symbols for use with i and a
(funcall define-scope "c"
(evil-textobj-tree-sitter-get-textobj "class.outer")
(evil-textobj-tree-sitter-get-textobj "class.inner"))
(funcall define-scope "f"
(evil-textobj-tree-sitter-get-textobj "function.outer")
(evil-textobj-tree-sitter-get-textobj "function.inner"))
;; Define jumps with ] and [
(funcall define-jumps "c" "class")
(funcall define-jumps "f" "function")))