]> code.delx.au - gnu-emacs-elpa/commitdiff
Allow to quote spaces while matching
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 1 May 2015 18:28:21 +0000 (20:28 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 1 May 2015 18:30:02 +0000 (20:30 +0200)
* ivy.el (ivy--split): New defun.

Use (ivy--split str) in place of (split-string str " +" t).
Allows to "quote" N spaces by inputting N+1 spaces.

ivy.el

diff --git a/ivy.el b/ivy.el
index eb0a8b6c63fdf5b60bdf9d837e2db127bea12e3b..307c98993fe1026f2fa2162fb191106c5bc8f171 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -722,6 +722,24 @@ Turning on Ivy mode will set `completing-read-function' to
   (make-hash-table :test 'equal)
   "Store pre-computed regex.")
 
+(defun ivy--split (str)
+  "Split STR into a list by single spaces.
+The remaining spaces stick to their left.
+This allows to \"quote\" N spaces by inputting N+1 spaces."
+  (let ((len (length str))
+        (start 0)
+        res s)
+    (while (and (string-match " +" str start)
+                (< start len))
+      (setq s (substring str start (1- (match-end 0))))
+      (unless (= (length s) 0)
+        (push s res))
+      (setq start (match-end 0)))
+    (setq s (substring str start))
+    (unless (= (length s) 0)
+      (push s res))
+    (nreverse res)))
+
 (defun ivy--regex (str &optional greedy)
   "Re-build regex from STR in case it has a space.
 When GREEDY is non-nil, join words in a greedy way."
@@ -731,7 +749,7 @@ When GREEDY is non-nil, join words in a greedy way."
         (prog1 (cdr hashed)
           (setq ivy--subexps (car hashed)))
       (cdr (puthash str
-                    (let ((subs (split-string str " +" t)))
+                    (let ((subs (ivy--split str)))
                       (if (= (length subs) 1)
                           (cons
                            (setq ivy--subexps 0)