]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow eshell to have an "erasedups"-like history
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 4 Feb 2021 10:55:44 +0000 (11:55 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 4 Feb 2021 10:55:47 +0000 (11:55 +0100)
* 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
lisp/eshell/em-hist.el

index 7cdb9d943021046c10af27988b9e7b7bdd4f1506..dddc150af1439f7948325fe4edf64d120fde8cb9 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -958,6 +958,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)'.
index 0d09ef4a12e64270ae2d9137329a2f25edfa437b..b7b1778ebb1dac9db2a26dda614bafe3f7ca4ab9 100644 (file)
@@ -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))