branch: externals/compat commit 625444b2b69724c71f6e4563b3d1d20d00c90dfb Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
compat-27: Add file-size-human-readable-iec --- NEWS.org | 1 + compat-27.el | 4 ++++ compat-tests.el | 6 +++++- compat.texi | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/NEWS.org b/NEWS.org index ed6425d2a2..2e8bdd9386 100644 --- a/NEWS.org +++ b/NEWS.org @@ -13,6 +13,7 @@ - compat-27: Add ~make-decoded-time~. - compat-27: Add ~minibuffer-history-value~. - compat-27: Add ~ring-resize~. +- compat-27: Add ~file-size-human-readable-iec~. - compat-28: Add ~color-dark-p~. - compat-28: Add ~directory-files-and-attributes~ with COUNT argument. - compat-28: Add ~text-quoting-style~. diff --git a/compat-27.el b/compat-27.el index eebd951fb0..de551642b0 100644 --- a/compat-27.el +++ b/compat-27.el @@ -375,6 +375,10 @@ in all cases, since that is the standard symbol for byte." (if (string= prefixed-unit "") "" (or space "")) prefixed-unit)))) +(compat-defun file-size-human-readable-iec (size) ;; <compat-tests:file-size-human-readable-iec> + "Human-readable string for SIZE bytes, using IEC prefixes." + (compat--file-size-human-readable size 'iec " ")) + (compat-defun exec-path () ;; <compat-tests:exec-path> "Return list of directories to search programs to run in remote subprocesses. The remote host is identified by `default-directory'. For remote diff --git a/compat-tests.el b/compat-tests.el index 58aa635dfa..5684aeb5ba 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -1515,6 +1515,10 @@ (should-equal (file-attribute-collect attrs 'group-id 'user-id) '(g u)) (should-equal (file-attribute-collect attrs 'size 'inode-number 'type) '(S i t)))) +(ert-deftest file-size-human-readable-iec () + (should-equal "1 KiB" (file-size-human-readable-iec 1024)) + (should-equal "2.1 MiB" (file-size-human-readable-iec 2223456))) + (ert-deftest file-size-human-readable () (should-equal "1000" (compat-call file-size-human-readable 1000)) (should-equal "1k" (compat-call file-size-human-readable 1024)) @@ -1523,7 +1527,7 @@ (should-equal "1T" (compat-call file-size-human-readable (expt 1024 4))) (should-equal "1k" (compat-call file-size-human-readable 1000 'si)) (should-equal "1KiB" (compat-call file-size-human-readable 1024 'iec)) - (should-equal "1KiB" (compat-call file-size-human-readable 1024 'iec)) + (should-equal "1__KiB" (compat-call file-size-human-readable 1024 'iec "__")) (should-equal "1 KiB" (compat-call file-size-human-readable 1024 'iec " ")) (should-equal "1KiA" (compat-call file-size-human-readable 1024 'iec nil "A")) (should-equal "1 KiA" (compat-call file-size-human-readable 1024 'iec " " "A")) diff --git a/compat.texi b/compat.texi index c944df6708..33876d7e62 100644 --- a/compat.texi +++ b/compat.texi @@ -1288,6 +1288,11 @@ This function returns non-@code{nil} if @var{mode} is derived from any of the major modes given by the symbols @var{modes}. @end defun +@c based on lisp/files.texi +@defun file-size-human-readable-iec size +Human-readable string for @var{size} bytes, using IEC prefixes. +@end defun + @c based on lispref/files.texi @defun make-empty-file filename &optional parents This function creates an empty file named @var{filename}. As