diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-18 21:21:39 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-18 21:34:16 +0100 |
| commit | 558053dcae1763003d15386092167a5078d9960a (patch) | |
| tree | 74ea254490ca3ced53efc84261db33c7f335c42c | |
| parent | 70ed788d8dd4ee1fcb7e73193c5016ea81edf24e (diff) | |
compat-28: Add directory-files-and-attributes with COUNT argument
| -rw-r--r-- | NEWS.org | 1 | ||||
| -rw-r--r-- | compat-28.el | 10 | ||||
| -rw-r--r-- | compat-tests.el | 7 |
3 files changed, 18 insertions, 0 deletions
@@ -7,6 +7,7 @@ - compat-27: Add ~make-decoded-time~. - compat-28: Add ~color-dark-p~. - compat-28: Add ~with-window-non-dedicated~. +- compat-28: Add ~directory-files-and-attributes~ with COUNT argument. - compat-29: Add ~compiled-function-p~. - compat-29: Add ~plist-get~ generalized variable. - compat-29: Add ~plistp~. diff --git a/compat-28.el b/compat-28.el index 6149106..953ce2e 100644 --- a/compat-28.el +++ b/compat-28.el @@ -135,6 +135,16 @@ If COUNT is non-nil and a natural number, the function will (setf (nthcdr count files) nil)) files)) +(compat-defun directory-files-and-attributes (directory &optional full match nosort id-format count) ;; <compat-tests:directory-files-and-attributs> + "Handle additional optional argument COUNT. +If COUNT is non-nil and a natural number, the function will + return COUNT number of file names (if so many are present)." + :explicit t + (let ((files (directory-files-and-attributes directory full match nosort id-format))) + (when (natnump count) + (setf (nthcdr count files) nil)) + files)) + ;;;; xfaces.c (compat-defun color-values-from-color-spec (spec) ;; <compat-tests:color-values-from-color-spec> diff --git a/compat-tests.el b/compat-tests.el index 9c8f4dd..b9e5a0b 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -1384,9 +1384,16 @@ (ert-deftest directory-files () (should-not (compat-call directory-files "." nil nil nil 0)) + (should (list-of-strings-p (compat-call directory-files "." nil nil nil 1))) (should-equal 1 (length (compat-call directory-files "." nil nil nil 1))) (should-equal 2 (length (compat-call directory-files "." nil nil nil 2)))) +(ert-deftest directory-files-and-attributes () + (should-not (compat-call directory-files-and-attributes "." nil nil nil nil 0)) + (should (consp (car (compat-call directory-files-and-attributes "." nil nil nil nil 1)))) + (should-equal 1 (length (compat-call directory-files-and-attributes "." nil nil nil nil 1))) + (should-equal 2 (length (compat-call directory-files-and-attributes "." nil nil nil nil 2)))) + (ert-deftest directory-name-p () (should (directory-name-p "/")) (should-not (directory-name-p "/file")) |
