File: cider-ns.el.html

Reloading namespaces and editing the ns form.

Smart code refresh functionality based on ideas from: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded

Note that refresh with clojure.tools.namespace.repl is a smarter way to reload code: the traditional way to reload Clojure code without restarting the JVM is (require ... :reload) or an editor/IDE feature that does the same thing.

This has several problems:

If you modify two namespaces which depend on each other, you must remember to reload them in the correct order to avoid compilation errors.

If you remove definitions from a source file and then reload it, those definitions are still available in memory. If other code depends on those definitions, it will continue to work but will break the next time you restart the JVM.

If the reloaded namespace contains defmulti, you must also reload all of the associated defmethod expressions.

If the reloaded namespace contains defprotocol, you must also reload any records or types implementing that protocol and replace any existing instances of those records/types with new instances.

If the reloaded namespace contains macros, you must also reload any namespaces which use those macros.

If the running program contains functions which close over values in the reloaded namespace, those closed-over values are not updated (This is common in web applications which construct the "handler stack" as a composition of functions.)

Commands that add requires and imports to the ns form of a Clojure buffer. The edits are plain text manipulation, so they work without a REPL; when one is connected, the prompts complete against it. Only cider-ns-add-missing needs a REPL, to find what provides a symbol.

The ns form is walked with scan-sexps and syntax-ppss, which follow the syntax table, rather than with forward-sexp, which clojure-ts-mode hands over to tree-sitter. clojure-mode and clojure-ts-mode have matching syntax tables, so the same code serves both.

Defined variables (21)

cider-ns-code-reload-tool
cider-ns-edit--class-history
cider-ns-edit--declined-aliases
cider-ns-edit--ns-history
cider-ns-edit--ns-regexp
cider-ns-edit--primitive-types
cider-ns-edit--select-error-buffer
cider-ns-edit--symbol-history
cider-ns-edit-actions
cider-ns-magic-require-aliases
cider-ns-magic-requiresWhether typing a slash after an alias the ns form lacks requires it.
cider-ns-refresh-after-fn
cider-ns-refresh-before-fn
cider-ns-refresh-log-mode-abbrev-table
cider-ns-refresh-log-mode-hook
cider-ns-refresh-log-mode-map
cider-ns-refresh-log-mode-menu
cider-ns-refresh-log-mode-syntax-table
cider-ns-refresh-show-log-buffer
cider-ns-save-files-on-refresh
cider-ns-save-files-on-refresh-modes

Defined functions (62)

cider-ns--mark-reloaded
cider-ns--present-error
cider-ns--reload-callback
cider-ns--reload-op
cider-ns-add-import(CLASS)
cider-ns-add-missing(SYMBOL)
cider-ns-add-require(NS &optional ALIAS)
cider-ns-clean(&optional INTERACTIVE)
cider-ns-edit--add-clause
cider-ns-edit--add-import
cider-ns-edit--add-missing
cider-ns-edit--add-require
cider-ns-edit--alias-before-slash
cider-ns-edit--alias-candidates
cider-ns-edit--aliases
cider-ns-edit--append
cider-ns-edit--check
cider-ns-edit--choose
cider-ns-edit--choose-alias-ns
cider-ns-edit--clause
cider-ns-edit--clauses
cider-ns-edit--clean
cider-ns-edit--clean-buffer
cider-ns-edit--clean-import
cider-ns-edit--clean-libspec
cider-ns-edit--default-alias
cider-ns-edit--delete-elements
cider-ns-edit--destructuring-p
cider-ns-edit--discarded-p
cider-ns-edit--edit
cider-ns-edit--elements
cider-ns-edit--empty-clause-p
cider-ns-edit--enumerate
cider-ns-edit--eval
cider-ns-edit--follow-up
cider-ns-edit--has-alias-p
cider-ns-edit--in-discarded-p
cider-ns-edit--libspec-ns
cider-ns-edit--libspec-option
cider-ns-edit--loads-p
cider-ns-edit--locate
cider-ns-edit--magic-require
cider-ns-edit--magic-require-namespaces
cider-ns-edit--merge-libspec
cider-ns-edit--ns-form-start
cider-ns-edit--option-indices
cider-ns-edit--platform
cider-ns-edit--qualifier
cider-ns-edit--read-ns
cider-ns-edit--referred
cider-ns-edit--require-message
cider-ns-edit--seq-p
cider-ns-edit--skip-blanks
cider-ns-edit--sort
cider-ns-edit--text
cider-ns-refresh(&optional MODE)
cider-ns-refresh--handle-response
cider-ns-refresh--save-modified-buffers
cider-ns-refresh-log-mode
cider-ns-refresh-log-mode-menu
cider-ns-reload(&optional PROMPT)
cider-ns-reload-all(&optional PROMPT)

Defined faces (0)