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

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

[elpa] master d1216eb 036/272: Add the '!' behavior into `ivy--regex-ign


From: Oleh Krehel
Subject: [elpa] master d1216eb 036/272: Add the '!' behavior into `ivy--regex-ignore-order'
Date: Mon, 25 Apr 2016 10:13:15 +0000

branch: master
commit d1216eb0ca3eaa878a7a2efbd961ed4d0d8d7d16
Author: Samuel Loury <address@hidden>
Commit: Samuel Loury <address@hidden>

    Add the '!' behavior into `ivy--regex-ignore-order'
---
 ivy.el |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/ivy.el b/ivy.el
index 9e456ae..6ff1e87 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1522,7 +1522,7 @@ When GREEDY is non-nil, join words in a greedy way."
                             ".*?")))))
                     ivy--regex-hash)))))
 
-(defun ivy--regex-ignore-order (str)
+(defun ivy--regex-ignore-order--part (str &optional discard)
   "Re-build regex from STR by splitting at spaces.
 Ignore the order of each group."
   (let* ((subs (split-string str " +" t))
@@ -1531,9 +1531,28 @@ Ignore the order of each group."
       (0
        "")
       (t
-       (mapcar (lambda (x) (cons x t))
+       (mapcar (lambda (x) (cons x (not discard)))
                subs)))))
 
+(defun ivy--regex-ignore-order (str)
+  "Re-build regex from STR by splitting at spaces.
+Ignore the order of each group. Everything before \"!\" should
+match. Everything after \"!\" should not match."
+  (let ((parts (split-string str "!" t)))
+    (cl-case (length parts)
+      (0
+       "")
+      (1
+       (if (string= (substring str 0 1) "!")
+           (list (cons "" t)
+                 (ivy--regex-ignore-order--part (car parts) t))
+         (ivy--regex-ignore-order--part (car parts))))
+      (2
+       (append
+        (ivy--regex-ignore-order--part (car parts))
+        (ivy--regex-ignore-order--part (cadr parts) t)))
+      (t (error "Unexpected: use only one !")))))
+
 (defun ivy--regex-plus (str)
   "Build a regex sequence from STR.
 Spaces are wild card characters, everything before \"!\" should



reply via email to

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