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

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

[elpa] master 073b071 115/167: Allow to sort files by last modification


From: Oleh Krehel
Subject: [elpa] master 073b071 115/167: Allow to sort files by last modification time.
Date: Tue, 08 Dec 2015 10:50:24 +0000

branch: master
commit 073b071a12e7c5e6004b5bb68e7e48ce980401bf
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Allow to sort files by last modification time.
    
    * ivy.el (ivy--sort-files-by-date): New defun.
    
    Example of use:
    
    (add-to-list
     'ivy-sort-matches-functions-alist
     '(read-file-name-internal . ivy--sort-files-by-date))
    
    This will result in e.g. `find-file' or `counsel-find-file' sorting
    files by last modification time.
    
    Fixes #213
---
 ivy.el |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/ivy.el b/ivy.el
index 0f62ab9..3dbfd82 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1726,6 +1726,15 @@ not matched collection functions.
 The alist VAL is a sorting function with the signature of
 `ivy--prefix-sort'.")
 
+(defun ivy--sort-files-by-date (_name candidates)
+  "Re-soft CANDIDATES according to file modification date."
+  (let ((default-directory ivy--directory))
+    (cl-sort candidates
+             (lambda (f1 f2)
+               (time-less-p
+                (nth 5 (file-attributes f2))
+                (nth 5 (file-attributes f1)))))))
+
 (defun ivy--sort (name candidates)
   "Re-sort CANDIDATES according to NAME.
 All CANDIDATES are assumed to match NAME."



reply via email to

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