@@ -194,9 +194,6 @@ CIDER 1.7."
194194This property value must be unique to avoid having adjacent inputs be
195195joined together." )
196196
197- (defvar-local cider-repl-input-history '()
198- " History list of strings read from the REPL buffer." )
199-
200197(defvar-local cider-repl-input-history-items-added 0
201198 " Variable counting the items added in the current session." )
202199
@@ -1468,6 +1465,9 @@ WIN, BUFFER and POS are the window, buffer and point under mouse position."
14681465(defvar cider-repl-history-pattern nil
14691466 " The regexp most recently used for finding input history." )
14701467
1468+ (defvar cider-repl-input-history '()
1469+ " History list of strings read from the REPL buffer." )
1470+
14711471(defun cider-repl--add-to-input-history (string )
14721472 " Add STRING to the input history.
14731473Empty strings and duplicates are ignored."
@@ -1593,9 +1593,11 @@ If USE-CURRENT-INPUT is non-nil, use the current input."
15931593 :safe #'integerp )
15941594
15951595(defcustom cider-repl-history-file nil
1596- " File to save the persistent REPL history to."
1597- :type 'string
1598- :safe #'stringp )
1596+ " File to save the persistent REPL history to.
1597+ If this is set to a path the history will be global to all projects. If this is
1598+ set to `per-project' , the history will be stored in a file (.cider-history) at
1599+ the root of each project."
1600+ :type '(choice string symbol))
15991601
16001602(defun cider-repl--history-read-filename ()
16011603 " Ask the user which file to use, defaulting `cider-repl-history-file' ."
@@ -1619,11 +1621,27 @@ defined filenames can be used to read special history files.
16191621
16201622The value of `cider-repl-input-history' is set by this function."
16211623 (interactive (list (cider-repl--history-read-filename)))
1622- (let ((f (or filename cider-repl-history-file)))
1623- ; ; TODO: probably need to set cider-repl-input-history-position as well.
1624- ; ; in a fresh connection the newest item in the list is currently
1625- ; ; not available. After sending one input, everything seems to work.
1626- (setq cider-repl-input-history (cider-repl--history-read f))))
1624+ (cond
1625+ (filename (setq cider-repl-history-file filename))
1626+ ((equal 'per-project cider-repl-history-file)
1627+ (make-local-variable 'cider-repl-input-history )
1628+ (when-let ((dir (clojure-project-dir)))
1629+ (setq-local
1630+ cider-repl-history-file (expand-file-name " .cider-history" dir)))))
1631+ (when cider-repl-history-file
1632+ (condition-case nil
1633+ ; ; TODO: probably need to set cider-repl-input-history-position as
1634+ ; ; well. In a fresh connection the newest item in the list is
1635+ ; ; currently not available. After sending one input, everything
1636+ ; ; seems to work.
1637+ (setq
1638+ cider-repl-input-history
1639+ (cider-repl--history-read cider-repl-history-file))
1640+ (error
1641+ (message
1642+ " Malformed cider-repl-history-file: %s" cider-repl-history-file)))
1643+ (add-hook 'kill-buffer-hook #'cider-repl-history-just-save t t )
1644+ (add-hook 'kill-emacs-hook #'cider-repl-history-save-all )))
16271645
16281646(defun cider-repl--history-write (filename )
16291647 " Write history to FILENAME.
@@ -1658,6 +1676,13 @@ This function is meant to be used in hooks to avoid lambda
16581676constructs."
16591677 (cider-repl-history-save cider-repl-history-file))
16601678
1679+ (defun cider-repl-history-save-all ()
1680+ " Save all histories."
1681+ (dolist (buffer (buffer-list ))
1682+ (with-current-buffer buffer
1683+ (when (equal major-mode 'cider-repl-mode )
1684+ (cider-repl-history-just-save)))))
1685+
16611686; ; SLIME has different semantics and will not save any duplicates.
16621687; ; we keep track of how many items were added to the history in the
16631688; ; current session in `cider-repl--add-to-input-history' and merge only the
@@ -2051,13 +2076,7 @@ in an unexpected place."
20512076 (setq-local prettify-symbols-alist clojure--prettify-symbols-alist)
20522077 ; ; apply dir-local variables to REPL buffers
20532078 (hack-dir-local-variables-non-file-buffer )
2054- (when cider-repl-history-file
2055- (condition-case nil
2056- (cider-repl-history-load cider-repl-history-file)
2057- (error
2058- (message " Malformed cider-repl-history-file: %s " cider-repl-history-file)))
2059- (add-hook 'kill-buffer-hook #'cider-repl-history-just-save t t )
2060- (add-hook 'kill-emacs-hook #'cider-repl-history-just-save ))
2079+ (cider-repl-history-load)
20612080 (add-hook 'completion-at-point-functions #'cider-complete-at-point nil t )
20622081 (add-hook 'paredit-mode-hook (lambda () (clojure-paredit-setup cider-repl-mode-map)))
20632082 (cider-repl-setup-paredit))
0 commit comments