From: Daniel Mendler Date: Sat, 11 Jan 2025 13:22:02 +0000 (+0100) Subject: ibuffer: New defcustom `ibuffer-human-readable-size' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d5b457ed38a92b300a9967908145bb1d8dd480be;p=emacs.git ibuffer: New defcustom `ibuffer-human-readable-size' * 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) --- diff --git a/etc/NEWS b/etc/NEWS index 7091732070d..157c96393f4 100644 --- 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. diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el index 723b18d7dc6..e911edcdfc1 100644 --- a/lisp/ibuffer.el +++ b/lisp/ibuffer.el @@ -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)