Keeping the REPL state clean, free from stale var definitions (symbols), minimises the need to restart the REPL process.
defn names can change during development as code is refactored. Un-define removes unwanted vars and keeps the REPL state clean, avoiding the need to restart the REPL.
, e u (
cider-undef) un-defines the current function name or var, e.g.
deftest, removing it from the running REPL.
When cursor is not on a function name or any var, the mini-buffer prompts for the name to undefine.
Cider refresh or restart for multiple changes
Refresh or restart the REPL when there are multiple changes made to a namespace or across multiple namespaces.
If the name of an existing test is changed, the original test will still run when calling the CIDER test runner commands (or other REPL based test runners).
Having stale test definitions leads to confusing test results.
, e u on a
deftest expression before changing its name to ensure that the existing test is removed from the REPL state and no longer run.
, undef in the REPL buffer (Evil Insert / Emacs state) prompts for a symbol to undefine.
TAB when typing the symbol name will popup a list of matching symbols available in the REPL. Select the name you wish to undef
Clojure core functionsλ︎
ns-unmap will remove a symbol from the running REPL. Use
*ns* dynamic variable to represent the current namespace.
Or specify the namespace if the symbol is not in the current namespace
ns-unalias will remove an alias added via a require form
Clojure tools.namespace.repl provides utilities to manage namespaces.
refresh function scans all directories on the classpath for source files, read their ns forms, builds a graph of their dependencies and load them in dependency order.
set-refresh-dirs defines directories that should be scanned.
Add the library as a dependency to the project file
Require the namespace and refer the function
Refresh the current namespace
The refresh function will load all namespaces found and list them as the output.
Set directories to include
set-refresh-dirs to only reload code from specific paths, e.g.
refresh will not act on namespaces that are defined on other paths, e.g.
dev, avoiding reloading code for REPL workflows (launching portal, log publishers, etc.)
All Code must be reloadable
If there are errors in one or more namespaces that prevent them from successfully loading, then reresh will error, showing which namespaces had issues to resolve.
Either refactor the troublesome code or move the code to a path that is not defined by
refresh in rich commentλ︎
Use a rich comment to ensure the refresh function is only called when directly evaluated.
Code inside the rich comment block will not be evaluated when evaluating the current buffer or loading the namespace.
Custom user namespace
Include clojure.tools.namespace.repl in a custom user namespace and call from the REPL prompt or by switching to the
user.clj file in the editor and calling