aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-21 20:58:55 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-21 20:58:55 +0100
commit625444b2b69724c71f6e4563b3d1d20d00c90dfb (patch)
tree5a5263329cca42c6c32e4891d1e3af04ee35b9e2
parent6d3eba3e872bf12d1e9647b97df930932de6577c (diff)
compat-27: Add file-size-human-readable-iec
-rw-r--r--NEWS.org1
-rw-r--r--compat-27.el4
-rw-r--r--compat-tests.el6
-rw-r--r--compat.texi5
4 files changed, 15 insertions, 1 deletions
diff --git a/NEWS.org b/NEWS.org
index ed6425d..2e8bdd9 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 eebd951..de55164 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 58aa635..5684aeb 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 c944df6..33876d7 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