Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ClojureHelpers.py #6

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
18 changes: 12 additions & 6 deletions ClojureHelpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re, sublime, sublime_plugin, sublimerepl, text_transfer
from sublimerepl import manager
import re, sublime, sublime_plugin, SublimeREPL
from SublimeREPL.sublimerepl import manager
from SublimeREPL import text_transfer

REFRESH_NAMESPACES_CMD = "(let [r 'user/reset] (if (find-var r) ((resolve r)) (clojure.tools.namespace.repl/refresh :after r)))"

Expand Down Expand Up @@ -148,14 +149,20 @@ def run(self, edit):
external_id = repl_external_id(self)
super( ListVarsWithDocsInSelectedNsCommand, self ).run(edit, external_id, text)

# Loads the current file in the REPL by telling the REPL to load it using the complete path
# This is much faster than the built in sublime repl command which copies the entire file into the
# REPL.
# Loads and switches to the ns of the current file in the REPL by telling the
# REPL to load it using the complete path.
# This is much faster than the built in sublime repl command which copies the
# entire file into the REPL.
class LoadFileInReplCommand(text_transfer.ReplTransferCurrent):
def run(self, edit):
form = "(load-file \"" + self.view.file_name() +"\")"
self.view.window().run_command("run_command_in_repl", {"command": form})

## Switch to the namespace of the current file
ns = re.sub("ns\s*", "", self.view.substr(self.view.find("ns\s*\S+",0)))
form2 = "(in-ns '" + ns + ")"
self.view.window().run_command("run_command_in_repl", {"command": form2})

# Writes the selected text to a temporary file then tells the REPL to load that file.
# This is much faster than copying every character to the REPL individually which echos everything.
class LoadSelectionInReplCommand(text_transfer.ReplSend):
Expand All @@ -166,4 +173,3 @@ def run(self, edit):
form = "(load-file \"" + f.name +"\")"
external_id = repl_external_id(self)
super( LoadSelectionInReplCommand, self ).run(edit, external_id, form)

41 changes: 26 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*I no longer actively use or maintain this configuration. This still works but I encourage you to try my [Atom editor](https://atom.io) package [Proto REPL](https://github.com/jasongilman/proto-repl).*

*NOTE: this is a fork of the original project, that is no longer being maintened, and has been updated to work with SUBLIME TEXT 3 and clj deps. Many thanks to jasongilman for his great work!*

SublimeClojureSetup
===================
Expand All @@ -8,19 +7,28 @@ A description of how I setup Sublime Text for Clojure development. It's a bit ha

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

## Why Sublime Text?

I have tested many other code editors but always find myself returning to Sublime Text with SublimeREPL. And why is that? Even though its setup is hacky and is far from perfect, no other editor can match its raw speed and convenience of keybindings shortcuts. As with many things, picking and setting up your code editor is more art than science and what works best for you is up to your specific tastes and requirements.

## Prerequisites

* Sublime Text 2 (Not yet tested with Sublime Text 3)
* Sublime Text 3
* Java
* [Leiningen 2](http://leiningen.org/)

### Leiningen

Install it then create `~/.lein/profiles.clj`. See [`profiles.clj`](profiles.clj) in this repo for contents.

## Sublime Text 2 With Clojure
## Sublime Text 3 With Clojure

### Paths assumed for each OS

This documents how to setup Sublime Text 2 with Clojure. It uses the sublime text [package manager](https://sublime.wbond.net/installation#st2). Follow the installation instructions to install the package manager into Sublime Text 2.
- OSX: `~/Library/Application\ Support/Sublime\ Text\ 3`
- Linux: `~/.config/sublime-text-3`

This documents how to setup Sublime Text 3 with Clojure. It uses the sublime text [package manager](https://sublime.wbond.net/installation#st2). Follow the installation instructions to install the package manager into Sublime Text 3.
If you already have the package manager installed make sure all packages are up to date.

* Bring up the command pallet - __cmd + shift + P__
Expand All @@ -41,6 +49,10 @@ 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.

Alternatively, if you wish to run the REPL with clj deps, you'll need to to open the SublimeREPL package and update the contents of `/Packages/SublimeREPL/config/Clojure/Default.sublime-commands` and `/Packages/SublimeREPL/config/Clojure/Main.sublime-menu` according to this [pull request](https://github.com/wuub/SublimeREPL/pull/537/commits/47bad8803f7eb6a3050ece1e88ea8b37f8e0947e#diff-c699bfc1a6f163eadf899a507a7fcfe4). Then,

* Invoke the command pallet - __cmd + shift + P__
* Type `repl` and select __SublimeREPL: Clj__

#### Keybindings

Expand Down Expand Up @@ -89,7 +101,7 @@ Install these packages using the package manager.

Add this code to your user preferences

* Add the following lines to `~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Preferences.sublime-settings`
* Add the following lines to `/Packages/User/Preferences.sublime-settings`

```
// This needs to be disabled since we're using Bracket Highlighter for highlighting brackets
Expand All @@ -100,7 +112,7 @@ Add this code to your user preferences

Sublime Text doesn't correctly identify Clojure symbols.

* Create `~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Clojure.sublime-settings` with the following contents.
* Create `/Packages/User/Clojure.sublime-settings` with the following contents.

```
{
Expand All @@ -117,15 +129,15 @@ Sublime Text doesn't correctly identify Clojure symbols.

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:

* Open `~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Default/Default (OSX).sublime-keymap`
* Open `/Packages/Default/Default (OSX).sublime-keymap`
* Search for "Auto-pair single quotes" which should be on line 274 or so.
* Comment out the block of about 30 lines directly following that comment to disable pairing of single quotes only.

##### 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.

* Edit `~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/SublimeREPL.sublime-settings` with the following changes
* Edit `/Packages/User/SublimeREPL.sublime-settings` with the following changes

```
{
Expand All @@ -140,11 +152,11 @@ This file updates SublimeREPL settings so leiningen in on the path. Update this

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/`
* `/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
Change `/config/Clojure/Main.sublime-menu` line 22 from
```
"osx": ["lein", "repl"]
```
Expand All @@ -159,17 +171,16 @@ This greatly improves the speed at which text is sent from a Clojure window to t

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

* Append the [`clojure_keybindings.sublime-keymap`](clojure_keybindings.sublime-keymap) in this repo to `~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Default (OSX).sublime-keymap`
* Append the [`clojure_keybindings.sublime-keymap`](clojure_keybindings.sublime-keymap) in this repo to `/Packages/User/Default (OSX).sublime-keymap`
* Keymap files contain JSON so make sure they're valid when saving or Sublime Text will fail with errors.

##### Clojure Helpers

The [`ClojureHelpers.py`](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.

* Copy `ClojureHelpers.py` to `~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/`
* `cp ClojureHelpers.py ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/`
* Copy `ClojureHelpers.py` to `/Packages/User/`

##### 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.
Copy the file `clojure_snippets.sublime-snippet` to `/Packages/User/clojure_snippets.sublime-snippet`. It contains some useful completions.