Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up SLIME & Inferior-Lisp for Clojure in Emacs

SLIME

I'm pretty new to both Clojure & emacs and I've been trying to set up SLIME for Clojure. The official documentation implicitly assumes you know what your doing with emacs. There isn't just a bunch of code you can stick into your configuration files. Since I am interested in Clojure for Data Analysis, I don't really want to deal with Leiningen if at all possible, but I want the dynamic environment that slime provides.

I have installed Clojure from git in /opt/clojure/ and clojure-contrib in /opt/clojure-contrib and I can get a repl. I installed swank-clojure, clojure-mode, and slime from github in `~/.bin following this tutorial. I changed a few things around when this wasn't working by adding some stuff from the comments section of the official documentation.

When I start slime with M-x slime I get a continuous Polling "/tmp/slime.14113".. (Abort with 'M-x slime-abort-connection'.).

Here is my init-clj.el:

;; clojure-mode
(add-to-list 'load-path "~/.bin/clojure-mode")


;; swank-clojure
(add-to-list 'load-path "~/.bin/swank-clojure")

(setq swank-clojure-jar-path "/opt/clojure/clojure.jar"
  swank-clojure-extra-classpaths (list
                  "~/.bin/swank-clojure/src/swank"
                  "/opt/clojure/clojure-contrib/target/clojure-contrib-1.2.0-SNAPSHOT.jar"))

(require 'swank-clojure)

;; slime
(eval-after-load "slime" 
  '(progn (slime-setup '(slime-repl))))

(add-to-list 'load-path "~/.bin/slime")
(require 'slime)
(eval-after-load 'slime '(setq slime-protocol-version 'ignore))
  (slime-setup '(slime-repl))
(require 'clojure-mode)
(require 'clojure-test-mode)

Here is the error I get when I call it when ants.clj is open:

(progn (load "/home/kca/.bin/slime/swank-loader.lisp" :verbose t) (funcall (read- from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "/tmp/slime.14113" :coding-system "iso-latin-1-unix"))

Clojure 1.2.0-master-SNAPSHOT
user=> java.lang.Exception: Unable to resolve symbol: progn in this context (NO_SOURCE_FILE:1)

Inferior Lisp

I made a script in .bin/ called clj-repl that holds the java command to start a repl. I then M-x set-variable inferior-lisp-program /home/wdkrnls/.bin/clj-repl. Emacs complains its the wrong type.

like image 214
wdkrnls Avatar asked Sep 01 '11 16:09

wdkrnls


2 Answers

The best way to use Clojure is to start by installing Leiningen.

Then install Swank Clojure as a Leiningen plugin.

Next, I'd recommend stripping your current custom Clojure setup from .emacs, and installing ELPA, and then setting up the following initialization code in your .emacs file:

;; Find this line, added by ELPA:
(require 'package)
;; and add the following expression:
(add-to-list 'package-archives
             '("marmalade" . 
               "http://marmalade-repo.org/packages/") t)
;; ... and the rest of the ELPA init code
(package-initialize)

Then, run package-list-packages and install clojure-mode and slime (and paredit for good measure), and anything else you might want.

This should have you all set up and ready to use SLIME in (Leiningen) Clojure projects. And despite the seemingly complex procedure here, you can create a single "uberjar" from your projects to deploy on other servers with absolutely no dependency hassle.

like image 181
John Cromartie Avatar answered Sep 22 '22 00:09

John Cromartie


Try the method detailed here. It takes a couple of minutes to set everything up from scratch on a clean unix or mac box:

http://www.learningclojure.com/2010/08/clojure-emacs-swank-slime-maven-maven.html

like image 23
John Lawrence Aspden Avatar answered Sep 18 '22 00:09

John Lawrence Aspden