From 25148d84b98b9e1ec61168021cc78304a9d7a0fd Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Sat, 2 Mar 2024 22:53:46 +0000 Subject: [PATCH] Support cider.clj-reload/reload ops See https://github.com/clojure-emacs/cider-nrepl/pull/850 for more. --- CHANGELOG.md | 3 ++ cider-ns.el | 31 +++++++++++++++++-- .../ROOT/pages/usage/misc_features.adoc | 7 +++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1363ed43f..79887023f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cider-ns.el b/cider-ns.el index 9e938f36e..d57a57566 100644 --- a/cider-ns.el +++ b/cider-ns.el @@ -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)) @@ -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)) @@ -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. @@ -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))) @@ -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))) diff --git a/doc/modules/ROOT/pages/usage/misc_features.adoc b/doc/modules/ROOT/pages/usage/misc_features.adoc index 96f0bfc6a..a721f78b0 100644 --- a/doc/modules/ROOT/pages/usage/misc_features.adoc +++ b/doc/modules/ROOT/pages/usage/misc_features.adoc @@ -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