]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't save to history from 'eshell-command' when aborting
authorJim Porter <jporterbugs@gmail.com>
Sat, 13 Jul 2024 18:43:42 +0000 (11:43 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 17 Jul 2024 17:40:08 +0000 (19:40 +0200)
* lisp/eshell/eshell.el (eshell-add-input-to-history)
(eshell--save-history): Declare.
(eshell-command-mode-exit): New function...
(eshell-command-mode): ... use it.

* lisp/eshell/em-hist.el (eshell-hist-initialize): Don't handle
minibuffer logic here.  Always read history file (this ensures that
'eshell-command' can see the history, too).
(eshell-add-command-to-history): Remove.

(cherry picked from commit 3407e274999ce80582932332b108d84fba69d107)

lisp/eshell/em-hist.el
lisp/eshell/eshell.el

index 9ffddfb611f9ba918b667406ecf85698cc170d27..fffd611c06fbded47ccd8181f35d6318b217bc21 100644 (file)
@@ -295,12 +295,8 @@ Returns nil if INPUT is prepended by blank space, otherwise non-nil."
   (setq-local eshell-hist--new-items 0)
 
   (setq-local eshell-history-ring nil)
-  (if (minibuffer-window-active-p (selected-window))
-      (progn
-        (setq-local eshell-history-append t)
-        (add-hook 'minibuffer-exit-hook #'eshell-add-command-to-history nil t))
-    (if eshell-history-file-name
-       (eshell-read-history nil t)))
+  (when eshell-history-file-name
+    (eshell-read-history nil t))
 
   (unless eshell-history-ring
     (setq eshell-history-ring (make-ring eshell-history-size)))
@@ -411,18 +407,6 @@ input."
   (setq eshell-save-history-index eshell-history-index)
   (setq eshell-history-index nil))
 
-(defun eshell-add-command-to-history ()
-  "Add the command entered at `eshell-command's prompt to the history ring.
-The command is added to the input history ring, if the value of
-variable `eshell-input-filter' returns non-nil when called on the
-command.
-
-This function is supposed to be called from the minibuffer, presumably
-as a `minibuffer-exit-hook'."
-  (eshell-add-input-to-history
-   (buffer-substring (minibuffer-prompt-end) (point-max)))
-  (eshell--save-history))
-
 (defun eshell-add-to-history ()
   "Add last Eshell command to the history ring.
 The command is entered into the input history ring, if the value of
index b7be3dd164368f958c7ee09e650d6c60d92802d7..d60101d51e19ca10f82a9fbbca13a71acc920785 100644 (file)
@@ -284,14 +284,26 @@ information on Eshell, see Info node `(eshell)Top'."
       (eshell-mode))
     buf))
 
+(declare-function eshell-add-input-to-history "em-hist" (input))
+(declare-function eshell--save-history "em-hist" ())
+
+(defun eshell-command-mode-exit ()
+  "Exit the `eshell-commad-mode' minibuffer and save Eshell history."
+  (interactive)
+  (when (eshell-using-module 'eshell-hist)
+    (eshell-add-input-to-history
+     (buffer-substring (minibuffer-prompt-end) (point-max)))
+    (eshell--save-history))
+  (exit-minibuffer))
+
 (define-minor-mode eshell-command-mode
   "Minor mode for `eshell-command' input.
 \\{eshell-command-mode-map}"
   :keymap (let ((map (make-sparse-keymap)))
-            (define-key map [(control ?g)] 'abort-recursive-edit)
-            (define-key map [(control ?m)] 'exit-minibuffer)
-            (define-key map [(control ?j)] 'exit-minibuffer)
-            (define-key map [(meta control ?m)] 'exit-minibuffer)
+            (define-key map [(control ?g)] #'abort-recursive-edit)
+            (define-key map [(control ?m)] #'eshell-command-mode-exit)
+            (define-key map [(control ?j)] #'eshell-command-mode-exit)
+            (define-key map [(meta control ?m)] #'eshell-command-mode-exit)
             map))
 
 (define-obsolete-function-alias 'eshell-return-exits-minibuffer