1

How to properly write the default value for a non-trivial defcustom form in standard for something like I have below: a list of 3-element lists, with choices of the types?

The defcustom form is: defcustom option standard doc [keyword value]...

The following defcustom works fine as long as it's default is nil.

As soon as I add a non-empty list of values in standard for the default value, Emacs *Customize* buffer UI fails (see below).

#1: My defcustom form: (with a nil value for the default, Emacs *Customize* buffer UI 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>))))))

The problem occurs when I specify a list of elements, or just one for default, as shown below:

#2: My defcustom form: (same code, but with an explicit default of one element):

(defcustom pel-key-chords
'((global   "<>"  "<>\C-b"))
"..."
...

With the default, Emacs *Customize* buffer UI fails: the INS and DEL buttons are not available and it is impossible to add or delete elements.

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.

1 Answer 1

1

Well, murphy's law strikes again...

I just realized that the Customize buffer was showing mismatch beside the data structure...

The problem I had tied to the fact that the last element of my inner list is itself a list, and the default declaration identified just 1 string.

So instead of writing

(defcustom pel-key-chords 
'((global "<>" "<>\C-b"))
"..."
...

What I need to do is to write it like this:

(defcustom pel-key-chords 
'((global "<>" ("<>\C-b")))
"..."
...

and all goes well.

I wish checkdoc was able to catch these types of errors.

4
  • +1 for both the Q and the A. Consider filing an enhancement request to, for example, make the mismatch indication more visible, and perhaps let you click it to get some more detailed information about why the current value is a mismatch. Use M-x report-emacs-bug to file an enhancment request or a bug report.
    – Drew
    Commented Jun 12, 2020 at 18:26
  • Thanks. I was able to figure out the first part, but then I stumble onto another issue: being able to declare a default using a list of different types. I edited my original question accordingly. Overall I think the mismatch indication is visible enough, but I would just like to see more examples in the manual. As usual it's a matter of not knowing what you don't know....
    – PRouleau
    Commented Jun 12, 2020 at 18:47
  • You're right. I'm doing that.
    – PRouleau
    Commented Jun 12, 2020 at 21:12
  • @Drew, I restored the flavour of my original question and I created another question How to properly specify defcustom default list of heterogeneous types?
    – PRouleau
    Commented Jun 12, 2020 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.