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

Emacs

313 readers
2 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.

top 4 comments
sorted by: hot top controversial new old
[–] 7890yuiop@alien.top 1 points 11 months ago

If you ensure that everything that you want to be compiled is currently compiled, you can let https://github.com/emacscollective/auto-compile manage it from there.

[–] nv-elisp@alien.top 1 points 11 months ago

Properly package that code (sounds like you're most of the way there) and let your package manager handle it.

[–] fediverser@alien.top 1 points 11 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.

[–] geza42@alien.top 1 points 11 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.