EDIT:
The comment of npostavs is true. When you load
"other-package"
during byte compilation the test result on byte-compilation in "other-package"
is negative.
You need to remember in the original package that you are byte-compiling.
You can do that by let-binding:
A minimal example:
Content of the original package:
(eval-when-compile
(let ((other-package-loading-for-compilation t))
(load "other-package")))
Content of "other-package"
:
(unless (bound-and-true-p other-package-loading-for-compilation)
(message "For initialization only"))
OLD Answer:
I assume that you have already compiled other-package
.
In that case
(cl-eval-when (load) ...)
in other-package
works.
The doc-string of cl-eval-when
:
(cl-eval-when (WHEN...) BODY...)
Control when BODY is evaluated.
If ‘compile’ is in WHEN, BODY is evaluated when compiled at top-level.
If ‘load’ is in WHEN, BODY is evaluated when loaded after top-level compile.
If ‘eval’ is in WHEN, BODY is evaluated when interpreted or at non-top-level.
From my perspective the load
case description is a bit misleading. It means that BODY is evaluated when the byte-compiled library is loaded -- not only directly after byte-compilation.
You can also combine the cases.
If you want BODY to be evaluated also when the source file is loaded you can use
(cl-eval-when (eval load) ...)
other-package
, therefore it is load time forother-package
. You could try checking if byte compilation is in progress likecl--compiling-file
does perhaps.cl--compiling-file
is to inspect the value of(bound-and-true-p byte-compile-current-file)
, which is only set during byte-compilation.