I'm writing a package that provides some Python functionality. I want to use python-rx
, which is part of Emacs' python.el.
(eval-when-compile (require 'python))
(defun python-foo-starts-defun-p ()
"Return non-nil if the current statement opens a defun."
(save-excursion
(python-nav-beginning-of-statement)
(looking-at (python-rx defun))))
(provide 'python-foo)
However, this gives me byte compilation errors:
the function `python-nav-beginning-of-statement' might not be defined at runtime.
the function `python-rx' is not known to be defined.
This error is correct: when I run my code in a fresh Emacs, I do get an error about python-rx
. However, I can open python.el and run M-x eval-buffer
and then my code works.
I believe this is because python-rx
is wrapped in an eval-when-compile
in python.el. How can I use it in my code?
eval-when-compile
toeval-and-compile
. – PythonNut Aug 13 '15 at 14:46eval-and-compile
is good, as it fixes thepython-nav-...
byte compilation issue, but not thepython-rx
issue. – Wilfred Hughes Aug 13 '15 at 15:08eval-and-compile
arequire
statement. If you just want macros you useeval-when-compile
. If you want functions and macros, you just use the plainrequire
. – Malabarba Aug 13 '15 at 17:31