patch-eshell.el 1.1 KB

12345678910111213141516171819202122232425
  1. ;;; REVIEW: Ignore dups in the entire ring, not just the last entry.
  2. ;;; Reported upstream, see #30466.
  3. (defun ambrevar/eshell-add-input-to-history (input)
  4. "Add the string INPUT to the history ring.
  5. Input is entered into the input history ring, if the value of
  6. variable `eshell-input-filter' returns non-nil when called on the
  7. input."
  8. (require 'subr-x)
  9. ;; TODO: Report this trick, so that "ls" and "ls " don't both get added to the
  10. ;; history. Doing this from eshell-expand-input-functions breaks Eshell
  11. ;; because the input is not expected to be modified.
  12. (setq input (string-trim-right input))
  13. (when (funcall eshell-input-filter input)
  14. (when (and eshell-hist-ignoredups
  15. (not (ring-empty-p eshell-history-ring)))
  16. (let ((dup-index (ring-member eshell-history-ring input)))
  17. (when dup-index
  18. (ring-remove eshell-history-ring dup-index))))
  19. (eshell-put-history input))
  20. (setq eshell-save-history-index eshell-history-index)
  21. (setq eshell-history-index nil))
  22. (advice-add 'eshell-add-input-to-history :override 'ambrevar/eshell-add-input-to-history)
  23. (provide 'patch-eshell)