(In case someone wants the sorting, without the column, the built-in
s v will sort by "recency" and should (roughly, see below) do the trick.)
I wanted something like this as well, so I put the above comments to work.
First create the actual column, via
buffer-display-time is a local variable, hence
with-current-buffer sets the context. I've formatted it here with my preferred display style (
YYYY-MM-DD HH:MM) but that can obviously be changed; see the the docs on
format-time-string. If you want it relative, you'll have to come up with a more involved, custom function (the definitions of
calendar-count-days-region may provide a jumping off point).
(:name "Last-viewed" :inline t)
(format-time-string "%Y-%m-%d %R" buffer-display-time)))
Then we need to actually insert the column where you want it in
ibuffer-formats. Here's what I've done, YMMV:
'((mark modified read-only locked " "
(name 18 18 :left :elide)
(size 9 -1 :right)
(mode 16 16 :left :elide)
(last-viewed 18 -1 :left)
" " filename-and-process)
(mark " "
(name 16 -1)
" " filename)))
That's it — the column should appear, and you should be able to sort with
There's something weird about that "recency" sorting I can't quite figure out — I think it's that it derives the list from
buffer-list, so it interacts poorly with
ibuffer-auto-mode? Regardless, it doesn't seem to reliably sort by
buffer-display-time, so I also created a custom sorter function to override that:
"Sort the buffers by last viewed time."
(string-lessp (with-current-buffer (car a)
(format-time-string "%Y-%m-%d %R" buffer-display-time))
(with-current-buffer (car b)
(format-time-string "%Y-%m-%d %R" buffer-display-time))))
(define-key ibuffer-mode-map (kbd "s v") 'ibuffer-do-sort-by-last-edited)