I went through the process of trying several bits of advice from various webpages, but nothing seemed to work. In particular, things that wanted other packages seemed incredibly wonky. After I got tired of (seemingly) randomly throwing code in my .emacs file and .el files into my .emacs.d directory, I decided to bite the bullet and actually figure out how emacs packages work.
It's not like I'm a emacs newbie, I've been using it almost exclusively since 1991. Back then, everyone made fun of it for being an inefficient memory hog; these days, it's like a cheetah compared to most applications. I even consider myself a "lisp guy", but it's been a loooong time since I've even touched elisp, let alone been familiar with whatever package management system emacs uses these days.
It basically says modern emacsen have an interactive mode for this, so I excitedly tried
M-x list-packages as suggested. It tells me [No Match].
So what's the problem? It turns out to be emacs itself, as shipped with OSX. I recently installed El Capitan, so I have the absolute latest version of the OS.
Out of the box Darwin ships with Emacs 22.x. Here's a clip from the splash screen:
GNU Emacs 22.1.1 (mac-apple-darwin) of 2015-08-04 on osx228.apple.com Copyright (C) 2007 Free Software Foundation, Inc.
So this binary was compiled late 2015 so it's really new. However the source code is version 22.1.1 from . . . 2007 ? Yeesh.
The Rabbit Hole
Further reading reveals that the current package manager evolved from something called ELPA. Older emacs installed the package manually, and the hook used to be
M-x package-list-packages. Emacs 23 seems to be the major target for this. My emacs didn't like this command either; no surprise there, I already knew my libraries probably sucked.
I valiantly cut and paste the "magic" to install ELPA: it churned for a few seconds, and it all looked good. No errors. So I quit emacs and re-ran it. No startup errors. Good so far. Next I typed
M-x package-list-packages. Tab complete even worked, so emacs knew about this new command. So I hit enter . . .
Ugh. Problems. Errors. Taking up the entire screen. The only ones I could make sense out of were the following:
An error has occurred while loading `/Users/val/.emacs': File error: Cannot open load file, /Users/val/.emacs.d/elpa/archives/-pkg
Ok, I know what the .emacs file is. But what's this archives package? Woe is me. A quick Google search on the error brought me to this Stack Overflow Page, where a similar complaint is voiced. Instead of a simple "oh, do this" answer, the hoi polloi don't seem to converge an on answer. The only useful tip seems to be "use the version that comes with your emacs". Great.
Here's an article on package management using emacs that says "you can even use this all the way back to version 23!", which is exactly one greater than the one shipping with OSX.
I'm stating to get the feeling that I'm using an old version of software no one cares about. Even if i debug the problem (How do I get the latest package management software to work on this old emacs), that hard fought knowledge will have questionable usefulness, and, worse, there's no guarantee that any of the packages you install won't break in random and hard-to-debug ways.
There's no guarantee that any of the packages you install won't break in random and hard-to-debug ways.
How do we jump out of this twisty maze and get back to working?
brew to the rescue
If you don't know about brew, you're missing out. It's a kick-ass package manager got OSX. Think of it as a similar tool to apt-get.
brew install emacs
Now you can run this using
Add the following to your
Now when I run this shiny new emacs, I get this for versioning:
GNU Emacs 24.5.1 (x86_64-apple-darwin14.3.0) of 2015-04-11 on yosemitevm.local Copyright (C) 2015 Free Software Foundation, Inc.
I love how the actual compile date is months before the OSX compile date. Still, they managed to get a version out that has a copyright of this year.
what about macports?
Ok, not everyone uses brew, some people use macports, another OSX package management package. Now we're at the point of installing multiple emacs using multiple OS-level package managers for the purpose of getting a decent package manager for emacs. Curiouser and curiouser.
sudo port install emacs
This is about the same as above, except the binary is
/opt/local/bin/emacs (port uses
/opt/local instead of
/usr/local as its default prefix. To each (package manager) his own.
Here's the lowdown on this emacs version:
GNU Emacs 24.5.1 (x86_64-apple-darwin14.5.0) of 2015-08-27 on tenten-slave.macports.org Copyright (C) 2015 Free Software Foundation, Inc.
Add the following to your
go all hardcore on it
The "real" emacs is in /usr/bin. That's kind of the first place everyone looks to find stuff. So, if you really want a newer emacs all the time, we can sort of shove the old one aside, then create a symlink to the one we really care about. All in all, it seems like the possible risks from upgrading your emacs seem really minimal.
cd /usr/bin sudo mv emacs emacs.old sudo ln -s /usr/local/bin/emacs . # brew # OR sudo ln -s /opt/local/bin/emacs . # port
Of course, once I had a modern version of emacs, everything just worked. I installed the js2-mode package and I was good to go. I even installed a couple more packages that looked interesting. That was . . . a lot easier than I expected.
If it's that easy to do packages, maybe I'll even look into elisp again.
YU no emacs24?
So, while it's nice that emacs is included as part of OSX, it's terrible that the version they picked was so old. I've heard this same complaint about other tools in the Darwin toolbelt, too. (Python, i'm looking at you here!) I wonder how many other tools in the toolchain are befallen with the same time-capsule-like fate?
Here's the obvious question:
Hey Tim Cook, why can't we have the newest toys right out of the box? - @val314159
Seriously. Almost every developer I know uses a mac. Don't make us have to worry about upgrades, we have a lot on our minds already.
It's 2015. Don't give us tools from 2007.