Skip to content

Commit

Permalink
added eval_shared
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Sep 27, 2022
1 parent 1071b3d commit 5454a8b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2.7.0 - Sep 27, 2022

- Added `eval_shared`

### 2.6.0 - Sep 27, 2022

- Added `format_on_save` option #76 thx @sainadh-d
Expand Down
4 changes: 4 additions & 0 deletions Clojure Sublimed.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
// False by default (enables parallel evals).
"eval_in_session": false,

// A form to be evaluated in shared session and inherited by all evals
// E.g. (set! *warn-on-reflection* true)
"eval_shared": "",

// reformat file on save, false by default
"format_on_save": false
}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This package provides Clojure support for Sublime Text and includes:

- Clojure and EDN syntax grammars (Sublime Text 3+)
- Clojure code formatter/indenter (Sublime Text 4075+)
- Clojure nREPL client (Sublime Text 4075+, nREPL 0.8+)
- Clojure nREPL client (Sublime Text 4075+, nREPL 0.9+)

## Clojure syntax

Expand Down Expand Up @@ -186,6 +186,16 @@ Finally, to clear evaluation results run `Clojure Sublimed: Clear Evaluation Res

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.
Expand All @@ -209,7 +219,7 @@ To set it up, run `Preferences: Clojure Sublimed Key Bindings` command and copy

Q: REPL/eval doesn’t work

A: Make sure you are using nREPL 0.8 or later.
A: Make sure you are using nREPL 0.9 or later.
A: Make sure you have assigned `Clojure (Sublimed)` syntax to the file.

## Credits
Expand Down
9 changes: 8 additions & 1 deletion package.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,25 @@ def handle_connect(msg):
return True

elif 2 == msg.get("id") and msg.get("status") == ["done"]:
id = 3 if settings().get("eval_shared") else 4
conn.send({"op": "add-middleware",
"middleware": [f"{ns}.middleware/clone-and-eval",
f"{ns}.middleware/time-eval",
f"{ns}.middleware/wrap-errors",
f"{ns}.middleware/wrap-output"],
"extra-namespaces": [f"{ns}.middleware"],
"session": conn.session,
"id": 3})
"id": id})
conn.set_status("🌔 Adding middlewares")
return True

elif 3 == msg.get("id") and msg.get("status") == ["done"]:
conn.send({"op": "eval",
"code": settings().get("eval_shared"),
"session": conn.session,
"id": 4})

elif 4 == msg.get("id") and msg.get("status") == ["done"]:
conn.set_status(f"🌕 {conn.host}:{conn.port}")
return True

Expand Down

0 comments on commit 5454a8b

Please sign in to comment.