This repository has been archived by the owner on May 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
repl.clj
53 lines (46 loc) · 1.6 KB
/
repl.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(ns trident.repl
"Convenience functions for working at the repl.
Suggested usage:
- Include `trident.repl` in the `extra-deps` of your `:dev` alias
- Launch a repl with this command:
`clj -Adev -e \"(do (require 'trident.repl) (trident.repl/init))\" -r`
This will:
- begin spec instrumentation with `orchestra.spec.test/instrument`
- start an nRepl server (on port 7888 by default)
- load all namespaces visible to `clojure.tools.namespace.repl/refresh`
- call `mount.core/start`
- add an alias to [[reset]] in the `user` namespace"
(:require [clojure.tools.namespace.repl :as tn]
[nrepl.server :as nrepl]
[mount.core :as mount]
[orchestra.spec.test :as st]))
(defn reset*
"Reloads namespaces, starting and stopping mount components"
([] (reset* {}))
([{:keys [mount?] :or {mount? true}}]
(do (mount/stop)
(if mount?
(tn/refresh :after 'mount.core/start)
(tn/refresh)))))
(defmacro reset
"Reloads namespaces, starting and stopping mount components"
[& args]
`(do (reset* ~@args)
(use 'clojure.repl)
:ready))
(defn init
([] (init {}))
([{:keys [nrepl-port] :or {nrepl-port 7888}}]
(st/instrument)
(nrepl/start-server :port nrepl-port)
(reset {})
(println "Run `(user/reset)` to reload all source changes.")
(println "Run this if your repl gets borked after a `(user/reset)`:")
(println)
(println " (do (require 'trident.repl) (trident.repl/reset))")
(println)))
(in-ns 'user)
(require 'trident.repl)
(defmacro reset [& args]
`(trident.repl/reset ~@args))
(in-ns 'trident.repl)