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

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

[elpa] externals/disk-usage 3fb4803 07/48: Display total size


From: Stefan Monnier
Subject: [elpa] externals/disk-usage 3fb4803 07/48: Display total size
Date: Tue, 19 Feb 2019 07:59:58 -0500 (EST)

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

    Display total size
---
 disk-usage.el | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/disk-usage.el b/disk-usage.el
index ca4bcf6..4fd0a2e 100644
--- a/disk-usage.el
+++ b/disk-usage.el
@@ -38,7 +38,6 @@
 (require 'tabulated-list)
 (require 'cl-macs)
 
-;; TODO: Print total size.
 ;; TODO: Toggle display of full paths.  Make sur Helm-FF still works.
 ;; TODO: Graph support.
 ;; TODO: Include screenshots.
@@ -145,15 +144,30 @@ This is slow but does not require any external process."
                        disk-usage--du-args path))
        (buffer-string))))))
 
+(defun disk-usage--set-format (total-size)
+  (setq tabulated-list-format
+        `[("Size"
+           ,(if (eq disk-usage--format #'file-size-human-readable)
+                8
+              12)
+           ,disk-usage--sort . (:right-align t))
+          (,(format "Files totalling %sB (%s) in '%s'"
+                    total-size
+                    (file-size-human-readable total-size)
+                    default-directory)
+           0 t)]))
+
 (defun disk-usage--refresh (&optional directory)
   (setq directory (or directory default-directory))
   ;; TODO: Set tabulated-list-entries to a function?
-  (setq tabulated-list-entries
-        (mapcar (lambda (e) (list nil (vector (number-to-string (aref e 0))
-                                              (if (file-directory-p (aref e 1))
-                                                  (cons (aref e 1) (list 
'action (lambda (s) (disk-usage (button-label s)))))
-                                                (aref e 1)))))
-                (disk-usage--list directory))))
+  (let ((listing (disk-usage--list directory)))
+    (disk-usage--set-format (disk-usage--total listing))
+    (setq tabulated-list-entries
+          (mapcar (lambda (e) (list nil (vector (number-to-string (aref e 0))
+                                                (if (file-directory-p (aref e 
1))
+                                                    (cons (aref e 1) (list 
'action (lambda (s) (disk-usage (button-label s)))))
+                                                  (aref e 1)))))
+                  listing))))
 
 (defun disk-usage--sort-size-< (a b)
   (let ((size-a (string-to-number (aref (cadr a) 0)))
@@ -173,7 +187,6 @@ Takes a number and returns a string.
   (if (eq disk-usage--format #'file-size-human-readable)
       (setq disk-usage--format #'number-to-string)
     (setq disk-usage--format #'file-size-human-readable))
-  (disk-usage--set-format)
   (tabulated-list-revert))
 
 (defun disk-usage--print-entry (id cols)
@@ -205,19 +218,9 @@ beings."
                          ;; guesses the right file.
                          help-echo ,(aref cols 1)))))
 
-(defun disk-usage--set-format ()
-  (setq tabulated-list-format
-        `[("Size"
-           ,(if (eq disk-usage--format #'file-size-human-readable)
-                8
-              12)
-           ,disk-usage--sort . (:right-align t))
-          (,(format "Files in '%s'" default-directory) 0 t)]))
-
 (define-derived-mode disk-usage-mode tabulated-list-mode "Disk Usage"
   "Mode to display disk usage."
   ;; TODO: Option to display extra attributes.
-  (disk-usage--set-format)
   (setq tabulated-list-sort-key (cons "Size" 'flip))
   (setq tabulated-list-printer #'disk-usage--print-entry)
   (add-hook 'tabulated-list-revert-hook 'disk-usage--refresh nil t)



reply via email to

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