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

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

[elpa] master 56d7802 15/31: Add an option for multi-tier regex matching


From: Oleh Krehel
Subject: [elpa] master 56d7802 15/31: Add an option for multi-tier regex matching
Date: Fri, 01 May 2015 14:28:51 +0000

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

    Add an option for multi-tier regex matching
    
    * ivy.el (ivy--regex-plus): New defun. This is an example for the
      multi-tier interface.
    (ivy--filter): Update.
    
    To use it, add e.g.:
    
    (setq ivy-re-builders-alist
          '((t . ivy--regex-plus)))
    
    Example using boost_1_58_0 and `find-file-in-project`:
    
    * "utility" - 234 matches
    * "utility hpp" - 139 matches
    * "utility !hpp" - 95 matches
    
    Fixes #62
---
 ivy.el |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/ivy.el b/ivy.el
index a1c088f..5b440f3 100644
--- a/ivy.el
+++ b/ivy.el
@@ -660,6 +660,23 @@ When GREEDY is non-nil, join words in a greedy way."
                             ".*?")))))
                     ivy--regex-hash)))))
 
+(defun ivy--regex-plus (str)
+  "Build a regex sequence from STR.
+Spaces are wild, everything before \"!\" should match.
+Everything after \"!\" should not match."
+  (let ((parts (split-string str "!" t)))
+    (cl-case (length parts)
+      (0
+       "")
+      (1
+       (ivy--regex (car parts)))
+      (2
+       (let ((r2 (ivy--regex (cadr parts)))
+             (r1 (ivy--regex (car parts))))
+         (list (cons r1 t)
+               (cons r2 nil))))
+      (t (error "Unexpected: use only one !")))))
+
 ;;** Rest
 (defun ivy--minibuffer-setup ()
   "Setup ivy completion in the minibuffer."
@@ -804,6 +821,8 @@ CANDIDATES are assumed to be static."
                             ivy--old-cands)
                        ivy--old-cands)
                       ((and ivy--old-re
+                            (stringp re)
+                            (stringp ivy--old-re)
                             (not (string-match "\\\\" ivy--old-re))
                             (not (equal ivy--old-re ""))
                             (memq (cl-search
@@ -816,10 +835,17 @@ CANDIDATES are assumed to be static."
                           (lambda (x) (string-match re x))
                           ivy--old-cands)))
                       (t
-                       (ignore-errors
-                         (cl-remove-if-not
-                          (lambda (x) (string-match re x))
-                          candidates)))))
+                       (let ((re-list (if (stringp re) (list (cons re t)) re))
+                             (res candidates))
+                         (dolist (re re-list)
+                           (setq res
+                                 (funcall
+                                  (if (cdr re)
+                                      #'cl-remove-if-not
+                                    #'cl-remove-if)
+                                  `(lambda (x) (string-match ,(car re) x))
+                                  res)))
+                         res))))
          (tail (nthcdr ivy--index ivy--old-cands))
          idx)
     (when (and tail ivy--old-cands)



reply via email to

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