aleix's blog

Install Emacs packages from command line

8 January 2013 4:33 pm (emacs)

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 elisp to install a package from the command line.

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

The elisp 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-refresh-contents)

(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:

#!/bin/sh

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

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

14 responses

  1. George Jones says:

    Thanks for the code.

    I had do

    (package-initialize)

    after

    (require 'package).

    Also had to explicitly call

    emacs-snapshot

    in the .sh script ... maybe it was pulling an older version?

    Thanks,
    ---George Jones

  2. Alejandro says:

    Thanks for the code.
    Great scripts man!
    =D

  3. Assignment Service by Buyassignment.com says:

    Command Prompt agenda permit you to employment in a circumstances that look more like a conservative working structure instead of the symbol.

  4. StephenScott says:

    They are the most confided in the business. The journalists are upbeat to help and they can compose on any given subject. One need not stress over the cost as the costs are extremely reasonable. The essayists make unique work buy coursework online and they convey on time.

  5. Coursework Writing Service says:

    Emacs incorporates an office that lets you effortlessly download and introduce bundles that execute extra highlights. Each bundle is a different Emacs Lisp program, now and then including different parts, for example, an Info manual.

  6. StephenScott says:
  7. vpn torrent says:

    thankyou for uploading this sitevpn torrent

  8. scienzappeal says:

    This is very basic programming tips that you give in this lesson. Students who new in this field ca understand easily.I am waiting for expert level programming.

  9. Bingwear says:

    This was a great and interesting article to read Nike Air Max Zero QS Men's Shoes Black / Grey 789695 001 . I have really enjoyed all of this very cool information

  10. Tyfanati says:

    The leading assignment help UK firm offers state of the art services to its clients with a promise of delivering all the required work well within the Zapatillas Adidas EQT Support ADV Unisexo Negro / Azul claro BA8338

  11. Bingwear says:

    This is great information for students. This article is very helpful i really like this Air Jordan 6 Retro Unisex Scarpe Bianca / Blu thanks. I also have some information relevant for online dissertation help.

  12. Sopfanati says:

    This is great information for students. This article is very helpful i really like this Nike Air Huarache Run Ultra Unisex Sko Sort 819685 002 thanks. I also have some information relevant for online dissertation help.

  13. Electronics Engineering Assignment Help says:

    This is great information for students. This article is very helpful i really like this blog thanks. I also have some information relevant for online dissertation help.

  14. Bingwear says:

    The Kvinner Air Jordan 7 Retro Hyper Rosa Joggesko Svart 442960-018 which you people are given are really good, These look really great.

Leave a Reply