Skip to content

Improvements to cider-eval-to-comment#4018

Draft
yuhan0 wants to merge 7 commits into
clojure-emacs:masterfrom
yuhan0:eval-to-comment-pr
Draft

Improvements to cider-eval-to-comment#4018
yuhan0 wants to merge 7 commits into
clojure-emacs:masterfrom
yuhan0:eval-to-comment-pr

Conversation

@yuhan0

@yuhan0 yuhan0 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Some improvements to cider-eval-defun-to-comment commands:

Prevent value and stderr comments from being interleaved

#3148 introduced printing of stderr output (e.g. reflection warnings, compile errors) into the comments, however these were naively concatenated with the value strings as they streamed in, producing out-of-order or interleaved text in some cases.
Stderr is now accumulated separately and appended after the value with a newline.

Replace stale eval comments on subsequent re-evals
Easier to explain with the following gif:

Screen.Recording.2026-06-25.at.19.06.02.mov

Importantly, it only matches against the exact cider-comment-prefix, and deletion only extends as far as the continued prefix.

Open question

Do we want to introduce a separate toggle defcustom for this behavior? I personally don't see a good reason a user would prefer the current behaviour of accumulating stale results. It's also easy enough to 'bypass' by adding even a single newline between the form and the eval comment, which breaks the match detection.

That was my original plan - 2771d8b adds this defcustom (defaulting to t) and the following commit 7df655e removes it entirely making the detect-and-replace behavior always active.

Will either drop the latter commit or squash away the back-and-forth changes depending on the decision.

Also fixes
Minor refactor bringing the point marker coercion (from #2607) into the handler instead of requiring callsites to pass a marker type. No user-facing change.

(disclosure: minor LLM assistance used in writing the test boilerplate, which I reviewed in full. All other changes certified organic and tested in person)

No changelog and user manual edits yet, pending the above question


Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (eldev test)
  • All code passes the linter (eldev lint) which is based on elisp-lint and includes
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the user manual (if adding/changing user-visible functionality)

yuhan0 added 2 commits June 25, 2026 18:33
The pprint-to-comment handler accumulated stderr into the same variable
as the eval value, so when nREPL response chunks interleaved (e.g. a
reflection warning arriving between value chunks), the result comment
would contain garbled output. Accumulate them separately and compose at
on-done: whichever is present alone, or value followed by a
newline-separated trimmed stderr block.
@yuhan0

yuhan0 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

(sorry, something seems to have broken when i fastforwarded the last 2-3 days worth of commits - currently investigating, will mark when it's ready for review)

yuhan0 added 5 commits June 25, 2026 19:52
Move the integer->marker coercion from the callsites into the handler
itself via copy-marker, so the handler's contract accepts both types.

No external facing change. Add a unit test covering the existing
behavior (introduced in clojure-emacs#2607)
Add an optional REPLACE arg to the multiline-comment eval handler and to
cider-pprint-form-to-comment.  When set, cider-maybe-delete-multiline-comment
removes the previously-inserted result region (both ;; line comments and
discarded #_/(comment ...) forms) before the new result is inserted, so
re-evaluating a form updates its comment in place instead of stacking.

cider-maybe-insert-multiline-comment now returns the bounds of the inserted
text (nil when nothing was inserted), and preserves blank lines in
pretty-printed output.
@yuhan0 yuhan0 force-pushed the eval-to-comment-pr branch from 5ee9bb8 to b085302 Compare June 25, 2026 12:06
@yuhan0

yuhan0 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the bug, which was due to me splitting out some WIP / personal changes from this PR - it should be ready for review now.
The spell checker failure looks like an existing false positive, unrelated to anything here:

  ./test/cider-log-tests.el:100: hel ==> help, hell, healuvx codespell --ignore-words=codespell.txt

@yuhan0 yuhan0 changed the title (Draft) Improvements to cider-eval-to-comment Improvements to cider-eval-to-comment Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant