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

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

[elpa] master d0b6e94 02/12: Allow to quote spaces while matching


From: Oleh Krehel
Subject: [elpa] master d0b6e94 02/12: Allow to quote spaces while matching
Date: Sun, 03 May 2015 11:04:50 +0000

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

    Allow to quote spaces while matching
    
    * 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 |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/ivy.el b/ivy.el
index eb0a8b6..307c989 100644
--- 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)



reply via email to

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