Function: cider-repl-history-setup

cider-repl-history-setup is a byte-compiled function defined in cider-repl-history.el.

Signature

(cider-repl-history-setup REPL-WIN REPL-BUF HISTORY-BUF &optional REGEXP)

Documentation

Setup.

REPL-WIN and REPL-BUF are where to insert commands; HISTORY-BUF is the history, and optional arg REGEXP is a filter.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/cider-repl-history.el
(defun cider-repl-history-setup (repl-win repl-buf history-buf &optional regexp)
  "Setup.
REPL-WIN and REPL-BUF are where to insert commands;
HISTORY-BUF is the history, and optional arg REGEXP is a filter."
  (cider-repl-history-preview-overlay-setup repl-buf)
  (with-current-buffer history-buf
    (unwind-protect
        (progn
          (cider-repl-history-mode)
          (setq buffer-read-only nil)
          (when (eq 'one-line cider-repl-history-display-style)
            (setq truncate-lines t))
          (let ((inhibit-read-only t))
            (erase-buffer))
          (setq cider-repl-history-repl-buffer repl-buf)
          (setq cider-repl-history-repl-window repl-win)
          (let* ((cider-repl-history-maximum-display-length
                  (if (and cider-repl-history-maximum-display-length
                           (<= cider-repl-history-maximum-display-length 3))
                      4
                    cider-repl-history-maximum-display-length))
                 (cider-command-history (cider-repl-history-get-history))
                 (items (mapcar
                         (if cider-repl-history-text-properties
                             #'copy-sequence
                           #'substring-no-properties)
                         cider-command-history)))
            (unless cider-repl-history-display-duplicates
              ;; display highest or lowest duplicate.
              ;; if `cider-repl-history-display-duplicate-highest' is t,
              ;; display highest (most recent) duplicate.
              (setq items (cl-delete-duplicates
                           items
                           :test #'equal
                           :from-end cider-repl-history-display-duplicate-highest)))
            (when (stringp regexp)
              (setq items (delq nil
                                (mapcar
                                 #'(lambda (item)
                                     (when (string-match regexp item)
                                       item))
                                 items))))
            (funcall (or (cdr (assq cider-repl-history-display-style
                                    cider-repl-history-display-styles))
                         (error "Invalid `cider-repl-history-display-style': %s"
                                cider-repl-history-display-style))
                     items)
            (when cider-repl-history-show-preview
              (cider-repl-history-preview-update-by-position (point-min))
              ;; Local post-command-hook, only happens in *cider-repl-history*
              (add-hook 'post-command-hook
                        #'cider-repl-history-preview-update-by-position
                        nil t)
              (add-hook 'kill-buffer-hook
                        #'cider-repl-history-cleanup-on-exit
                        nil t))
            (when cider-repl-history-highlight-current-entry
              (add-hook 'post-command-hook
                        #'cider-repl-history-update-highlighted-entry
                        nil t))
            (message
             (let* ((history-length (length cider-command-history))
                    (entry (if (= 1 history-length)
                               "entry"
                             "entries")))
               (concat
                (if (and (not regexp)
                         cider-repl-history-display-duplicates)
                    (format "%s %s in the command history."
                            history-length entry)
                  (format "%s (of %s) %s in the command history shown."
                          (length items) history-length entry))
                (substitute-command-keys
                 "  Type \\[cider-repl-history-quit] to quit.  \\[describe-mode] for help."))))
            (set-buffer-modified-p nil)
            (goto-char (point-min))
            (cider-repl-history-forward 0)
            (setq mode-name (if regexp
                                (concat "History [" regexp "]")
                              "History"))
            (run-hooks 'cider-repl-history-hook)))
      (setq buffer-read-only t))))