]> code.delx.au - gnu-emacs-elpa/commitdiff
swiper.el (swiper-query-replace): Improve "M-n"
authorOleh Krehel <ohwoeowho@gmail.com>
Thu, 31 Mar 2016 14:06:23 +0000 (16:06 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Thu, 31 Mar 2016 14:06:23 +0000 (16:06 +0200)
To replace a symbol with a similar symbol,

1. Press "C-s" "M-n" for `swiper' and select the symbol at point as input.
2. Press "M-q" for `swiper-query-replace'
3. Press "M-n" to yank the symbol to replace.

Here step-3 was modified to yank e.g. "symbol" instead of "\_<symbo\_>"
previously.

swiper.el

index 6eb433fb14778d41d6fc4629015359cce856d1b1..b6b4c84d3e6fe8556e4c97ffbab557f622df5fb1 100644 (file)
--- a/swiper.el
+++ b/swiper.el
       (user-error "Should only be called in the minibuffer through `swiper-map'")
     (let* ((enable-recursive-minibuffers t)
            (from (ivy--regex ivy-text))
-           (to (query-replace-read-to from "Query replace" t)))
+           (to (minibuffer-with-setup-hook
+                   (lambda ()
+                     (setq minibuffer-default
+                           (if (string-match "\\`\\\\_<\\(.*\\)\\\\_>\\'" ivy-text)
+                               (match-string 1 ivy-text)
+                             ivy-text)))
+                 (read-from-minibuffer (format "Query replace %s with: " from)))))
       (swiper--cleanup)
       (ivy-exit-with-action
        (lambda (_)