all repos — nixfiles @ a8b77222abc943966a7113193367b6e1c4b6632c

System and user configuration, managed by nix and home-manager

emacs: configure tree-sitter based text objects
Alan Pearce alan@alanpearce.eu
Sun, 14 May 2023 21:57:31 +0200
commit

a8b77222abc943966a7113193367b6e1c4b6632c

parent

491ed560454754936b2e37b3efcba371026abea2

2 files changed, 28 insertions(+), 0 deletions(-)

jump to
M user/emacs/init.eluser/emacs/init.el
@@ -470,6 +470,33 @@ (add-hook 'org-agenda-mode-hook #'evil-org-agenda-set-keys))   :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
M user/settings/emacs.nixuser/settings/emacs.nix
@@ -117,6 +117,7 @@ evil-org         evil-quickscope
         evil-space
         evil-surround
+        evil-textobj-tree-sitter
         eyebrowse
         format-all
         flycheck