More vtable fun

I was inspired by a bug report on tabulated-list-mode to do more work on vtable. (Funny how that works.)

As you probably won’t remember, vtable is a new library in Emacs 29 that aims at being a replacement for tabulated-list-mode, but with a much easier interface. For instance, the following is a toy replacement for C-x C-b:

(make-vtable
 :columns '((:name "Name" :width 20) "Size" "File")
 :objects (buffer-list)
 :actions '("k" kill-buffer
            "RET" display-buffer)
 :getter (lambda (object column vtable)
           (pcase (vtable-column vtable column)
             ("Name" (buffer-name object))
             ("Size" (buffer-size object))
             ("File" (or (buffer-file-name object) "")))))

And results in the following buffer:

The bug report pointed out that tabular displays might be more readable if columns had alternating colours, especially if they are very dense. This example doesn’t really have that problem, but it’s a nice test, anyway. So I’ve now made it possible to say:

:column-colors '("#202020" "#404040")

And then you get:

Conversely, the readability problem might be with the rows instead of the columns, so:

:row-colors '("#202020" "#404040")

A kind of a line printer vibe, eh?

And what if you combine both of them like so?

:row-colors '("#202020" "#404040")
:column-colors '("#202020" "#404040")

Well, of course:

Hey, that’s not so bad…

:row-colors '("red" "green")
:column-colors '("blue" "purple")

That, on the other hand, is pretty bad. Heh heh. I’m pretty sure I got the colour blending algo totally wrong.

And while I was poking at this, I also added a divider thing, so you
can say:

:divider-width "2px"

And get:

Or, well, anything:

:divider " 🍉 "

I think that’s the optimal table design, right? Right.

7 thoughts on “More vtable fun”

  1. How easy will it be to update a single row in the table? Would that require updating the entire table (buffer?) or can you update single rows? And looking at the `:action` keyword, how do the functions in that list know which object to act upon? Is it possible to pass a keymap to `:action`?

    Just asking because I have a particular use-case in mind, that I wasn’t able to use `tabulated-list-mode` for (either because it’s simply not possible or because I didn’t manage to figure out how…)

    1. Updating a single row should be fast — there’s supposed to be two choices for that: Either respect the current widths, or update the table if it needs widening/shortening. (But that’s not implemented yet.) The vtable manual has the details on :actions.

  2. Thanks for your answer. I could live with respecting the current widths, because in my use-case they are set by the user, I wouldn’t need to be able to update them.

Leave a Reply to AndréCancel reply