Skip to content

Commit c4fa1a8

Browse files
filipesilvavemv
authored andcommitted
Support new cider.clj-reload/reload cider-nrepl middlewarex
1 parent 6403a8d commit c4fa1a8

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
- [#3622](https://github.com/clojure-emacs/cider/pull/3461): Basic support for using CIDER from [clojure-ts-mode](https://github.com/clojure-emacs/clojure-ts-mode).
88
- The `clojure-mode` dependency is still required for CIDER to function.
99
- Some features like `cider-dynamic-indentation` and `cider-font-lock-dynamically` do not work with `clojure-ts-mode` (yet).
10+
- [#3624](https://github.com/clojure-emacs/cider/pull/3624): Support new `cider.clj-reload/reload` cider-nrepl middleware.
11+
- adds `cider-ns-refresh-tool` defcustom, defaulting to `'tools.namespace`.
12+
- you can change it to `'clj-reload` to use [clj-reload](https://github.com/tonsky/clj-reload) instead of [tools.namespace](https://github.com/clojure/tools.namespace).
1013

1114
### Changes
1215

cider-ns.el

+29-4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ namespace-qualified function of zero arity."
118118
:group 'cider
119119
:package-version '(cider . "0.10.0"))
120120

121+
(defcustom cider-ns-code-reload-tool 'tools.namespace
122+
"Which tool to use for ns refresh.
123+
Current options: tools.namespace and clj-reload."
124+
:group 'cider
125+
:type '(choice (const :tag "tools.namespace https://github.com/clojure/tools.namespace" tools.namespace)
126+
(const :tag "clj-reload https://github.com/tonsky/clj-reload" clj-reload))
127+
:package-version '(cider . "1.14.0"))
128+
121129
(defun cider-ns--present-error (error)
122130
"Render the `ERROR' stacktrace,
123131
and jump to the adequate file/line location,
@@ -156,7 +164,7 @@ presenting the error message as an overlay."
156164

157165
(defun cider-ns-refresh--handle-response (response log-buffer)
158166
"Refresh LOG-BUFFER with RESPONSE."
159-
(nrepl-dbind-response response (out err reloading status error error-ns after before)
167+
(nrepl-dbind-response response (out err reloading progress status error error-ns after before)
160168
(cl-flet* ((log (message &optional face)
161169
(cider-emit-into-popup-buffer log-buffer message face t))
162170

@@ -184,6 +192,9 @@ presenting the error message as an overlay."
184192
(reloading
185193
(log-echo (format "Reloading %s\n" reloading) 'font-lock-string-face))
186194

195+
(progress
196+
(log-echo progress 'font-lock-string-face))
197+
187198
((member "reloading" (nrepl-dict-keys response))
188199
(log-echo "Nothing to reload\n" 'font-lock-string-face))
189200

@@ -223,6 +234,19 @@ Its behavior is controlled by `cider-ns-save-files-on-refresh' and
223234
(file-in-directory-p buffer-file-name dir))
224235
dirs)))))))
225236

237+
(defun cider-ns--reload-op (op-name)
238+
"Return the reload operation to use.
239+
Based on OP-NAME and the value of cider-ns-code-reload-tool defcustom."
240+
(list "op"
241+
(if (eq cider-ns-code-reload-tool 'tools.namespace)
242+
(cond ((string= op-name "reload") "refresh")
243+
((string= op-name "reload-all") "refresh-all")
244+
((string= op-name "reload-clear") "refresh-clear"))
245+
246+
(cond ((string= op-name "reload") "cider.clj-reload/reload")
247+
((string= op-name "reload-all") "cider.clj-reload/reload-all")
248+
((string= op-name "reload-clear") "cider.clj-reload/reload-clear")))))
249+
226250
;;;###autoload
227251
(defun cider-ns-reload (&optional prompt)
228252
"Send a (require 'ns :reload) to the REPL.
@@ -275,9 +299,10 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
275299
(interactive "p")
276300
(cider-ensure-connected)
277301
(cider-ensure-op-supported "refresh")
302+
(cider-ensure-op-supported "cider.clj-reload/reload")
278303
(cider-ns-refresh--save-modified-buffers)
279304
(let ((clear? (member mode '(clear 16)))
280-
(refresh-all? (member mode '(refresh-all 4)))
305+
(all? (member mode '(refresh-all 4)))
281306
(inhibit-refresh-fns (member mode '(inhibit-fns -1))))
282307
(cider-map-repls :clj
283308
(lambda (conn)
@@ -292,11 +317,11 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
292317
nil
293318
t))
294319
(when clear?
295-
(cider-nrepl-send-sync-request '("op" "refresh-clear") conn))
320+
(cider-nrepl-send-sync-request (cider-ns--reload-op "reload-clear") conn))
296321
(cider-nrepl-send-request
297322
(thread-last
298323
(map-merge 'list
299-
`(("op" ,(if refresh-all? "refresh-all" "refresh")))
324+
`(,(cider-ns--reload-op (if all? "reload-all" "reload")))
300325
(cider--nrepl-print-request-map fill-column)
301326
(when (and (not inhibit-refresh-fns) cider-ns-refresh-before-fn)
302327
`(("before" ,cider-ns-refresh-before-fn)))

doc/modules/ROOT/pages/usage/misc_features.adoc

+17
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ and `cider-ns-reload-all` commands can be used instead. These commands
130130
invoke Clojure's `+(require ... :reload)+` and `+(require
131131
... :reload-all)+` commands at the REPL.
132132

133+
You can also use https://github.com/tonsky/clj-reload[clj-reload] instead.
134+
It provides support for
135+
https://github.com/tonsky/clj-reload/blob/469da68/README.md#usage-keeping-vars-between-reloads[keeping vars between reloads]
136+
among some
137+
https://github.com/tonsky/clj-reload/blob/469da68/README.md#comparison-toolsnamespace[other differences]
138+
from `tools.namespace`.
139+
140+
[source,lisp]
141+
----
142+
(setq cider-ns-code-reload-tool 'clj-reload)
143+
----
144+
145+
With `clj-reload` you should set the source dirs as described in
146+
https://github.com/tonsky/clj-reload/blob/469da68/README.md##usage[the usage docs]
147+
. If you don't set them manually, it will default to the current project's resource dirs in the same
148+
way `tools.namespace` does.
149+
133150
== CIDER Selector
134151

135152
The `cider-selector` (kbd:[C-c M-s]) command allows you to quickly navigate to

0 commit comments

Comments
 (0)