9

I'm using Emacs 28.2 on Debian 12.1 with just some org-mode settings in the init file, and it suddenly produces an eln-cache/ every time I start it and populates it with a lot of files. It's annoying as I regularly synchronise my ~/.emacs.d/ across a number of machines.

I checked my init.el but there is no reason for this behaviour to be found.

What is an eln-cache/, and is there a way to get rid of it again?

1
  • Similar issues with synrclone/rlcone. Another directory causing sync to go mad is var/dap : for some reason the vscode files in there kept regenerating. Very strange. Commented Nov 20, 2023 at 9:55

2 Answers 2

12

The eln-cache directory stores the native-compiled *.eln files for your configuration's *.el files.

This feature was added in Emacs 28.1, and is optional at build-time. It is not enabled by default, so you have either installed a version of Emacs which someone else built with this feature enabled, or else you have compiled Emacs yourself with this feature enabled.

If you install a version of Emacs which was not built --with-native-compilation then no *.eln files will be generated anywhere.

(Update: Starting from Emacs 30, native-compilation is enabled by default as a build option, and so you should explicitly ./configure --with-native-compilation=no when building Emacs if you wish to disable this.)


If you still want native-compilation, then I suggest something along the lines of:

  • Exit Emacs
  • mv ~/.emacs.d/eln-cache ~/.eln-cache
  • ln -s ../.eln-cache ~/.emacs.d/eln-cache
  • Start Emacs

Assuming that when you synchronise your config to another machine the symlink gets copied as a symlink.

You would need to create ~/.eln-cache on each of your machines, of course. (I'm not actually sure what Emacs will do in that situation if eln-cache is a broken symlink.)


Starting from Emacs 29, you can alternatively call the following function in your early-init.el file to move the cache outside of the directory that you are synchronising:

(defun startup-redirect-eln-cache (cache-directory) "Redirect the user's eln-cache directory to CACHE-DIRECTORY. CACHE-DIRECTORY must be a single directory, a string. This function destructively changes `native-comp-eln-load-path' so that its first element is CACHE-DIRECTORY. If CACHE-DIRECTORY is not an absolute file name, it is interpreted relative to `user-emacs-directory'. For best results, call this function in your early-init file, so that the rest of initialization and package loading uses the updated value." ;; Remove the original eln-cache. (setq native-comp-eln-load-path (cdr native-comp-eln-load-path)) ;; Add the new eln-cache. (push (expand-file-name (file-name-as-directory cache-directory) user-emacs-directory) native-comp-eln-load-path)) 

I've included the definition in full in case you want to experiment with that in Emacs 28. (I haven't tried doing that, so I have no idea whether or not it would work.)

13
  • Check to see if there's an alternative package without it. If not, there should be, as there are scenarios (including very low-powered machines and the presence of certain virus scanners) where native-compilation is problematic. So chase that up if necessary. I suspect there may already be an alternative package though. Commented Jul 26, 2023 at 9:59
  • Thanks, with that help I found the relating bug report at Debian. Obviously it won't be fixed. bugs.debian.org/cgi-bin/… Commented Jul 26, 2023 at 10:04
  • I suggest raising another one requesting an alternative package without native-compilation. They might say no, but it doesn't hurt to ask. They should understand that some of their users may be using such low-powered hardware that native-compilation is not reasonable (I saw a report from one user who estimated that their machine would take an entire day to finish native-compiling everything, and the traditional byte-code interpreter was good enough, so the performance hit of native-comp was insane for them. They weren't running Debian but the principle is the same). Commented Jul 26, 2023 at 11:02
  • 1
    It's really a mess, because all my workflow is based on Emacs and its org-mode. So far there is no alternative package. As anticipated, the workaround with a softlink breaks during synchronisation and is, hence, no solution. Applying (defun startup-redirect-eln-cache (cache-directory) has no effect, Emacs 28.1 still creates .emacs.d/eln-cache and populates it with files. Commented Jul 27, 2023 at 9:28
  • 1
    As anticipated, the maintainers declined the plea to provide a package without --with-native-compilation. For me, this is a rather sad lesson in Unix principles, because a complex programme uniting different functions finally broke my neck. The advantages of Emacs and org-mode are simply vanishing, when I have to take care of an eln-cache prior to every synchronisation. Commented Jul 29, 2023 at 5:54
1

I'm on Emacs 29.1 and I really like the XDG Base Directory standard to keep my home directory uncluttered and let cache, data and config stay in separate directories.

I have thus tried my best to make my ~/.config/emacs/ clean of cache files by setting variables to point that stuff to ~/.cache/emacs/ instead.

To that end this is what I have in ~/.config/emacs/early-init.el for eln-cache and package-user-dir (the rest can be set through regular customize):

(setq package-user-dir (string-replace ".config" ".cache" package-user-dir)) (setcar native-comp-eln-load-path (string-replace ".config" ".cache" (car native-comp-eln-load-path))) 

For the authors issue specifically (if they want some other specific directory) something like this should work:

(setcar native-comp-eln-load-path "/path/to/some/dir") 
1
  • 4
    There's a built-in function in Emacs 29 to do the (setcar native-comp-eln-load-path "/path/to/some/dir") part: (startup-redirect-eln-cache "/path/to/some/dir"). Also, Emacs has an XDG library, so a more correct way to do what you specifically wanted would be (require 'xdg) (startup-redirect-eln-cache (expand-file-name "emacs/elpa" (xdg-cache-home))) (the value of $XDG_CACHE_HOME should be checked before using ~/.cache) Commented May 25, 2024 at 3:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.