# HG changeset patch # User Juanma Barranquero # Date 1051787781 0 # Node ID 5e248d2a95e7f3c51938323fd17852e96df5b7b8 # Parent fc9cb527333da2fb36476217341751e5eb675af6 (ls-lisp-format-file-size): New function to implement "-h" switch. (ls-lisp-format): Use it. diff -r fc9cb527333d -r 5e248d2a95e7 lisp/ls-lisp.el --- a/lisp/ls-lisp.el Thu May 01 04:39:07 2003 +0000 +++ b/lisp/ls-lisp.el Thu May 01 11:16:21 2003 +0000 @@ -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 @@ (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 @@ 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