2018-03-09 12:07:58 +01:00
|
|
|
;;; REVIEW: Ignore dups in the entire ring, not just the last entry.
|
|
|
|
;;; Reported upstream, see #30466.
|
2021-02-04 18:34:44 +01:00
|
|
|
;; Should be done as of Emacs 28.
|
2019-03-03 13:12:04 +01:00
|
|
|
(defun ambrevar/eshell-add-input-to-history (input)
|
2018-03-09 12:07:58 +01:00
|
|
|
"Add the string INPUT to the history ring.
|
|
|
|
Input is entered into the input history ring, if the value of
|
|
|
|
variable `eshell-input-filter' returns non-nil when called on the
|
|
|
|
input."
|
2019-03-06 11:26:35 +01:00
|
|
|
(require 'subr-x)
|
|
|
|
;; TODO: Report this trick, so that "ls" and "ls " don't both get added to the
|
|
|
|
;; history. Doing this from eshell-expand-input-functions breaks Eshell
|
|
|
|
;; because the input is not expected to be modified.
|
|
|
|
(setq input (string-trim-right input))
|
2018-03-09 12:07:58 +01:00
|
|
|
(when (funcall eshell-input-filter input)
|
2019-05-28 18:31:05 +02:00
|
|
|
(when (and eshell-hist-ignoredups
|
|
|
|
(not (ring-empty-p eshell-history-ring)))
|
2019-06-27 13:40:42 +02:00
|
|
|
(let ((dup-index (ring-member eshell-history-ring input)))
|
|
|
|
(when dup-index
|
|
|
|
(ring-remove eshell-history-ring dup-index))))
|
2018-03-09 12:07:58 +01:00
|
|
|
(eshell-put-history input))
|
|
|
|
(setq eshell-save-history-index eshell-history-index)
|
|
|
|
(setq eshell-history-index nil))
|
2019-03-03 13:12:04 +01:00
|
|
|
(advice-add 'eshell-add-input-to-history :override 'ambrevar/eshell-add-input-to-history)
|
2018-03-09 12:07:58 +01:00
|
|
|
|
2020-09-27 10:25:43 +02:00
|
|
|
(provide 'patch-eshell)
|