Function: cider-interactive-eval

cider-interactive-eval is a byte-compiled function defined in cider-eval.el.

Signature

(cider-interactive-eval FORM &optional CALLBACK BOUNDS ADDITIONAL-PARAMS)

Documentation

Evaluate FORM and dispatch the response to CALLBACK.

If the code to be evaluated comes from a buffer, it is preferred to use a nil FORM, and specify the code via the BOUNDS argument instead.

This function is the main entry point in CIDER's interactive evaluation API. Most other interactive eval functions should rely on this function. If CALLBACK is nil use cider-interactive-eval-handler. BOUNDS, if non-nil, is a list of two numbers marking the start and end positions of FORM in its buffer. ADDITIONAL-PARAMS is a plist to be merged into the request message.

If cider-interactive-eval-override is a function, call it with the same arguments and only proceed with evaluation if it returns nil.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/cider-eval.el
(defun cider-interactive-eval (form &optional callback bounds additional-params)
  "Evaluate FORM and dispatch the response to CALLBACK.
If the code to be evaluated comes from a buffer, it is preferred to use a
nil FORM, and specify the code via the BOUNDS argument instead.

This function is the main entry point in CIDER's interactive evaluation
API.  Most other interactive eval functions should rely on this function.
If CALLBACK is nil use `cider-interactive-eval-handler'.
BOUNDS, if non-nil, is a list of two numbers marking the start and end
positions of FORM in its buffer.
ADDITIONAL-PARAMS is a plist to be merged into the request message.

If `cider-interactive-eval-override' is a function, call it with the same
arguments and only proceed with evaluation if it returns nil."
  (let ((form  (or form (apply #'buffer-substring-no-properties bounds)))
        (additional-params (nrepl--alist-to-plist additional-params))
        (start (car-safe bounds))
        (end   (car-safe (cdr-safe bounds))))
    (when (and start end)
      ;; NOTE: don't use `remove-overlays' as it splits and leaves behind
      ;; partial overlays, leading to duplicate eval results in some situations.
      (dolist (ov (overlays-in start end))
        (when (eq (overlay-get ov 'cider-temporary) t)
          (delete-overlay ov))))
    (unless (and cider-interactive-eval-override
                 (functionp cider-interactive-eval-override)
                 (condition-case _
                     (funcall cider-interactive-eval-override form callback bounds additional-params)
                   (wrong-number-of-arguments
                    ;; fallback for backward compatibility
                    (funcall cider-interactive-eval-override form callback bounds))))
      (cider-map-repls :auto
        (lambda (connection)
          (cider--prep-interactive-eval form connection)
          (cider-nrepl-request:eval
           form
           (or callback (cider-interactive-eval-handler nil bounds))
           ;; always eval ns forms in the user namespace
           ;; otherwise trying to eval ns form for the first time will produce an error
           (if (cider-ns-form-p form) "user" (cider-current-ns))
           (when start (line-number-at-pos start))
           (when start (cider-column-number-at-pos start))
           additional-params
           connection))))))