diff options
author | Juanma Barranquero <lekktu@gmail.com> | 2003-05-01 11:16:21 +0000 |
---|---|---|
committer | Juanma Barranquero <lekktu@gmail.com> | 2003-05-01 11:16:21 +0000 |
commit | a3723f134b507d2bcedda70c0e0331d059eafdc8 (patch) | |
tree | f6804de8b3b0fc78880061473c8824741d370a64 /lisp/ls-lisp.el | |
parent | 2bf07f07f73381041e8d6e2a5b643b0cb95d9423 (diff) | |
download | emacs-a3723f134b507d2bcedda70c0e0331d059eafdc8.tar.gz |
(ls-lisp-format-file-size): New function to implement "-h" switch.
(ls-lisp-format): Use it.
Diffstat (limited to 'lisp/ls-lisp.el')
-rw-r--r-- | lisp/ls-lisp.el | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index 1d0ace7613e..54c76a9d725 100644 --- a/lisp/ls-lisp.el +++ b/lisp/ls-lisp.el @@ -65,6 +65,8 @@ ;;; Code: +(eval-when-compile (require 'cl)) + (defgroup ls-lisp nil "Emulate the ls program completely in Emacs Lisp." :version "21.1" @@ -533,7 +535,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) " " @@ -587,6 +589,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 |