about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-10T20·30+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-17T10·56+0000
commitae75a9df9cc492fcdc80e11d68f7567f758f2b6a (patch)
treed776707639a7eaa26b898597e62da8381a31cd4c
parent06817539299dd428ebdbfa7c567cdd519f7c3606 (diff)
Configure deadgrep
Configuring deadgrep to do a number of things:
1. Set `deadgrep--context` to see more context "after" in the output.
2. Define `deadgrep/dwim` to use a region if one is present; otherwise just
   behave as `deadgrep`.

Warning: This commit relies on a patch I made to deadgrep: supporting the
`deadgrep--additional-flags`.
-rw-r--r--configs/shared/.emacs.d/wpc/packages/wpc-misc.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/configs/shared/.emacs.d/wpc/packages/wpc-misc.el b/configs/shared/.emacs.d/wpc/packages/wpc-misc.el
index 2515633fd55b..18f1e76dd80c 100644
--- a/configs/shared/.emacs.d/wpc/packages/wpc-misc.el
+++ b/configs/shared/.emacs.d/wpc/packages/wpc-misc.el
@@ -148,6 +148,19 @@
    :keymaps 'deadgrep-mode-map
    :states 'normal
    "o" #'deadgrep-visit-result-other-window)
+  (setq-default deadgrep--context '(0 . 3))
+  (defun deadgrep/region ()
+    "Run a ripgrep search on the active region."
+    (interactive)
+    (deadgrep (region/to-string)))
+  (defun deadgrep/dwim ()
+    "If a region is active, use that as the search, otherwise don't."
+    (interactive)
+    (with-current-buffer (current-buffer)
+      (if (region-active-p)
+          (setq deadgrep--additional-flags '("--multiline"))
+          (deadgrep/region)
+        (call-interactively #'deadgrep))))
   (advice-add
    'deadgrep--format-command
    :filter-return