@@ -194,9 +194,6 @@ CIDER 1.7."
194
194
This property value must be unique to avoid having adjacent inputs be
195
195
joined together." )
196
196
197
- (defvar-local cider-repl-input-history '()
198
- " History list of strings read from the REPL buffer." )
199
-
200
197
(defvar-local cider-repl-input-history-items-added 0
201
198
" Variable counting the items added in the current session." )
202
199
@@ -1468,6 +1465,9 @@ WIN, BUFFER and POS are the window, buffer and point under mouse position."
1468
1465
(defvar cider-repl-history-pattern nil
1469
1466
" The regexp most recently used for finding input history." )
1470
1467
1468
+ (defvar cider-repl-input-history '()
1469
+ " History list of strings read from the REPL buffer." )
1470
+
1471
1471
(defun cider-repl--add-to-input-history (string )
1472
1472
" Add STRING to the input history.
1473
1473
Empty strings and duplicates are ignored."
@@ -1593,9 +1593,11 @@ If USE-CURRENT-INPUT is non-nil, use the current input."
1593
1593
:safe #'integerp )
1594
1594
1595
1595
(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))
1599
1601
1600
1602
(defun cider-repl--history-read-filename ()
1601
1603
" 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.
1619
1621
1620
1622
The value of `cider-repl-input-history' is set by this function."
1621
1623
(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 )))
1627
1645
1628
1646
(defun cider-repl--history-write (filename )
1629
1647
" Write history to FILENAME.
@@ -1658,6 +1676,13 @@ This function is meant to be used in hooks to avoid lambda
1658
1676
constructs."
1659
1677
(cider-repl-history-save cider-repl-history-file))
1660
1678
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
+
1661
1686
; ; SLIME has different semantics and will not save any duplicates.
1662
1687
; ; we keep track of how many items were added to the history in the
1663
1688
; ; current session in `cider-repl--add-to-input-history' and merge only the
@@ -2051,13 +2076,7 @@ in an unexpected place."
2051
2076
(setq-local prettify-symbols-alist clojure--prettify-symbols-alist)
2052
2077
; ; apply dir-local variables to REPL buffers
2053
2078
(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)
2061
2080
(add-hook 'completion-at-point-functions #'cider-complete-at-point nil t )
2062
2081
(add-hook 'paredit-mode-hook (lambda () (clojure-paredit-setup cider-repl-mode-map)))
2063
2082
(cider-repl-setup-paredit))
0 commit comments