jasongilman / SublimeClojureSetup

Sublime Text Clojure Workflow and Setup
88 stars 10 forks source link

I no longer actively use or maintain this configuration. This still works but I encourage you to try my Atom editor package Proto REPL.

SublimeClojureSetup

A description of how I setup Sublime Text for Clojure development. It's a bit hacky but it works if you prefer to use Sublime Text for your editing. This is specific to my own workflow on a Mac but should be mostly applicable to development on other platforms with Sublime Text.

Initially based on instructions here: https://gist.github.com/jamesmacaulay/5457344

Prerequisites

Leiningen

Install it then create ~/.lein/profiles.clj. See profiles.clj in this repo for contents.

Sublime Text 2 With Clojure

This documents how to setup Sublime Text 2 with Clojure. It uses the sublime text package manager. Follow the installation instructions to install the package manager into Sublime Text 2. If you already have the package manager installed make sure all packages are up to date.

How to perform basic tasks

Open a Clojure REPL

The Sublime REPL is used to open a REPL within Sublime Text. It can be opened by:

Very Important: Most of the time you'll want a REPL open for the current project. Sublime REPL only knows to connect the REPL to the current project if you start the REPL with a Clojure file open in the project and your cursor is in it.

Keybindings

These are setup in the instructions Sublime Text setup instructions below.

Setup

Install These Packages

Install these packages using the package manager.

Sublime Preference Files

Fix Match Brackets

Add this code to your user preferences

// This needs to be disabled since we're using Bracket Highlighter for highlighting brackets
"match_brackets": false
Fix identification of Clojure Symbols

Sublime Text doesn't correctly identify Clojure symbols.

{
  "extensions":
  [
    "cljs"
  ],
  "word_separators": "\\()\"',;@$%^&|[]{}`~"
}
Disable auto-pairing of single quotes

Clojure uses single quote characters by themselves like (def my-literal-list '(1 2 3)). Sublime Text will automatically close single quotes. This becomes annoying when writing Clojure code in sublime text. Turn it off by following these steps:

Add Leiningen to SublimeREPL Path

This file updates SublimeREPL settings so leiningen in on the path. Update this file to include the directory where you installed leiningen.

{
  // Has to include path to lein
  "default_extend_env":
  {
    "PATH": "REPLACE_ME_WITH_LEIN_DIR:{PATH}:/usr/local/bin"
  }
}

Configure Lisp Indentation Settings

The lispindent.sublime-settings defines which forms use function style indentation. I've added additional ones that are typically used in Clojure Applications

* `cp lispindent.sublime-settings ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/`

Speed up text transfer in SublimeREPL

Change ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/SublimeREPL/config/Clojure/Main.sublime-menu line 22 from

"osx":  ["lein", "repl"]

to:

"osx":  ["lein", "trampoline", "run", "-m", "clojure.main"]

This greatly improves the speed at which text is sent from a Clojure window to the REPL. Based on answer here http://stackoverflow.com/questions/20835788/is-it-normal-to-have-really-slow-text-transfer-in-sublime-text-2-with-the-clojur

Setup Keybindings

We'll setup some keybindings in Sublime Text to make it easier to send code to the repl, run tests, etc.

Clojure Helpers

The ClojureHelpers.py file provides some helper functions that make working with Sublime REPL and Clojure a little better. These are associated with key bindings. You can also add your own helpers to this file.

Clojure Snippets

Copy the file clojure_snippets.sublime-snippet to ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/clojure_snippets.sublime-snippet. It contains some useful completions.