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.

13 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.

  3. Is it possible to change the font used in vtable ? I’ve defined my own defface which inherits from ‘vtable in order to make it larger and bold. I’ve even inherited from fl:function-name-face to see if it would change color. Nothing seems to work.

    There are a number of things I’d like to see, but I’m wondering if it’s even feasable.
    I would have thought passing a :face in would work.

    I’d like centering, Highlight/different face of current cell, and colored vertical and horizontal separators. But I don’t even see that there is horizontal separators.

    There are very few examples of vtable usage, I found none in my entire Elpa install.
    I don’t mind tabulated list, but it only seems to move by rows not x,y however you like.

    1. To use a different face in vtable, just say “:face ‘whatever” in `make-vtable’. vtable is documented in the Emacs Lisp manual, and there should be copious examples there.

      1. yes. thats what I did. It didn’t matter what I changed or even if I just
        used a different basic system face. I’m not unfamiliar with defface.

        I haven’t seen a single example of changing the face of a vtable. I even
        searched for vtable with ag through my elpa packages.

        I’ve read the manual thoroughly multiple times, and I’ve even followed
        my face into the table definition with the debugger. I didn’t dig deeper to
        see why it is not used.

        I figured out that I need to propertize the rows to get anything looking
        nice anyway, so I might just switch to tabulated-list.

Leave a Reply