all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#75495: [PATCH] ibuffer: New defcustom `ibuffer-human-readable-size'
@ 2025-01-11 13:28 Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2025-01-12 12:34 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-01-11 13:28 UTC (permalink / raw)
  To: 75495

[-- Attachment #1: Type: text/plain, Size: 166 bytes --]

Tags: patch

This patch adds the customization option `ibuffer-human-readable-size'.
If customized to t, buffer sizes in Ibuffer are shown in human readable
format.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ibuffer-New-defcustom-ibuffer-human-readable-size.patch --]
[-- Type: text/patch, Size: 2439 bytes --]

From e516d867edcfeda4840ba8e067534bc8582ee0e9 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <mail@daniel-mendler.de>
Date: Sat, 11 Jan 2025 14:22:02 +0100
Subject: [PATCH] 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.
---
 etc/NEWS        |  3 +++
 lisp/ibuffer.el | 26 +++++++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d017c872fa3..d20c71897bc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -338,6 +338,9 @@ modal editing packages.
 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 32bc8140703..65f8ca53693 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -186,6 +186,10 @@ ibuffer-fontification-alist
 		(sexp :tag "Test Form")
                 face)))
 
+(defcustom ibuffer-human-readable-size nil
+  "Show buffer sizes in human-readable format."
+  :type 'boolean)
+
 (defcustom ibuffer-use-other-window nil
   "If non-nil, display Ibuffer in another window by default."
   :type 'boolean)
@@ -1714,15 +1718,19 @@ size
   (: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 sum
+             (or (get-text-property 0 'ibuffer--buffer-size s) 0))))
+       (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--buffer-size size)))
 
 (define-ibuffer-column recency
   (:inline t :summarizer ignore :header-mouse-map ibuffer-recency-header-map)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#75495: [PATCH] ibuffer: New defcustom `ibuffer-human-readable-size'
  2025-01-11 13:28 bug#75495: [PATCH] ibuffer: New defcustom `ibuffer-human-readable-size' Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-01-12 12:34 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-01-12 12:34 UTC (permalink / raw)
  To: 75495

[-- Attachment #1: Type: text/plain, Size: 367 bytes --]

Daniel Mendler <mail@daniel-mendler.de> writes:

> This patch adds the customization option `ibuffer-human-readable-size'.
> If customized to t, buffer sizes in Ibuffer are shown in human readable
> format.

I have attached an improved version of the patch to this mail, where it
is ensured that the summarizer works for a left or right aligned size
column.

Daniel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ibuffer-New-defcustom-ibuffer-human-readable-size.patch --]
[-- Type: text/x-diff, Size: 2498 bytes --]

From 556b043da41f6196072d71cf4dfbc4fd2c1f1695 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <mail@daniel-mendler.de>
Date: Sat, 11 Jan 2025 14:22:02 +0100
Subject: [PATCH 1/2] 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.
---
 etc/NEWS        |  3 +++
 lisp/ibuffer.el | 27 ++++++++++++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d017c872fa3..d20c71897bc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -338,6 +338,9 @@ modal editing packages.
 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 32bc8140703..cb69915e6b7 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -186,6 +186,10 @@ ibuffer-fontification-alist
 		(sexp :tag "Test Form")
                 face)))
 
+(defcustom ibuffer-human-readable-size nil
+  "Show buffer sizes in human-readable format."
+  :type 'boolean)
+
 (defcustom ibuffer-use-other-window nil
   "If non-nil, display Ibuffer in another window by default."
   :type 'boolean)
@@ -1714,15 +1718,20 @@ size
   (: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 sum
+             (or (get-text-property (1- (length s)) 'ibuffer-size s)
+                 (get-text-property 0 'ibuffer-size s) 0))))
+       (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)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-12 12:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-11 13:28 bug#75495: [PATCH] ibuffer: New defcustom `ibuffer-human-readable-size' Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-01-12 12:34 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.