branch: master
commit 10755b2df561125c06ff03cf0d0e0046a47d228b
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
swiper.el (swiper-isearch-toggle): Add
Fixes #2061
---
swiper.el | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/swiper.el b/swiper.el
index 204677f..40fb1b9 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1397,6 +1397,24 @@ When not running `swiper-isearch' already, start it."
(ivy-set-occur 'swiper-isearch 'swiper-occur)
+(defun swiper-isearch-toggle ()
+ "Two-way toggle between `swiper-isearch' and isearch."
+ (interactive)
+ (if isearch-mode
+ (let ((query (if isearch-regexp
+ isearch-string
+ (regexp-quote isearch-string))))
+ (isearch-exit)
+ (goto-char (match-beginning 0))
+ (swiper-isearch query))
+ (ivy-exit-with-action
+ (lambda (_)
+ (when (looking-back ivy--old-re (line-beginning-position))
+ (goto-char (match-beginning 0)))
+ (isearch-mode t)
+ (unless (string= ivy-text "")
+ (isearch-yank-string ivy-text))))))
+
(provide 'swiper)
;;; swiper.el ends here