Skip to content

Commit

Permalink
Make cider-repl-input-history really global
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzull committed Nov 7, 2023
1 parent cbf815e commit b51600d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
11 changes: 1 addition & 10 deletions cider-repl-history.el
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ call `cider-repl-history' again.")
(defvar cider-repl-history-previous-overlay nil
"Previous overlay within *cider-repl-history* buffer.")


(defun cider-repl-history-get-history ()
"Function to retrieve history from the REPL buffer."
(if cider-repl-history-repl-buffer
(buffer-local-value
'cider-repl-input-history
cider-repl-history-repl-buffer)
(error "Variable `cider-repl-history-repl-buffer' not bound to a buffer")))

(defun cider-repl-history-resize-window ()
"Resize the *cider-repl-history* window if needed.
Controlled by variable `cider-repl-history-resize-window'."
Expand Down Expand Up @@ -597,7 +588,7 @@ HISTORY-BUF is the history, and optional arg REGEXP is a filter."
(<= cider-repl-history-maximum-display-length 3))
4
cider-repl-history-maximum-display-length))
(cider-command-history (cider-repl-history-get-history))
(cider-command-history cider-repl-input-history)
(items (mapcar
(if cider-repl-history-text-properties
#'copy-sequence
Expand Down
29 changes: 6 additions & 23 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ See also `cider-repl-eval-init-code'."
:type '(list string)
:package-version '(cider . "0.21.0"))

(defvar cider-repl-input-history '()
"History list of strings read from the REPL buffer.")

(defcustom cider-repl-display-help-banner t
"When non-nil a bit of help text will be displayed on REPL start."
:type 'boolean
Expand Down Expand Up @@ -194,12 +197,6 @@ CIDER 1.7."
This property value must be unique to avoid having adjacent inputs be
joined together.")

(defvar-local cider-repl-input-history '()
"History list of strings read from the REPL buffer.")

(defvar-local cider-repl-input-history-items-added 0
"Variable counting the items added in the current session.")

(defvar-local cider-repl-output-start nil
"Marker for the start of output.
Currently its only purpose is to facilitate `cider-repl-clear-buffer'.")
Expand Down Expand Up @@ -1473,8 +1470,7 @@ WIN, BUFFER and POS are the window, buffer and point under mouse position."
Empty strings and duplicates are ignored."
(unless (or (equal string "")
(equal string (car cider-repl-input-history)))
(push string cider-repl-input-history)
(cl-incf cider-repl-input-history-items-added)))
(push string cider-repl-input-history)))

(defun cider-repl-delete-current-input ()
"Delete all text after the prompt."
Expand Down Expand Up @@ -1629,11 +1625,8 @@ The value of `cider-repl-input-history' is set by this function."
"Write history to FILENAME.
Currently coding system for writing the contents is hardwired to
utf-8-unix."
(let* ((mhist (cider-repl--histories-merge cider-repl-input-history
cider-repl-input-history-items-added
(cider-repl--history-read filename)))
;; newest items are at the beginning of the list, thus 0
(hist (cl-subseq mhist 0 (min (length mhist) cider-repl-history-size))))
(let* ((end (min (length cider-repl-input-history) cider-repl-history-size))
(hist (cl-subseq cider-repl-input-history 0 end)))
(unless (file-writable-p filename)
(error (format "History file not writable: %s" filename)))
(let ((print-length nil) (print-level nil))
Expand All @@ -1658,16 +1651,6 @@ This function is meant to be used in hooks to avoid lambda
constructs."
(cider-repl-history-save cider-repl-history-file))

;; SLIME has different semantics and will not save any duplicates.
;; we keep track of how many items were added to the history in the
;; current session in `cider-repl--add-to-input-history' and merge only the
;; new items with the current history found in the file, which may
;; have been changed in the meantime by another session.
(defun cider-repl--histories-merge (session-hist n-added-items file-hist)
"Merge histories from SESSION-HIST adding N-ADDED-ITEMS into FILE-HIST."
(append (cl-subseq session-hist 0 n-added-items)
file-hist))


;;; REPL shortcuts
(defcustom cider-repl-shortcut-dispatch-char ?\,
Expand Down

0 comments on commit b51600d

Please sign in to comment.