3

I have a defcustom with :type variable, and I would like to constrain the variable name to comply to a pattern.

How would I do that?

for instance let say I want the custom to only accept a variable name starting with some prefix.

4

Don't use type variable. Use type restricted-sexp.

The predicate checks for a symbolp that is boundp (i.e., a variable) and whose symbol-name is matched by your chosen prefix.

See the Elisp manual, node Composite Types.

  • Thanks Drew. I tried your solution, but for a strange reason the validating function is being called with nil except for the initial value. Besides the set handler is also called! Any idea why? – AdrieanKhisbe Sep 21 '17 at 21:11
  • Here is the code in question: gist.github.com/AdrieanKhisbe/81dbd538b6b8cca0b2dadd33ac24a6ed – AdrieanKhisbe Sep 21 '17 at 21:12
  • Looks like you accidentally used fboundp' in one place, instead of boundp'. – Drew Sep 21 '17 at 23:11
  • And you spot it right! Thanks a lot @Drew! :) – AdrieanKhisbe Sep 22 '17 at 11:44

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.