aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2013-12-18 18:01:43 +0200
committerEli Zaretskii2013-12-18 18:01:43 +0200
commit64e4c76edfed1464ee91848bba29ee0d385208e1 (patch)
treeea9b1da48088ccf443b0cc8cff529ca3376ee348
parent18874304db15434bbc2a9bcf28b71c86f6dc4bd8 (diff)
downloademacs-64e4c76edfed1464ee91848bba29ee0d385208e1.tar.gz
emacs-64e4c76edfed1464ee91848bba29ee0d385208e1.zip
Fix bug #16179 with ls-lisp emulation of the ls -s switch.
src/ls-lisp.el (ls-lisp-insert-directory): Don't modify %d and %f formats for displaying file sizes when the -s switch is given. Instead, compute a separate format for displaying the size in blocks, which is displayed in addition to the "regular" size. When -h is given in addition to -s, produce size in blocks in human-readable form as well.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/ls-lisp.el37
2 files changed, 33 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e8bd967c0f2..9b68897a32b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12013-12-18 Eli Zaretskii <eliz@gnu.org>
2
3 * ls-lisp.el (ls-lisp-insert-directory): Don't modify %d and %f
4 formats for displaying file sizes when the -s switch is given.
5 Instead, compute a separate format for displaying the size in
6 blocks, which is displayed in addition to the "regular" size.
7 When -h is given in addition to -s, produce size in blocks in
8 human-readable form as well. (Bug#16179)
9
12013-12-18 Tassilo Horn <tsdh@gnu.org> 102013-12-18 Tassilo Horn <tsdh@gnu.org>
2 11
3 * textmodes/reftex-vars.el (reftex-label-alist-builtin): Reference 12 * textmodes/reftex-vars.el (reftex-label-alist-builtin): Reference
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 67bcdc8c82b..ae6fcb0599d 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -208,6 +208,8 @@ to fail to line up, e.g. if month names are not all of the same length."
208 "Format to display integer file sizes.") 208 "Format to display integer file sizes.")
209(defvar ls-lisp-filesize-f-fmt "%.0f" 209(defvar ls-lisp-filesize-f-fmt "%.0f"
210 "Format to display float file sizes.") 210 "Format to display float file sizes.")
211(defvar ls-lisp-filesize-b-fmt "%.0f"
212 "Format to display file sizes in blocks (for the -s switch).")
211 213
212;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 214;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
213 215
@@ -356,17 +358,15 @@ not contain `d', so that a full listing is expected."
356 (setq ls-lisp-gid-d-fmt (format " %%-%dd" max-gid-len)) 358 (setq ls-lisp-gid-d-fmt (format " %%-%dd" max-gid-len))
357 (setq ls-lisp-gid-s-fmt (format " %%-%ds" max-gid-len)) 359 (setq ls-lisp-gid-s-fmt (format " %%-%ds" max-gid-len))
358 (setq ls-lisp-filesize-d-fmt 360 (setq ls-lisp-filesize-d-fmt
359 (format " %%%dd" 361 (format " %%%dd" (length (format "%.0f" max-file-size))))
360 (if (memq ?s switches)
361 (length (format "%.0f"
362 (fceiling (/ max-file-size 1024.0))))
363 (length (format "%.0f" max-file-size)))))
364 (setq ls-lisp-filesize-f-fmt 362 (setq ls-lisp-filesize-f-fmt
365 (format " %%%d.0f" 363 (format " %%%d.0f" (length (format "%.0f" max-file-size))))
366 (if (memq ?s switches) 364 (if (memq ?s switches)
365 (setq ls-lisp-filesize-b-fmt
366 (format "%%%d.0f "
367 (length (format "%.0f" 367 (length (format "%.0f"
368 (fceiling (/ max-file-size 1024.0)))) 368 (fceiling
369 (length (format "%.0f" max-file-size))))) 369 (/ max-file-size 1024.0)))))))
370 (setq files file-alist) 370 (setq files file-alist)
371 (while files ; long (-l) format 371 (while files ; long (-l) format
372 (setq elt (car files) 372 (setq elt (car files)
@@ -653,9 +653,20 @@ SWITCHES and TIME-INDEX give the full switch list and time data."
653 (cdr inode)))) 653 (cdr inode))))
654 (format " %18d " inode)))) 654 (format " %18d " inode))))
655 ;; nil is treated like "" in concat 655 ;; nil is treated like "" in concat
656 (if (memq ?s switches) ; size in K 656 (if (memq ?s switches) ; size in K, rounded up
657 (format ls-lisp-filesize-f-fmt 657 ;; In GNU ls, -h affects the size in blocks, displayed
658 (fceiling (/ file-size 1024.0)))) 658 ;; by -s, as well.
659 (if (memq ?h switches)
660 (format "%6s "
661 (file-size-human-readable
662 ;; We use 1K as "block size", although
663 ;; most Windows volumes use 4KB to 8KB
664 ;; clusters, and exFAT will usually have
665 ;; clusters of 32KB or even 128KB. See
666 ;; KB article 140365 for the details.
667 (* 1024.0 (fceiling (/ file-size 1024.0)))))
668 (format ls-lisp-filesize-b-fmt
669 (fceiling (/ file-size 1024.0)))))
659 drwxrwxrwx ; attribute string 670 drwxrwxrwx ; attribute string
660 (if (memq 'links ls-lisp-verbosity) 671 (if (memq 'links ls-lisp-verbosity)
661 (format "%3d" (nth 1 file-attr))) ; link count 672 (format "%3d" (nth 1 file-attr))) ; link count
@@ -737,7 +748,7 @@ All ls time options, namely c, t and u, are handled."
737 ls-lisp-filesize-f-fmt 748 ls-lisp-filesize-f-fmt
738 ls-lisp-filesize-d-fmt) 749 ls-lisp-filesize-d-fmt)
739 file-size) 750 file-size)
740 (format " %7s" (file-size-human-readable file-size)))) 751 (format " %6s" (file-size-human-readable file-size))))
741 752
742(provide 'ls-lisp) 753(provide 'ls-lisp)
743 754