branch: externals/compat commit ba2918d6d30022118e2f88d4394aeafb9b58166d Author: Philip Kaludercic <phil...@posteo.net> Commit: Philip Kaludercic <phil...@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)