Function: cider-ns-add-missing

cider-ns-add-missing is an autoloaded, interactive and byte-compiled function defined in cider-ns.el.

Signature

(cider-ns-add-missing SYMBOL)

Documentation

Require or import what SYMBOL needs, in the buffer's ns form.

Ask the REPL which loaded namespaces have a public var named like SYMBOL and which classes have its name, and add the one picked from those. A SYMBOL that already resolves gets nothing, so its meaning stays put.

What gets added depends on how SYMBOL is written:

- for foo, refer it, as in [some.ns :refer [foo]];
- for alias/foo, require the namespace as alias, as in [some.ns :as alias];
- for some.ns/foo, require some.ns;
- for a class, import it, and require the namespace that defines it too
  when it's made by deftype or defrecord.

A namespace that's already required gets the alias or the refer added to its libspec. A second alias for it, or an alias or a refer that another libspec already has, is an error.

Interactively, SYMBOL is the symbol at point, or one read from the minibuffer when there's none.

After a change, do what cider-ns-edit-actions asks for.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20261106.1225/cider-ns.el
;;;###autoload
(defun cider-ns-add-missing (symbol)
  "Require or import what SYMBOL needs, in the buffer's ns form.
Ask the REPL which loaded namespaces have a public var named like SYMBOL
and which classes have its name, and add the one picked from those.  A
SYMBOL that already resolves gets nothing, so its meaning stays put.

What gets added depends on how SYMBOL is written:

- for foo, refer it, as in [some.ns :refer [foo]];
- for alias/foo, require the namespace as alias, as in [some.ns :as alias];
- for some.ns/foo, require some.ns;
- for a class, import it, and require the namespace that defines it too
  when it's made by `deftype' or `defrecord'.

A namespace that's already required gets the alias or the refer added
to its libspec.  A second alias for it, or an alias or a refer that
another libspec already has, is an error.

Interactively, SYMBOL is the symbol at point, or one read from the
minibuffer when there's none.

After a change, do what `cider-ns-edit-actions' asks for."
  (interactive
   (progn
     (cider-ns-edit--check)
     (cider-current-repl 'infer 'ensure)
     (list (or (cider-symbol-at-point)
               (read-string "Add missing symbol: " nil 'cider-ns-edit--symbol-history)))))
  (let ((symbol (string-trim symbol)))
    (when (string-empty-p symbol)
      (user-error "No symbol given"))
    (when (string-prefix-p ":" symbol)
      (user-error "%s is a keyword, not a symbol" symbol))
    (let* ((candidates (or (cider-sync-request:resolve-missing symbol (cider-current-ns))
                           (user-error "Found nothing to add for %s" symbol)))
           (candidate (cider-ns-edit--choose symbol candidates)))
      (pcase-let ((`(,changed . ,texts)
                   (cider-ns-edit--edit
                    (lambda (start) (cider-ns-edit--add-missing start symbol candidate)))))
        (if changed
            (message "Resolved %s with %s" symbol (string-join texts " and "))
          (message "Nothing to add for %s, the ns form has %s"
                   symbol (string-join texts " and ")))))))