14

In two of my packages I have a macro where the body depends on a variable defined in a defcustom form.

When installing the packages from Melpa, the byte-compilation ends with:

Error: Symbol's value as variable is void: my-defcustom-variable

Then, manually byte-compiling the file by opening it in a buffer works.

I tried with an autoload cookie but still have the same behavior.

I'm missing something important here.

3
  • 1
    Depending on a defcustom in a macro body is a strange thing to do, for the defcustom will only ever come into effect during byte-compilation (where the macro is expanded). This doesn't seem to make much sense to me.
    – user227
    Commented Nov 17, 2014 at 14:18
  • Thank you Sebastian, you are right and it explains a lot of things.
    – syl20bnr
    Commented Nov 17, 2014 at 15:11
  • As a scenario where such a thing might be useful: I was trying to do something similar: a macro that was checking if a argument corresponds to a defcustom variable and take a decision based on that. I was trying to improve error checking on code that was adding properties to these defcustom variables right after the defcustom form. Stefan's explained why that does not work.
    – PRouleau
    Commented Apr 28, 2021 at 14:42

1 Answer 1

16

The defcustom expression are not evaluated during byte-compilation, so when your macro is expanded, the variable does not exist yet because that defcustom was compiled but not run. You can either move the defcustom to another file (which you then require at the beginning of your file), or you can wrap the defcustom inside eval-and-compile.

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.