Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up the Clojure classpath in Emacs after installing with ELPA?

I'm trying to add paths to my classpath in the Clojure REPL that I've set up in Emacs using ELPA. Apparently, this isn't the $CLASSPATH environment variable, but rather the swank-clojure-classpath variable that Swank sets up. Because I used ELPA to install Swank, Clojure, etc., there are a ton of .el files that take care of everything instead of my .emacs file. Unfortunately, I can't figure out how to change the classpath now.

I've tried using (setq 'swank-clojure-extra-classpaths (list ...)) both before and after the ELPA stuff in my .emacs, and I've tried adding paths directly to swank-clojure-classpath in .emacs, .emacs.d/init.el, and .emacs.d/user/user.el, but nothing works.

What I'm ultimately trying to do is to add both the current directory "." and the directory in which I keep my Clojure programs. I'm assuming swank-clojure-classpath is the thing I need to set here. Thanks for your help.

like image 502
derefed Avatar asked Mar 07 '10 22:03

derefed


2 Answers

As mac says, you can use

M-x swank-clojure-project

to establish a slime REPL to a clojure project; the command will ask you for your projects root directory, and will establish a classpath that includes a variety of directories including src/ lib/ and resources/ if they are present.

Alternatively, if you are using leiningen, you can start that in a terminal with the command

$ lein swank

from inside your project root directory. This will establish a standard project classpath (as above). From here you can connect to this running process via Emacs with the command

M-x slime-connect

Finally a third option which I'd recommend is to connect via Emacs/slime (with M-x slime-connect) to a process started by your own shell script which specifies a custom set of JVM command line arguments e.g.

#!/bin/bash 

java -server -cp "./lib/*":./src clojure.main -e "(do (require 'swank.swank) (swank.swank/start-repl))"

This allows you explicit control over how the VM is started, and is likely similar to what you will likely have to do in production anyway.

like image 68
Rick Moynihan Avatar answered Sep 28 '22 05:09

Rick Moynihan


You want:

M-x swank-clojure-project

This adds all jars in your /lib dir.

If you want to :use a clojure file (bar.clj), in for instance /foo you would do:

(ns foo
  (:use foo.bar)) 
like image 35
mac Avatar answered Sep 28 '22 05:09

mac