this post was submitted on 04 Dec 2023
2 points (100.0% liked)

Emacs

310 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] geza42@alien.top 1 points 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.