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.

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

    This post is an automated archive from a submission made on /r/emacs, powered by Fediverser software running on alien.top. Responses to this submission will not be seen by the original author until they claim ownership of their alien.top account. Please consider reaching out to them let them know about this post and help them migrate to Lemmy.

    Lemmy users: you are still very much encouraged to participate in the discussion. There are still many other subscribers on !emacs@communick.news that can benefit from your contribution and join in the conversation.

    Reddit users: you can also join the fediverse right away by getting by visiting https://portal.alien.top. If you are looking for a Reddit alternative made for and by an independent community, check out Fediverser.

  • 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.