diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-11-18 12:15:09 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-11-18 12:15:09 +0100 |
commit | a4464fd5552066c1e7f5f74d163c848fcf56e49e (patch) | |
tree | d66ee5ed33949a5fc84147ce9a4329e1e2227b6e /.config/emacs/modules | |
parent | 38d514d590dccf6604862d6cc1a00bcad55e9ce2 (diff) |
emacs: Add expreg for tree-sitter selections
Diffstat (limited to '.config/emacs/modules')
-rw-r--r-- | .config/emacs/modules/mm-treesit.el | 30 |
1 files changed, 30 insertions, 0 deletions
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 |