8

The use-package is a useful and popular macro for installing packages, but flycheck always complains about it since it hides variable definitions. For example, if I attempt (use-package org), Flycheck will warn of a reference to free variable 'org.

I also have a defcom macro that simplifies command definitions for me, but which hides variable definitions in the same way. Flycheck chokes on these too.

How can I advise Flycheck that these instances are okay? Alternatively, how can I selectively disable this warning? Getting Flycheck to ignore unknown macros also seems like a safe bet, since macros redefine syntax and will usually require new rules.

4
  • Why do you not use (eval-when-compile (require 'use-package))? If you use the macro then presumably you want to also require its definition, including at byte-compile time. And if you do use e-w-c that way, and flycheck still complains, then the misbehavior you describe sounds like a flycheck bug/misfeature.
    – Drew
    Commented Oct 24, 2015 at 20:31
  • I have that exact statement in my config. Is this enough information to make a good bug report? Commented Oct 24, 2015 at 21:52
  • 1
    Try putting that statement before anything else that has to do with use-package.
    – Drew
    Commented Oct 24, 2015 at 23:26
  • You can submit a bug report with any info. But it helps if you can give a reproducible recipe (preferably fairly minimal), starting from emacs -Q. That is, without an init file, load a minimal file explicitly or execute explicit commands.
    – Drew
    Commented Oct 24, 2015 at 23:26

1 Answer 1

2

You must (require …) or (eval-and-compile (load …)) the libraries or files that provide the definitions of these macros in every file where you use these macros, before their first use, and you need to set up flycheck-emacs-lisp-load-path to include the directories containing these libraries.

Otherwise the byte compiler does not even know that these symbols are macros and necessarily must treat invocations as normal function calls and arguments as normal Emacs Lisp expressions.

3
  • +1. Why does (eval-and-compile) work but (eval-when-compile) doesn't for these requires? Commented Jan 9, 2016 at 20:36
  • @MichaelHoffman I'm not sure what you mean. Perhaps ask a separate question with specific details? Generally, you need to load everything that you need at runtime at runtime, hence eval-and-compile—although, (eval-and-compile (require …)) is redundant, require is always evaluated at compile time as well. (eval-when-compile (require …)) is only sufficient for compile-time only definitions, e.g. macros.
    – user227
    Commented Jan 9, 2016 at 21:25
  • I've created another question with a minimal example: "Flycheck emacs-lisp checker loads macros with (eval-and-compile) but not (eval-when-compile)". Commented Jan 9, 2016 at 22:00

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.