Looking at the code (specifically the
readevalloop function in
lread.c) shows that the following prevents eager macroexpansion from being attempted:
However it turns out that you can't actually put that in a library which causes other libraries to be loaded, as it makes the function unbound at a point after it has been established to exist, and consequently Emacs attempts to call it later on.
Zacharias' solution to this is to not unbind the function, but replace it with something which is effectively a no-op for this particular case: A function which returns the same form it is given, unmodified (i.e. something which Emacs thinks will perform macroexpansion, but which does no such thing).
(defun internal-macroexpand-for-load (form) form)
Alternatively, you can disable eager macroexpansion within a temporary local scope as follows; which means you can keep it enabled in general (for the usual performance benefits), but perform individual library loads (or any other evaluations) without eager expansion for the specific things you're interested in:
(cl-letf (((symbol-function 'internal-macroexpand-for-load) nil))
(Obviously you need to be specific about
.el in this scenario.)
n.b. this one does seem to work fine in general with that
fmakunbound call (and relatedly, while 24.3 complained if that call was absent, Emacs 24.5 was seemingly happy to equate a
nil with an unbound function, and appeared to work as desired with no
fmakunbound call in the
(You could, of course, use a function which returns its argument in this
cl-letf version as well. I think the code above is fine as-is, but if you ever encountered an issue with it, that would be a sensible alternative to try.)