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

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

[elpa] master 687aae2 246/399: swiper.el (swiper-query-replace): Check f


From: Oleh Krehel
Subject: [elpa] master 687aae2 246/399: swiper.el (swiper-query-replace): Check for empty input
Date: Sat, 20 Jul 2019 14:57:33 -0400 (EDT)

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

    swiper.el (swiper-query-replace): Check for empty input
    
    Fixes #2066
---
 swiper.el | 51 +++++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/swiper.el b/swiper.el
index 1e92c79..106723a 100644
--- a/swiper.el
+++ b/swiper.el
@@ -157,30 +157,33 @@
 (defun swiper-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-map'")
-    (swiper--query-replace-setup)
-    (unwind-protect
-         (let* ((enable-recursive-minibuffers t)
-                (from (ivy--regex ivy-text))
-                (to (minibuffer-with-setup-hook
-                        (lambda ()
-                          (setq minibuffer-default
-                                (if (string-match "\\`\\\\_<\\(.*\\)\\\\_>\\'" 
ivy-text)
-                                    (match-string 1 ivy-text)
-                                  ivy-text)))
-                      (ivy-read
-                       (format "Query replace %s with: " from) nil
-                       :update-fn #'swiper--query-replace-updatefn))))
-           (swiper--cleanup)
-           (ivy-exit-with-action
-            (lambda (_)
-              (with-ivy-window
-                (move-beginning-of-line 1)
-                (let ((inhibit-read-only t))
-                  (perform-replace from to
-                                   t t nil))))))
-      (swiper--query-replace-cleanup))))
+  (cond ((null (window-minibuffer-p))
+         (user-error "Should only be called in the minibuffer through 
`swiper-map'"))
+        ((string= "" ivy-text)
+         (user-error "Empty input"))
+        (t
+         (swiper--query-replace-setup)
+         (unwind-protect
+              (let* ((enable-recursive-minibuffers t)
+                     (from (ivy--regex ivy-text))
+                     (to (minibuffer-with-setup-hook
+                             (lambda ()
+                               (setq minibuffer-default
+                                     (if (string-match 
"\\`\\\\_<\\(.*\\)\\\\_>\\'" ivy-text)
+                                         (match-string 1 ivy-text)
+                                       ivy-text)))
+                           (ivy-read
+                            (format "Query replace %s with: " from) nil
+                            :update-fn #'swiper--query-replace-updatefn))))
+                (swiper--cleanup)
+                (ivy-exit-with-action
+                 (lambda (_)
+                   (with-ivy-window
+                     (move-beginning-of-line 1)
+                     (let ((inhibit-read-only t))
+                       (perform-replace from to
+                                        t t nil))))))
+           (swiper--query-replace-cleanup)))))
 
 (defvar inhibit-message)
 



reply via email to

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