• Stars
    star
    353
  • Rank 120,322 (Top 3 %)
  • Language
    Clojure
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clojure support for Sublime Text 4

Clojure support for Sublime Text 4

This package provides Clojure support for Sublime Text and includes:

  • Clojure and EDN syntax grammars (Sublime Text 3+)
  • Code formatter/indenter (Sublime Text 4075+)
  • nREPL, Socket REPL, ShadowCLJS REPL clients (Sublime Text 4075+)

Installation

Package Control: Install Package โ†’ Clojure Sublimed

Clojure syntax

Syntaxes

Clojure Sublimed ships with its own syntax definition for Clojure and EDN. Unlike default Clojure syntax, this package is:

  • slightly more pedantic as per EDN spec and Clojure Reader,
  • rigorously tested,
  • can be used to highlight rainbow parentheses,
  • punctuation and validation inside regexps,
  • quoted and unquoted regions are marked for highlighting,
  • semantically correct tokenization, perfect for fonts with ligatures,
  • has separate EDN syntax, same way JSON is separate from JavaScript in Sublime Text.

How to enable? Assign syntax to Clojure files:

  • open any clj/cljc/cljs file,
  • run View โ†’ Syntax โ†’ Open all with current extension as... โ†’ Clojure Sublimed โ†’ Clojure (Sublimed).

Want to put your parser to test? Check out syntax_test_edn.edn and syntax_test_clojure.cljc.

Formatter/indenter

Clojure Sublimed includes optional support for Simple Clojure Formatting rules. It doesnโ€™t require REPL connection, any Clojure runtime or external tools.

To reformat whole file, run Clojure Sublimed: Reindent Buffer.

To reindent only selected line(s), run Clojure Sublimed: Reindent Lines.

To enable reindenting/formatting on save, add format_on_save: true to settings. (See how to edit settings)

To enable correct indentations as you type code, rebind Enter to Clojure Sublimed: Insert Newline:

{"keys":    ["enter"],
 "command": "clojure_sublimed_insert_newline",
 "context": [{"key": "selector", "operator": "equal", "operand": "source.edn | source.clojure"},
             {"key": "auto_complete_visible", "operator": "equal", "operand": false},
             {"key": "panel_has_focus", "operator": "equal", "operand": false}]}

Best way to do it is through running Preferences: Clojure Sublimed Key Bindings.

REPL clients

Clojure Sublimed REPL clients enable interactive development from the comfort of your editor.

Principles:

  • Minimal distraction. Display evaluation results inline.
  • Decomplected. Eval code and nothing more.

Features:

  • evaluate code,
  • display evaluation results inline.
  • display stack traces inline,
  • interrupt evaluation,
  • eval multiple forms at once (parallel evaluation),
  • lookup symbol info,
  • show evaluation time,
  • bind keys to eval arbitrary code.

Clojure Sublimed has four REPL clients:

  1. Raw nREPL: no extra middlewares, could work with any nREPL server.
  2. JVM nREPL: only works with JVM server.
  3. ShadowCLJS nREPL: works with ShadowCLJS
  4. JVM Socket REPL: works with raw Socket REPL on JVM

All four support same basic features (eval, lookup, interrupt on JVM), maybe with slightly different quality of implementation.

How to choose which REPL to use?

  1. Are you on JVM? Use Socket REPL.
  2. CLJS? Use ShadowCLJS REPL.
  3. Only have basic nREPL? Use Raw nREPL.
  4. JVM nREPL is mostly a carryover from Clojure Sublime v1-2 and is now superseded by Socket REPL. Works better than Raw nREPL but worse than Socket REPL.

We intentionally excluded following features:

  • Autocomplete. Static analysis is much simpler and much more reliable than requiring an always-live connection to the working app.

Look at Sublime LSP with Clojure LSP or SublimeLinter with clj-kondo if you need autocompletion.

How to use

For Clojure apps:

  1. Run Socket Server, e.g. with either
clj -X clojure.core.server/start-server :name repl :port 5555 :accept clojure.core.server/repl :server-daemon false

or

clj "-J-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl :server-daemon false}"
  1. Run Clojure Sublimed: Connect to Socket REPL command.

For Shadow-cljs apps:

  1. Run shadow-cljs watch app. (This starts a HTTP server and an nREPL)
  2. If you are building a web-app, open the http-server url (from step 1) in the browser. This connects the shadow server to JS runtime.
  3. Run Clojure Sublimed: Connect shadow-cljs command.

For other nREPL apps:

  1. Run nREPL server.
  2. Run Clojure Sublimed: Connect to raw nREPL command.

Evaluating code from buffer

From here you have three options:

Clojure Sublimed: Evaluate without selection evaluates topmost form around your cursor:

Evaluate Topmost

Clojure Sublimed: Evaluate with selection evaluates selected text:

Evaluate Selection

Clojure Sublimed: Evaluate Buffer will evaluate the entire file:

Evaluate Buffer

You donโ€™t have to wait for one form to finish evaluating to evaluate something else. Multiple things can be executed in parallel:

Evaluate in Parallel

By default, Clojure Sublimed will also print evaluation time if it takes more than 100 ms:

Elapsed time

Copying evaluation results

Sometimes you want to copy evaluation result. It is recommended to rebind Cmd+C/Ctrl+C from copy to sublime_clojure_copy. This will copy evaluation result if inside evaluated region and fallback to default copy otherwise.

Interrupting

If your evaluation runs too long and you want to interrupt it, run Clojure Sublimed: Interrupt Pending Evaluations:

Interrupt

Opening stacktrace

If your evaluation failed, put your cursor inside failed region and run Clojure Sublimed: Toggle Stacktrace:

Toggle Stacktrace

Clojure Sublimed will display stacktraces in a Clojure-friendly way. Compare with the default REPL:

Stacktraces

Looking up symbol

To show symbol info, run Clojure Sublimed: Toggle Symbol Info:

Toggle Symbol Info

Universal Clojure Sublimed: Toggle Info command acts as either Toggle Stacktrace or Toggle Symbol Info, depending on context.

Binding keys to eval code

Every project is different, and sometimes itโ€™s convenient to run a piece of code so often youโ€™d want it on a shortcut. It might be a namespace reload, test execution, database reconnect, linter, formatter โ€” possibilities are endless.

To support such use cases, Clojure Sublimed allows you to bind arbitrary piece of code to a keyboard shortcut. Run Preferences: Clojure Sublimed Key Bindings and add something like this:

{"keys": ["ctrl+t"],
 "command": "clojure_sublimed_eval_code",
 "args": {"code": "(clojure.test/run-all-tests)"}}

Then, whenever you press Ctrl + T, youโ€™ll see the result in the status bar, like this:

Eval Code

Tip: use (clojure.test/run-all-tests (re-pattern (str *ns*)))) to run tests in current namespace.

Tip: bind (user/reload) to Cmd R to reload your app with tools.namespace.

Clearing results

Finally, to clear evaluation results run Clojure Sublimed: Clear Evaluation Results.

Editing settings

To edit settings, run Preferences: Clojure Sublimed Settings command.

Session-wide settings

It is sometimes desirable to set dynamic Clojure vars for the whole session. To do that, edit "eval_shared" setting. For example:

"eval_shared": "(do (set! *warn-on-reflection* true) (set! *print-namespace-maps* false))"

This will be applied to every evaluation.

Default Key Bindings

Clojure Sublimed comes with no keybindings enabled by default to guarantee they wonโ€™t conflict with any other extension (Sublime Textโ€™s limitation).

This is the recommended keymap:

Command macOS Windows/Linux Mnemonic
Evaluate Ctrl Enter Ctrl Alt Enter
Evaluate Buffer Ctrl B Ctrl Alt B [B]uffer
Interrupt Pending Evaluations Ctrl C Ctrl Alt C [C]ancel
Toggle Info Ctrl I Ctrl Alt I [I]nfo
Clear Evaluation Results Ctrl L Ctrl Alt L c[L]ear
Copy Evaluation Results Command C Ctrl C [C]opy
Reindent Lines Ctrl F Ctrl Alt F [F]ormat
Reindent Buffer Ctrl Shift F Ctrl Alt Shift F Capital [F]ormat

To set it up, run Preferences: Clojure Sublimed Key Bindings command and copy example keybindings to your local Key Bindings file.

stdout/stderr

Clojure Sublimed does things a little different when it comes to stdout. Normally REPL would show you all stdout/stderr that originated from your session. I find it confusing, because it doesnโ€™t always work and you have to check two places for output. Moreover, thereโ€™s no output panel, so thereโ€™s no place to show stdout anyway.

So instead, Clojure Sublimed does not redirect neither stdout nor stderr. Check original console to see what was printed there.

Stdout redirect

Frequently Asked Questions

Q: REPL/eval doesnโ€™t work

A: Make sure you are using nREPL 0.9 or later. A: Also check console (Cmd `) for errors


Q: How to connect to a Babashka REPL?

A: Use Raw nREPL.

Credits

Made by Niki Tonsky.

With contributions by Jaihindh Reddy.

See also

Writer Color Scheme: A color scheme optimized for long-form writing.

Alabaster Color Scheme: Minimal color scheme for coding.

Sublime Profiles: Profile switcher.

License

MIT License

More Repositories

1

FiraCode

Free monospaced font with programming ligatures
Clojure
75,408
star
2

AnyBar

OS X menubar status indicator
Objective-C
5,877
star
3

datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Clojure
5,446
star
4

rum

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript
HTML
1,791
star
5

vscode-theme-alabaster

A light theme for Visual Studio Code
Clojure
393
star
6

tongue

Do-it-yourself i18n library for Clojure/Script
Clojure
306
star
7

Universal-Layout

ะŸะฐะบะตั‚ ะธะท ะฐะฝะณะปะธะนัะบะพะน ะธ ั€ัƒััะบะพะน ั€ะฐัะบะปะฐะดะพะบ, ัะฟั€ะพะตะบั‚ะธั€ะพะฒะฐะฝะฝั‹ั… ะดะปั ัƒะดะพะฑะฝะพะณะพ ัะพะฒะผะตัั‚ะฝะพะณะพ ะธัะฟะพะปัŒะทะพะฒะฐะฝะธั
Shell
300
star
8

uberdeps

Uberjar builder for deps.edn
Clojure
300
star
9

font-writer

Monospaced font for long-form writing
253
star
10

sublime-scheme-alabaster

Minimalist color scheme for Sublime Text 3
243
star
11

datascript-chat

Sample SPA using DataScript and core.async
Clojure
160
star
12

clj-reload

Smarter way to reload Clojure code
Clojure
149
star
13

grumpy

Minimalistic blog engine
Clojure
141
star
14

compact-uuids

Compact 26-char URL-safe representation of UUIDs
Clojure
129
star
15

net.async

Network commucations with clojure.core.async interface
Clojure
124
star
16

sublime-scheme-writer

A color scheme for focused long-form writing
122
star
17

clojure-future-spec

A backport of clojure.spec for Clojure 1.8
Clojure
115
star
18

intellij-alabaster

Alabaster color scheme for IntelliJ IDEA
101
star
19

datascript-transit

Transit handlers for DataScript database and datoms
Clojure
100
star
20

sublime-profiles

Profile Switcher for Sublime Text
Python
83
star
21

datascript-todo

DataScript ToDo Sample Application
Clojure
78
star
22

persistent-sorted-set

Fast B-tree based persistent sorted set for Clojure/Script
Clojure
78
star
23

tonsky.github.io

HTML
65
star
24

clojure-warrior

Visual Studio Code extension for Clojure development
TypeScript
57
star
25

cljs-drag-n-drop

Sane wrapper around Drag-n-Drop DOM API
Clojure
55
star
26

clj-simple-router

Simple order-independent Ring router
Clojure
53
star
27

vec

React.js + Immutable.js vector editor
JavaScript
51
star
28

clojure.unicode

Unicode symbols for Clojure
Clojure
49
star
29

41-socks

Simple match game in cljs+om+react
Clojure
37
star
30

remote-require

Require any Clojure snippet from anywhere in the Internet
Clojure
33
star
31

Sublime-Executor

Run any executable from your working dir in Sublime Text
Python
32
star
32

sane-math

Clojure/Script library for infix (normal) math expressions
Clojure
32
star
33

Heroes

A turn-based tactical game in ClojureScript, DataScript and Rum
Clojure
30
star
34

cljs-skeleton

Skeleton CLJS client/server app with WS, Transit, Rum
Clojure
30
star
35

icfpc2019-rust

Re-implementaion of https://github.com/tonsky/icfpc2019 in Rust to compare performance
Rust
29
star
36

alabaster-lighttable-skin

Light skin & theme for LightTable
CSS
27
star
37

openshift-clojure

Clojure/lein openshift cartridge template
Shell
26
star
38

datascript-storage-sql

SQL Storage implementation for DataScript
Clojure
24
star
39

sublime-scheme-commander

Retro color scheme for Sublime Text
23
star
40

Levinson-Layout

Keymap & EN/RU layouts for Levinson 40% split ortholinear keyboard
C
22
star
41

sublime-clojure-repl

Basic Clojure REPL for Sublime Text
Python
21
star
42

extend-clj

Easily extend clojure.core built-in protocols
Clojure
18
star
43

boot-anybar

A boot task reporting build status to AnyBar
Clojure
18
star
44

down-the-rabbit-hole

Entry to Ludum Dare 48
Clojure
16
star
45

bloknote

Fast online notepad
Clojure
16
star
46

sublime-color-schemes

Fun and simple color schemes for Sublime Text
Rust
15
star
47

katybot

Campfire bot written in Clojure
Clojure
14
star
48

toml-clj

Fast TOML parser for Clojure
Java
14
star
49

java-graphics-benchmark

Java Graphics benchmark
Java
13
star
50

Helix-Layout

C
13
star
51

datascript-menu

JavaScript
11
star
52

DarkModeToggle

Statusbar app to quickly toggle between light and dark modes
Swift
11
star
53

tonsky.me

Clojure
11
star
54

icfpc2021

Clojure
11
star
55

humble-ants

Clojure
10
star
56

advent-of-code

https://adventofcode.com/
Clojure
9
star
57

icfpc2019

Clojure
8
star
58

tgadmin

Clojure
7
star
59

jwm

Objective-C++
6
star
60

homm

Clojure
5
star
61

GMTKJam2022

GDScript
5
star
62

advent2018

Solutions to https://adventofcode.com/2018 in Clojure
Clojure
5
star
63

spectre

Fantom
3
star
64

imdbparse

Parser for IMDb text database
Clojure
3
star
65

icfpc2022

Clojure
3
star
66

clojure-bits

Clojure
3
star
67

tonsky

2
star
68

2017-05-RigaDevDays

JavaScript
2
star
69

clojure-bits-server

Clojure
2
star
70

2017-10-Reactive

JavaScript
2
star
71

lein-figwheel-immutant

[tonsky/figwheel-sidecar-immutant "0.5.9"]
Clojure
2
star
72

2018-05-UWDC

http://tonsky.me/2018-05-UWDC/slides/
JavaScript
2
star
73

codingame-fall-2022

Coding Games Fall Challenge 2022
Clojure
2
star
74

datascript-perf

Datasets for DataScript perf testing
Clojure
2
star
75

grumpy_video

1
star
76

icfpc2023

Clojure
1
star
77

roam-calculator

Shell
1
star
78

datascript_compiler_race

Clojure
1
star
79

ldjam53

GDScript
1
star
80

glutin_resize_issue

Rust
1
star