Emacs clojure mode: how to set current directory & classpath

190 views
Skip to first unread message

Howard Lewis Ship

unread,
Jul 20, 2009, 1:26:19 PM7/20/09
to clo...@googlegroups.com
I've gotten a bit frustrated by the alpha Eclipse plugin and I'm
trying my hand at (Aqua)Emacs again.

My biggest frustration is gettting the classpath & current directory
set up correctly.

I have main my code in package folders under src/main/clojure, and my
tests under src/test/clojure ... and I need src/main/resources and
src/test/resources on the classpath as well.

I'm wondering what other people do to manage these issues. Currently,
I'm using Ant to run my tests, but doing anything in the REPL is hard,
as I have to carefully load my namespaces in the right order, as they
can't be resolved automatically (as that is dependent on having the
classpath set up correctly).

--
Howard M. Lewis Ship

Creator of Apache Tapestry
Director of Open Source Technology at Formos

Chris Dean

unread,
Jul 20, 2009, 1:40:38 PM7/20/09
to clo...@googlegroups.com

> My biggest frustration is gettting the classpath & current directory
> set up correctly.
> I'm wondering what other people do to manage these issues.

What I do is run clojure under slime and have an external script that
creates the correct classspath and then launches clojure. The script
(called clojure) is hooked into slime using something like:

(setq slime-lisp-implementations
`((k-clj ("clojure" "--project" ,(expand-file-name "~/work/kineto")
"--no-rlwrap")
:init swank-clojure-init)
;; ...
(ccl ("/usr/local/bin/ccl"))))


The script makes many assumptions about what needs to be in the
classpath, but it works well for me. I don't expect the script to be
useful to anyone else, but you can look at it in
http://github.com/ctdean/clojure-launch/tree/master

It's written in Ruby and is Unix-centric.

Cheers,
Chris Dean

Phil Hagelberg

unread,
Jul 20, 2009, 1:59:07 PM7/20/09
to clo...@googlegroups.com
Howard Lewis Ship <hls...@gmail.com> writes:

> I have main my code in package folders under src/main/clojure, and my
> tests under src/test/clojure ... and I need src/main/resources and
> src/test/resources on the classpath as well.
>
> I'm wondering what other people do to manage these issues. Currently,
> I'm using Ant to run my tests, but doing anything in the REPL is hard,
> as I have to carefully load my namespaces in the right order, as they
> can't be resolved automatically (as that is dependent on having the
> classpath set up correctly).

I use the clojure-project function to launch slime; it sets up the
classpath according to my project conventions:

http://github.com/technomancy/emacs-starter-kit/blob/a46328f2ad0cb437bf22aaf42f4f25f53126102f/starter-kit-lisp.el#L104

As long as you unpack your deps all in one place and stick to the same
classpath conventions, the fact that you can't change the classpath at
runtime is not a significant problem.

For running tests, I wrote clojure-test-mode:

http://github.com/technomancy/clojure-mode/blob/ef9556612617c5cf0a14bb9f9e2cc03c3b51b465/clojure-test-mode.el

(This hasn't been updated to reflect the move of test-is -> clojure.test
yet; patches welcome.)

It will run tests in-process via SLIME. Of course, you can't rely on
this solely because your results can be affected by a "dirty JVM", so
it's important to do a sanity-check with a fresh instance before each
check-in. But running in SLIME speeds up the test-implement-refactor
rhythm pretty significantly for me at least.

-Phil

Baishampayan Ghose

unread,
Jul 20, 2009, 2:58:16 PM7/20/09
to clo...@googlegroups.com
Phil,

> As long as you unpack your deps all in one place and stick to the same
> classpath conventions, the fact that you can't change the classpath at
> runtime is not a significant problem.

Can you kindly explain exactly what kind of conventions you follow as
far as laying out the code, dependencies are concerned?

A sample directory structure would help.

Regards,
BG

--
Baishampayan Ghose <b.g...@ocricket.com>
oCricket.com

signature.asc

Laurent PETIT

unread,
Jul 20, 2009, 3:04:11 PM7/20/09
to clo...@googlegroups.com
So bad you had a bad user experience with the clojure plugin, but I can understand that you have not been "patient" (*) enough for us to fix the performance issue you found.

I hope you will give it a try from time to time, though.

Regards,

--
Laurent


(*) pun intended in relation with another thread in this ml :-p


2009/7/20 Howard Lewis Ship <hls...@gmail.com>

Howard Lewis Ship

unread,
Jul 20, 2009, 3:23:14 PM7/20/09
to clo...@googlegroups.com
On Mon, Jul 20, 2009 at 12:04 PM, Laurent PETIT<lauren...@gmail.com> wrote:
> So bad you had a bad user experience with the clojure plugin, but I can
> understand that you have not been "patient" (*) enough for us to fix the
> performance issue you found.
>
> I hope you will give it a try from time to time, though.

I'll definitely keep track; I'm very clumsy in Emacs ... but until the
perf. issue is resolved, plus maybe adding some debugging support,
there's no advantage to running inside Eclipse. In addition, it's also
the very immature Git plugin ... it's easier to just use the git
command line. In other words, why use an IDE if things aren't
Integrated?

Phil Hagelberg

unread,
Jul 20, 2009, 3:25:07 PM7/20/09
to clo...@googlegroups.com
Baishampayan Ghose <b.g...@ocricket.com> writes:

> Phil,
>
>> As long as you unpack your deps all in one place and stick to the same
>> classpath conventions, the fact that you can't change the classpath at
>> runtime is not a significant problem.
>
> Can you kindly explain exactly what kind of conventions you follow as
> far as laying out the code, dependencies are concerned?

Sure. It's explained in this post.

http://technomancy.us/126#projects

Basically:

* Source under src/
* Tests under test/
* AOT bytecode under target/classes/
* Dependencies all unpacked together under target/dependency/

Since I use the same conventions for every single project, I never have
to change my classpath.

-Phil

Howard Lewis Ship

unread,
Jul 20, 2009, 3:27:28 PM7/20/09
to clo...@googlegroups.com
How well does the Emacs Starter Kit work in AquaEmacs?

Phil Hagelberg

unread,
Jul 20, 2009, 3:47:58 PM7/20/09
to clo...@googlegroups.com
Howard Lewis Ship <hls...@gmail.com> writes:

> How well does the Emacs Starter Kit work in AquaEmacs?

Unfortunately I can't test it with Aquamacs myself since it's not
portable, but I've heard reports of it working well. Aquamacs is
incompatible with GNU Emacs in a number of undocumented edge-cases, but
the Starter Kit is pretty simple.

You'll definitely have fewer compatibility issues in the long run with
GNU Emacs though, especially now that the 23 release (scheduled for
release this Wednesday) includes a Cocoa port.

-Phil

Howard Lewis Ship

unread,
Jul 20, 2009, 4:53:04 PM7/20/09
to clo...@googlegroups.com
What version of emacs should I be using? Currently I'm using Emacs
22.1.1, which I believe is the built-in version for mac.

When I m-x clojure-project, it prompts for a directory, but then fails with:

Symbol's function definition is void: swank-clojure-cmd

In addition, if I open a Clojure (.clj) file, it doesn't switch to a
Clojure (or Lisp) editor.

Any advice?

Howard Lewis Ship

unread,
Jul 20, 2009, 4:54:34 PM7/20/09
to clo...@googlegroups.com
I'm dense ... missed the part about installing the clojure mode, trying again.

Howard Lewis Ship

unread,
Jul 20, 2009, 4:58:13 PM7/20/09
to clo...@googlegroups.com
Marking those packages, then 'x' to execute, generates a number of errors:

Compiling file /Users/Howard/.emacs.d/elpa/clojure-mode-1.1/clojure-mode-pkg.el
at Mon Jul 20 \
13:56:16 2009
^L
Compiling file /Users/Howard/.emacs.d/elpa/clojure-mode-1.1/clojure-mode.el
at Mon Jul 20 13:5\
6:16 2009

In clojure-font-lock-extend-region-def:
clojure-mode.el:262:32:Warning: reference to free variable
`font-lock-beg'
clojure-mode.el:269:29:Warning: assignment to free variable
`font-lock-beg'
clojure-mode.el:270:32:Warning: reference to free variable
`font-lock-end'
clojure-mode.el:272:18:Warning: assignment to free variable
`font-lock-end'

In clojure-font-lock-extend-region-comment:
clojure-mode.el:287:26:Warning: reference to free variable
`font-lock-beg'
clojure-mode.el:284:49:Warning: reference to free variable
`font-lock-end'
clojure-mode.el:288:17:Warning: assignment to free variable
`font-lock-beg'
clojure-mode.el:292:17:Warning: assignment to free variable
`font-lock-end'

In clojure-indent-function:
clojure-mode.el:421:33:Warning: reference to free variable
`calculate-lisp-indent-last-sexp'

In end of data:
clojure-mode.el:677:1:Warning: the following functions are not known
to be defined:
comint-get-source, comint-check-source, comint-send-string,
inferior-lisp-proc, switch-to-lisp, slime-setup,
swank-clojure-slime-mode-hook
^L
Compiling no file at Mon Jul 20 13:56:16 2009
^L
Compiling file /Users/Howard/.emacs.d/elpa/clojure-test-mode-1.2/clojure-test-mode-pkg.el
at M\
on Jul 20 13:56:16 2009
^L
Compiling file /Users/Howard/.emacs.d/elpa/clojure-test-mode-1.2/clojure-test-mode.el
at Mon J\
ul 20 13:56:16 2009
clojure-test-mode.el:88:1:Error: Cannot open load file: slime

Luke Renn

unread,
Jul 20, 2009, 5:34:45 PM7/20/09
to Clojure
On Jul 20, 3:25 pm, Phil Hagelberg <p...@hagelb.org> wrote:
> Basically:
>
> * Source under src/
> * Tests under test/
> * AOT bytecode under target/classes/
> * Dependencies all unpacked together under target/dependency/
>
> Since I use the same conventions for every single project, I never have
> to change my classpath.

Emacs Starter Kit will also add any jars in lib/ to your classpath.

Phil Hagelberg

unread,
Jul 20, 2009, 7:13:57 PM7/20/09
to clo...@googlegroups.com
Howard Lewis Ship <hls...@gmail.com> writes:

> What version of emacs should I be using? Currently I'm using Emacs
> 22.1.1, which I believe is the built-in version for mac.

That should do the trick; you might as well wait for the release if you
want to get version 23 since it's so soon. The package manager situation
on the Mac leaves much to be desired.

> Marking those packages, then 'x' to execute, generates a number of errors:

Those are mostly just warnings; the only error (for clojure-test) is the
fact that slime hasn't been installed. Once you've got clojure-mode
installed and run M-x clojure-install, the slime dependency will be
satisfied. So that shouldn't be a problem; just go ahead.

-Phil

Garth Sheldon-Coulson

unread,
Jul 20, 2009, 4:56:09 PM7/20/09
to clo...@googlegroups.com
If the Eclipse plugin isn't working for you and you're looking for an
IDE, you might try the La Clojure plugin for IDEA. It's stable and
featureful and works great for me.
--
Sent from my mobile device

Baishampayan Ghose

unread,
Jul 21, 2009, 8:18:33 AM7/21/09
to clo...@googlegroups.com
Phil,

Many thanks.

I tried using your clojure-project script, I am facing two problems:

1. When I try running the function on a fresh Emacs, it bails out
because swank-clojure-extra-vm-args is not defined at that stage. I
fixed that by running the SLIME repl once before running the
clojure-project function.

2. After that, it still fails to work as it remains stuck at the
"Polling /tmp/slime.634..." stage.

Any pointers?

signature.asc

Baishampayan Ghose

unread,
Jul 21, 2009, 8:40:28 AM7/21/09
to clo...@googlegroups.com
Phil,

Another question. Where do I put the clojure & clojure-contrib JAR files?

signature.asc

Anne Ogborn

unread,
Jul 20, 2009, 7:52:51 PM7/20/09
to clo...@googlegroups.com

While we're on this subject, anybody know the same information for La Clojure? That is, how to set up the current directory and classpath so one can compile java classes from Clojure?

IntelliJ has many strengths, but a simple, transparent mechanism to add an arbitrary directory or jar to the classpath isn't among them.



Phil Hagelberg

unread,
Jul 21, 2009, 12:15:02 PM7/21/09
to clo...@googlegroups.com
Baishampayan Ghose <b.g...@ocricket.com> writes:

> Another question. Where do I put the clojure & clojure-contrib JAR files?

If you use the M-x clojure-install command, this should get all the dependencies.

If you're getting stuck at the "Polling" stage, it's probably because
you didn't do M-x clojure-install. If you do that and you still see the
error, then paste the contents of your *inferior-lisp* buffer for
debugging.

-Phil

Glen Stampoultzis

unread,
Jul 21, 2009, 10:45:05 PM7/21/09
to clo...@googlegroups.com

2009/7/21 Anne Ogborn <anni...@yahoo.com>



While we're on this subject, anybody know the same information for La Clojure?  That is, how to set up the current directory and classpath so one can compile java classes from Clojure?

IntelliJ has many strengths, but a simple, transparent mechanism to add an arbitrary directory or jar to the classpath isn't among them.


Project Settings -> Modules -> Dependencies (tab) -> Add.

I'm not sure if that's what you mean by transparent mechanism.  You always setup the dependencies on a per project basis.  You can set up "Jar Directories" to automatically include all jars inside a particular directory. This stops you having to specify them individually.

I'm hoping we don't have to wait too much longer for the next release of La Clojure.  The current version is a nice start but is a little rough around the edges.


Baishampayan Ghose

unread,
Jul 28, 2009, 5:15:39 AM7/28/09
to clo...@googlegroups.com
Phil,

>> Another question. Where do I put the clojure & clojure-contrib JAR files?
>
> If you use the M-x clojure-install command, this should get all the dependencies.
>
> If you're getting stuck at the "Polling" stage, it's probably because
> you didn't do M-x clojure-install. If you do that and you still see the
> error, then paste the contents of your *inferior-lisp* buffer for
> debugging.

OK. I found the problem. I didn't unzip clojure.jar inside
target/dependency. Now it works fine, which brings me to another issue.

Do I have to unzip all dependencies into target/dependency? Can't I work
with just JAR files? For example, I really wanted to put the
clojure-contrib.jar in the folder, but it didn't work. I had to unzip it
and then it worked. Same with some other external deps.

Is there any way for me to just put the JAR files somewhere and get them
added to the classpath?

Thanks in advance.

signature.asc

Piyush Ranjan

unread,
Jul 28, 2009, 6:58:23 AM7/28/09
to clo...@googlegroups.com

For me it works like this
.bashrc
export CLASSPATH=.:/usr/local/clojure/clojure-1.0.0.jar
 
.emacs
(setq inferior-lisp-program "java -server clojure.lang.Repl")
(setq load-path (cons "/usr/local/clojure/clojure-mode" load-path))
(require 'clojure-mode)



Thanks in advance.

Regards,
BG

--
Baishampayan Ghose <b.g...@ocricket.com>
oCricket.com

Phil,

Baishampayan Ghose

unread,
Jul 28, 2009, 8:43:01 AM7/28/09
to clo...@googlegroups.com
Piyush,

> For me it works like this
> .bashrc
> export CLASSPATH=.:/usr/local/clojure/clojure-1.0.0.jar
>
> .emacs
> (setq inferior-lisp-program "java -server clojure.lang.Repl")
> (setq load-path (cons "/usr/local/clojure/clojure-mode" load-path))
> (require 'clojure-mode)

I was not talking about the Clojure JAR. I wanted a nice way to use
external library JARs along with the clojure-project function which Phil
has written.

signature.asc

Luke Renn

unread,
Jul 28, 2009, 10:09:48 AM7/28/09
to Clojure
On Jul 28, 5:15 am, Baishampayan Ghose <b.gh...@ocricket.com> wrote:
> Is there any way for me to just put the JAR files somewhere and get them
> added to the classpath?

Put them in a lib/ folder at your project root.

Luke

Baishampayan Ghose

unread,
Jul 28, 2009, 10:32:11 AM7/28/09
to clo...@googlegroups.com
Luke,

>> Is there any way for me to just put the JAR files somewhere and get them
>> added to the classpath?
>
> Put them in a lib/ folder at your project root.

Many thanks Luke. That worked. I should have looked at the source of
clojure-project before.

Thanks again.

signature.asc

Luke Amdor

unread,
Jul 29, 2009, 9:09:56 AM7/29/09
to Clojure
I wrote a emacs macro to help set up different slime implementations
for clojure. It has been really helpful. It's at

http://github.com/rubbish/rubbish-emacs-setup/blob/ad5bfc6f74cc9f794470e50080f8076b5599fb24/mine/mine-slime.el#L19

I probably should contribute it back to swank-clojure though.

Luke
> Baishampayan Ghose <b.gh...@ocricket.com>
> oCricket.com
>
>  signature.asc
> < 1KViewDownload
Reply all
Reply to author
Forward
0 new messages