2

i'm writing a defcustom, and i would like to provide a list of strings containing valid options (in a manner akin to how completing-read takes a collection and you can require-match). i have tried the :options keyword, but it doesn't seem to work with :type 'string (nor, unless i'm mistaken, which is highly possible, with :type '(choice ....

i can't just populate a '(choice (const ... set manually, because the list of strings changes depending on how another defcustom is set, ie: if defcustom B is X, then defcustom A should have P list of valid options shown. if defcustom B is Y, then defcustom A should have Q list of valid options to choose from.

all valid options would ideally be strings.

how can i provide a context-dependent list of valid values in this way?

EDIT:

what i'm interested in having is the equivalent of

  :type '(choice (const :tag "op1" op1)
                 (const :tag "op2" op2)
                 (const :tag "op3" op3)))

(or equally a radio button list), so that the user is presented with a drop-down list of options that they must choose from. but i cannot hard-code the options because the list of them depends on another how another defcustom is set. i don't just want to specify the type, but specify the specific list of valid options that can be chosen from.

if the other defcustom is set to A, i want this defcustom to offer a list like ("op1" "op2" "op3" ...), and if the other defcustom is set to B, i want this defcustom to offer a different list of the same format.

EDIT 2:

i coded something that creates the structure i wanted more or less:

(defun map-ops-for-customize ()
  (let ((ops (get-valid-ops)))
    (append '(choice)
            (mapcar (lambda (x)
                      `(const ,x))
                    ops))))

(get-valid-ops checks the other defcustom and returns the list of currently valid options.)

then i set the :type in my defcustom to simply run this function.

it returns

(choice (const "op1") (const "op2") ...

which is correct.

but the only problem with this is that when the other defcustom is changed, this code isn't run again, and so the options aren't updated. is it possible for them to be updated?

martian
  • 548
  • 3
  • 11
  • It might help if you describe the behavior you want a little better - e.g. show what you want with an example, and show what problems/limits you encountered with what you've tried so far. Just a suggestion. – Drew Jun 03 '22 at 14:39

0 Answers0