emacs-diffs
[Top][All Lists]
Advanced

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

master a90dc11e24: Improve format of values returned by 'file-size-human


From: Eli Zaretskii
Subject: master a90dc11e24: Improve format of values returned by 'file-size-human-readable'
Date: Mon, 14 Feb 2022 12:00:48 -0500 (EST)

branch: master
commit a90dc11e24895c4e6e5bfcfc991d8524f4075223
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Improve format of values returned by 'file-size-human-readable'
    
    * lisp/files.el (file-size-human-readable): Emit one digit of the
    fractional part of the size only if there's just one digit before
    the decimal point.
---
 lisp/files.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/files.el b/lisp/files.el
index cfa1a5972c..b2792818e6 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1493,8 +1493,13 @@ in all cases, since that is the standard symbol for 
byte."
                                (if (string= prefix "") "" "i")
                                (or unit "B"))
                             (concat prefix unit))))
-      (format (if (and (>= (mod file-size 1.0) 0.05)
+      ;; Mimic what GNU "ls -lh" does:
+      ;; If the formatted size will have just one digit before the decimal...
+      (format (if (and (< file-size 10)
+                       ;; ...and its fractional part is not too small...
+                       (>= (mod file-size 1.0) 0.05)
                        (< (mod file-size 1.0) 0.95))
+                  ;; ...then emit one digit after the decimal.
                  "%.1f%s%s"
                "%.0f%s%s")
              file-size



reply via email to

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