Sunday, 10 January 2010

Further Adventures in Emacs

I've decided, if I want to be a Clojure programmer - if I want to be a serious hacker - then I need to learn Emacs. Enough screwing around. I don't need to learn it all at once. If I start using it now, and learn the shortcuts as and when I need them, then in a few months (years?) I should be fairly proficient.
So - I need to set Emacs up on my main Ubuntu PC, on my Mac, and on my Windows work PC. I already tried to set up my work PC using the Emacs Starter Kit, but I couldn't make it work with my company's proxy. I therefore plan to set it up on my Windows PC at home, then send myself a tar ball of the .emacs.d directory for work.

But, first things first. I need to install Emacs + Clojure + Slime on my Ubuntu PC. In a previous post I linked to some articles which described how to set this up. However, I have since discovered that the preferred way is to use the Emacs Starter Kit to install swank-clojure. So that's what I'm going to do. I will document the steps for future reference, and for anyone else who wants to do the same.

From home directory:
  1. Install Emacs: sudo apt-get install emacs23
  2. Get the Emacs Starter Kit: git clone git://github.com/technomancy/emacs-starter-kit.git .emacs.d
  3. Run Emacs: emacs &
  4. In Emacs, install swank-clojure: M-x package-list-packages, put an 'I' beside package swank-clojure, and then press 'x' to install.
  5. Run slime: M-x slime
  6. That should prompt to install Clojure. Type 'y' and all should be working.
When I first tried to install this I was getting problems with starting up Slime.
user=> java.io.FileNotFoundException: Could not locate swank/swank__init.class or swank/swank.clj on classpath:  (NO_SOURCE_FILE:0)
user=> user=> java.lang.ClassNotFoundException: swank.swank (NO_SOURCE_FILE:0)
user=> user=> nil
java.lang.ClassNotFoundException: swank.swank (NO_SOURCE_FILE:0)
user=> user=>
It turns out this was because I had already manually installed Clojure into my ~/.clojure directory. When I removed the .clojure directory and tried again, it all worked fine. Watching the video at http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-clojure-slime-installed/ pointed me in the right direction for solving this. I realized that I wasn't being prompted to install Clojure, which suggested to me that I should mask the manually installed version.

Now to try to do the same on Windows...

Update 1: I followed the same process on my Windows PC, but got the following error when installing swank-clojure: "Local variables entry is missing the suffix". A quick Google brought me to http://groups.google.com/group/clojure/browse_thread/thread/c4d00ba0f1614c49?pli=1. Basically the solution was to edit my ~/.emacs.d/package.el file to make the changes indicated in that post. I've placed the edited version that I used at: http://files.nwalex.com/package.el. Use at your own risk.

Update 2: I also made the following changes to make Emacs work better on my work PC. The Emacs Starter Kit will look for a file called [username].el, and load it as part of the initialization process. So I created a file called alexanc.el in .emacs.d and added the following to make it work well with our proxy:
;;; set up the proxy
(setq url-using-proxy t)
(setq url-proxy-services
'(("http" . "our-proxy:8080")))
I'm starting to really enjoy working with Emacs.

2 comments:

  1. Hi, I've used your update 2 to solve the proxy problem I was facing but I found I still cannot invoke M-x package-refresh-contents to install the Startup Kit.

    I'm new to Emacs and just want to make sure if I need the ' on line 4?

    My IE proxy needs authentication, do you have any recommendation?

    ReplyDelete
  2. Sorry Dean, I'm not an Emacs expert. I just documented this at the time for my own future reference. My best advice would be to Google for it.

    I'm pretty sure I copied that directly from my config file, so the ' is there for a reason.

    Hope you work it out!

    ReplyDelete