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

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

[elpa] externals/dired-duplicates 2f9735e213 15/57: Implement applying c


From: ELPA Syncer
Subject: [elpa] externals/dired-duplicates 2f9735e213 15/57: Implement applying custom file filter functions
Date: Sat, 4 Nov 2023 06:58:27 -0400 (EDT)

branch: externals/dired-duplicates
commit 2f9735e213127a48f106ade32031177cf7d2047d
Author: Harald Judt <h.judt@gmx.at>
Commit: Harald Judt <h.judt@gmx.at>

    Implement applying custom file filter functions
    
    Introduce a new variable for calling custom file filter functions to filter 
out
    unwanted candidates. For example, these could filter by size or modification
    date.
---
 find-dupes-dired.el | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/find-dupes-dired.el b/find-dupes-dired.el
index 92dd78843d..3783dbdf7d 100644
--- a/find-dupes-dired.el
+++ b/find-dupes-dired.el
@@ -32,6 +32,15 @@ ascending or descending order."
   :type '(choice (const :tag "Ascending" :value <)
                  (const :tag "Descending" :value >)))
 
+(defcustom find-dupes-file-filter-functions
+  nil
+  "Filter functions applied to all files found in a directory. A
+filter function must accept as its single argument the file and
+return boolean t if the file matches a criteria, otherwise nil."
+  :group 'find-dupes-dired
+  :tag "File filter functions"
+  :type 'hook)
+
 (defvar find-dupes-directories nil
   "List of directories that will be searched for duplicate files.")
 
@@ -66,12 +75,20 @@ ascending or descending order."
      (when find-dupes-use-separator-file
        (find-dupes--remove-separator-file))))
 
+(defun find-dupes--apply-file-filter-functions (files)
+  (if (and find-dupes-file-filter-functions files)
+      (dolist (filter-func find-dupes-file-filter-functions files)
+        (setf files (delete-if-not filter-func files)))
+    files))
+
 (defun find-dupes--duplicate-files (directories)
   "Given one or more root directories, search below the directories
 for duplicate files. Returns a hash-table with the checksums as
 keys and a list of size and duplicate files as values."
-  (cl-loop with files = (mapcan #'(lambda (d) (directory-files-recursively d 
".*"))
-                                (ensure-list directories))
+  (cl-loop with files = (find-dupes--apply-file-filter-functions
+                         (mapcan #'(lambda (d)
+                                     (directory-files-recursively d ".*"))
+                                       (ensure-list directories)))
            and same-size-table = (make-hash-table)
            and checksum-table = (make-hash-table :test 'equal)
            for f in files



reply via email to

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