Subject: Re: bug#73047: 31; [PATCH] - add recency column to ibuffer

From: Daniel Mendler <[email-masked]>
Date: Sat, 11 Jan 2025 13:24:05 +0100

Eli Zaretskii <[email-masked]> writes:

>> Cc: JD Smith <[email-masked]>
>> Date: Sat, 28 Dec 2024 13:50:20 +0100
>> From:  Daniel Mendler via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>> 
>> Daniel Mendler <[email-masked]> writes:
>> 
>> > I've attached a patch to this mail which adds a recency column to
>> > Ibuffer. It uses the `seconds-to-string' function with the READABLE
>> > argument.
>> 
>> Please disregard the earlier patch, which was a wrong version.  I've
>> attached a better patch to this mail.  Thanks.
>
> Thanks.  Should this be called out in NEWS?

Yes. I've added an entry to the NEWS file. See the updated patch
attached to this mail. Thanks.

Daniel

>From d1529b64ae044c583376b38d49bfa032757025c7 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <[email-masked]>
Date: Sat, 28 Dec 2024 13:21:46 +0100
Subject: [PATCH] ibuffer: Define recency column

Define a column which shows how many seconds ago the respective
buffer has been displayed.  The time is formatted with the
`seconds-to-string' function, with the new arguments READABLE=t
and ABBREV=t.

* lisp/ibuffer.el (ibuffer-recency-header-map): New keymap.
(define-ibuffer-column recency): New column.
* etc/NEWS: Mention new `recency' column.
---
 etc/NEWS        |  5 +++++
 lisp/ibuffer.el | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 00e9e1871cd..a9774cf88d7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -315,6 +315,11 @@ modal editing packages.
 
 * Changes in Specialized Modes and Packages in Emacs 31.1
 
+** Ibuffer
+*** New 'recency' column.
+The variable 'ibuffer-formats' configures the Ibuffer formats.  Add
+'recency' to a format to display the column.
+
 ** Smerge
 *** New command 'smerge-extend' extends a conflict over surrounding lines.
 
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 64f1b5991c2..32bc8140703 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -775,6 +775,9 @@ ibuffer-size-header-map
 (defvar-keymap ibuffer-mode-header-map
   "<mouse-1>"      #'ibuffer-do-sort-by-major-mode)
 
+(defvar-keymap ibuffer-recency-header-map
+  "<mouse-1>"      #'ibuffer-do-sort-by-recency)
+
 (defvar-keymap ibuffer-mode-filter-group-map
   "<mouse-1>"      #'ibuffer-mouse-toggle-mark
   "<mouse-2>"      #'ibuffer-mouse-toggle-filter-group
@@ -1721,6 +1724,13 @@ size
        (format "%.0f" total))))
   (format "%s" (buffer-size)))
 
+(define-ibuffer-column recency
+  (:inline t :summarizer ignore :header-mouse-map ibuffer-recency-header-map)
+  (if-let* ((time (buffer-local-value 'buffer-display-time buffer)))
+      (format "%s ago" (seconds-to-string
+                        (float-time (time-since time)) t t))
+    "never"))
+
 (define-ibuffer-column mode
   (:inline t
    :header-mouse-map ibuffer-mode-header-map
-- 
2.45.2