abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

preconfigured recursive-search with multiple ivy-re-builders-alists #2036

Open drorbemet opened 5 years ago

drorbemet commented 5 years ago

Which places in ivy would be best for implementing a preconfigured recursive-search that uses multiple ivy-builders-alists?

I have difficulties following ivy-builders-alist to figure out it's usage in order to implement the following example demonstrates the desired behavior:

(require 's)
(require 'dash)

(defun the-narrow-rule (s)
  ;; this would be ivy-re-builders-alist-1
  (s-matches? "^fuzz " s))

(defun the-wide-rule (s)
  ;; this would be ivy-re-builders-alist-2
  (s-matches? "fuzz" s))

(defun combining-two-search-result-sets ()
  "Takes two matching-rules of different relevance and a set of
candidates and returns matches according to their relevance
without duplicates."
  (let* ((candidates
          (s-split "\n" 
                   "not matching 0
matching but less relevant fuzz 1
matching fuzz but less relevant 2
fuzz matching and more relevant 3
matching but less relevant fuzz 4
not matching 5
matching fuzz but less relevant 6
not matching 7"))
         (matches0
          (-filter
           (lambda (cand)
             (the-wide-rule cand))
           candidates))
         (matches1
          (-remove
           (lambda (cand)
             (the-narrow-rule cand))
           matches0))
         (matches2
          (-filter
           (lambda (cand)
             (the-narrow-rule cand))
           matches0)))
    (-concat matches2 matches1)))
(combining-two-search-result-sets)
  ;; ("fuzz matching and more relevant 3"
  ;;  "matching but less relevant fuzz 1"
  ;;  "matching fuzz but less relevant 2"
  ;;  "matching but less relevant fuzz 4"
  ;;  "matching fuzz but less relevant 6")
abo-abo commented 5 years ago

You need to pass your own :matcher to ivy-read. See counsel--find-file-matcher for an example.