[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 828b3d9: Allow eshell to have an "erasedups"-like history
From: |
Lars Ingebrigtsen |
Subject: |
master 828b3d9: Allow eshell to have an "erasedups"-like history |
Date: |
Thu, 4 Feb 2021 05:55:52 -0500 (EST) |
branch: master
commit 828b3d93eca4215baac4bab74156eeb3fa02955e
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Allow eshell to have an "erasedups"-like history
* lisp/eshell/em-hist.el (eshell-add-input-to-history): Use the
new value (bug#30466).
(eshell-hist-ignoredups): Allow "erasedups"-like value.
---
etc/NEWS | 3 +++
lisp/eshell/em-hist.el | 30 ++++++++++++++++++++++--------
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 7cdb9d9..dddc150 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -959,6 +959,9 @@ command line under point (and any following output).
** Eshell
---
+*** 'eshell-hist-ignoredups' can now also be used to mimic "erasedups" in bash.
+
+---
*** Environment variable 'INSIDE_EMACS' is now copied to subprocesses.
Its value equals the result of evaluating '(format "%s,eshell" emacs-version)'.
diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el
index 0d09ef4..b7b1778 100644
--- a/lisp/eshell/em-hist.el
+++ b/lisp/eshell/em-hist.el
@@ -99,8 +99,12 @@ If it is nil, Eshell will use the value of HISTFILE."
(defcustom eshell-hist-ignoredups nil
"If non-nil, don't add input matching the last on the input ring.
-This mirrors the optional behavior of bash."
- :type 'boolean)
+The value `erase' mirrors the \"erasedups\" value of HISTCONTROL
+in bash, and any other non-nil value mirrors the \"ignoredups\"
+value."
+ :type '(choice (const :tag "Don't ignore anything" nil)
+ (const :tag "Ignore consecutive duplicates" t)
+ (const :tag "Only keep last duplicate" 'erase)))
(defcustom eshell-save-history-on-exit t
"Determine if history should be automatically saved.
@@ -371,12 +375,22 @@ unless a different file is specified on the command
line.")
Input is entered into the input history ring, if the value of
variable `eshell-input-filter' returns non-nil when called on the
input."
- (if (and (funcall eshell-input-filter input)
- (or (null eshell-hist-ignoredups)
- (not (ring-p eshell-history-ring))
- (ring-empty-p eshell-history-ring)
- (not (string-equal (eshell-get-history 0) input))))
- (eshell-put-history input))
+ (when (and (funcall eshell-input-filter input)
+ (if (eq eshell-hist-ignoredups 'erase)
+ ;; Remove any old occurrences of the input, and put
+ ;; the new one at the end.
+ (progn
+ (ring-remove eshell-history-ring
+ (ring-member eshell-history-ring input))
+ t)
+ ;; Always add...
+ (or (null eshell-hist-ignoredups)
+ ;; ... or add if it's not already present at the
+ ;; end.
+ (not (ring-p eshell-history-ring))
+ (ring-empty-p eshell-history-ring)
+ (not (string-equal (eshell-get-history 0) input)))))
+ (eshell-put-history input))
(setq eshell-save-history-index eshell-history-index)
(setq eshell-history-index nil))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 828b3d9: Allow eshell to have an "erasedups"-like history,
Lars Ingebrigtsen <=