emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r115593: Fix bug #16179 with ls-lisp emulation of th


From: Eli Zaretskii
Subject: [Emacs-diffs] trunk r115593: Fix bug #16179 with ls-lisp emulation of the ls -s switch.
Date: Wed, 18 Dec 2013 16:02:20 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 115593
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/16179
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Wed 2013-12-18 18:01:43 +0200
message:
  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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/ls-lisp.el                lslisp.el-20091113204419-o5vbwnq5f7feedwu-191
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-12-18 14:54:24 +0000
+++ b/lisp/ChangeLog    2013-12-18 16:01:43 +0000
@@ -1,3 +1,12 @@
+2013-12-18  Eli Zaretskii  <address@hidden>
+
+       * 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.  (Bug#16179)
+
 2013-12-18  Tassilo Horn  <address@hidden>
 
        * textmodes/reftex-vars.el (reftex-label-alist-builtin): Reference

=== modified file 'lisp/ls-lisp.el'
--- a/lisp/ls-lisp.el   2013-09-17 07:43:14 +0000
+++ b/lisp/ls-lisp.el   2013-12-18 16:01:43 +0000
@@ -208,6 +208,8 @@
   "Format to display integer file sizes.")
 (defvar ls-lisp-filesize-f-fmt "%.0f"
   "Format to display float file sizes.")
+(defvar ls-lisp-filesize-b-fmt "%.0f"
+  "Format to display file sizes in blocks (for the -s switch).")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -356,17 +358,15 @@
          (setq ls-lisp-gid-d-fmt (format " %%-%dd" max-gid-len))
          (setq ls-lisp-gid-s-fmt (format " %%-%ds" max-gid-len))
          (setq ls-lisp-filesize-d-fmt
-               (format " %%%dd"
-                       (if (memq ?s switches)
-                           (length (format "%.0f"
-                                           (fceiling (/ max-file-size 
1024.0))))
-                         (length (format "%.0f" max-file-size)))))
+               (format " %%%dd" (length (format "%.0f" max-file-size))))
          (setq ls-lisp-filesize-f-fmt
-               (format " %%%d.0f"
-                       (if (memq ?s switches)
+               (format " %%%d.0f" (length (format "%.0f" max-file-size))))
+         (if (memq ?s switches)
+             (setq ls-lisp-filesize-b-fmt
+                   (format "%%%d.0f "
                            (length (format "%.0f"
-                                           (fceiling (/ max-file-size 
1024.0))))
-                         (length (format "%.0f" max-file-size)))))
+                                           (fceiling
+                                            (/ max-file-size 1024.0)))))))
          (setq files file-alist)
          (while files                  ; long (-l) format
            (setq elt (car files)
@@ -653,9 +653,20 @@
                                   (cdr inode))))
                    (format " %18d " inode))))
            ;; nil is treated like "" in concat
-           (if (memq ?s switches)      ; size in K
-               (format ls-lisp-filesize-f-fmt
-                       (fceiling (/ file-size 1024.0))))
+           (if (memq ?s switches)      ; size in K, rounded up
+               ;; In GNU ls, -h affects the size in blocks, displayed
+               ;; by -s, as well.
+               (if (memq ?h switches)
+                   (format "%6s "
+                           (file-size-human-readable
+                            ;; We use 1K as "block size", although
+                            ;; most Windows volumes use 4KB to 8KB
+                            ;; clusters, and exFAT will usually have
+                            ;; clusters of 32KB or even 128KB.  See
+                            ;; KB article 140365 for the details.
+                            (* 1024.0 (fceiling (/ file-size 1024.0)))))
+                 (format ls-lisp-filesize-b-fmt
+                         (fceiling (/ file-size 1024.0)))))
            drwxrwxrwx                  ; attribute string
            (if (memq 'links ls-lisp-verbosity)
                (format "%3d" (nth 1 file-attr))) ; link count
@@ -737,7 +748,7 @@
                  ls-lisp-filesize-f-fmt
                ls-lisp-filesize-d-fmt)
              file-size)
-    (format " %7s" (file-size-human-readable file-size))))
+    (format " %6s" (file-size-human-readable file-size))))
 
 (provide 'ls-lisp)
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]