From 4ef985d7e68c647ae500bf82f0fdf2d4b58b293a Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Wed, 30 Nov 2022 01:08:28 -0800 Subject: [PATCH] Add treesitter based navigation Also add rustic --- init.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/init.el b/init.el index bf4a269..e33e4fd 100644 --- a/init.el +++ b/init.el @@ -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")))