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

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

[elpa] master e0b6c0c 46/57: Update the way spaces are quoted using ivy


From: Oleh Krehel
Subject: [elpa] master e0b6c0c 46/57: Update the way spaces are quoted using ivy
Date: Tue, 19 May 2015 14:21:39 +0000

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

    Update the way spaces are quoted using ivy
    
    * ivy.el (ivy--split): Split only on single spaces. From all other space
      groups, remove one space.
    
    * ivy-test.el (ivy--split): Add test.
    
    Fixes #109
---
 ivy-test.el |   12 ++++++++++++
 ivy.el      |   30 +++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index 951bfda..91e0dc3 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -69,3 +69,15 @@
                    "^[0-9][0-9 ]\\{4\\}\\(a\\)"))
   (should (string= (swiper--re-builder "^a b")
                    "^[0-9][0-9 ]\\{4\\}\\(a\\).*?\\(b\\)")))
+
+(ert-deftest ivy--split ()
+  (should (equal (ivy--split "King of the who?")
+                 '("King" "of" "the" "who?")))
+  (should (equal (ivy--split "The  Brittons.")
+                 '("The Brittons.")))
+  (should (equal (ivy--split "Who  are the  Brittons?")
+                 '("Who are" "the Brittons?")))
+  (should (equal (ivy--split "We're  all  Britons and   I   am your   king.")
+                 '("We're all Britons"
+                  "and  I  am"
+                   "your  king."))))
diff --git a/ivy.el b/ivy.el
index 121e8f5..c0bbedb 100644
--- a/ivy.el
+++ b/ivy.el
@@ -801,17 +801,29 @@ Minibuffer bindings:
 The remaining spaces stick to their left.
 This allows to \"quote\" N spaces by inputting N+1 spaces."
   (let ((len (length str))
-        (start 0)
+        start0
+        (start1 0)
         res s)
-    (while (and (string-match " +" str start)
-                (< start len))
-      (setq s (substring str start (1- (match-end 0))))
+    (while (and (string-match " +" str start1)
+                (< start1 len))
+      (setq match-len (- (match-end 0) (match-beginning 0)))
+      (if (= match-len 1)
+          (progn
+            (when start0
+              (setq start1 start0)
+              (setq start0 nil))
+            (push (substring str start1 (match-beginning 0)) res)
+            (setq start1 (match-end 0)))
+        (setq str (replace-match
+                   (make-string (1- match-len) ?\ )
+                   nil nil str))
+        (setq start0 (or start0 start1))
+        (setq start1 (1- (match-end 0)))))
+    (if start0
+        (push (substring str start0) res)
+      (setq s (substring str start1))
       (unless (= (length s) 0)
-        (push s res))
-      (setq start (match-end 0)))
-    (setq s (substring str start))
-    (unless (= (length s) 0)
-      (push s res))
+        (push s res)))
     (nreverse res)))
 
 (defun ivy--regex (str &optional greedy)



reply via email to

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