Movatterモバイル変換


[0]ホーム

URL:


ctrl+shift+p filters::st2:st3:win:osx:linux
Browse

Clojure Sublimed

bytonskyST4

Clojure support for Sublime Text 4

Labelsclojure,repl,nrepl,language syntax

Details

Installs

  • Total3K
  • Win556
  • Mac1K
  • Linux665
Feb 20Feb 19Feb 18Feb 17Feb 16Feb 15Feb 14Feb 13Feb 12Feb 11Feb 10Feb 9Feb 8Feb 7Feb 6Feb 5Feb 4Feb 3Feb 2Feb 1Jan 31Jan 30Jan 29Jan 28Jan 27Jan 26Jan 25Jan 24Jan 23Jan 22Jan 21Jan 20Jan 19Jan 18Jan 17Jan 16Jan 15Jan 14Jan 13Jan 12Jan 11Jan 10Jan 9Jan 8Jan 7Jan 6
Windows0000000000000000000000000001202000001021100111
Mac0020000001011010000010100000000000000110101111
Linux0100000110000000000100000020001000000020100000

Readme

Source
raw.​githubusercontent.​com

This package provides Clojure support for Sublime Text and includes:

  • Clojure syntax
  • Color scheme
  • Code formatter/indenter
  • Clients for nREPL, Socket REPL, ShadowCLJS REPL

Installation

Package Control: Install PackageClojure Sublimed

Clojure syntax

Syntaxes

Clojure Sublimed ships with its own syntax definition for Clojure and EDN. Unlike default Clojure syntax, our syntax can:

  • mark reader comments#_ with the following form, including stacked comments,
  • markcomment forms,
  • mark quoted/unquoted forms,
  • mark metadata,
  • mark parentheses nesting,
  • mark and validate punctuation inside regexps,
  • do semantically correct tokenization, perfect for fonts with ligatures,

How to enable? Assign syntax to Clojure files:

For each file type (.clj, .cljs, .cljc, .edn) do:

  • Open any file with that extension
  • Go to menu ->ViewSyntaxOpen all with current extension as...
  • SelectClojure (Sublimed)

Want to put your parser to test? Check outsyntax_test_clojure.cljc.

Color scheme

Color Scheme

To make best use of improved syntax definitions, Clojure Sublimed offers its own color scheme:

  • Cmd/Ctrl + Shift + P (Command Palette)
  • UI: Select Color Scheme
  • SelectAuto ->Clojure Sublimed Light ->Clojure Sublimed Dark

These color schemes will work for other languages, too.

Formatter/indenter

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:

  • Downloadcljfmt binary fromhttps://github.com/weavejester/cljfmt/releases/latest
  • Addcljfmt to$PATH
  • Add"clojure_sublimed_formatter": "cljfmt" toPreferences: Settings

To 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:

Pretty print

Toggle comment command

There are three types of comment in Clojure:

  • Line comments;; are intended for textual / unstructured comments about code
  • Reader discard form#_ is intended for temporarily disabling parts of code
  • comment form for coding snippets for future use

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

Align cursors command

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:

Align cursors

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:

  • [x] evaluate code,
  • [x] display evaluation results inline.
  • [x] display stack traces inline,
  • [x] interrupt evaluation,
  • [x] eval multiple forms at once (parallel evaluation),
  • [x] lookup symbol info,
  • [x] show evaluation time,
  • [x] 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. On JVM and only have nREPL? Use JVM nREPL.
  3. CLJS? Use ShadowCLJS REPL.
  4. Otherwise (e.g. babashka, sci, …) use Raw nREPL.

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 atSublime LSP withClojure LSP orSublimeLinter withclj-kondo if you need autocompletion.

How to use

Clojure Sublimed will not run your app for you. Use any other way, e.g.:

  • Separate terminal app
  • Terminus plugin
  • Sublime Executor plugin

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-daemonfalse

or

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

For Shadow-cljs apps:

  1. Runshadow-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. RunClojure Sublimed: Connect shadow-cljs command.

For other nREPL apps:

  1. Run nREPL server.
  2. RunClojure 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 rebindCmd+C/Ctrl+C fromcopy tosublime_clojure_copy. This will copy evaluation result if inside evaluated region and fallback to defaultcopy otherwise.

Interrupting

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

Interrupt

Opening stacktrace

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

Toggle Stacktrace

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

Stacktraces

Watches

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:

  • Select a right-hand expression
  • RunClojure Sublimed: Add Watch command
  • Now every time function is executed, for any reason, watched expressions will display values they evaluate to, in real time.

Watches are only supported in Socket REPL.

Looking up symbol

To show symbol info, runClojure Sublimed: Toggle Symbol Info:

Toggle Symbol Info

UniversalClojure Sublimed: Toggle Info command acts as eitherToggle Stacktrace orToggle Symbol Info, depending on context.

Binding keys to eval custom 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. 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:

Eval Code

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)"}}

Transforming code before eval

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:

Clearing results

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

Editing settings

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.

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:

CommandmacOSWindows/LinuxMnemonic
EvaluateCtrlEnterCtrlAltEnter
Evaluate BufferCtrlBCtrlAltB[B]uffer
Interrupt Pending EvaluationsCtrlCCtrlAltC[C]ancel
Toggle InfoCtrlICtrlAltI[I]nfo
Clear Evaluation ResultsCtrlLCtrlAltLc[L]ear
Copy Evaluation ResultsCommandCCtrlC[C]opy
Reindent LinesCtrlFCtrlAltF[F]ormat
Reindent BufferCtrlShiftFCtrlAltShiftFCapital [F]ormat
Toggle CommentCommand/Ctrl/Comment [/]

To set it up, runPreferences: 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 Sublimeddoes 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 toa Babashka REPL?

A: Use Raw nREPL.

Credits

Made byNiki Tonsky.

With contributions byJaihindh Reddy andKgOfHedgehogs.

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


[8]ページ先頭

©2009-2026 Movatter.jp