about summary refs log tree commit diff stats
path: root/.emacs.d/lisp/init-crux.el
diff options
context:
space:
mode:
authorDavid Morgan <djm_uk@protonmail.com>2022-10-05 16:38:32 +0100
committerDavid Morgan <djm_uk@protonmail.com>2022-10-05 16:38:32 +0100
commitb47430d46cfed1a9e128ccc684b5a570db2bca62 (patch)
treeeaf435a3ae8e5ea26de29d783c3b3d6d6134d79e /.emacs.d/lisp/init-crux.el
parent62243a3444643c903369b01a81a125da027ebbfe (diff)
downloaddotfiles-b47430d46cfed1a9e128ccc684b5a570db2bca62.tar.gz
Use crux advice macros
Diffstat (limited to '.emacs.d/lisp/init-crux.el')
-rw-r--r--.emacs.d/lisp/init-crux.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/.emacs.d/lisp/init-crux.el b/.emacs.d/lisp/init-crux.el
index f7f30a7..c819c25 100644
--- a/.emacs.d/lisp/init-crux.el
+++ b/.emacs.d/lisp/init-crux.el
@@ -3,7 +3,25 @@
 ;;; Code:
 
 (use-package crux
+  :defer 5
   :commands crux-start-or-switch-to
+  :config
+  (defmacro crux-with-region-or-sexp-or-line (func)
+    "When called with no active region, call FUNC on current sexp."
+    `(defadvice ,func (before with-region-or-sexp-or-line activate compile)
+       (interactive
+        (cond
+         (mark-active (list (region-beginning) (region-end)))
+         ((in-string-p) (flatten-list (bounds-of-thing-at-point 'string)))
+         ((thing-at-point 'list) (flatten-list (bounds-of-thing-at-point 'list)))
+         (t (list (line-beginning-position) (line-beginning-position 2)))))))
+
+  (crux-with-region-or-sexp-or-line sp-kill-region)
+  (crux-with-region-or-sexp-or-line paredit-kill-region)
+  (crux-with-region-or-buffer shell-command-on-region)
+  (crux-with-region-or-buffer indent-region)
+  (crux-with-region-or-buffer untabify)
+  (crux-with-region-or-line comment-or-uncomment-region)
   :bind
   ("C-^" . crux-top-join-line)
   ("C-<backspace>" . crux-kill-line-backwards)