Function: cider-load-buffer

cider-load-buffer is an interactive and byte-compiled function defined in cider-eval.el.

Signature

(cider-load-buffer &optional BUFFER CALLBACK UNDEF-ALL)

Documentation

Load (eval) BUFFER's file in nREPL.

If no buffer is provided the command acts on the current buffer. If the buffer is for a cljc file, and both a Clojure and ClojureScript REPL exists for the project, it is evaluated in both REPLs. Optional argument CALLBACK will override the default ‘cider-load-file-handler’. When UNDEF-ALL is non-nil or called with C-u (universal-argument), removes all ns aliases and var mappings from the namespace before reloading it.

Key Bindings

Aliases

cider-eval-buffer

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/cider-eval.el
(defun cider-load-buffer (&optional buffer callback undef-all)
  "Load (eval) BUFFER's file in nREPL.
If no buffer is provided the command acts on the current buffer.  If the
buffer is for a cljc file, and both a Clojure and ClojureScript REPL exists
for the project, it is evaluated in both REPLs.
Optional argument CALLBACK will override the default ‘cider-load-file-handler’.
When UNDEF-ALL is non-nil or called with \\[universal-argument], removes
all ns aliases and var mappings from the namespace before reloading it."
  (interactive (list (current-buffer) nil (equal current-prefix-arg '(4))))
  (setq buffer (or buffer (current-buffer)))
  ;; When cider-load-buffer or cider-load-file are called in programs the
  ;; current context might not match the buffer's context. We use the caller
  ;; context instead of the buffer's context because that's the common use
  ;; case. For the other use case just let-bind the default-directory.
  (let ((orig-default-directory default-directory))
    (with-current-buffer buffer
      (check-parens)
      (let ((default-directory orig-default-directory))
        (unless buffer-file-name
          (user-error "Buffer `%s' is not associated with a file" (current-buffer)))
        (when (and cider-save-file-on-load
                   (buffer-modified-p)
                   (or (eq cider-save-file-on-load t)
                       (y-or-n-p (format "Save file %s? " buffer-file-name))))
          (save-buffer))
        (remove-overlays nil nil 'cider-temporary t)
        (when undef-all
          (cider-undef-all (cider-current-ns)))
        (cider--clear-compilation-highlights)
        (cider--quit-error-window)
        (let ((filename (buffer-file-name buffer))
              (ns-form  (cider-ns-form)))
          (cider-map-repls :auto
            (lambda (repl)
              (when ns-form
                (cider-repl--cache-ns-form ns-form repl))
              (cider-request:load-file (cider--file-string filename)
                                       (funcall cider-to-nrepl-filename-function
                                                (cider--server-filename filename))
                                       (file-name-nondirectory filename)
                                       repl
                                       callback)))
          (message "Loading %s..." filename))))))