Decouple nrepl-make-eval-handler from CIDER's UI layer#3892
Merged
Conversation
Closes #1099. After Step 1 (#3890) introduced the keyword-arg API, `nrepl-make-eval-handler' still embedded several CIDER-specific concerns: it consulted `nrepl-namespace-handler-function', `nrepl-err-handler-function', and `nrepl-need-input-handler-function', and emitted the hardcoded "Evaluation interrupted." and "Namespace `%s' not found." messages. That kept the transport tied to the editor, which is what #1099 was originally about. Strip those concerns out of the transport. `nrepl-make-eval-handler' loses its `:buffer' slot and its dispatches on the global handler hooks. Two new keyword slots take their place: :on-ns called with NS whenever a response carries an `ns' slot. :on-status called with (STATUS RESPONSE) when the response carries a `status' slot. STATUS is the list of flags; RESPONSE is the full dict so handlers can read sibling slots (e.g. `ns' for "namespace-not-found"). Add `cider-make-eval-handler' in cider-eval.el as the editor wrapper that layers CIDER's UI back on top: ns tracking via `cider--update-buffer-ns', default `:on-eval-error' -> `cider-default-err-handler', `need-input' prompt via `cider-need-input', and the "Evaluation interrupted." / "Namespace not found." messages. All ~14 in-tree callers in cider-client.el, cider-repl.el, cider-eval.el, and cider-profile.el switch to it. The obsolete `nrepl-make-response-handler' shim is updated to wire up the global handler hooks and the legacy status messages itself, so extension code targeting the old positional API sees no behavior change. New Buttercup specs cover: `:on-ns' firing on ns-bearing responses, `:on-status' receiving (status response), `cider-make-eval-handler''s ns tracking / err-handler default / need-input prompting, and a regression guard that the legacy shim still consults the global hooks.
tarsius
pushed a commit
to emacsmirror/cider
that referenced
this pull request
Apr 29, 2026
`cider--debug-response-handler' was a hand-rolled callback that dispatched on the debug-specific status flags (`enlighten', `eval-error', `stack', `need-debug-input', `done') and explicitly called `nrepl--mark-id-completed' for the done branch. Now that `nrepl-make-eval-handler' has an `:on-status' slot (clojure-emacs#3892), this handler fits the eval-handler shape exactly: pass an `:on-status' that walks the same status flags and let the helper do the mark-id-completed bookkeeping for free. Changes the function from "I am a handler" to "I build a handler" (callsite goes from `#'cider--debug-response-handler' to `(cider--debug-response-handler)'), matching the convention of `cider-make-eval-handler', `cider-repl-handler', etc. No behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1099.
After #3890 introduced the keyword-arg API,
nrepl-make-eval-handlerstill embedded several CIDER-specific concerns: it consultednrepl-namespace-handler-function,nrepl-err-handler-function, andnrepl-need-input-handler-function, and emitted the hardcoded"Evaluation interrupted."and"Namespace \%s' not found."` messages. That kept the transport tied to the editor, which is what #1099 was originally about back in 2017.This PR strips those concerns out.
Transport (
nrepl-client.el)nrepl-make-eval-handlerloses its:bufferslot and its dispatches on the global handler hooks. Two new keyword slots take their place::on-ns-- called withNSwhenever a response carries annsslot, regardless of which other slots are present.:on-status-- called with(STATUS RESPONSE)when the response carries astatusslot.STATUSis the list of flags;RESPONSEis the full dict so handlers can read sibling slots (e.g.nsfor"namespace-not-found").Net result:
nrepl-make-eval-handleris now a transport-layer building block. Any Emacs nREPL client could use it without dragging CIDER's UI semantics along.Editor (
cider-eval.el)New
cider-make-eval-handlerwraps the transport one and layers CIDER's UI back on:cider--update-buffer-ns:on-eval-error->cider-default-err-handlerneed-inputprompt viacider-need-input"Evaluation interrupted."and"Namespace \%s' not found."` messagesAll ~14 in-tree callers in
cider-client.el,cider-repl.el,cider-eval.el, andcider-profile.elswitch to it. The two file-crossing references getdeclare-functiondecls.Backward compatibility
The obsolete
nrepl-make-response-handlershim is updated to wire up the global handler hooks and the legacy status messages itself. Extension code targeting the old positional API sees no behavior change -- if you were settingnrepl-namespace-handler-function,nrepl-err-handler-function, ornrepl-need-input-handler-function, the shim still consults them.A new Buttercup spec (
nrepl-make-response-handler legacy shim) is the regression guard: it asserts thatnrepl-namespace-handler-functionandnrepl-err-handler-functionstill get called when the legacy form is invoked.Tests
8 new specs:
nrepl-make-eval-handler--:on-nsfiring,:on-statusreceiving(status response),:on-eval-errordirect invocationcider-make-eval-handler-- ns tracking, err-handler default, custom err handler override, need-input prompt, namespace-not-found messagenrepl-make-response-handler legacy shim-- still consults the global hooks (regression guard)Full suite: 542/544 pass, 0 failures (8 new specs over the 534-spec baseline from #3891).