I am trying to make sure a package that is installed from Melpa (org-ref) byte compiles correctly, and a typical issue is related to the use of macros. For example, if I use org-with-wide-buffer which is a macro defined in org-macs.el I need to make sure to put

(eval-and-compile (require 'org-macs)) in it so the package works as expected from Melpa.

The tricky thing is finding all the macro calls, so I know when to do this. I wondered if there is a way to find these in an elisp file. It seems like one just walks through all the s-exps and checks if the (macrop (car sexp)) is non-nil, and print it or something so I can figure out what to put at the top. Does something like this already exist?

Or is there some way to test if there are uncompiled macro calls? I already can cleanly compile the package; the issues come up when using the functions.

  • Your need might be to also have the macros defined at runtime, in which case eval-and-compile is appropriate. But your question (a very good one) is otherwise more general, and in the more typical case eval-when-compile is called for (the macros are needed only at compile time). If you agree, you might consider either mentioning this or in some other way generalizing your question. We don't have a lot of good questions about Elisp macros here...
    – Drew
    Commented Nov 1, 2021 at 20:57
  • I have a lot of related questions on this topic, like how to tell when you need eval-and-compile vs eval-when-compile. Do you think that could go here, or should be a separate question? Commented Nov 2, 2021 at 21:37
  • A separate question, I think. Specific or narrow questions are generally more helpful and get better answers, I think.
    – Drew
    Commented Nov 3, 2021 at 1:10

1 Answer 1


I found a way to do it interactively with el-search (http://elpa.gnu.org/packages/el-search.html).

M-x el-search `(,(pred macrop) ,_)

finds them. Interestingly, it matches backticked s-exps like `(:annotation-function ,type-annotation) too.

Here is an interactive function version:

(defun find-macro-calls-1 ()
  (goto-char (point-min))
  (el-search (read "`(,(pred macrop) ,_)")))
  • el-search.el is Michael Heerdegen's library; it's not part of vanilla Emacs (yet), right? If so, please consider adding a link to the library or info about it. Thx.
    – Drew
    Commented Nov 1, 2021 at 20:59

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.