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

From: Daniel Mendler <[email-masked]>
Date: Sat, 28 Dec 2024 13:50:20 +0100

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.

Daniel

>From aed32b8dbf8fa0f17acc76ea2e444436bc347e12 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.
---
 lisp/ibuffer.el | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 405fb98d4d4..4f849bed27b 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