emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/disk-usage 7e0705e 47/48: Display percentage in disk-us


From: Stefan Monnier
Subject: [elpa] externals/disk-usage 7e0705e 47/48: Display percentage in disk-usage
Date: Tue, 19 Feb 2019 08:00:06 -0500 (EST)

branch: externals/disk-usage
commit 7e0705e52a693f9258b23c02023ba9a2df8d0704
Author: Pierre Neidhardt <address@hidden>
Commit: Pierre Neidhardt <address@hidden>

    Display percentage in disk-usage
---
 disk-usage.el | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/disk-usage.el b/disk-usage.el
index eb04016..42ec3d0 100644
--- a/disk-usage.el
+++ b/disk-usage.el
@@ -228,6 +228,7 @@ Takes a number and returns a string."
                 8
               12)
            disk-usage--sort-by-size . (:right-align t))
+          ("%%" 6 disk-usage--sort-by-size . (:right-align t))
           (,(format "Files %sin '%s'"
                     (if total-size
                         (format "totalling %sB (%s) "
@@ -239,12 +240,16 @@ Takes a number and returns a string."
 
 (defun disk-usage--refresh (&optional directory)
   (setq directory (or directory default-directory))
-  (let ((listing (funcall disk-usage-list-function directory)))
-    (disk-usage--set-tabulated-list-format (disk-usage--total listing))
+  (let* ((listing (funcall disk-usage-list-function directory))
+         (total-size (disk-usage--total listing)))
+    (disk-usage--set-tabulated-list-format )
     (tabulated-list-init-header)
     (setq tabulated-list-entries
           (mapcar (lambda (file-info)
                     (list file-info (vector (number-to-string 
(disk-usage--file-info-size file-info))
+                                            (format "%.1f%%"
+                                                    (* 100 (/ (float 
(disk-usage--file-info-size file-info))
+                                                              total-size)))
                                             (let ((name 
(disk-usage--file-info-name file-info)))
                                               (if (file-directory-p name)
                                                   ;; Make button.
@@ -318,8 +323,9 @@ beings."
                          cols)
                      cols))))
       (setq x (tabulated-list-print-col 0 (funcall 
disk-usage-size-format-function (string-to-number (aref cols 0))) x))
-      (setq x (tabulated-list-print-col 1 (disk-usage--print-file-col (aref 
cols 1)) x))
-      (cl-loop for i from 2 below ncols
+      (setq x (tabulated-list-print-col 1 (aref cols 1) x))
+      (setq x (tabulated-list-print-col 2 (disk-usage--print-file-col (aref 
cols 2)) x))
+      (cl-loop for i from 3 below ncols
                do (setq x (tabulated-list-print-col i (aref cols i) x))))
     (insert ?\n)
     ;; Ever so slightly faster than calling `put-text-property' twice.



reply via email to

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