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

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

[elpa] master 473c595 064/348: Facilitate the sorting of cons cell input


From: Oleh Krehel
Subject: [elpa] master 473c595 064/348: Facilitate the sorting of cons cell input to ivy-read
Date: Sat, 8 Apr 2017 11:03:26 -0400 (EDT)

branch: master
commit 473c5958db9fccf4e3281191e5e878e6ce1d04a6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Facilitate the sorting of cons cell input to ivy-read
    
    * ivy.el (ivy--reset-state): When an alist is passed to `ivy-read', and
      a sorting function is associated via 'caller, the sorting function
      will receive two cons cells as arguments, instead of two strings as
      usual.
    
    Re #554
    
    Example:
    
    (defvar ivy-sorter-data '(("b 1" . 1) ("a 2" . 2) ("d 0" . 0) ("c 5" . 5)))
    
    (defun isn (a b)
      (< (cdr a) (cdr b)))
    
    (add-to-list 'ivy-sort-functions-alist '(ivy-sorter . isn))
    
    (ivy-read "string: " ivy-sorter-data
              :sort t
              :caller 'ivy-sorter)
---
 ivy.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/ivy.el b/ivy.el
index f4f590d..4fcabbd 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1499,10 +1499,18 @@ This is useful for recursive `ivy-read'."
              (setq coll (ivy--buffer-list "" ivy-use-virtual-buffers 
predicate)))
             (dynamic-collection
              (setq coll (funcall collection ivy-text)))
+            ((and (consp collection) (listp (car collection)))
+             (if (and sort (setq sort-fn (cdr (assoc caller 
ivy-sort-functions-alist))))
+                 (progn
+                   (setq sort nil)
+                   (setq coll (mapcar #'car
+                                      (cl-sort
+                                       (copy-sequence collection)
+                                       sort-fn))))
+               (setq coll (all-completions "" collection predicate))))
             ((or (functionp collection)
                  (byte-code-function-p collection)
                  (vectorp collection)
-                 (and (consp collection) (listp (car collection)))
                  (hash-table-p collection)
                  (and (listp collection) (symbolp (car collection))))
              (setq coll (all-completions "" collection predicate)))



reply via email to

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