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

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

[elpa] externals/ivy-hydra 83873c7 152/395: ivy.el (ivy--dynamic-collect


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra 83873c7 152/395: ivy.el (ivy--dynamic-collection-cands): Accept alist from dynamic-collection
Date: Thu, 25 Feb 2021 08:31:51 -0500 (EST)

branch: externals/ivy-hydra
commit 83873c735afe19e7b961ba6755a3bbd854a79da7
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    ivy.el (ivy--dynamic-collection-cands): Accept alist from dynamic-collection
    
    * ivy-test.el (ivy-read): Add test.
    
    Fixes #2355
    Re #2463
---
 ivy-test.el | 12 +++++++++++-
 ivy.el      |  8 ++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index 15f3956..37b7ee1 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -182,7 +182,17 @@ will bring the behavior in line with the newer Emacsen."
   (should (equal (ivy-with
                   '(ivy-read "x: " '("one" "two" ("three" . "four")))
                   "th C-m")
-                 "three")))
+                 "three"))
+  (should (equal (ivy-with
+                  '(ivy-read "x: "
+                    (lambda (_input)
+                      '(("one" . 1)
+                        ("two" . 2)))
+                    :dynamic-collection t
+                    :action (lambda (choice)
+                              (message "%s" choice)))
+                  "C-m")
+                 "one")))
 
 (ert-deftest ivy-read-sort-alist ()
   (should (equal (ivy-with '(let ((coll '(("b" . "1") ("a" . "2"))))
diff --git a/ivy.el b/ivy.el
index 029df86..27cf645 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2390,7 +2390,7 @@ This is useful for recursive `ivy-read'."
                                                counsel-switch-buffer)))
                          predicate)))
             (dynamic-collection
-             (setq coll (funcall collection (or initial-input ""))))
+             (setq coll (ivy--dynamic-collection-cands (or initial-input ""))))
             ((consp (car-safe collection))
              (setq collection (cl-remove-if-not predicate collection))
              (when (and sort (setq sort-fn (ivy--sort-function caller)))
@@ -3341,6 +3341,10 @@ Should be run via minibuffer `post-command-hook'."
         (ivy--insert-minibuffer new-minibuffer)))
     t))
 
+(defun ivy--dynamic-collection-cands (input)
+  (mapcar (lambda (x) (if (consp x) (car x) x))
+          (funcall (ivy-state-collection ivy-last) input)))
+
 (defun ivy--update-minibuffer ()
   (prog1
       (if (ivy-state-dynamic-collection ivy-last)
@@ -3350,7 +3354,7 @@ Should be run via minibuffer `post-command-hook'."
                 coll in-progress)
             (unless (equal ivy--old-text ivy-text)
               (while-no-input
-                (setq coll (funcall (ivy-state-collection ivy-last) ivy-text))
+                (setq coll (ivy--dynamic-collection-cands ivy-text))
                 (when (eq coll 0)
                   (setq coll nil)
                   (setq ivy--old-re nil)



reply via email to

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