[Fix #3915] Fix cider-repl-history crashing on second invocation#3921
Merged
Conversation
`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.
|
Wow! That's quite a comprehensive addressing of the problem. Thanks, @bbatsov ! |
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.
Fixes #3915.
cider-repl-historyreuses*cider-repl-history*across invocations, and the setup re-rancider-repl-history-mode' on the buffer *before* erasing it. That firesclojure-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-doctorcommand (requested by the reporter): scanscider-repl-input-history' for entries that don't balance, shows each in a side buffer, prompts y/n/q, and rewritescider-repl-history-file` if one is set.