Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vlaaad/remote-repl
Remote repl for Clojure
https://github.com/vlaaad/remote-repl
clojure repl
Last synced: 4 months ago
JSON representation
Remote repl for Clojure
- Host: GitHub
- URL: https://github.com/vlaaad/remote-repl
- Owner: vlaaad
- License: mit
- Created: 2020-08-02T13:51:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-18T19:11:18.000Z (about 3 years ago)
- Last Synced: 2024-09-28T17:40:53.453Z (4 months ago)
- Topics: clojure, repl
- Language: Clojure
- Homepage:
- Size: 13.7 KB
- Stars: 34
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Remote repl
[![Clojars Project](https://img.shields.io/clojars/v/vlaaad/remote-repl.svg)](https://clojars.org/vlaaad/remote-repl)## Rationale
Sometimes I want to open a remote socket repl from my repl, but Clojure does not
provide a way to do this out of the box.## Usage
To give it a try, you need a socket repl available on the network. You can start
it with this shell command:
```sh
$ clj "-J-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl}"
```Now you can connect to that process from another process
```
$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}'
Clojure 1.10.1
user=> (require '[vlaaad.remote-repl :as rr])
nil
user=> (rr/repl :port 5555)
;; at this point, forms sent to the repl are evaluated on the remote process
user=> (System/getProperty "clojure.server.repl")
"{:port 5555 :accept clojure.core.server/repl}"
user=> :repl/quit
;; now we are back to evaluating in our local process.
nil
user=>
```You can use `-main` to immediately drop into a remote repl:
```
$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}' -m vlaaad.remote-repl :port 5555
user=> (System/getProperty "clojure.server.repl")
"{:port 5555 :accept clojure.core.server/repl}"
user=> :repl/quit
```You can use `-X` style invocation:
```
$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}' -X vlaaad.remote-repl/repl :port 5555
```You can install remote repl as a tool:
```
clj -Ttools install \
vlaaad/remote-repl '{:git/url "https://github.com/vlaaad/remote-repl.git" :git/tag "v1.2.12"}' \
:as remote-repl
clj -Tremote-repl repl :port 5555
```## Reconnecting
It might be useful to automatically reconnect to the remote REPL. For
example, you might want to restart your REPL server during development to update
dependencies. You can use `:reconnect true` option to keep the REPL client
reconnecting, that way it will keep connecting to the remote REPL while the JVM is alive.Example:
```shell
$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}' \
-X vlaaad.remote-repl/repl \
:port 5757 :reconnect true
Reconnecting to localhost:5757
Reconnecting to localhost:5757
...
```Then, start a REPL server on port 5757 in a different terminal:
```shell
$ clj -J-Dclojure.server.repl='{:port 5555 :accept clojure.core.server/repl}'
```Once it starts, first terminal will establish the connection:
```shell
...
Reconnecting to localhost:5757
Reconnecting to localhost:5757
user=>
```## Acknowledgements
This project is similar to [tubular](https://github.com/mfikes/tubular), but
smaller (only 70 lines of code and no dependencies). It is inspired by
[clojure.core.server/remote-prepl](https://github.com/clojure/clojure/blob/0035cd8d73517e7475cb8b96c7911eb0c43a1a9d/src/clj/clojure/core/server.clj#L295-L338),
but does not require its target to be a prepl.