From c24b6de1a2ce9e04b9b917b6ef8cbc9c09e09be7 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Thu, 31 Mar 2016 16:06:23 +0200 Subject: [PATCH] swiper.el (swiper-query-replace): Improve "M-n" 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 "\_" previously. --- swiper.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/swiper.el b/swiper.el index 6eb433fb1..b6b4c84d3 100644 --- a/swiper.el +++ b/swiper.el @@ -94,7 +94,13 @@ (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 (_) -- 2.39.2