Subject: bug#69454: Not possible to insert an empty vtable

From: Joost Kremers <[email-masked]>
Date: Tue, 30 Apr 2024 11:10:32 +0200

On Sat, Mar 09 2024, Eli Zaretskii wrote:
>> Date: Wed, 28 Feb 2024 15:29:11 +0100
>> From: Eric Marsden <[email-masked]>
>> 
>> Hello,
>> 
>> The following generates an error. It seems to me that it would be 
>> preferable to insert the header line and show zero rows for the vtable.
>> 
>>     (require 'vtable)
>>     (make-vtable :columns '("tweedle" "dum") :objects (list))
>> 
>> Debugger entered--Lisp error: (wrong-number-of-arguments #<subr max> 0)
>>    max()
>>    apply(max nil)
>>    seq-max(nil)
>

I ran into this same problem myself, trying to use vtable for my package
Ebib[1]. I did some digging and found that the cause of the problem is not that
the vtable is empty, but rather that the column widths cannot be determined. If
you pass explicit widths for each column, `make-vtable` (or rather
`vtable-insert`) works just fine with an empty table:

```
(make-vtable :columns '((:name "tweedle" :width 30) (:name "dum" :width 10))
             :objects (list))
```

The error occurs in `vtable--compute-widths`, which returns a vector with the
widths of each column. For columns that don't have their width set explicitly,
the width is computed on the basis of the elements in the column, but if there
are no elements, that fails.

> I'm not sure we want to support zero-size vtables.  A better error
> message would be nice, though.  What do others think?

For my purpose (i.e., Ebib), support for empty vtables would be a big plus. I
wouldn't even want to display some sort of text or warning, just the header and
nothing else. (I guess this could be made configurable, though. Something like
an :if-empty slot specifying a function to call if the table is empty. This
function could then display some text, give a warning in the minibuffer, raise
an error, or do nothing at all.)

In order to support empty vtables, the column width issue would have to be
resolved, of course. My suggestion (again coming from my use-case) would be that
if some columns have no :width slot, the remaining available width (i.e., the
window width minus the explicit column widths) is divided evenly between them.

Of course, that may turn out to be suboptimal once objects are added to the
vtable, but I don't think it's unreasonable to expect the programmer to take
that into account when using vtable.el. And the user always has the option of
regenerating the table. (There's `vtable-revert-command`, after all.)

For me, the reason why this would be useful is that the data that I want to
display in a vtable has one field that can be very long, while the others are
usually fairly short. In my current, custom table implementation, this long
field is the right-most column and can thus use the full width of the window to
display its data. This works fine with vtable, except if the table is empty.

Footnotes:
[1]  https://github.com/joostkremers/ebib/tree/devel/vtable

-- 
Joost Kremers
Life has its moments