Eshell: Extract ring-delete-first-item-duplicates from eshell-history-remove-duplicates.
parent
696969c378
commit
ed1ad20c1a
|
@ -164,6 +164,27 @@ everything in a way that's suitable for kconfig."
|
|||
(interactive)
|
||||
(setq fill-column (default-value 'fill-column)))
|
||||
|
||||
(defun ambrevar/ring-delete-first-item-duplicates (ring)
|
||||
"Remove duplicates of last command in history.
|
||||
Return RING.
|
||||
|
||||
This should be faster then `seq-uniq'. Unlike
|
||||
`eshell-hist-ignoredups' or `comint-input-ignoredups', it does
|
||||
not allow duplicates ever.
|
||||
Surrounding spaces are ignored when comparing."
|
||||
(let ((first (ring-ref ring 0))
|
||||
(index 1))
|
||||
(while (<= index (1- (ring-length ring)))
|
||||
(if (string= (string-trim first)
|
||||
(string-trim (ring-ref ring index)))
|
||||
;; REVIEW: We could stop at the first match, it would be faster and it
|
||||
;; would eliminate duplicates if we started from a fresh history.
|
||||
;; From an existing history that would not clean up existing
|
||||
;; duplicates beyond the first one.
|
||||
(ring-remove ring index)
|
||||
(setq index (1+ index))))
|
||||
ring))
|
||||
|
||||
(defun ambrevar/sort-lines-unique (arg)
|
||||
"Remove trailing white space, then duplicate lines, then sort the result.
|
||||
Do not fold case with \\[universal-argument] or non-nil ARG."
|
||||
|
|
|
@ -187,18 +187,8 @@
|
|||
(add-hook 'eshell-mode-hook 'ambrevar/eshell-hist-use-global-history)
|
||||
|
||||
(defun ambrevar/eshell-history-remove-duplicates ()
|
||||
"Remove duplicates of last command in history.
|
||||
This should be faster then `seq-uniq'."
|
||||
(let ((first (ring-ref eshell-history-ring 0))
|
||||
(index 1))
|
||||
(while (<= index (1- (ring-length eshell-history-ring)))
|
||||
(if (string= first (ring-ref eshell-history-ring index))
|
||||
;; REVIEW: We could stop at the first match, it would be faster and it
|
||||
;; would eliminate duplicates if we started from a fresh history.
|
||||
;; From an existing history that would not clean up existing
|
||||
;; duplicates beyond the first one.
|
||||
(ring-remove eshell-history-ring index)
|
||||
(setq index (1+ index))))))
|
||||
(require 'functions) ; For `ambrevar/ring-delete-first-item-duplicates'.
|
||||
(ambrevar/ring-delete-first-item-duplicates eshell-history-ring))
|
||||
(add-hook 'eshell-pre-command-hook 'ambrevar/eshell-history-remove-duplicates)
|
||||
|
||||
;; Always save history
|
||||
|
|
Loading…
Reference in New Issue