ELPA

ELPA

ELPA is the Emacs Lisp Package Archive, written originally by TomTromey. It is included in GnuEmacs, starting with version 24. package.el is the package manager library for ELPA.

“Our goal is to make it simple to install, use, and upgrade Emacs Lisp packages. We supply package.el a simple package manager for Emacs, and a repository of pre-packed Emacs Lisp code.”

package.el supports multiple ELPA repositories. Sometimes “ELPA” is used to refer to an ELPA repository.

GnuELPA The GNU ELPA repository contains FSF-sanctioned Emacs packages. It is the default repository used by package.el.

You can use other repositories. The following examples show how to access Marmalade and MELPA repositories, in addition to GNU ELPA.

Add this to your init file:

(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
                         ("marmalade" . "https://marmalade-repo.org/packages/")
                         ("melpa" . "https://melpa.org/packages/")))

Any combination of repositories is fine. You should probably always include “gnu”, which is for GNU ELPA, but it is not required.

Package archives may also be local to your machine.

You can also add repositories one at a time:

(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t) ; Org-mode's repository

Emacs users in China mainland can use popkit.org(http://elpa.popkit.org/) archive:

(add-to-list 'package-archives
          '("popkit" . "http://elpa.popkit.org/packages/"))

You can also customize option ‘package-archives’:

M-x customize-variable [RET] package-archives [RET]

You get a UI and then you can add the archives directly:

Hide Package Archives:
INS DEL Archive name: gnu
            URL or directory name: https://elpa.gnu.org/packages/
INS DEL Archive name: marmalade
            URL or directory name: https://marmalade-repo.org/packages/
INS
    State : SAVED and set.
   An alist of archives from which to fetch. Hide
   The default value points to the GNU Emacs package repository.

Contributing to GNU ELPA

Package authors may wish to contribute their packages to the GNU ELPA repository.

The first and main step is to complete your FSF copyright assignment to cover changes to Emacs, and to make sure that all significant contributors to the package have done the same.

Then visit the Savannah GNU website and create an account. You can request inclusion in the emacs group.

Once granted, clone the GNU ELPA repository as shown on this page, using the instructions from section Member clone. Be sure to read the README file in the repository.

You should now be able to push to the ELPA repo.

You might also want to look at the details of MakingPackages for ELPA and Marmalade.

Contributing to other package repositories

There are varying degrees of difficulty and hoops to contribute to MarmaladeRepo and MELPA.

How Packages work in Emacs 24

The Elisp Manual describes how the package system is initialized:

Whenever Emacs starts up, it automatically calls the function ‘package-initialize’ to load installed packages. This is done after loading the init file and abbrev file (if any) and before running ‘after-init-hook’ (see Startup Summary). Automatic package loading is disabled if the user option package-enable-at-startup is nil.

So packages are initialized AFTER the init.el is loaded. This means you should NOT put package specific initialization into your init.el except in a few ways:

    (add-to-list 'auto-mode-alist '("\\.gradle" . groovy-mode))
    (add-hook 'groovy-mode-hook (lambda () (setq tab-width 4)))
    (global-set-key (kbd "C-'")     'shell-switcher-switch-buffer)
    ;; basic initialization, (require) non-ELPA packages, etc.
    (setq package-enable-at-startup nil)
    (package-initialize)
    ;; (require) your ELPA packages, configure them as normal
    (add-hook 'after-init-hook 'cycbuf-init)

Using the `after-init-hook' for package config

Some people think that using after-init-hook seems like a last resort because it may force the load of the package you’re referring to (thus slowing down Emacs). Others point out that moving your whole initialization to after ELPA is loaded makes things easier to use.

You can do that by putting this in your init file:

(add-hook 'after-init-hook (lambda () (load "<real init file>")))

and moving all your normal init to the <<real init file>>.

See also PackagesForConfig

Using `eval-after-load' for package config

Using ‘eval-after-load’ is one way of achieving fine grained configuration per-package. It falls back gracefully if the package is not present.

The following code is an example of customizing a hypothetical major mode called abcd-mode using eval-after-load:

    (eval-after-load "abcd-mode" ; <-- "abcd-mode", not 'abcd-mode
      '(progn
         (setq-default abcd-basic-offset 7) ; setting some option
         (add-to-list 'abcd-globals-list "console") ; appending to a list option
         (add-hook 'abcd-mode-hook 'prepare-some-abcd-soup) ; things to do for abcd mode buffers
         (define-key abcd-mode-map (kbd "C-c C-c") 'play-some-abcd-song) ; add some key binding for abcd mode
     ))

And here is an example for a hypothetical global minor mode called broccoli mode.

    (eval-after-load "broccoli-autoloads" ; <-- "broccoli-autoloads", not "broccoli"
      '(progn
         (if (require 'broccoli nil t)
             (progn
               (broccoli-mode 1) ; Turn on Broccoli global minor mode if broccoli-autoloads.el doesn't do it.
               (setq-default broccoli-how 'steamed) ; set some option.
               (add-to-list 'broccoli-additional-stuff 'salt) ; add to a list option.
               )
           (warn "broccoli is not found."))))

Using `with-eval-after-load' for package config

Starting in emacs 24.4, ‘with-eval-after-load’ is simpler than ‘eval-after-load’:

    (with-eval-after-load 'abcd-mode
       (setq-default abcd-basic-offset 7) ; setting some option
       (add-to-list 'abcd-globals-list "console") ; appending to a list option
       (add-hook 'abcd-mode-hook 'prepare-some-abcd-soup) ; things to do for abcd mode buffers
       (define-key abcd-mode-map (kbd "C-c C-c") 'play-some-abcd-song) ; add some key binding for abcd mode
     )

I (who?) didn’t see anything here about actually using the program (what program?). After setting variable ‘package-archives’ via the instructions above, refresh the repository via ‘M-x package-refresh-contents’.

Then to install a program, for example ‘geiser’, use: ‘M-x package-install RET geiser’. (Note package geiser requires the Marmalade repo.)

Another hint, if the installed package doesn’t seem to work, is to confirm that the package is actually installed, using ‘package-list-packages’. Search for the package name. The reason I added this step was that I had used install a few times before it actually was verified as installed, after which it worked. During each installation, I got a question about saving the contents to a local file, and I’m not sure what that was about. But in the end, I was able to get this running. [[Who?]]

ELPA policy

ELPA policy for Emacs 24 was discussed here: http://thread.gmane.org/gmane.emacs.devel/132634/focus=132640

Downgrading to an earlier version of a package

Suppose that Auctex 11.88 complains about TeX-auto-add-type . One lazy solution is to downgrade to an earlier version. If auctex 11.88 came from elpa, go to https://elpa.gnu.org/packages/ and then to auctex and download the tar file of the latest version of auctex 11.87 and save it under your elpa archives (~/.emacs.d/elpa/auctex-11.87.7.tar). Then suppress the 11.88 with list-package, marking d on auctex and x to execute the deletion.

Now, type the command ‘package-install-file’ and load file ~/.emacs.d/elpa/auctex-11.87.7.tar . The tar file must contain a -pkg.el file which is the cas from the elpa.gnu.org site.

(Note: Auctex 11.88 from gnu archives works fine for me. Only auctex from melpa complains about TeX-auto-add-type.)

How packages work in Emacs 23

You can make packages work in Emacs 23, you need to add something like this to your init.el:

(require 'package)
;; Any add to list for package-archives (to add marmalade or melpa) goes here, e.g.:
(add-to-list 'package-archives 
    '("marmalade" .
      "https://marmalade-repo.org/packages/"))
(package-initialize)

The following package.el version must be placed in one of the directories in your load path: http://git.savannah.gnu.org/gitweb/?p=emacs.git;a=blob_plain;hb=ba08b24186711eaeb3748f3d1f23e2c2d9ed0d09;f=lisp/emacs-lisp/package.el

In case Emacs 23 shows this error at startup: File error: Cannot load file, package, a solution to this error message is to add the following code to your Emacs init file, and of course to make sure the version of package.el noted above is :

(when
    (load
     (expand-file-name "~/.emacs.d/package.el")))

(Idea is from http://ergoemacs.org/emacs/emacs23_install_elpa.html)

Other Repositories

AndrewHyatt has written an implementation of ELPA for AppEngine, written in Go. It is not yet running publicly yet, as of April 2013.

The source code for Marmalade is available on GitHub. It is a complete EmacsLisp project, an Elnode webapp.

Create Local Repositories

https://github.com/redguardtoo/elpa-mirror creates a local fallback repository from installed packages.

For example, you successfully installed all the packages from https://melpa.org at home computer. You can run command `M-x elpamr-create-mirror-from-installed` to create a local repository which containing all the packages you are using.

At office computer you can use that local repository to install packages if corp firewall blocks https://melpa.org


CategoryCode CategoryPackaging