diff options
| author | Robin Joy | 2024-05-24 14:26:39 +0200 |
|---|---|---|
| committer | Jim Porter | 2024-05-24 19:29:20 -0700 |
| commit | 984fb346fdf0d5ec9eaea6126aad0bea8823b8a3 (patch) | |
| tree | 9dfe5d68c47ae5680f4811fb20a08c38407c94be | |
| parent | f3dd0d981cbb9c0fa10a3c5b05b244ed7a0f4e6b (diff) | |
| download | emacs-984fb346fdf0d5ec9eaea6126aad0bea8823b8a3.tar.gz emacs-984fb346fdf0d5ec9eaea6126aad0bea8823b8a3.zip | |
Erase existing duplicates in eshell-history-ring
Erase all existing duplicates instead of just the last duplicate entry
when 'eshell-hist-ignoredups' is set to 'erase'. Multiple duplicates
can exist in case 'eshell-hist-ignoredups' was set to something else
than 'erase' in the past or if the history file contains duplicates
(bug#71107).
* lisp/eshell/em-hist.el (eshell-add-input-to-history): Remove all
duplicates from history ring.
* test/lisp/eshell/em-hist-tests.el
(em-hist-test/add-to-history/erase-existing-dups): New test.
| -rw-r--r-- | lisp/eshell/em-hist.el | 8 | ||||
| -rw-r--r-- | test/lisp/eshell/em-hist-tests.el | 17 |
2 files changed, 20 insertions, 5 deletions
diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index 21029eae1bc..b171a2850ff 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el | |||
| @@ -398,11 +398,9 @@ input." | |||
| 398 | (pcase eshell-hist-ignoredups | 398 | (pcase eshell-hist-ignoredups |
| 399 | ('nil t) ; Always add to history | 399 | ('nil t) ; Always add to history |
| 400 | ('erase ; Add, removing any old occurrences | 400 | ('erase ; Add, removing any old occurrences |
| 401 | (when-let ((old-index (ring-member eshell-history-ring input))) | 401 | (while-let ((old-index (ring-member eshell-history-ring input))) |
| 402 | ;; Remove the old occurrence of this input so we can | 402 | ;; Remove the old occurrences of this input so we can |
| 403 | ;; add it to the end. FIXME: Should we try to | 403 | ;; add it to the end. |
| 404 | ;; remove multiple old occurrences, e.g. if the user | ||
| 405 | ;; recently changed to using `erase'? | ||
| 406 | (ring-remove eshell-history-ring old-index)) | 404 | (ring-remove eshell-history-ring old-index)) |
| 407 | t) | 405 | t) |
| 408 | (_ ; Add if not already the latest entry | 406 | (_ ; Add if not already the latest entry |
diff --git a/test/lisp/eshell/em-hist-tests.el b/test/lisp/eshell/em-hist-tests.el index a4e1e01b124..40e6f90478d 100644 --- a/test/lisp/eshell/em-hist-tests.el +++ b/test/lisp/eshell/em-hist-tests.el | |||
| @@ -163,6 +163,23 @@ elements against that; if t (the default), check against EXPECTED." | |||
| 163 | (should (equal (ring-elements eshell-history-ring) | 163 | (should (equal (ring-elements eshell-history-ring) |
| 164 | '("echo hi" "echo bye")))))) | 164 | '("echo hi" "echo bye")))))) |
| 165 | 165 | ||
| 166 | (ert-deftest em-hist-test/add-to-history/erase-existing-dups () | ||
| 167 | "Test adding to history, erasing any old dups after switching to 'erase." | ||
| 168 | (let ((eshell-hist-ignoredups nil)) | ||
| 169 | (with-temp-eshell | ||
| 170 | (eshell-insert-command "echo hi") | ||
| 171 | (eshell-insert-command "echo bye") | ||
| 172 | (eshell-insert-command "echo bye") | ||
| 173 | (eshell-insert-command "echo hi") | ||
| 174 | (eshell-insert-command "echo bye") | ||
| 175 | (setq eshell-hist-ignoredups 'erase) | ||
| 176 | (eshell-insert-command "echo hi") | ||
| 177 | (should (equal (ring-elements eshell-history-ring) | ||
| 178 | '("echo hi" "echo bye" "echo bye" "echo bye"))) | ||
| 179 | (eshell-insert-command "echo bye") | ||
| 180 | (should (equal (ring-elements eshell-history-ring) | ||
| 181 | '("echo bye" "echo hi")))))) | ||
| 182 | |||
| 166 | (provide 'em-hist-test) | 183 | (provide 'em-hist-test) |
| 167 | 184 | ||
| 168 | ;;; em-hist-tests.el ends here | 185 | ;;; em-hist-tests.el ends here |