Mark Engelberg <mark.engelb...@gmail.com> writes:

> Phil makes a reasonable point that it is possible to create a single
> "project" for one-off tasks.  I'm not sure how well that would work
> with the way I have things organized, and with my source control, but
> it's something I can look into.

I have a "scratch" project which I use for that sort of thing.  I still
use M-x slime (not lein swank or that new jack-in stuff) when doing
non-project stuff.  I don't know if M-x slime is still supported in
newer versions, I haven't updated swank-clojure in ages.  I hope it is,
it's really handy.

M-x slime just picks up jars from ~/.swank-clojure so I just turn that
into symlink for my scratch project's lib directory.

Here are the steps for setting it up (once off):

1. Create a scratch project.

    $ cd ~/src && lein new scratch

2. Edit ~/src/scratch/project.clj with whatever libs you want.  The
essentials:

    :dependencies [[org.clojure/clojure "1.2.1"]
                   [org.clojure/clojure-contrib "1.2.0"]
                   [swank-clojure "1.2.1"]] 

Newer swank-clojure jars don't work with the old elisp (1.1.0) I'm
running.  Use whatever works for you.

3. Fetch 'em:

    $ cd ~/src/scratch && lein deps

4. For M-x slime in Emacs:

    $ ln -s ~/src/scratch/lib ~/.swank-clojure

5. Make up a ~/bin/clj launch script for CLI use and chmod a+x it:
    
    #!/bin/sh
    exec rlwrap java -cp "$HOME/src/scratch/lib/*" clojure.main "$@"

Now use M-x slime and "clj" as you would expect.  If you want to install
some more jars, update the scratch project.clj, rerun lein deps and
restart emacs.

What's much nicer about this than the Python/Ruby model is that whatever
libs you put in your scratch area are not automatically on the load
path for all your proper projects.  That keeps away the load path
pollution and version conflict issues that led to the creation of ugly
workarounds like RVM.

----------------------------------------------------------------------

A fun little project for someone might be to wrap this workflow into a
tiny lein plugin with a couple of convenience commands for setting it up
and updating project.clj.  Perhaps something like:

    leni scratch setup   # init project, clj script, swank symlink
    lein scratch install foo 1.5.0
    lein scratch uninstall foo
    lein scratch swank
    lein scratch repl

----------------------------------------------------------------------

Tip: If you create a symlink from a source *directory* (not a jar) into
~/src/scratch/lib and just name it ".jar" swank and lein will both stick
that directory on the classpath.  They don't actually check that it's a
jar file.

So if you've got lots of mini-projects scattered around that you want
on your scratch classpath you can just do something like:

    $ ln -s ~/src/coolproject/src/ ~/src/scratch/lib/coolproject-src.jar
    $ ln -s ~/src/junk-clj-files ~/src/scratch/lib/junk.jar

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to