So, I’m trying to add Customize support to packages that use a lot of plists, and where the value of pretty much any option can be either a single item or a list. I could have every single plist option’s value-type wrapped in a choice between “Single item” and “Multiple items,” but on an interface level that is cumbersome and counterintuitive. What I need is something like the specification (plist :options ((:meow (repeat (const purr)))))
, but: while multiple entries in the repeat
will yield the overall value (:meow (purr purr …))
, a single entry in the repeat
should yield (:meow purr)
instead of (:meow (purr))
.
I tried making a simple version of this:
(defun tina/oom-value-set (widget value)
(widget-put widget :inline (if (cdr value) nil t))
(widget-default-value-set (widget value)))
(define-widget 'one-or-more 'repeat
"Like ‘repeat’, but becomes inline when set with only one value.
Becomes non-inline when set with multiple values."
:value-set 'tina/oom-value-set)
(defcustom tina/oom-test '(:meow)
"Test my custom widget"
:type '(plist :options ((:meow (one-or-more (const purr))))))
But, to my sadness, after customizing tina/oom-test
, adding one “purr”, and saving it, the variable is now bound to (:meow (purr))
, instead of (:meow purr)
as I intended.
How can I get this working?