summary refs log tree commit diff stats
path: root/user/emacs
diff options
context:
space:
mode:
authorAlan Pearce2023-05-14 21:57:31 +0200
committerAlan Pearce2023-05-14 21:57:31 +0200
commita8b77222abc943966a7113193367b6e1c4b6632c (patch)
tree96f4dd407ee6d815867b790b7fb77c1f04a7aa95 /user/emacs
parent491ed560454754936b2e37b3efcba371026abea2 (diff)
downloadnixfiles-a8b77222abc943966a7113193367b6e1c4b6632c.tar.lz
nixfiles-a8b77222abc943966a7113193367b6e1c4b6632c.tar.zst
nixfiles-a8b77222abc943966a7113193367b6e1c4b6632c.zip
emacs: configure tree-sitter based text objects
Diffstat (limited to 'user/emacs')
-rw-r--r--user/emacs/init.el27
1 files changed, 27 insertions, 0 deletions
diff --git a/user/emacs/init.el b/user/emacs/init.el
index d91781fc..43c4571f 100644
--- a/user/emacs/init.el
+++ b/user/emacs/init.el
@@ -470,6 +470,33 @@ _p_rev       _u_pper              _=_: upper/lower       _r_esolve
   :ghook ('org-mode-hook #'evil-org-mode)
   :gfhook #'evil-org-set-key-theme)
 
+(defun etts/start-of-next-function ()
+  (interactive)
+  (evil-textobj-tree-sitter-goto-textobj "function.outer" nil nil))
+(defun etts/start-of-prev-function ()
+  (interactive)
+  (evil-textobj-tree-sitter-goto-textobj "function.outer" t nil))
+(defun etts/end-of-next-function ()
+  (interactive)
+  (evil-textobj-tree-sitter-goto-textobj "function.outer" nil t))
+(defun etts/end-of-prev-function ()
+  (interactive)
+  (evil-textobj-tree-sitter-goto-textobj "function.outer" t t))
+(use-package evil-textobj-tree-sitter
+  :after evil
+  :general
+  (:keymaps 'evil-outer-text-objects-map
+            "f" (evil-textobj-tree-sitter-get-textobj "function.outer")
+						"a" (evil-textobj-tree-sitter-get-textobj ("conditional.outer" "loop.outer")))
+	(:keymaps 'evil-inner-text-objects-map
+            "f" (evil-textobj-tree-sitter-get-textobj "function.inner")
+            "a" (evil-textobj-tree-sitter-get-textobj ("conditional.inner" "loop.inner")))
+  (:states 'normal
+           "]f" #'etts/start-of-next-function
+           "[f" #'etts/start-of-prev-function
+           "]F" #'etts/end-of-next-function
+           "[F" #'etts/end-of-prev-function))
+
 ;;; Completion
 
 (use-package company