Function: nrepl-make-response-handler
nrepl-make-response-handler is a byte-compiled function defined in
nrepl-client.el.
Signature
(nrepl-make-response-handler BUFFER VALUE-HANDLER STDOUT-HANDLER STDERR-HANDLER DONE-HANDLER &optional EVAL-ERROR-HANDLER CONTENT-TYPE-HANDLER TRUNCATED-HANDLER)
Documentation
Make a response handler for connection BUFFER.
A handler is a function that takes one argument - response received from
the server process. The response is an alist that contains at least id
and session keys. Other standard response keys are value, out, err,
and status.
The presence of a particular key determines the type of the response. For
example, if value key is present, the response is of type value, if
out key is present the response is stdout etc.
Depending on the type, the handler dispatches the appropriate value to one of the supplied handlers: VALUE-HANDLER, STDOUT-HANDLER, STDERR-HANDLER, DONE-HANDLER, EVAL-ERROR-HANDLER, CONTENT-TYPE-HANDLER, and TRUNCATED-HANDLER.
Handlers are functions of the buffer and the value they handle, except for
the optional CONTENT-TYPE-HANDLER which should be a function of the buffer,
content, the content-type to be handled as a list (type attrs).
If the optional EVAL-ERROR-HANDLER is nil, the default nrepl-err-handler
is used. If any of the other supplied handlers are nil nothing happens for
the corresponding type of response.
Source Code
;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/nrepl-client.el
(defun nrepl-make-response-handler (buffer value-handler stdout-handler
stderr-handler done-handler
&optional eval-error-handler
content-type-handler
truncated-handler)
"Make a response handler for connection BUFFER.
A handler is a function that takes one argument - response received from
the server process. The response is an alist that contains at least `id'
and `session' keys. Other standard response keys are `value', `out', `err',
and `status'.
The presence of a particular key determines the type of the response. For
example, if `value' key is present, the response is of type `value', if
`out' key is present the response is `stdout' etc.
Depending on the type, the handler dispatches the appropriate value to one
of the supplied handlers: VALUE-HANDLER, STDOUT-HANDLER, STDERR-HANDLER,
DONE-HANDLER, EVAL-ERROR-HANDLER, CONTENT-TYPE-HANDLER, and
TRUNCATED-HANDLER.
Handlers are functions of the buffer and the value they handle, except for
the optional CONTENT-TYPE-HANDLER which should be a function of the buffer,
content, the content-type to be handled as a list `(type attrs)'.
If the optional EVAL-ERROR-HANDLER is nil, the default `nrepl-err-handler'
is used. If any of the other supplied handlers are nil nothing happens for
the corresponding type of response."
(lambda (response)
(nrepl-dbind-response response (content-type content-transfer-encoding body
value ns out err status id)
(when (buffer-live-p buffer)
(with-current-buffer buffer
(when (and ns (not (cider-clojure-major-mode-p)))
(cider-set-buffer-ns ns))))
(cond ((and content-type content-type-handler)
(funcall content-type-handler buffer
(if (string= content-transfer-encoding "base64")
(base64-decode-string body)
body)
content-type))
(value
(when value-handler
(funcall value-handler buffer value)))
(out
(when stdout-handler
(funcall stdout-handler buffer out)))
(err
(when stderr-handler
(funcall stderr-handler buffer err)))
(status
(when (and truncated-handler (member "nrepl.middleware.print/truncated" status))
(let ((warning (format "\n... output truncated to %sB ..."
(file-size-human-readable cider-print-quota))))
(funcall truncated-handler buffer warning)))
(when (member "notification" status)
(nrepl-dbind-response response (msg type)
(nrepl-notify msg type)))
(when (member "interrupted" status)
(message "Evaluation interrupted."))
(when (member "eval-error" status)
(funcall (or eval-error-handler nrepl-err-handler) buffer))
(when (member "namespace-not-found" status)
(message "Namespace `%s' not found." ns))
(when (member "need-input" status)
(cider-need-input buffer))
(when (member "done" status)
(nrepl--mark-id-completed id)
(when done-handler
(funcall done-handler buffer))))))))