8 Jan 2013 aleix   » (Journeyer)

Install Emacs packages from command line

Lately, I have found myself playing with packages and my .emacs too much. Sometimes I had to comment the use of a package (e.g. smex) because it was not installed.

So, at the end, I wrote this basic Emacs lisp to install a package from the command line. Just type:

$ emacs --batch --expr "(define pkg-to-install 'smex)" -l emacs-pkg-install.el

The script looks like this:

;; Install package from command line. Example:
;;   $ emacs --batch --expr "(define pkg-to-install 'smex)" -l emacs-pkg-install.el

(require 'package)

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

(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)

;; Fix HTTP1/1.1 problems
(setq url-http-attempt-keepalives nil)


(package-install pkg-to-install)

For convenience, you can wrap it in a shell script and simply type:

$ ./emacs-pkg-install.sh smex

The shell script:


if [ $# -ne 1 ]
  echo "Usage: `basename $0` <package>"
  exit 1

emacs --batch --eval "(defconst pkg-to-install '$1)" -l emacs-pkg-install.el

Syndicated 2013-01-08 10:20:12 from aleix's blog

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!