<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>insomnia bytes &#187; emacs</title>
	<atom:link href="http://bytes.inso.cc/category/emacs/feed/" rel="self" type="application/rss+xml" />
	<link>http://bytes.inso.cc</link>
	<description></description>
	<lastBuildDate>Sat, 13 Aug 2011 01:33:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Auto-installing packages in Emacs with ELPA and el-get</title>
		<link>http://bytes.inso.cc/2011/08/13/auto-installing-packages-in-emacs-with-elpa-and-el-get/</link>
		<comments>http://bytes.inso.cc/2011/08/13/auto-installing-packages-in-emacs-with-elpa-and-el-get/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 23:05:45 +0000</pubDate>
		<dc:creator>seb</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[.emacs]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[el-get]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[package.el]]></category>

		<guid isPermaLink="false">http://bytes.inso.cc/?p=177</guid>
		<description><![CDATA[Those who live in emacs all know the pain of manually installing extra modes and extensions, especially on different hosts. System packages sometimes help, but they differ on every OS (Debian packages, MacPorts, etc.), don&#8217;t always exist, and need to be installed manually. A better alternative is to use emacs itself to manage, install and [...]]]></description>
			<content:encoded><![CDATA[<p>Those who live in <a href="http://www.gnu.org/software/emacs/">emacs</a> all know the pain of manually installing extra modes and extensions, especially on different hosts. System packages sometimes help, but they differ on every OS (Debian packages, MacPorts, etc.), don&#8217;t always exist, and need to be installed manually.</p>
<p>A better alternative is to use emacs itself to manage, install and update all the required extra code. The <a href="http://tromey.com/elpa/">ELPA</a> project provides a way to install packages from different repositories, while <a href="https://github.com/dimitri/el-get"><code>el-get</code></a> can help you declare recipes to install and update code from ELPA, or even Github or Emacswiki.</p>
<p><span id="more-177"></span>First, let&#8217;s setup some code that tries to load ELPA and <code>el-get</code>, and installs them if they are not present.</p>
<pre name="code" class="lisp">
; derived from ELPA installation
; http://tromey.com/elpa/install.html
(defun eval-url (url)
  (let ((buffer (url-retrieve-synchronously url)))
  (save-excursion
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (eval-region (point) (point-max))
    (kill-buffer (current-buffer)))))

;; Load ELPA
(add-to-list 'load-path "~/.emacs.d/elpa")

(defun install-elpa ()
  (eval-url "http://tromey.com/elpa/package-install.el"))

(if (require 'package nil t)
    (progn
      ;; Emacs 24+ includes ELPA, but requires some extra setup
      ;; to use the (better) tromey repo
      (if (>= emacs-major-version 24)
          (setq package-archives
                (cons '("tromey" . "http://tromey.com/elpa/")
                package-archives)))
      (package-initialize))
  (install-elpa))

;; Load el-get
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")

(defun install-el-get ()
  (eval-url
   "https://github.com/dimitri/el-get/raw/master/el-get-install.el"))

(unless (require 'el-get nil t)
  (install-el-get))
</pre>
<p>Note that when using emacs 24, <code>package.el</code> is distributed with emacs but it points to the GNU package repository; the code above adds tromey&#8217;s more complete ELPA repository to the sources.</p>
<p>Unfortunately, the ELPA installer script appends a snippet of code to the end of the <code>~/.emacs</code> file to auto-load <code>package.el</code> on startup. To avoid any problem, it is best to manually remove that code any only keep the load-or-install code above.</p>
<p>Now that ELPA and <code>el-get</code> are setup, we can declare all the packages we want installed. They will be installed the first time emacs is started, and simply loaded in the future.</p>
<pre name="code" class="lisp">
; extra recipes for packages unknown to el-get (yet)
(setq el-get-sources
      '((:name css-mode :type elpa)
        (:name js2-mode-mooz
               :type git
               :url "git://github.com/mooz/js2-mode.git"
               :load "js2-mode.el"
               :compile ("js2-mode.el")
               :features js2-mode)))

; list all packages you want installed
(setq my-el-get-packages
      (append
       '(css-mode egg gist js2-mode-mooz)
       (mapcar 'el-get-source-name el-get-sources)))

(el-get 'sync my-el-get-packages)
</pre>
<p>The <code>el-get 'sync</code> call does all the magic, based on all the packages past in argument (as <code>my-el-get-packages</code>). Any packages for which <code>el-get</code> has a <a href="https://github.com/dimitri/el-get/tree/master/recipes">recipe</a> can be installed.</p>
<p>The <code>el-get-sources</code> variable allows to declare extra custom recipes for code to install. In the example above, <code>css-mode</code> is simply pulled from the ELPA repository, while <code>js2-mode-mooz</code> is fetched directly from Github.</p>
<p>Replicating this code in all your <code>~/.emacs</code> files is a very easy and convenient way to bootstrap the same emacs environment on multiple hosts.</p>
]]></content:encoded>
			<wfw:commentRss>http://bytes.inso.cc/2011/08/13/auto-installing-packages-in-emacs-with-elpa-and-el-get/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

