Clojure support for Sublime Text 4
| Feb 20 | Feb 19 | Feb 18 | Feb 17 | Feb 16 | Feb 15 | Feb 14 | Feb 13 | Feb 12 | Feb 11 | Feb 10 | Feb 9 | Feb 8 | Feb 7 | Feb 6 | Feb 5 | Feb 4 | Feb 3 | Feb 2 | Feb 1 | Jan 31 | Jan 30 | Jan 29 | Jan 28 | Jan 27 | Jan 26 | Jan 25 | Jan 24 | Jan 23 | Jan 22 | Jan 21 | Jan 20 | Jan 19 | Jan 18 | Jan 17 | Jan 16 | Jan 15 | Jan 14 | Jan 13 | Jan 12 | Jan 11 | Jan 10 | Jan 9 | Jan 8 | Jan 7 | Jan 6 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Windows | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 2 | 1 | 1 | 0 | 0 | 1 | 1 | 1 |
| Mac | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
| Linux | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
This package provides Clojure support for Sublime Text and includes:
Package Control: Install Package →Clojure Sublimed

Clojure Sublimed ships with its own syntax definition for Clojure and EDN. Unlike default Clojure syntax, our syntax can:
#_ with the following form, including stacked comments,comment forms,How to enable? Assign syntax to Clojure files:
For each file type (.clj, .cljs, .cljc, .edn) do:
View →Syntax →Open all with current extension as...Clojure (Sublimed)Want to put your parser to test? Check outsyntax_test_clojure.cljc.

To make best use of improved syntax definitions, Clojure Sublimed offers its own color scheme:
UI: Select Color SchemeAuto ->Clojure Sublimed Light ->Clojure Sublimed DarkThese color schemes will work for other languages, too.
Clojure Sublimed includes support for bothBetter Clojure Formatting andcljfmt.
Better Clojure Formatting doesn’t require REPL connection, Clojure runtime or external tools. It is enabled by default.
To enablecljfmt:
cljfmt binary fromhttps://github.com/weavejester/cljfmt/releases/latestcljfmt to$PATH"clojure_sublimed_formatter": "cljfmt" toPreferences: SettingsTo reformat whole file, runClojure Sublimed: Reindent. If you have non-empty selection, it will only reformat selected lines.
To enable reindenting/formatting on save, add"clojure_sublimed_format_on_save": true toPreferences: Settings.
To enable correct indentations as you type code, rebindEnter toClojure 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}]}Indent will fix indentation, but will not create new lines. To format a completely unformatted source, usePretty-print selection command:

There are three types of comment in Clojure:
;; are intended for textual / unstructured comments about code#_ is intended for temporarily disabling parts of codecomment form for coding snippets for future useBy default, Sublime will try to use;; because it’s most similar to other languages and is simple to implement. One can argue, however, that we disable/enable parts of the code way more often than write textual comments about them. Therefore,#_ might work better.
Clojure Sublimed offerToggle Comment command that can be used instead of Sublime provided one in Clojure sources. See Keymap on how to enable.
If you select multiple cursors on different lines and runAlign cursors command, Clojure Sublimed will align them in a column. Works with multiple columns, too:

Clojure Sublimed REPL clients enable interactive development from the comfort of your editor.
Principles:
Features:
Clojure Sublimed has four REPL clients:
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?
We intentionally excluded following features:
Look atSublime LSP withClojure LSP orSublimeLinter withclj-kondo if you need autocompletion.
Clojure Sublimed will not run your app for you. Use any other way, e.g.:
For Clojure apps:
clj -X clojure.core.server/start-server :name repl :port 5555 :accept clojure.core.server/repl :server-daemonfalseor
clj"-J-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl :server-daemon false}"Clojure Sublimed: Connect to Socket REPL command.For Shadow-cljs apps:
shadow-cljs watch app. (This starts a HTTP server and an nREPL)Clojure Sublimed: Connect shadow-cljs command.For other nREPL apps:
Clojure Sublimed: Connect to raw nREPL command.From here you have three options:
Clojure Sublimed: Evaluate without selection evaluates topmost form around your cursor:

Clojure Sublimed: Evaluate with selection evaluates selected text:

Clojure Sublimed: Evaluate Buffer will evaluate the entire file:

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

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

Sometimes you want to copy evaluation result. It is recommended to rebindCmd+C/Ctrl+C fromcopy tosublime_clojure_copy. This will copy evaluation result if inside evaluated region and fallback to defaultcopy otherwise.
If your evaluation runs too long and you want to interrupt it, runClojure Sublimed: Interrupt Pending Evaluations:

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

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

Watches are great alternative to debug prints: they allow you to monitor intermediate values during function execution right in the editor.
This is how they work:
Clojure Sublimed: Add Watch commandWatches are only supported in Socket REPL.
To show symbol info, runClojure Sublimed: Toggle Symbol Info:

UniversalClojure Sublimed: Toggle Info command acts as eitherToggle Stacktrace orToggle Symbol Info, depending on context.
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. RunPreferences: 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 pressCtrl +T, you’ll see the result in the status bar, like this:

Other possible use-cases (select key combinations to your linking):
Only run tests from current namespace:
{"keys": ["ctrl+shift+t"], "command": "clojure_sublimed_eval_code", "args": {"code": "(clojure.test/run-all-tests (re-pattern (str *ns*)))"}}Reload code withclj-reload:
{"keys": ["ctrl+r"], "command": "clojure_sublimed_eval_code", "args": {"code": "(clj-reload.core/reload)"}}You can also modify eval to run a transformed version of code under cursor/inside selection.
For example, this will pretty-print result of your evaluation to stdout:
{"keys": ["ctrl+p"], "command": "clojure_sublimed_eval", "args": {"transform": "(doto %code clojure.pprint/pprint)"}}transform is a format string that takes selected form, formats it according to described rules and then sends resulting code to evaluation.
If you now pressctrl+p on a form like(+ 1 2), the actual eval sent to REPL will be:
(doto (+ 1 2) clojure.pprint/pprint)
Which will pretty-print evaluation result to stdout. This pattern might be useful for large results that don’t fit inline.
We can implement macroexpand this way:
{"keys": ["ctrl+e"], "command": "clojure_sublimed_eval", "args": {"transform": "(macroexpand-1 '%code)", "expand": true}}Another use-case might be “eval to buffer”:
{"keys": ["ctrl+b"], "command": "chain", "args": { "commands": [ ["clojure_sublimed_eval", {"transform": "(with-open [w (clojure.java.io/writer \"/tmp/sublimed_output.edn\")] (doto %code (clojure.pprint/pprint w)))"}], ["open_file", {"file": "/tmp/sublimed_output.edn"}] ] }}Eval to buffer at work:
Insidetransform you can also use%ns (current ns) and%symbol (if selected form isdef-something, it will be replaced with defined name, otherwisenil).
This allows us to implement “run test under cursor”:
{"keys": ["super+shift+t"], "command": "clojure_sublimed_eval", "args": {"transform": "(clojure.test/run-test-var #'%symbol)"}}Run test under cursor at work:
Finally, to clear evaluation results runClojure Sublimed: Clear Evaluation Results.
To edit settings, runPreferences: Clojure Sublimed Settings command.
If you prefer setting settings in main file, you can do so by prepending"clojure_sublimed_" to each setting name. E.g.
"debug": True,
inClojure Sublimed.sublime-settings becomes
"clojure_sublimed_debug": True,
inPreferences.sublime-settings. Settings fromPreferences.sublime-settings take priority.
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.
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 | CtrlEnter | CtrlAltEnter | |
| Evaluate Buffer | CtrlB | CtrlAltB | [B]uffer |
| Interrupt Pending Evaluations | CtrlC | CtrlAltC | [C]ancel |
| Toggle Info | CtrlI | CtrlAltI | [I]nfo |
| Clear Evaluation Results | CtrlL | CtrlAltL | c[L]ear |
| Copy Evaluation Results | CommandC | CtrlC | [C]opy |
| Reindent Lines | CtrlF | CtrlAltF | [F]ormat |
| Reindent Buffer | CtrlShiftF | CtrlAltShiftF | Capital [F]ormat |
| Toggle Comment | Command/ | Ctrl/ | Comment [/] |
To set it up, runPreferences: Clojure Sublimed Key Bindings command and copy example keybindings to your local Key Bindings file.
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 Sublimeddoes not redirect neither stdout nor stderr. Check original console to see what was printed there.

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 toa Babashka REPL?
A: Use Raw nREPL.
Made byNiki Tonsky.
With contributions byJaihindh Reddy andKgOfHedgehogs.
Writer Color Scheme: A color scheme optimized for long-form writing.
Alabaster Color Scheme: Minimal color scheme for coding.
Sublime Profiles: Profile switcher.