Skip to content

[Fix #3915] Fix cider-repl-history crashing on second invocation#3921

Merged
bbatsov merged 2 commits into
masterfrom
fix-repl-history-display
May 17, 2026
Merged

[Fix #3915] Fix cider-repl-history crashing on second invocation#3921
bbatsov merged 2 commits into
masterfrom
fix-repl-history-display

Conversation

@bbatsov
Copy link
Copy Markdown
Member

@bbatsov bbatsov commented May 17, 2026

Fixes #3915.

cider-repl-history reuses *cider-repl-history* across invocations, and the setup re-ran cider-repl-history-mode' on the buffer *before* erasing it. That fires clojure-mode-hookagainst the previous render's content. If the user has anything likecheck-parenson that hook (paredit-adjacent configs commonly do),scan-sexpswalks the entire buffer and fails on any history entry with unbalanced parens — typically a typo the user once typed into the REPL. The user-error fromcheck-parens` aborts the rest of setup, so the second invocation shows an empty buffer with "Unmatched bracket or quote".

The fix flips the order: erase first, then enter the mode. Hooks always see an empty buffer, matching the first-invocation behavior. Zero user data is lost — the offending entry stays in history and remains recallable via M-p.

Also adds a new cider-repl-history-doctor command (requested by the reporter): scans cider-repl-input-history' for entries that don't balance, shows each in a side buffer, prompts y/n/q, and rewrites cider-repl-history-file` if one is set.

bbatsov added 2 commits May 15, 2026 18:12
`cider-repl-history' reuses the `*cider-repl-history*' buffer across
invocations. `cider-repl-history-setup' called `cider-repl-history-mode'
*before* erasing the buffer, so on the second invocation the mode hooks
fired against the previous render's content.

That's fine for most users, but `cider-repl-history-mode' inherits
from `clojure-mode', and a fairly common safety net is to run
`check-parens' from `clojure-mode-hook'.  If any entry in the
previously-rendered history had unbalanced parens (typically a typo
the user committed to history while editing), `check-parens' would
fail with "Unmatched bracket or quote" and abort the render -- the
user saw the error and an empty buffer instead of their history.

The fix is to flip the order: erase first, then enter the mode.  Hooks
always see an empty buffer, matching the first-invocation behavior.

Adds a regression test that installs a `check-parens'-style hook and
verifies a second invocation with a malformed history entry no longer
errors.
Per the user's suggestion in #3915: when REPL history accumulates
typo-ed entries that break the history browser, the user wants a way
to see which entries are problematic and clean them up.

`M-x cider-repl-history-doctor' walks `cider-repl-input-history' for
entries whose parens don't balance under Clojure syntax (the kind of
corruption that trips the browser via `check-parens'-style hooks),
shows each candidate in a side buffer, and prompts y/n/q.  When done,
it rewrites the history file if `cider-repl-history-file' is set so
the cleanup survives a restart.
@bbatsov bbatsov merged commit 186c34f into master May 17, 2026
13 checks passed
@bbatsov bbatsov deleted the fix-repl-history-display branch May 17, 2026 09:17
@cch1
Copy link
Copy Markdown

cch1 commented May 17, 2026

Wow! That's quite a comprehensive addressing of the problem. Thanks, @bbatsov !

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.

cider-repl-history is corrupted

2 participants