Function: cider-repl-set-ns

cider-repl-set-ns is an interactive and byte-compiled function defined in cider-repl.el.

Signature

(cider-repl-set-ns NS)

Documentation

Switch the namespace of the REPL buffer to NS.

If called from a cljc buffer act on both the Clojure and ClojureScript REPL if there are more than one REPL present. If invoked in a REPL buffer the command will prompt for the name of the namespace to switch to.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/cider-repl.el
(defun cider-repl-set-ns (ns)
  "Switch the namespace of the REPL buffer to NS.
If called from a cljc buffer act on both the Clojure and ClojureScript REPL
if there are more than one REPL present.  If invoked in a REPL buffer the
command will prompt for the name of the namespace to switch to."
  (interactive (list (if (or (derived-mode-p 'cider-repl-mode)
                             (null (cider-ns-form)))
                         (completing-read "Switch to namespace: "
                                          (cider-sync-request:ns-list))
                       (cider-current-ns))))
  (when (or (not ns) (equal ns ""))
    (user-error "No namespace selected"))
  (cider-map-repls :auto
    (lambda (connection)
      ;; NOTE: `require' and `in-ns' are special forms in ClojureScript.
      ;; That's why we eval them separately instead of combining them with `do'.
      (when cider-repl-require-ns-on-set
        (cider-sync-tooling-eval (format "(require '%s)" ns) nil connection))
      (let ((f (if (equal 'cljs
                          (with-current-buffer connection
                            cider-repl-type))
                   ;; For cljs, don't use cider-tooling-eval, because Piggieback will later change the ns (issue #3503):
                   #'cider-nrepl-request:eval
                 ;; When possible, favor cider-tooling-eval because it preserves *1, etc (commit 5f705b):
                 #'cider-tooling-eval)))
        (funcall f (format "(in-ns '%s)" ns)
                 (cider-repl-switch-ns-handler connection))))))