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

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

[elpa] master 5a4ede4 130/348: Fix swiper-all for ivy--regex-ignore-orde


From: Oleh Krehel
Subject: [elpa] master 5a4ede4 130/348: Fix swiper-all for ivy--regex-ignore-order
Date: Sat, 8 Apr 2017 11:03:42 -0400 (EDT)

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

    Fix swiper-all for ivy--regex-ignore-order
    
    * ivy.el (ivy-re-match): New defun.
    
    * ivy-test.el (ivy-re-match): New test.
    
    * swiper.el (swiper-all-function): Separate the cons regex into two
      parts. Check if the second part also matches.  Set `ivy--old-re' so
      that there's fancy highlighting in the minibuffer.
    
    Fixes #620
---
 ivy-test.el |  6 ++++++
 ivy.el      | 23 +++++++++++++++++++++++
 swiper.el   | 16 ++++++++++------
 3 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index 9cc9313..121e63f 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -401,5 +401,11 @@
             "C-u 123 C-m")
            123)))
 
+(ert-deftest ivy-re-match ()
+  (should (ivy-re-match '(("counsel" . t)) "(defun counsel"))
+  (should (ivy-re-match '(("defun" . t) ("counsel" . t)) "(defun counsel"))
+  (should (ivy-re-match '(("counsel" . t) ("defun" . t)) "(defun counsel"))
+  (should (not (ivy-re-match '(("counsel" . nil) ("defun" . t)) "(defun 
counsel")))
+  (should (not (ivy-re-match '(("defun" . t) ("counsel" . nil)) "(defun 
counsel"))))
 
 (provide 'ivy-test)
diff --git a/ivy.el b/ivy.el
index f9f1d97..1ba266a 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1805,6 +1805,29 @@ Minibuffer bindings:
 
 ;;* Implementation
 ;;** Regex
+(defun ivy-re-match (re-seq str)
+  "Return non-nil if RE-SEQ matches STR.
+
+RE-SEQ is a list of (RE . MATCH-P).
+
+RE is a regular expression.
+
+MATCH-P is t when RE should match STR and nil when RE should not
+match STR.
+
+Each element of RE-SEQ must match for the funtion to return true.
+
+This concept is used to generalize regular expressions for
+`ivy--regex-plus' and `ivy--regex-ignore-order'."
+  (let ((res t)
+        re)
+    (while (and res (setq re (pop re-seq)))
+      (setq res
+            (if (cdr re)
+                (string-match-p (car re) str)
+              (not (string-match-p (car re) str)))))
+    res))
+
 (defvar ivy--regex-hash
   (make-hash-table :test #'equal)
   "Store pre-computed regex.")
diff --git a/swiper.el b/swiper.el
index 7cb95a4..3a96907 100644
--- a/swiper.el
+++ b/swiper.el
@@ -718,10 +718,13 @@ Run `swiper' for those buffers."
                            (eq (with-current-buffer b
                                  major-mode) 'dired-mode)))
                      (buffer-list)))
-           (re (funcall ivy--regex-function str))
-           (re (if (consp re) (caar re) re))
-           cands
-           match)
+           (re-full (funcall ivy--regex-function str))
+           re re-tail
+           cands match)
+      (if (stringp re-full)
+          (setq re re-full)
+        (setq re (caar re-full))
+        (setq re-tail (cdr re-full)))
       (dolist (buffer buffers)
         (with-current-buffer buffer
           (save-excursion
@@ -739,8 +742,9 @@ Run `swiper' for those buffers."
                (buffer-name)
                match)
               (put-text-property 0 1 'point (point) match)
-              (push match cands)))))
-      (setq ivy--old-re nil)
+              (when (or (null re-tail) (ivy-re-match re-tail match))
+                (push match cands))))))
+      (setq ivy--old-re re-full)
       (if (null cands)
           (list "")
         (setq ivy--old-cands (nreverse cands))))))



reply via email to

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