Skip to content

Commit

Permalink
review items
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Mar 9, 2024
1 parent 23b1445 commit d832797
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
32 changes: 16 additions & 16 deletions cider-ns.el
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ namespace-qualified function of zero arity."
:group 'cider
:package-version '(cider . "0.10.0"))

(defcustom cider-ns-refresh-tool 'tools.namespace
(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)
: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"))
:package-version '(cider . "1.14.0"))

(defun cider-ns--present-error (error)
"Render the `ERROR' stacktrace,
Expand Down Expand Up @@ -234,18 +234,18 @@ 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."
(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"
(cond
((eq cider-ns-refresh-tool 'tools.namespace)
op-name)
(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"))

((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"))))))
(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)
Expand Down Expand Up @@ -302,7 +302,7 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
(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)
Expand All @@ -317,11 +317,11 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
nil
t))
(when clear?
(cider-nrepl-send-sync-request (cider-ns-refresh--refresh-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
`(,(cider-ns-refresh--refresh-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)))
Expand Down
19 changes: 17 additions & 2 deletions doc/modules/ROOT/pages/usage/misc_features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,28 @@ 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:
You can also use https://github.com/tonsky/clj-reload[clj-reload] instead.
It provides supports
https://github.com/tonsky/clj-reload?tab=readme-ov-file#usage-keeping-vars-between-reloads[keeping vars between reloads]
among some
https://github.com/tonsky/clj-reload?tab=readme-ov-file#comparison-toolsnamespace[other differences]
from `tools.namespace`.

[source,lisp]
----
(setq cider-ns-refresh-tool 'clj-reload)
(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?tab=readme-ov-file#usage[the usage docs]
. If you don't set them manually, it will default to the current source dirs in the same
way `tools.namespace` does.

Another difference is that `cider-ns-refresh-before-fn` and `cider-ns-refresh-after-fn` are
not used with `clj-reload`, but in turns it supports per-namespace
https://github.com/tonsky/clj-reload?tab=readme-ov-file#usage-unload-hooks[unload hooks]
.

== CIDER Selector

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

0 comments on commit d832797

Please sign in to comment.