Monthly Archives: August 2011

Setting up Emacs for Clojure using Lein

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

  • Download “lein”
  • $ wget

  • 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

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


    Changing Caps_Lock as third Ctrl key

  • create map
  • $ sudo dumpkeys | head -1 > /usr/share/keymaps/

  • add following lines to that file
  • keycode 58 = Control # This makes Caps act as Ctrl
    # keycode 29 = Caps_Lock # This makes Ctrl act as Caps
    # alt_is_meta # This fixes the Alt key

  • run loadkeys on that file
  • $ sudo loadkeys /usr/share/keymaps/

  • to revert and load default keymap
  • $ sudo loadkeys -d

    Reference :

    Another option is to execute following command

    $ setxkbmap -option ctrl:nocaps