Tag Archives: swank

Setting up Emacs for Clojure using Lein

  • Create a directory “~/bin”
  • $ cd ~/bin

  • Download “lein”
  • $ wget https://github.com/technomancy/leiningen/raw/1.6.1/bin/lein

  • Install packages
  • $ aptitude -Ry install emacs23-nox openjdk-6-jdk

  • Create a project directory
  • $ lein new myproject

  • Edit project.clj
  • $ cd myproject
    $ emacs project.clj

    Add “swank-clojure” and “clojure-contrib” lines to it

    File should look like this

    (defproject myproject "1.0.0-SNAPSHOT"
    :description "FIXME: write description"
    :dependencies [[org.clojure/clojure "1.2.1"]
    [org.clojure/clojure-contrib "1.2.0"]]
    :dev-dependencies [[swank-clojure "1.2.1"]])

    Save file and exit out of emacs

  • Download “lein” dependencies
  • $ lein deps

  • Install “emacs” packages
  • Open following link in browser
    http://tromey.com/elpa/install.html

    Open “emacs” and Switch to *scratch* buffer

    $ emacs -nw and then C-x C-b *scratch*

    Follow instructions given on “install.html” link, alternatively copy following
    code to *scratch* buffer

    (let ((buffer (url-retrieve-synchronously
    "http://tromey.com/elpa/package-install.el")))
    (save-excursion
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (eval-region (point) (point-max))
    (kill-buffer (current-buffer))))

    Evaluate above code using “M-x eval-buffer” command

  • Install “emacs modes”
  • Run “M-x package-list-packages”

    Install “swank-clojure” package
    Use “C-s” to Search package name
    Use “i” to select package and then press “x” to install.
    This should also install “clojure-mode” “slime” “slime-repl” packages.

  • Run “swank server”
  • Switch to another terminal
    $ cd ~/myproject
    $ lein swank

    This will start “swank” server on 127.0.0.1:4005 by default

  • Connect to “swank” using “slime”
  • Go back to running emacs instance and type

    “M-x slime-connect”

    It will prompt for “host” and “port”, press to accept default values

    Your Hacking Starts Now!!!

    You may get a version mismatch warning after running “slime-connect”. To remove
    this warning

    $ cd ~/.emacs.d/elpa/slime-20100404/
    and remove .elc file
    $ rm slime.elc

    Distro : Ubuntu 11.04
    Package Versions : Emacs – 23.2, Lein – 1.6.1, Clojure – 1.2.1, Clojure-Contrib – 1.2.0, Swank-Clojure – 1.2.1, OpenJDK-6-JDK – 6b22-1

    Advertisements