doomemacs/modules/tools/tree-sitter/config.el
Jeetaditya Chatterjee e1056f0053
tweak(tree-sitter): rebind conditional nav key
Move the conditional bindings from `i` to `v` this is
to reflect the text object, the thinking being if users have to learn
one anti mnemonic then it should reflect all cases to make it easier to
swallow.
2022-05-27 00:04:56 +01:00

66 lines
3 KiB
EmacsLisp

;;; tools/tree-sitter/config.el -*- lexical-binding: t; -*-
(use-package! tree-sitter
:hook (tree-sitter-after-on . tree-sitter-hl-mode)
:config
(require 'tree-sitter-langs)
;; This makes every node a link to a section of code
(setq tree-sitter-debug-jump-buttons t
;; and this highlights the entire sub tree in your code
tree-sitter-debug-highlight-jump-region t))
(use-package! evil-textobj-tree-sitter
:when (featurep! :editor evil +everywhere)
:after tree-sitter
:config
(defvar +tree-sitter-inner-text-objects-map (make-sparse-keymap))
(defvar +tree-sitter-outer-text-objects-map (make-sparse-keymap))
(defvar +tree-sitter-goto-previous-map (make-sparse-keymap))
(defvar +tree-sitter-goto-next-map (make-sparse-keymap))
(evil-define-key '(visual operator) 'tree-sitter-mode
"i" +tree-sitter-inner-text-objects-map
"a" +tree-sitter-outer-text-objects-map)
(evil-define-key 'normal 'tree-sitter-mode
"[g" +tree-sitter-goto-previous-map
"]g" +tree-sitter-goto-next-map)
(map! (:map +tree-sitter-inner-text-objects-map
"A" (+tree-sitter-get-textobj '("parameter.inner" "call.inner"))
"f" (+tree-sitter-get-textobj "function.inner")
"F" (+tree-sitter-get-textobj "call.inner")
"C" (+tree-sitter-get-textobj "class.inner")
"v" (+tree-sitter-get-textobj "conditional.inner")
"l" (+tree-sitter-get-textobj "loop.inner"))
(:map +tree-sitter-outer-text-objects-map
"A" (+tree-sitter-get-textobj '("parameter.outer" "call.outer"))
"f" (+tree-sitter-get-textobj "function.outer")
"F" (+tree-sitter-get-textobj "call.outer")
"C" (+tree-sitter-get-textobj "class.outer")
"c" (+tree-sitter-get-textobj "comment.outer")
"v" (+tree-sitter-get-textobj "conditional.outer")
"l" (+tree-sitter-get-textobj "loop.outer"))
(:map +tree-sitter-goto-previous-map
"a" (+tree-sitter-goto-textobj "parameter.outer" t)
"f" (+tree-sitter-goto-textobj "function.outer" t)
"F" (+tree-sitter-goto-textobj "call.outer" t)
"C" (+tree-sitter-goto-textobj "class.outer" t)
"c" (+tree-sitter-goto-textobj "comment.outer" t)
"v" (+tree-sitter-goto-textobj "conditional.outer" t)
"l" (+tree-sitter-goto-textobj "loop.outer" t))
(:map +tree-sitter-goto-next-map
"a" (+tree-sitter-goto-textobj "parameter.outer")
"f" (+tree-sitter-goto-textobj "function.outer")
"F" (+tree-sitter-goto-textobj "call.outer")
"C" (+tree-sitter-goto-textobj "class.outer")
"c" (+tree-sitter-goto-textobj "comment.outer")
"v" (+tree-sitter-goto-textobj "conditional.outer")
"l" (+tree-sitter-goto-textobj "loop.outer")))
(after! which-key
(setq which-key-allow-multiple-replacements t)
(pushnew!
which-key-replacement-alist
'(("" . "\\`+?evil-textobj-tree-sitter-function--\\(.*\\)\\(?:.inner\\|.outer\\)") . (nil . "\\1")))))