Function: cider-repl-history-doctor

cider-repl-history-doctor is an interactive and byte-compiled function defined in cider-repl.el.

Signature

(cider-repl-history-doctor)

Documentation

Interactively review and delete malformed entries in the REPL history.

Walks cider-repl-input-history looking for entries whose parens don't balance under Clojure syntax -- the kind of corruption that causes cider-history to fail with "Unmatched bracket or quote" (see issue #3915). Each problematic entry is shown in a side buffer; answer y to delete it, n to keep it, q to stop reviewing. When done, the history file is rewritten if cider-repl-history-file is set.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-repl.el
(defun cider-repl-history-doctor ()
  "Interactively review and delete malformed entries in the REPL history.

Walks `cider-repl-input-history' looking for entries whose parens don't
balance under Clojure syntax -- the kind of corruption that causes
`cider-history' to fail with \"Unmatched bracket or quote\" (see
issue #3915).  Each problematic entry is shown in a side buffer; answer
`y' to delete it, `n' to keep it, `q' to stop reviewing.  When done,
the history file is rewritten if `cider-repl-history-file' is set."
  (interactive)
  (let ((repl (or (and (derived-mode-p 'cider-repl-mode) (current-buffer))
                  (bound-and-true-p cider-history-repl-buffer)
                  (and (fboundp 'cider-current-repl) (cider-current-repl))
                  (user-error "No CIDER REPL available"))))
    (let* ((history (buffer-local-value 'cider-repl-input-history repl))
           (malformed (cider-repl--history-malformed-entries history))
           (total (length malformed)))
      (cond
       ((zerop total)
        (message "REPL history is clean (%d entries, all parse)."
                 (length history)))
       (t
        (message "Found %d malformed %s out of %d.  Reviewing..."
                 total (if (= total 1) "entry" "entries") (length history))
        (let ((deleted (cider-repl--history-doctor-walk repl malformed)))
          (cond
           ((null deleted)
            (message "No entries deleted."))
           (t
            (when cider-repl-history-file
              (with-current-buffer repl
                (cider-repl--history-write cider-repl-history-file)))
            (message "Deleted %d %s%s."
                     (length deleted)
                     (if (= 1 (length deleted)) "entry" "entries")
                     (if cider-repl-history-file
                         (format ", saved %s" cider-repl-history-file)
                       ""))))))))))