summaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
Diffstat (limited to 'emacs')
-rw-r--r--emacs/functions.el11
-rw-r--r--emacs/init.el3
2 files changed, 12 insertions, 2 deletions
diff --git a/emacs/functions.el b/emacs/functions.el
index fc8431f..b322af6 100644
--- a/emacs/functions.el
+++ b/emacs/functions.el
@@ -19,6 +19,17 @@ is active."
(isearch-yank-string (buffer-substring-no-properties
(region-beginning) (region-end)))))
+(defun my/swiper (&optional swiper-all)
+ "Call ‘swiper’ (‘swiper-all’ when prefixed) with the contents
+of the region if it is active."
+ (interactive "P")
+ (if (use-region-p)
+ (let ((initial-input (buffer-substring-no-properties
+ (region-beginning) (region-end))))
+ (deactivate-mark)
+ (if swiper-all (swiper-all initial-input) (swiper initial-input)))
+ (if swiper-all (swiper-all) (swiper))))
+
;; Theme Functions
diff --git a/emacs/init.el b/emacs/init.el
index 554d7c1..30140ce 100644
--- a/emacs/init.el
+++ b/emacs/init.el
@@ -89,8 +89,7 @@
(counsel-mode 1)
(diminish 'counsel-mode)
-(global-set-key (kbd "C-c s") #'swiper)
-(global-set-key (kbd "C-c x") #'swiper-all)
+(global-set-key (kbd "C-c s") #'my/swiper)
(dolist (fn '(isearch-forward isearch-backward))
(advice-add fn :after #'my/isearch-region))