What’s the best practice to have your custom elisp natively compiled, along with external packages?

So far I’ve only succeeded by doing the following:

  • Move my custom elisp to a new file (emacs-lib.el) which starts with (provide 'emacs-lib)

  • Manually run emacs-lisp-native-compile-and-load while visiting that file

  • Change my init file to load the library:

    (setq elisp-dir “~/config/elisp”) (add-to-list 'load-path elisp-dir) (require 'emacs-lib)

After restarting Emacs, I’ve checked that many of my custom functions are indeed native-compiled.

It would be nice if I could have my init file take care of compiling the library when missing or outdated. Even better if I didn’t need the separate file, but that’s no big deal.

  • geza42B
    link
    fedilink
    English
    arrow-up
    1
    ·
    9 months ago

    I simply use:

    (defun my-recompile-init-eln ()
      (interactive)
      (byte-compile-file "~/.emacs.d/early-init.el")
      (native-compile "~/.emacs.d/early-init.el")
      (byte-compile-file "~/.emacs.d/init.el")
      (native-compile "~/.emacs.d/init.el"))
    

    I use it manually, but I don’t care too much because I don’t edit my init files too often anymore. But it shouldn’t be too hard to run this function automatically at boot if the .elc is outdated compared to the .el.