I would like to have a variable, say my-info that would have an alist attached to it. In normal programming it would look like this:

(setq my-info '((my-name . "Giuseppe Sextus-Packus") (my-email . "joep@packllc.com") (my-phone . "39.06.4434.0147")))

However, I want to populate my-info in a customization buffer, i.e., callable with customize-variable my-info. Furthermore, I would like each key to be presented with a blank field to fill in the value. I know I have to declare this variable as a defcustom but the details of offering all three keys for the user to complete with values is beyond my understanding. Are there templates out there for how to declare such a defcustom? How could I do this?


Something like this?

(defcustom foo-alist
  '((key-a "value-a1" "value-a2")
    (key-b "value-b1" "value-b2"))
  "Each element is a list comprising (KEY \"VALUE1\" \"VALUE2\") ..."
  :type '(alist :key-type (symbol :tag "Key")
                :value-type (list (string :tag "Value 1")
                                  (string :tag "Value 2")))
  :group 'foo)

Or in this particular case:

(defcustom my-info-alist
  '((my-name . "Giuseppe Sextus-Packus")
    (my-email . "joep@packllc.com")
    (my-phone . "39.06.4434.0147"))
  "Each element is a cons cell (KEY . \"VALUE1\") ..."
  :type '(alist :key-type (symbol :tag "Key")
                :value-type (string :tag "Value"))
  :group 'my-info)
| improve this answer | |
  • I guess the second example would create the alist my-info-alist already populated with values for the keys. But is there a way to create the customization group my-info where the values were left to be filled in by the individual user? – 147pm Apr 21 '19 at 14:27
  • You can just use empty strings as the default values, no? – phils Apr 21 '19 at 22:44
  • Of course. Excellent. – 147pm Apr 22 '19 at 0:19
  • You can also use nil as the default value (if that's appropriate for use). Your tags plus Customize type-checking should be sufficient to guide a user to enter legitimate values. That's what they're for. You should be able to use the default value that is most appropriate as the default value for default, immediate use, and not have to come up with a default value whose purpose is to help someone understand the value structure and typing. – Drew Jun 21 '19 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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