Skip to content

Instantly share code, notes, and snippets.

@plexus
Created July 12, 2014 17:34
Show Gist options
  • Save plexus/f538a5a7ff2f6521a69b to your computer and use it in GitHub Desktop.
Save plexus/f538a5a7ff2f6521a69b to your computer and use it in GitHub Desktop.

package.el

Before Emacs 24 the only way to benefit from third party elisp packages was to copy them to your configuration. RMS always opposed a package manager in Emacs because it would make it too easy to install non-free additions (this might not be a 100% accurate represetation of what happened, it’s what I remember hearing/reading).

In any case, Emacs 24 shipped with package.el, so now there’s a package manager. You can do M-x list-packages and it will fetch a list of packages from one or more package repositories. You find the package you want, type i, then x and it installs.

repositories

There are a few different repositories. The “official” one from GNU is called ELPA. The most popular one with lots more than ELPA is MELPA. Here is how you add MELPA to your config:

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)

Another “third party” repository is Marmalade, and apparently org-mode has their own if you want to latest greatest org-mode packages. emacs24-starter-kit simply includes them all.

(require 'package)
(setq package-archives
  '(("gnu"         . "http://elpa.gnu.org/packages/")
    ("org"         . "http://orgmode.org/elpa/")
    ("melpa"       . "http://melpa.milkbox.net/packages/")
    ("marmalade"   . "http://marmalade-repo.org/packages/")))
(package-initialize)

So make sure you have at least ELPA and MELPA.

stuff on top of package.el

Custom

The problem with “just” package.el is that when you install packages, there’s no trace of that in your emacs config. So when you move to a different machine you have to manually install those packages again.

It’s not a big deal since it’s easy to solve yourself. For example, this is from Bodil Stokke’s config

(defun package-require (pkg)
  "Install a package only if it's not already installed."
  (when (not (package-installed-p pkg))
    (package-install pkg)))

So you can just write (package-require 'yasnippet) in your config, and it will install it if it’s not installed yet.

Cask

You can also use Cask, which is basically like Bundler. You define a file ~/.emacs.d/Cask with the packages you want

(source "melpa" "http://melpa.milkbox.net/packages/")
(source "gnu" "http://elpa.gnu.org/packages/")

(depends-on "auto-complete")
(depends-on "cask")
(depends-on "cider")

It has a command line tool and everything, it’s pretty complete. You can combine it with pallet, This will automatically add packages to your Cask file when you install them through the install-packages interface.

el-get

Even with Melpa and Marmelade you’ll find that not everything is available as a package. There are tons of useful files on Emacswiki, some stuff is only on Github, etc. el-get allows you to install from any of these sources, including package.el.

So you then do something like this

(setq el-get-sources
      '((:name xml-rpc :type elpa)
        (:name yasnippet :type elpa)
        (:name hexrgb :type emacswiki)))

(el-get 'sync '("xml-rpc" "yasnippet" "hexrgb"))

Conclusion

The simplest thing to do would be to add melpa, and use the “package-require” in your init.el. You’ll still be copying stuff from time to time e.g. from emacswiki. If you want to manage that better as well, have a look at el-get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment