10

I alternatively run 24.5 and 25.0.50. Unfortunately, packages installed and compiled from 25.0.50 don't work with Emacs 24.5 (cl-struct-define is a common culprit).

One trivial solution is to not byte-compile anything. That makes things pretty slow, though.

How can I use compiled packages (for performance) while using the same .emacs.d for both 24.5 and 25.0.50? I'd also be ok with 24.5 ignoring the compiled files.

Clément
  • 3,924
  • 1
  • 22
  • 37
  • [This question](http://emacs.stackexchange.com/questions/2322/how-to-run-multiple-versions-of-emacs-for-package-development) is similar, but not exactly the same: it focuses on easily keeping a bunch of versions side by side for testing purposes, but it doesn't discuss byte-compiled files at all. – Clément Jun 18 '15 at 00:14
  • 3
    I set [`package-user-dir`](https://github.com/kaushalmodi/.emacs.d/blob/master/setup-packages.el#L24) and [few other dirs and files](https://github.com/search?utf8=✓&q=user%3Akaushalmodi+extension%3Ael++"emacs-version-short"&type=Code&ref=searchresults) based on [emacs version](https://github.com/kaushalmodi/.emacs.d/blob/master/init.el#L12). I can write a detailed answer when I am at a computer. – Kaushal Modi Jun 18 '15 at 01:28
  • @kaushalmodi: Won't that force me to install each package twice? – Clément Jun 18 '15 at 08:28
  • Yes. Each package is installed multiple times (and each installation folder will have that emacs version specific byte compiled files). But you don't do that manually. I maintain an alist in my `init.el` and all those packages are auto-installed on emacs startup (if not already installed). You can even use the `:ensure` keyword of `use-package` to auto-install packages. – Kaushal Modi Jun 18 '15 at 11:07

2 Answers2

3

Put the byte-compiled files for different Emacs versions in different directories. Make your load-path conditional on the Emacs version you are running, so that you load the appropriate byte-compiled libraries.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 2
    (IMO, it's too bad that Emacs dev no longer makes an effort to maintain forward compatibility for byte-compiled files. It used to be the case that you could use a library compiled using an older version in a newer version. You might not have been able to take advantage of a few new features, but generally there was no problem. This is still the case for most things, but for less and less, unfortunately.) – Drew Jun 18 '15 at 01:14
  • Thanks, that's a nice idea. Is there a way to make the package manager put elc files in that version-specific directory though? Some sort of default destination for byte-compile-file maybe? – Clément Jun 18 '15 at 08:26
  • Dunno; sorry. Someone else will hopefully answer that question. I'm not an expert on the pkg mgr. I would think (&hope) that the answer is yes, that it provides an easy way to do that. – Drew Jun 18 '15 at 13:40
1

It is perfectly possible to have packages.el put byte-compiled code into versioned subdirectories of the elpa package. This gives a structure like this:

┌ elpa
└┬ the-package-date.time
 ├─ the-package.el
 ├┬ 23.4
 │└─ the-package.elc
 ├┬ 26.3
 │└─ the-package.elc
 └┬ 27.1
  └─ the-package.elc

The load path is constructed in such a fashion, that the versioned directory appears before the source directory, e.g.:

'(
  "/home/../.emacs.d/elpa/the-package-date.time/27.1"
  "/home/../.emacs.d/elpa/the-package-date.time" 
  ;; ...
 )

To accomplish all of this, I have just written the package package-compat, which uses mostly adviced functions to provide that feature for Emacs 23 to Emacs 27.

The package mechanism is just used for distribution in this case, since the code must be loaded before any packages are activated and/or installed.

Either add "https://almost-un.org/selpa/packages" to the variable package-archives

(add-to-list 'package-archives ("almost-un.org" . "https://almost-un.org/selpa/packages/") t)

and download the package with (package-install 'package-compat) or download the tar(1) archive from the above page.

Then follow the instructions in any of the Emacs lisp files.

wolfmanx
  • 131
  • 4