branch: elpa/cider commit c4fa1a84a3b3d03ef5f61cc5d33ff4e91b9a1dce Author: filipesilva <filipesi...@users.noreply.github.com> Commit: vemv <v...@users.noreply.github.com>
Support new `cider.clj-reload/reload` cider-nrepl middlewarex --- CHANGELOG.md | 3 +++ cider-ns.el | 33 ++++++++++++++++++++++--- doc/modules/ROOT/pages/usage/misc_features.adoc | 17 +++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4105108377..d17f69c16e 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 new `cider.clj-reload/reload` cider-nrepl middleware. + - 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 51ab0ed125..70e06d0be9 100644 --- a/cider-ns.el +++ b/cider-ns.el @@ -118,6 +118,14 @@ namespace-qualified function of zero arity." :group 'cider :package-version '(cider . "0.10.0")) +(defcustom cider-ns-code-reload-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.14.0")) + (defun cider-ns--present-error (error) "Render the `ERROR' stacktrace, and jump to the adequate file/line location, @@ -156,7 +164,7 @@ presenting the error message as an overlay." (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)) @@ -184,6 +192,9 @@ presenting the error message as an overlay." (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)) @@ -223,6 +234,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--reload-op (op-name) + "Return the reload operation to use. +Based on OP-NAME and the value of cider-ns-code-reload-tool defcustom." + (list "op" + (if (eq cider-ns-code-reload-tool 'tools.namespace) + (cond ((string= op-name "reload") "refresh") + ((string= op-name "reload-all") "refresh-all") + ((string= op-name "reload-clear") "refresh-clear")) + + (cond ((string= op-name "reload") "cider.clj-reload/reload") + ((string= op-name "reload-all") "cider.clj-reload/reload-all") + ((string= op-name "reload-clear") "cider.clj-reload/reload-clear"))))) + ;;;###autoload (defun cider-ns-reload (&optional prompt) "Send a (require 'ns :reload) to the REPL. @@ -275,9 +299,10 @@ 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))) + (all? (member mode '(refresh-all 4))) (inhibit-refresh-fns (member mode '(inhibit-fns -1)))) (cider-map-repls :clj (lambda (conn) @@ -292,11 +317,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--reload-op "reload-clear") conn)) (cider-nrepl-send-request (thread-last (map-merge 'list - `(("op" ,(if refresh-all? "refresh-all" "refresh"))) + `(,(cider-ns--reload-op (if all? "reload-all" "reload"))) (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 96f0bfc6a1..cfa2f93ea4 100644 --- a/doc/modules/ROOT/pages/usage/misc_features.adoc +++ b/doc/modules/ROOT/pages/usage/misc_features.adoc @@ -130,6 +130,23 @@ 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. +It provides support for +https://github.com/tonsky/clj-reload/blob/469da68/README.md#usage-keeping-vars-between-reloads[keeping vars between reloads] +among some +https://github.com/tonsky/clj-reload/blob/469da68/README.md#comparison-toolsnamespace[other differences] +from `tools.namespace`. + +[source,lisp] +---- +(setq cider-ns-code-reload-tool 'clj-reload) +---- + +With `clj-reload` you should set the source dirs as described in +https://github.com/tonsky/clj-reload/blob/469da68/README.md##usage[the usage docs] +. If you don't set them manually, it will default to the current project's resource dirs in the same +way `tools.namespace` does. + == CIDER Selector The `cider-selector` (kbd:[C-c M-s]) command allows you to quickly navigate to