Skip to content

Commit e707d10

Browse files
committed
Support cider.clj-reload/reload ops
See clojure-emacs/cider-nrepl#850 for more.
1 parent dc58ed1 commit e707d10

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
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 cider.clj-reload/reload ops
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

+28-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,17 @@ namespace-qualified function of zero arity."
118118
:group 'cider
119119
:package-version '(cider . "0.10.0"))
120120

121+
(defcustom cider-ns-refresh-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.13.1"))
128+
121129
(defun cider-ns-refresh--handle-response (response log-buffer)
122130
"Refresh LOG-BUFFER with RESPONSE."
123-
(nrepl-dbind-response response (out err reloading status error error-ns after before)
131+
(nrepl-dbind-response response (out err reloading progress status error error-ns after before)
124132
(cl-flet* ((log (message &optional face)
125133
(cider-emit-into-popup-buffer log-buffer message face t))
126134

@@ -148,6 +156,9 @@ namespace-qualified function of zero arity."
148156
(reloading
149157
(log-echo (format "Reloading %s\n" reloading) 'font-lock-string-face))
150158

159+
(progress
160+
(log-echo progress 'font-lock-string-face))
161+
151162
((member "reloading" (nrepl-dict-keys response))
152163
(log-echo "Nothing to reload\n" 'font-lock-string-face))
153164

@@ -186,6 +197,19 @@ Its behavior is controlled by `cider-ns-save-files-on-refresh' and
186197
(file-in-directory-p buffer-file-name dir))
187198
dirs)))))))
188199

200+
(defun cider-ns-refresh--refresh-op (op-name)
201+
"Return the refresh operation to use.
202+
Based on OP-NAME and the value of cider-ns-refresh-tool defcustom."
203+
(list "op"
204+
(cond
205+
((eq cider-ns-refresh-tool 'tools.namespace)
206+
op-name)
207+
208+
((eq cider-ns-refresh-tool 'clj-reload)
209+
(cond ((string= op-name "refresh") "cider.clj-reload/reload")
210+
((string= op-name "refresh-all") "cider.clj-reload/reload-all")
211+
((string= op-name "refresh-clear") "cider.clj-reload/reload-clear"))))))
212+
189213
;;;###autoload
190214
(defun cider-ns-reload (&optional prompt)
191215
"Send a (require 'ns :reload) to the REPL.
@@ -237,6 +261,7 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
237261
(interactive "p")
238262
(cider-ensure-connected)
239263
(cider-ensure-op-supported "refresh")
264+
(cider-ensure-op-supported "cider.clj-reload/reload")
240265
(cider-ns-refresh--save-modified-buffers)
241266
(let ((clear? (member mode '(clear 16)))
242267
(refresh-all? (member mode '(refresh-all 4)))
@@ -254,11 +279,11 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
254279
nil
255280
t))
256281
(when clear?
257-
(cider-nrepl-send-sync-request '("op" "refresh-clear") conn))
282+
(cider-nrepl-send-sync-request (cider-ns-refresh--refresh-op "refresh-clear") conn))
258283
(cider-nrepl-send-request
259284
(thread-last
260285
(map-merge 'list
261-
`(("op" ,(if refresh-all? "refresh-all" "refresh")))
286+
`(,(cider-ns-refresh--refresh-op (if refresh-all? "refresh-all" "refresh")))
262287
(cider--nrepl-print-request-map fill-column)
263288
(when (and (not inhibit-refresh-fns) cider-ns-refresh-before-fn)
264289
`(("before" ,cider-ns-refresh-before-fn)))

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

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ 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+
135+
[source,lisp]
136+
----
137+
(setq cider-ns-refresh-tool 'clj-reload)
138+
----
139+
133140
== CIDER Selector
134141

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

0 commit comments

Comments
 (0)