Echo Area

eval-and-compile

27 July 2012 9:19 PM (emacs | elisp | config | coding)

I'm reading up a little on byte-compilation in GNU Emacs and I read about just exactly a feature that I needed.

A while ago, I was working on my init file, adding some auto-complete code since I wanted to try it again. I noticed that, because auto-complete is installed through package, it couldn't load the appropriate files at compile time.

I know that package-initialize should be called before calling or using any package-installed functions and I have it in my init file, but this doesn't help at compile time. So, ugly as I thought it was, I added

(eval-when-compile (package-initialize))

just above the call to the auto-complete functions. I hated having to do that, I know it's just one line, but its not at all DRY.

Just now, though, I read about eval-and-compile, and according to the documentation in the elisp reference manual, it should do exactly what I want, eval both when running and when compiling.

(eval-and-compile (package-initialize))

I'm currently trying it out, I just tested it once and it seems to work like a charm.

Of course, this might never have been an issue if I didn't use emacs -Q to compile my init file, just to speed up loading during compilation a little bit.

No responses

Leave a Reply