emacs-diffs
[Top][All Lists]
Advanced

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

master 7df1adab1e1 6/8: Use file-size-human-readable in eshell


From: Stefan Kangas
Subject: master 7df1adab1e1 6/8: Use file-size-human-readable in eshell
Date: Sat, 5 Aug 2023 12:00:12 -0400 (EDT)

branch: master
commit 7df1adab1e1a9a37920f3fa107794c2d081ebaf4
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>

    Use file-size-human-readable in eshell
    
    * lisp/eshell/esh-util.el (eshell-printable-size): Simplify using
    file-size-human-readable.
---
 lisp/eshell/esh-util.el | 40 +++++++++-------------------------------
 1 file changed, 9 insertions(+), 31 deletions(-)

diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el
index 82b0d9fc623..6353e3d4aae 100644
--- a/lisp/eshell/esh-util.el
+++ b/lisp/eshell/esh-util.el
@@ -439,37 +439,15 @@ Prepend remote identification of `default-directory', if 
any."
     (error "human-readable must be 1000 or 1024"))
   (let ((size (float (or filesize 0))))
     (if human-readable
-       (if (< size human-readable)
-           (if (= (round size) 0)
-               "0"
-             (if block-size
-                 "1.0k"
-               (format "%.0f" size)))
-         (setq size (/ size human-readable))
-         (if (< size human-readable)
-             (if (<= size 9.94)
-                 (format "%.1fk" size)
-               (format "%.0fk" size))
-           (setq size (/ size human-readable))
-           (if (< size human-readable)
-               (let ((str (if (<= size 9.94)
-                              (format "%.1fM" size)
-                            (format "%.0fM" size))))
-                 (if use-colors
-                     (put-text-property 0 (length str)
-                                        'face 'bold str))
-                 str)
-             (setq size (/ size human-readable))
-             (if (< size human-readable)
-                 (let ((str (if (<= size 9.94)
-                                (format "%.1fG" size)
-                              (format "%.0fG" size))))
-                   (if use-colors
-                       (put-text-property 0 (length str)
-                                          'face 'bold-italic str))
-                    str)
-                (let ((flavor (and (= human-readable 1000) 'si)))
-                  (file-size-human-readable filesize flavor))))))
+        (let* ((flavor (and (= human-readable 1000) 'si))
+               (str (file-size-human-readable size flavor)))
+          (if (not use-colors)
+              str
+            (cond ((> size (expt human-readable 3))
+                   (propertize str 'face 'bold-italic))
+                  ((> size (expt human-readable 2))
+                   (propertize str 'face 'bold))
+                  (t str))))
       (if block-size
          (setq size (/ size block-size)))
       (format "%.0f" size))))



reply via email to

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