How to properly write the default value for a non-trivial defcustom
form for something like I have below: a list of 3-element lists, with choices of the types?
The following defcustom
works fine as long as:
- it's default is nil
- it's a list of one or several elements of the first type
It fails with a "mismatch" warning in the customize buffer as soon as the default is a list of heterogeneous types (e.g. one element is from the second or third choice).
My defcustom form: (with a nil
default, it works fine)
(defcustom pel-key-chords nil
"..."
:group 'pel-pkg-for-key-chord
:type '(repeat
(choice
(list
:tag "expansion-keys"
(symbol :tag "mode " :value global)
(string :tag "the 2 keys ")
(repeat
(key-sequence :tag "key")))
(list
:tag "command"
(symbol :tag "mode " :value global)
(string :tag "the 2 keys ")
(function :tag "command "))
(list
:tag "lambda"
(symbol :tag "mode " :value global)
(string :tag "the 2 keys ")
(function :tag "elisp code "
:value (lambda () (interactive) <YOUR CODE HERE>))))))
If, instead of nil
as the default I write a list with just one entry, the customization menu fails to properly show the widgets to enter new entries. For example if the first lines of the above code are replaced by the following, I'm not able to enter new values:
My defcustom form: (same code, but with an explicit default that works fine: a list of elements of the first choice:
(defcustom pel-key-chords
'((global "<>" ("<>\C-b"))
(global "[]" ("[]\C-b"))
(c++-mode "{}" ("{\n\n}\C-p")))
"..."
...
My defcustom form: (same code, but with an explicit default that fails with a mismatch: a list of 3 elements of the first choice, then 1 element of the second choice:
(defcustom pel-key-chords
'((global "<>" ("<>\C-b"))
(global "[]" ("[]\C-b"))
(c++-mode "{}" ("{\n\n}\C-p"))
(global ".;" pel-search-word-from-top))
"..."
...
I read Emacs Lisp Customization Settings section and some code like the dump-jump.el
code that defines some complex data with initialization. I assume I must identify some keywords in my declaration of the default, but for some reason I can't find the proper syntax for initializing the data I defined above.