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

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

[elpa] master 39dfc80 05/54: Fix :dynamic-collection not being sorted


From: Oleh Krehel
Subject: [elpa] master 39dfc80 05/54: Fix :dynamic-collection not being sorted
Date: Tue, 29 Sep 2015 14:09:47 +0000

branch: master
commit 39dfc80a51a2f809f16338c568960de693f69ec9
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Fix :dynamic-collection not being sorted
    
    * ivy.el (ivy--sort-maybe): New defun. If the current completion has
      sorting enabled, try to find the sorting function either in :sort or
      `ivy-sort-functions-alist'.
    (ivy--exhibit): Use `ivy--sort-maybe'.
    
    * counsel.el (counsel--async-sentinel): Use `ivy--sort-maybe'.
---
 counsel.el |    4 +++-
 ivy.el     |   20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/counsel.el b/counsel.el
index 2d41766..f667916 100644
--- a/counsel.el
+++ b/counsel.el
@@ -430,7 +430,9 @@ Skip some dotfiles unless `ivy-text' requires them."
   (if (string= event "finished\n")
       (progn
         (with-current-buffer (process-buffer process)
-          (setq ivy--all-candidates (split-string (buffer-string) "\n" t))
+          (setq ivy--all-candidates
+                (ivy--sort-maybe
+                 (split-string (buffer-string) "\n" t)))
           (setq ivy--old-cands ivy--all-candidates))
         (ivy--exhibit))
     (if (string= event "exited abnormally with code 1\n")
diff --git a/ivy.el b/ivy.el
index 6aa06a7..b6b5d00 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1289,6 +1289,23 @@ Insert .* between each char."
 
 (defvar inhibit-message)
 
+(defun ivy--sort-maybe (collection)
+  "Sort COLLECTION if needed."
+  (let ((sort (ivy-state-sort ivy-last))
+        entry)
+    (if (null sort)
+        collection
+      (let ((sort-fn (cond ((functionp sort)
+                            sort)
+                           ((setq entry (assoc (ivy-state-collection ivy-last)
+                                               ivy-sort-functions-alist))
+                            (cdr entry))
+                           (t
+                            (cdr (assoc t ivy-sort-functions-alist))))))
+        (if (functionp sort-fn)
+            (cl-sort (copy-sequence collection) sort-fn)
+          collection)))))
+
 (defun ivy--exhibit ()
   "Insert Ivy completions display.
 Should be run via minibuffer `post-command-hook'."
@@ -1301,7 +1318,8 @@ Should be run via minibuffer `post-command-hook'."
           (unless (equal ivy--old-text ivy-text)
             (while-no-input
               (setq ivy--all-candidates
-                    (funcall (ivy-state-collection ivy-last) ivy-text))
+                    (ivy--sort-maybe
+                     (funcall (ivy-state-collection ivy-last) ivy-text)))
               (setq ivy--old-text ivy-text)))
           (when ivy--all-candidates
             (ivy--insert-minibuffer



reply via email to

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