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

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

[elpa] master 297008b 09/18: Allow to customize the file sorting order


From: Oleh Krehel
Subject: [elpa] master 297008b 09/18: Allow to customize the file sorting order
Date: Mon, 20 Apr 2015 12:39:04 +0000

branch: master
commit 297008b37236cd74f65f2ba1d198c6b04270ff11
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Allow to customize the file sorting order
    
    * ivy.el (ivy-sort-file-function-default): New defun.
    (ivy-sort-file-function): New defvar. Set this to your preference.
    (ivy--sorted-files): Update.
    
    Fixes #38
---
 ivy.el |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/ivy.el b/ivy.el
index 5cccbfe..50704f6 100644
--- a/ivy.el
+++ b/ivy.el
@@ -279,6 +279,21 @@ On error (read-only), call `ivy-on-del-error-function'."
        (when ivy-on-del-error-function
          (funcall ivy-on-del-error-function))))))
 
+(defun ivy-sort-file-function-default (x y)
+  "Compare two files X and Y.
+Prioritize directories."
+  (if (file-directory-p x)
+      (if (file-directory-p y)
+          (string< x y)
+        t)
+    (if (file-directory-p y)
+        nil
+      (string< x y))))
+
+(defvar ivy-sort-file-function 'ivy-sort-file-function-default
+  "The function that compares file names.
+It should take two string arguments and return nil and non-nil.")
+
 (defun ivy--sorted-files (dir)
   "Return the list of files in DIR.
 Directories come first."
@@ -288,14 +303,7 @@ Directories come first."
         seq
       (setq seq (cl-sort
                  (delete "./" (delete "../" seq))
-                 (lambda (x y)
-                   (if (file-directory-p x)
-                       (if (file-directory-p y)
-                           (string< x y)
-                         t)
-                     (if (file-directory-p y)
-                         nil
-                       (string< x y))))))
+                 ivy-sort-file-function))
       (dolist (dir ivy-extra-directories)
         (push dir seq))
       seq)))



reply via email to

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