]> git.eshelyaron.com Git - emacs.git/commitdiff
ibuffer: New defcustom `ibuffer-human-readable-size'
authorDaniel Mendler <mail@daniel-mendler.de>
Sat, 11 Jan 2025 13:22:02 +0000 (14:22 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 25 Jan 2025 17:46:44 +0000 (18:46 +0100)
* lisp/ibuffer.el (ibuffer-human-readable-size): New
defcustom.
(define-ibuffer-column size): Use it.

* etc/NEWS: Mention new defcustom.
(Bug#75495)

(cherry picked from commit 35576fde5670dffe104a6b2a76837a1f0a4c16ce)

etc/NEWS
lisp/ibuffer.el

index 7091732070d116fd5ad630631ee040c969382529..157c96393f4d442264cd6542e66c5ad62989d145 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -254,6 +254,9 @@ You can now set `asm-comment-char' from 'asm-mode-hook' instead.
 The variable 'ibuffer-formats' configures the Ibuffer formats.  Add
 'recency' to the format to display the column.
 
+*** New user option 'ibuffer-human-readable-size'.
+When non-nil, buffer sizes are shown in human readable format.
+
 ** Smerge
 *** New command 'smerge-extend' extends a conflict over surrounding lines.
 
index 723b18d7dc694da3e107b806c654533e19915827..e911edcdfc17b145fd2f9b35397239db54ea4b9b 100644 (file)
@@ -186,6 +186,12 @@ recreate it for the change to take effect."
                (sexp :tag "Test Form")
                 face)))
 
+(defcustom ibuffer-human-readable-size nil
+  "Show buffer sizes in human-readable format.
+Use the function `file-size-human-readable' for formatting."
+  :type 'boolean
+  :version "31.1")
+
 (defcustom ibuffer-use-other-window nil
   "If non-nil, display Ibuffer in another window by default."
   :type 'boolean)
@@ -1716,15 +1722,20 @@ If point is on a group name, this function operates on that group."
   (:inline t
    :header-mouse-map ibuffer-size-header-map
    :summarizer
-   (lambda (column-strings)
-     (let ((total 0))
-       (dolist (string column-strings)
-        (setq total
-              ;; like, ewww ...
-              (+ (float (string-to-number string))
-                 total)))
-       (format "%.0f" total))))
-  (format "%s" (buffer-size)))
+   (lambda (strings)
+     (let ((total
+            (cl-loop
+             for s in strings
+             for i = (text-property-not-all 0 (length s) 'ibuffer-size nil s)
+             if i sum (get-text-property i 'ibuffer-size s))))
+       (if ibuffer-human-readable-size
+           (file-size-human-readable total)
+         (number-to-string total)))))
+  (let ((size (buffer-size)))
+    (propertize (if ibuffer-human-readable-size
+                    (file-size-human-readable size)
+                  (number-to-string size))
+                'ibuffer-size size)))
 
 (define-ibuffer-column recency
   (:inline t :summarizer ignore :header-mouse-map ibuffer-recency-header-map)