]> git.eshelyaron.com Git - emacs.git/commitdiff
(ls-lisp-format-file-size): New function to implement "-h" switch.
authorJuanma Barranquero <lekktu@gmail.com>
Thu, 1 May 2003 11:31:31 +0000 (11:31 +0000)
committerJuanma Barranquero <lekktu@gmail.com>
Thu, 1 May 2003 11:31:31 +0000 (11:31 +0000)
(ls-lisp-format): Use it.

lisp/ChangeLog
lisp/ls-lisp.el

index 0c0c9172bd45bb30a17407955872073f29605259..f1b7539530669ce71c74a3d40c276b39066554d2 100644 (file)
@@ -1,4 +1,10 @@
-2003-04-23  Kenichi Handa  <handa@etlken2>
+2003-05-01  Eduardo Mu\e,Aq\e(Boz  <emufer@terra.es>  (tiny change)
+
+       * ls-lisp.el (ls-lisp-format-file-size): New function to implement
+       "-h" switch.
+       (ls-lisp-format): Use it.
+
+2003-04-23  Kenichi Handa  <handa@m17n.org>
 
        * language/devanagari.el ("Devanagari"): Documentation string
        modified.
index f30d98daa6c479f806c4b909970449a604947873..2de5559d3829fec574a5a11bfd759b1a3c7422a7 100644 (file)
@@ -65,6 +65,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
+
 ;;;###autoload
 (defgroup ls-lisp nil
   "Emulate the ls program completely in Emacs Lisp."
@@ -497,7 +499,7 @@ SWITCHES, TIME-INDEX and NOW give the full switch list and time data."
                        (if group
                            (format " %-8s" group)
                          (format " %-8d" gid))))))
-           (format (if (floatp file-size) " %8.0f" " %8d") file-size)
+           (ls-lisp-format-file-size file-size (memq ?h switches))
            " "
            (ls-lisp-format-time file-attr time-index now)
            " "
@@ -537,6 +539,15 @@ All ls time options, namely c, t and u, are handled."
         time)
       (error "Unk  0  0000"))))
 
+(defun ls-lisp-format-file-size (file-size human-readable)
+  (if (or (not human-readable)
+          (< file-size 1024))
+      (format (if (floatp file-size) " %8.0f" " %8d") file-size)
+    (do ((file-size (/ file-size 1024.0) (/ file-size 1024.0))
+         ;; kilo, mega, giga, tera, peta, exa
+         (post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes)))
+        ((< file-size 1024) (format " %7.0f%s"  file-size (car post-fixes))))))
+
 (provide 'ls-lisp)
 
 ;;; ls-lisp.el ends here