emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master d7a1fda 143/348: swiper.el (swiper-all): "M-q" calls query


From: Oleh Krehel
Subject: [elpa] master d7a1fda 143/348: swiper.el (swiper-all): "M-q" calls query-replace
Date: Sat, 8 Apr 2017 11:03:44 -0400 (EDT)

branch: master
commit d7a1fdadfaf2ff89ecdd3ea9195f04cb2f8b8c9e
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    swiper.el (swiper-all): "M-q" calls query-replace
    
    * swiper.el (swiper-all-query-replace): New defun.
    (swiper-all-map): New keymap.
    (swiper-all): Update prompt, use `swiper-all-map'.
    
    Fixes #623
---
 swiper.el | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/swiper.el b/swiper.el
index 3a96907..ca84b26 100644
--- a/swiper.el
+++ b/swiper.el
@@ -114,6 +114,28 @@
            (perform-replace from to
                             t t nil)))))))
 
+(defun swiper-all-query-replace ()
+  "Start `query-replace' with string to replace from last search string."
+  (interactive)
+  (if (null (window-minibuffer-p))
+      (user-error
+       "Should only be called in the minibuffer through `swiper-all-map'")
+    (let* ((enable-recursive-minibuffers t)
+           (from (ivy--regex ivy-text))
+           (to (query-replace-read-to from "Query replace" t)))
+      (swiper--cleanup)
+      (ivy-exit-with-action
+       (lambda (_)
+         (let ((wnd-conf (current-window-configuration))
+               (inhibit-message t))
+           (unwind-protect
+                (dolist (cand ivy--old-cands)
+                  (let ((buffer (get-text-property 0 'buffer cand)))
+                    (switch-to-buffer buffer)
+                    (goto-char (point-min))
+                    (perform-replace from to t t nil)))
+             (set-window-configuration wnd-conf))))))))
+
 (defvar avy-background)
 (defvar avy-all-windows)
 (defvar avy-style)
@@ -640,7 +662,6 @@ WND, when specified is the window."
          re
          regexp-search-ring-max)))))
 
-;; (define-key isearch-mode-map (kbd "C-o") 'swiper-from-isearch)
 (defun swiper-from-isearch ()
   "Invoke `swiper' from isearch."
   (interactive)
@@ -779,16 +800,23 @@ Run `swiper' for those buffers."
      cands
      "\n")))
 
+(defvar swiper-all-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "M-q") 'swiper-all-query-replace)
+    map)
+  "Keymap for `swiper-all'.")
+
 (defun swiper-all ()
   "Run `swiper' for all opened buffers."
   (interactive)
   (let ((ivy-format-function #'swiper--all-format-function))
-    (ivy-read "Swiper: " 'swiper-all-function
+    (ivy-read "swiper-all: " 'swiper-all-function
               :action 'swiper-all-action
               :unwind #'swiper--cleanup
               :update-fn (lambda ()
                            (swiper-all-action ivy--current))
               :dynamic-collection t
+              :keymap swiper-all-map
               :caller 'swiper-multi)))
 
 (defun swiper-all-action (x)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]