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

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

[elpa] externals/ivy-hydra a159810 120/395: counsel-recentf: Sort by acc


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra a159810 120/395: counsel-recentf: Sort by access time when including XDG list.
Date: Thu, 25 Feb 2021 08:31:44 -0500 (EST)

branch: externals/ivy-hydra
commit a1598100ce063cdf72b3de9ad4945ea8503b5133
Author: dude <ej32u@protonmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    counsel-recentf: Sort by access time when including XDG list.
    
    To interleave the XDG list and Emacs's `recentf-list`, sort the combined 
list by
    access time using the `file-attributes` function.
    
    Another approach would be to sort by modification time with
    `file-newer-than-file-p`, but since not all viewed files are modified, 
access
    time is probably the better choice.
    
    Edit doc strings to better compy with checkdoc test.
    
    Fixes #2423
---
 counsel.el | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/counsel.el b/counsel.el
index f681510..bf17bfa 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2246,13 +2246,23 @@ 
https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec/.";
    ("x" counsel-find-file-extern "open externally")))
 
 (defun counsel-recentf-candidates ()
-  "Return candidates for `counsel-recentf'."
-  (append (mapcar #'substring-no-properties recentf-list)
-          (and counsel-recentf-include-xdg-list
-               (version< "25" emacs-version)
-               (counsel--recentf-get-xdg-recent-files))))
+  "Return candidates for `counsel-recentf'.
+
+When `counsel-recentf-include-xdg-list' is non-nil, also include
+the files in said list, sorting the combined list by file access
+time."
+  (if (and counsel-recentf-include-xdg-list
+           (version< "25" emacs-version))
+      (delete-dups
+       (sort (append (mapcar #'substring-no-properties recentf-list)
+                     (counsel--recentf-get-xdg-recent-files))
+             (lambda (file1 file2)
+               (> (time-to-seconds (file-attribute-access-time 
(file-attributes file1)))
+                  (time-to-seconds (file-attribute-access-time 
(file-attributes file2)))))))
+    (mapcar #'substring-no-properties recentf-list)))
 
 (defun counsel--strip-prefix (prefix str)
+  "Strip PREFIX from STR."
   (let ((l (length prefix)))
     (when (string= (substring str 0 l) prefix)
       (substring str l))))
@@ -2268,7 +2278,7 @@ Requires Emacs 25.
 
 It searches for the file \"recently-used.xbel\" which lists files
 and directories, in the directory returned by the function
-`xdg-data-home'. This file is processed using functionality
+`xdg-data-home'.  This file is processed using functionality
 provided by the libxml2 bindings and the \"dom\" library."
   (require 'dom)
   (let ((file-of-recent-files



reply via email to

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