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

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

[elpa] externals/compat ba2918d6d3 21/27: Add file-backup-file-names


From: ELPA Syncer
Subject: [elpa] externals/compat ba2918d6d3 21/27: Add file-backup-file-names
Date: Sat, 5 Mar 2022 04:57:28 -0500 (EST)

branch: externals/compat
commit ba2918d6d30022118e2f88d4394aeafb9b58166d
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add file-backup-file-names
---
 MANUAL       |  1 +
 compat-28.el | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/MANUAL b/MANUAL
index 16b42cd83d..b4577489ac 100644
--- a/MANUAL
+++ b/MANUAL
@@ -355,6 +355,7 @@ provided by compat by default:
 - Function ~color-values-from-color-spec~ :: Defined in ~xfaces.c~.
 - Function ~file-modes-number-to-symbolic~ :: See [[info:elisp#Changing 
Files][(elisp) Changing
   Files]].
+- Function ~file-backup-file-names~ :: See [[info:elisp#Backup Names][(elisp) 
Backup Names]].
 
 These functions are prefixed with ~compat~ prefix, and are only loaded
 when ~compat-28~ is required:
diff --git a/compat-28.el b/compat-28.el
index 6324126e8c..27b1dba7a2 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -663,6 +663,27 @@ the leading `-' char."
        (if (zerop (logand   1 mode)) ?- ?x)
      (if (zerop (logand   1 mode)) ?T ?t))))
 
+(compat-defun file-backup-file-names (filename)
+  "Return a list of backup files for FILENAME.
+The list will be sorted by modification time so that the most
+recent files are first."
+  ;; `make-backup-file-name' will get us the right directory for
+  ;; ordinary or numeric backups.  It might create a directory for
+  ;; backups as a side-effect, according to `backup-directory-alist'.
+  (let* ((filename (file-name-sans-versions
+                   (make-backup-file-name (expand-file-name filename))))
+         (dir (file-name-directory filename)))
+    (sort
+     (seq-filter
+      (lambda (candidate)
+        (and (backup-file-name-p candidate)
+             (string= (file-name-sans-versions candidate) filename)))
+      (mapcar
+       (lambda (file)
+         (concat dir file))
+       (file-name-all-completions (file-name-nondirectory filename) dir)))
+     #'file-newer-than-file-p)))
+
 ;;;; Defined in minibuffer.el
 
 (compat-defun format-prompt (prompt default &rest format-args)



reply via email to

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