Installation and configuration should be as simple as putting this
file into your Emacs config, pressing M-x clojure-install, and following
a few simple instructions:
I blogged about the details here: http://technomancy.us/122
I've tested this on GNU/Linux systems (Emacs 23 and 22), and it's been
reported to work well on Mac OS X also. Please let me know how it works
for you or if you have any comments. This has definitely been a pain
point in the past, and it would be great if it could be streamlined.
-Phil
> (defun get-classpath-list ()
> (if
> (or
> (eq 'windows-nt system-type)
> (eq 'ms-dos system-type))
> (split-string (getenv "CLASSPATH") ";")
> (split-string (getenv "CLASSPATH") ":")))
>
> (setq swank-clojure-jar-path
> (dev-dir "clojure/clojure.jar"))
> (setq swank-clojure-extra-classpaths
> (get-classpath-list))
>
> Get the classpath from the system and set it as your swank classpath.
Thanks; this looks useful. But I've heard people say that using
environment variables for your classpath should be avoided. I'm not sure
what the reasoning behind this is though. Maybe it's just a case of "you
should be explicit instead of implicit"; I could see how it would be
annoying to track down problems that result from the value of an
invisible variable that lives outside your code base.
If the general consensus is that using environment variables is a good
idea, then I can merge this into clojure-mode.
For projects that depend on Java jars, my approach so far has been to
construct the classpath list from a directory listing and then include
the elisp code to do so in the source directory:
(setq concourse-dir (file-name-directory
(or (buffer-file-name) load-file-name))
swank-clojure-jar-path (concat concourse-dir "/jars/clojure.jar")
swank-clojure-extra-classpaths (directory-files (concat concourse-dir "/jars/")
t ".jar$"))
-Phil
Ditto, I'm still busted on Windows with the latest snaps of
everything, just as I was a couple of weeks ago. Haven't tried
installing on my Ubuntu box yet to see if this is indeed windows
specific.
-tree
--
Tom Emerson
trem...@gmail.com
http://treerex.blogspot.com/
> Had to use a different .emacs. Just autoload and add-to-list didn't
> seem to load clojure-mode.el.
That's correct; this will not load the code. It just sets it up so that
the file gets loaded on-demand when you open a clojure file. I will add
a note mentioning that the first time you want to run the installer you
should manually load clojure-mode.el yourself since the autoload won't
help you. This is unclear in the current instructions; sorry.
> Took a moment to figure out that I had to set clojure-src-root as
> well, as that isn't mentioned at the top of the clojure-mode.el
> file. I've no clue why autoload won't work.
That's not actually right; you don't need to set clojure-src-root to use
clojure-mode. You only need it to use SLIME if you install somewhere
other than ~/src. It will give you instructions about this when the
installation completes, but it looks like you had network connectivity
issues keeping this from working.
> (push "/home/boris/.emacs.d" load-path)
This is actually already on the load-path by default; no need to add it.
> (load-library "clojure-mode")
You only need to do this when you're running the installer, so it's
probably not worth running every single time you launch Emacs.
> The kevinoneill clojure-contrib failed for me (might be my
> connection), so I replaced both kevinoneills with the svn checkouts
> from googlecode. In retrospect it might have been because I didn't
> replace git:// with http:// that is neccesary for me to git past a
> proxy. The slime git worked fine, but took ages.. I replaced it with
> git clone http://git.boinkor.net/git/slime.git
Ugh... I didn't think about nasty firewalls blocking the git port. I
don't want to switch it to http by default, but maybe it could provide a
fallback mechanism?
> Furthermore, it might be nice to have an 'overwrite? ignore? keep?
> option when clojure-install encounters relevant directories in the
> clojure-src-root already. With all the failed gits, I've been
> downloading clojure and clojure-contrib 5 times before all was
> downloaded.
Maybe. I was trying to keep it simple, but if this turns out to be a
common problem I could add it.
> The whole thing compiled without any trouble, and after a M-x slime
> told me it "Cannot open load file: slime-repl". I am guessing it is
> because I use a different slime git.
Your slime checkout should have a contrib directory containing
slime-repl.el. If this doesn't exist, then it's a problem with the
checkout. If it does, it's a problem with the way the load-path is set
up.
-Phil
>>> (push "/home/boris/.emacs.d" load-path)
>>This is actually already on the load-path by default; no need to add it.
>
> Standard load-path on ubuntu didn't include ~/.emacs.d for me. Not
> sure why not.
You're right; my bad.
> 1. Creating a .emacs with the load-path .emacs.d
> 2. Downloading clojure-mode.el
> 3. replacing git:// with http:// to get past my proxy
> 4. The slime git kept failing (stalled somewhere near the end of
> downloading), so I removed that line from clojure-mode.el and
> installed a snapshot of slime myself.
> 5. The clojure git failed as well, I replaced it with the "svn
> checkout http://clojure.googlecode.com/svn/trunk/ clojure" in clojure-
> mode.el
I can't reproduce these download problems... Has anyone else had trouble
with these URLs?
> I think perhaps the best thing to do with the failing gits (for
> whatever reason) is to just let the script skip the downloading of new
> checkouts if an old checkout is present, and to let it give a message
> like this: "Failed to checkout slime, please do so manually, install
> in ~/src and rerun M-x clojure-install".
Yeah, not a bad idea.
> 1. It can't find M-x slime clojure-slime-config doesn't seem to be an
> option either to manually run with M-x clojure<tab>
clojure-slime-config is a function, but it's not a command, so you can't
invoke it via M-x. It should only be invoked from your .emacs file. I
suspect you're missing the autoload that it mentions in the
clojure-mode.el header:
;; (autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
;; (add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
That should go in your .emacs file.
I should have mentioned that if you don't already have an Emacs config,
you could try the Emacs Starter Kit, where clojure-mode is already
installed for you. (You would still have to install Clojure though.) But
the autoloads are all set up for you.
http://github.com/technomancy/emacs-starter-kit
> (setq swank-clojure-jar-path (concat clojure-src-root "/clojure/clojure.jar")
> swank-clojure-extra-classpaths
> (list (concat clojure-src-root "/contrib/src/"))))
This isn't right according to the default installation, but if you
checked things out manually it could be different.
-Phil
> I have a small problem with clojure-mode in your setup.
>
> Since clojure-mode is autoloaded, it, and SLIME, aren't available
> until I load a '.clj' file.
> Starting SLIME, though, doesn't add the SLIME menu to the previously
> loaded '.clj' buffer
> (Newly loaded files get the menu, as they should).
Yeah, I've thought about a hook that runs after SLIME loads to activate
slime-mode for all pre-existing clojure-mode buffers; just haven't
gotten around to it.
If you're handy with elisp, I'd love a patch, otherwise I'll get around
to it eventually. =)
-Phil
> I can't really claim to be handy with elisp, but I got by.
> (Is there a guide to elisp functions anywhere? The Lisp
> reference didn't include the Common Lisp emulation library,
> and I never did find an equivalent to the clojure filter()).
The Elisp CL emulation package is documented in its own top-level Info
node for some reason rather than in the Elisp manual.
> Anyway, here's what I added to my .emacs:
>
> (defun add-slime-mode-to-existing-buffers ()
> (interactive)
> (let ((clojure-buffers (remove-if-not 'is-clojure-buffer (buffer-
> list))))
> (dolist (b clojure-buffers)
> (set-buffer b)
> (slime-mode))))
> (eval-after-load 'slime '(add-slime-mode-to-existing-buffers))
Cool! It's a little simpler to check for the value of the major-mode
local variable rather than to use the filename, so here's what I ended
up with:
(defun clojure-enable-slime-on-existing-buffers ()
(interactive)
(dolist (buffer (buffer-list))
(if (equal '(major-mode . clojure-mode)
(assoc 'major-mode (buffer-local-variables buffer)))
(with-current-buffer buffer
(slime-mode t)))))
> Let me know if you add it to your repository.
I've committed this to my copy, but I don't know when it will go
upstream to the mainline clojure-mode branch, as the maintainer has been
out of communication for some time.
http://github.com/technomancy/clojure-mode/
> There could conceivably be some issues with multiple slime
> connections, or with running slime-mode repeatedly on the same
> buffer. I couldn't find any easy way to determine if a buffer already
> had slime-mode -- love to hear from someone who is actually handy
> with elisp!
Calling slime-mode with an argument of t forces it to enable rather than
toggling it. I don't know about multiple slime connections though; it
seems kind of edge-casey, though I can look into it if it causes
problems.
Thanks for getting the ball rolling on this.
-Phil