Site icon Random Thoughts

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.

Exit mobile version