aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/files.el28
-rw-r--r--lisp/ls-lisp.el10
3 files changed, 36 insertions, 9 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f06ca5bfaf9..6dfcbdbcdc7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12011-04-08 Eli Zaretskii <eliz@gnu.org>
2
3 * files.el (file-size-human-readable): New function.
4
5 * ls-lisp.el (ls-lisp-format-file-size): Use it, instead of
6 computing the representation inline. Don't require `cl'.
7
12011-04-08 Glenn Morris <rgm@gnu.org> 82011-04-08 Glenn Morris <rgm@gnu.org>
2 9
3 * man.el (Man-page-header-regexp): Solaris < 2.6 no longer supported. 10 * man.el (Man-page-header-regexp): Solaris < 2.6 no longer supported.
diff --git a/lisp/files.el b/lisp/files.el
index 7d8f3ee4503..fd241041b74 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1140,6 +1140,34 @@ it means chase no more than that many links and then stop."
1140 (setq count (1+ count)))) 1140 (setq count (1+ count))))
1141 newname)) 1141 newname))
1142 1142
1143;; A handy function to display file sizes in human-readable form.
1144;; See http://en.wikipedia.org/wiki/Kibibyte for the reference.
1145(defun file-size-human-readable (file-size &optional flavor)
1146 "Produce a string showing FILE-SIZE in human-readable form.
1147
1148Optional second argument FLAVOR controls the units and the display format:
1149
1150 If FLAVOR is nil or omitted, each kilobyte is 1024 bytes and the produced
1151 suffixes are \"k\", \"M\", \"G\", \"T\", etc.
1152 If FLAVOR is `si', each kilobyte is 1000 bytes and the produced suffixes
1153 are \"k\", \"M\", \"G\", \"T\", etc.
1154 If FLAVOR is `iec', each kilobyte is 1024 bytes and the produced suffixes
1155 are \"KiB\", \"MiB\", \"GiB\", \"TiB\", etc."
1156 (let ((power (if (or (null flavor) (eq flavor 'iec))
1157 1024.0
1158 1000.0))
1159 (post-fixes
1160 ;; none, kilo, mega, giga, tera, peta, exa, zetta, yotta
1161 (list "" "k" "M" "G" "T" "P" "E" "Z" "Y")))
1162 (while (and (>= file-size power) (cdr post-fixes))
1163 (setq file-size (/ file-size power)
1164 post-fixes (cdr post-fixes)))
1165 (format "%.0f%s%s" file-size
1166 (if (and (eq flavor 'iec) (string= (car post-fixes) "k"))
1167 "K"
1168 (car post-fixes))
1169 (if (eq flavor 'iec) "iB" ""))))
1170
1143(defun make-temp-file (prefix &optional dir-flag suffix) 1171(defun make-temp-file (prefix &optional dir-flag suffix)
1144 "Create a temporary file. 1172 "Create a temporary file.
1145The returned file name (created by appending some random characters at the end 1173The returned file name (created by appending some random characters at the end
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 55ec835831a..44e8bce5b8d 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -62,8 +62,6 @@
62 62
63;;; Code: 63;;; Code:
64 64
65(eval-when-compile (require 'cl))
66
67(defgroup ls-lisp nil 65(defgroup ls-lisp nil
68 "Emulate the ls program completely in Emacs Lisp." 66 "Emulate the ls program completely in Emacs Lisp."
69 :version "21.1" 67 :version "21.1"
@@ -726,13 +724,7 @@ All ls time options, namely c, t and u, are handled."
726 ls-lisp-filesize-f-fmt 724 ls-lisp-filesize-f-fmt
727 ls-lisp-filesize-d-fmt) 725 ls-lisp-filesize-d-fmt)
728 file-size) 726 file-size)
729 (if (< file-size 1024) 727 (format " %4s" (file-size-human-readable file-size))))
730 (format " %4d" file-size)
731 (do ((file-size (/ file-size 1024.0) (/ file-size 1024.0))
732 ;; kilo, mega, giga, tera, peta, exa
733 (post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes)))
734 ((< file-size 1024)
735 (format " %3.0f%s" file-size (car post-fixes)))))))
736 728
737(provide 'ls-lisp) 729(provide 'ls-lisp)
738 730