(pcase eshell-hist-ignoredups
('nil t) ; Always add to history
('erase ; Add, removing any old occurrences
- (when-let ((old-index (ring-member eshell-history-ring input)))
- ;; Remove the old occurrence of this input so we can
- ;; add it to the end. FIXME: Should we try to
- ;; remove multiple old occurrences, e.g. if the user
- ;; recently changed to using `erase'?
+ (while-let ((old-index (ring-member eshell-history-ring input)))
+ ;; Remove the old occurrences of this input so we can
+ ;; add it to the end.
(ring-remove eshell-history-ring old-index))
t)
(_ ; Add if not already the latest entry
(should (equal (ring-elements eshell-history-ring)
'("echo hi" "echo bye"))))))
+(ert-deftest em-hist-test/add-to-history/erase-existing-dups ()
+ "Test adding to history, erasing any old dups after switching to 'erase."
+ (let ((eshell-hist-ignoredups nil))
+ (with-temp-eshell
+ (eshell-insert-command "echo hi")
+ (eshell-insert-command "echo bye")
+ (eshell-insert-command "echo bye")
+ (eshell-insert-command "echo hi")
+ (eshell-insert-command "echo bye")
+ (setq eshell-hist-ignoredups 'erase)
+ (eshell-insert-command "echo hi")
+ (should (equal (ring-elements eshell-history-ring)
+ '("echo hi" "echo bye" "echo bye" "echo bye")))
+ (eshell-insert-command "echo bye")
+ (should (equal (ring-elements eshell-history-ring)
+ '("echo bye" "echo hi"))))))
+
(provide 'em-hist-test)
;;; em-hist-tests.el ends here