branch: master commit 073b071a12e7c5e6004b5bb68e7e48ce980401bf Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
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."