From a4464fd5552066c1e7f5f74d163c848fcf56e49e Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 18 Nov 2024 12:15:09 +0100 Subject: emacs: Add expreg for tree-sitter selections --- .config/emacs/modules/mm-treesit.el | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to '.config/emacs') diff --git a/.config/emacs/modules/mm-treesit.el b/.config/emacs/modules/mm-treesit.el index ed8a299..df3d85a 100644 --- a/.config/emacs/modules/mm-treesit.el +++ b/.config/emacs/modules/mm-treesit.el @@ -155,4 +155,34 @@ This alist is used to configure `auto-mode-alist'.") (setq treesit-font-lock-settings (append treesit-font-lock-settings mm-c-font-lock-rules)))) + +;;; Region Expansion + +(defun mm-expreg-expand (n) + "Expand to N syntactic units." + (interactive "p") + (dotimes (_ n) + (expreg-expand))) + +(defun mm-expreg-expand-dwim () + "Do-What-I-Mean `expreg-expand' to start with symbol or word. +If over a real symbol, mark that directly, else start with a word. Fall +back to regular `expreg-expand'." + (interactive) + (if (region-active-p) + (expreg-expand) + (let ((symbol (bounds-of-thing-at-point 'symbol))) + (cond + ((equal (bounds-of-thing-at-point 'word) symbol) + (mm-expreg-expand 1)) + (symbol + (mm-expreg-expand 2)) + (:else + (expreg-expand)))))) + +(use-package expreg + :ensure t + :commands (mm-expreg-expand mm-expreg-expand-dwim) + :bind ("M-SPC" . mm-expreg-expand-dwim)) + (provide 'mm-treesit) \ No newline at end of file -- cgit v1.2.3