Common idiom to workaround macro expansion or resolve warning about undefined variables during byte-compilation:
(eval-when-compile
(require 'cl-lib))
But this require ...
compiled into .elc
file! I found that cl-eval-when
have proper semantic (according to name).
Normally we don't need for require
as site file and package.el
For example I want to byte-compile my .emacs
which uses some external macros, but silently pass through if there are no such package:
(cl-eval-when 'compile
(condition-case err
(require 'w3m-util)
(error (byte-compile-warn "Failed by: %S" err))))
(w3m-util-DEPENDENT-CODE ...)
Another way to do this is:
(ignore-error
(require 'w3m-util)
(w3m-util-DEPENDENT-CODE ...))
But now we are not a top level form...
Do I properly fill that eval-when-compile
name do something that is not expected from its name?
w3m-DEPENDENT-CODE
from a missingw3m-util
. – Drew Oct 13 '15 at 15:27(when (require 'w3m-util nil t) (w3m-util-DEPENDENT-CODE...))
– Drew Oct 13 '15 at 15:29(when (require 'w3m-util nil t) ...)
is nice idiom! But I try to make perfect.emacs
file, not a library. So have in mind delayed (on-request) code loading with help of auto-loading. For this reason I extensively useeval-after-load
, askedrequire
needs only to make byte-compilation success with macro expansion. – gavenkoa Oct 14 '15 at 21:20