Skip to content

Commit

Permalink
Support cider.clj-reload/reload ops
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Mar 3, 2024
1 parent dc58ed1 commit e707d10
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- [#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)
- The `clojure-mode` dependency is still required for CIDER to function
- Some features like `cider-dynamic-indentation` and `cider-font-lock-dynamically` do not work with `clojure-ts-mode` (yet).
- [#3624](https://github.com/clojure-emacs/cider/pull/3624): Support cider.clj-reload/reload ops
- adds `cider-ns-refresh-tool` defcustom, defaulting to `'tools.namespace`
- 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).

### Changes

Expand Down
31 changes: 28 additions & 3 deletions cider-ns.el
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,17 @@ namespace-qualified function of zero arity."
:group 'cider
:package-version '(cider . "0.10.0"))

(defcustom cider-ns-refresh-tool 'tools.namespace
"Which tool to use for ns refresh.
Current options: tools.namespace and clj-reload."
:group 'cider
:type '(choice (const :tag "tools.namespace https://github.com/clojure/tools.namespace" tools-namespace)
(const :tag "clj-reload https://github.com/tonsky/clj-reload" clj-reload))
:package-version '(cider . "1.13.1"))

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

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

(progress
(log-echo progress 'font-lock-string-face))

((member "reloading" (nrepl-dict-keys response))
(log-echo "Nothing to reload\n" 'font-lock-string-face))

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

(defun cider-ns-refresh--refresh-op (op-name)
"Return the refresh operation to use.
Based on OP-NAME and the value of cider-ns-refresh-tool defcustom."
(list "op"
(cond
((eq cider-ns-refresh-tool 'tools.namespace)
op-name)

((eq cider-ns-refresh-tool 'clj-reload)
(cond ((string= op-name "refresh") "cider.clj-reload/reload")
((string= op-name "refresh-all") "cider.clj-reload/reload-all")
((string= op-name "refresh-clear") "cider.clj-reload/reload-clear"))))))

;;;###autoload
(defun cider-ns-reload (&optional prompt)
"Send a (require 'ns :reload) to the REPL.
Expand Down Expand Up @@ -237,6 +261,7 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
(interactive "p")
(cider-ensure-connected)
(cider-ensure-op-supported "refresh")
(cider-ensure-op-supported "cider.clj-reload/reload")
(cider-ns-refresh--save-modified-buffers)
(let ((clear? (member mode '(clear 16)))
(refresh-all? (member mode '(refresh-all 4)))
Expand All @@ -254,11 +279,11 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
nil
t))
(when clear?
(cider-nrepl-send-sync-request '("op" "refresh-clear") conn))
(cider-nrepl-send-sync-request (cider-ns-refresh--refresh-op "refresh-clear") conn))
(cider-nrepl-send-request
(thread-last
(map-merge 'list
`(("op" ,(if refresh-all? "refresh-all" "refresh")))
`(,(cider-ns-refresh--refresh-op (if refresh-all? "refresh-all" "refresh")))
(cider--nrepl-print-request-map fill-column)
(when (and (not inhibit-refresh-fns) cider-ns-refresh-before-fn)
`(("before" ,cider-ns-refresh-before-fn)))
Expand Down
7 changes: 7 additions & 0 deletions doc/modules/ROOT/pages/usage/misc_features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ and `cider-ns-reload-all` commands can be used instead. These commands
invoke Clojure's `+(require ... :reload)+` and `+(require
... :reload-all)+` commands at the REPL.

You can also use https://github.com/tonsky/clj-reload[clj-reload] instead:

[source,lisp]
----
(setq cider-ns-refresh-tool 'clj-reload)
----

== CIDER Selector

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

0 comments on commit e707d10

Please sign in to comment.