A TextMate bundle for Clojure. Check out the screencast here.
This bundle has only been tested with Clojure 1.2.0, though we'd love to hear experience reports about 1.1.0.
$ cd ~/Library/Application\ Support/TextMate/Bundles $ git clone git://github.com/swannodette/textmate-clojure.git Clojure.tmbundle $ osascript -e 'tell app "TextMate" to reload bundles'
If you are using RVM it is important to follow the TextMate integration instructions pretty closely. More details of the issues on this thread
This fork adds quite a few commands via Cake which makes the TextMate experience considerably more "Lispy".
First you need to install Cake.
sudo gem install cake
If you already have Cake installed make sure you have at least version 0.5.6.
Once installed you can create and save a new file with the
.clj extension. Type the following expression into this new file and place your cursor as indicated:
(+ 4 5) -------^
Control-X. If you haven't saved the file yet, you will be prompted to do so. The first time you run this command it will take several seconds to see a result. This is because the JVM is starting up. After the first time,
Control-X will be much, much, much faster.
Most of the time you won't be working with single files. You'll be working with projects. Let's make a new project:
cake new hello-world cd hello-world mate .
project.clj to look like the following:
(defproject hello-world "0.0.1-SNAPSHOT" :description "TODO: add summary of your project" :dependencies [[org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"]])
Then from the command line:
Create a source file in your
src directory called
hello_world.clj. Paste this code into there:
(ns hello-world) (defn hello-world  (println "Hello world!"))
Command-Shift-L. This will load your file. You now have a function that you can run. One way is by typing the following and
Control-X in the position indicated:
But this would be ignoring the versatility of Cake's REPL. At the command line from your project directory type:
This will drop you into the same persistent REPL that your project is using, type the following incomplete sexpr and press the
Tab key. This should autocomplete the hello-world namespace:
user=> (in-ns 'he
Close the paren and press enter. You are now in the namespace of the file you are currently working on. Running the
hello-world fn from here is an exercise left to the reader ;)
This bundle works great with your lein projects. Just
cd into them and run
mate. TextMate will load the directory you can just type
Command-R and this will start Cake.
- Cake Start : Start up a persistent REPL
- Cake Restart : Restart Cake
- Load File : load the entire file into the current REPL.
- Eval : will evaluate the selected code in the current REPL for the project directory.
- Eval Last Sexpr : will evaluate the sexpr immediate before the cursor
- Wrap Sexpr : wrap the selected sexpr
- Unwrap Sexpr : unwrap the selected sexpr
- Autocomplete : autocomplete a partially typed symbol
- Show Source : shows the source of the selected function in a new window.
- Show Doc : shows the document of the selected function in a new window.
- Jump To Definition : jump to the definition of a symbol (currently only works on files not in jars)
- Macroexpand : macroexpands the selected sexpr.
- Macroexpand all : fully macroexpands the selected sexpr.
Hacking & Contributing
This bundle is written almost entirely in Clojure. All commands trigger Clojure scripts which you can find in the bundle under
textmate-clojure/Support/bin. Feel free to fork and contribute. There's also a support mailing list here.
In order to get proper word movement in Clojure you might want to set your Word Characters to
_/-.: in the Text Editing tab of the TextMate Preferences window.
For an even more SLIME like experience you could install Visor so that switching to the REPL is just a key-stroke away.