From 9d3af94619df698e9507ce54d276f9ee644bec66 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Tue, 28 May 2024 14:43:28 -0700 Subject: [PATCH] Fix adding to history via 'eshell-command' * lisp/eshell/eshell.el (eshell-read-command): Don't handle history here. * lisp/eshell/em-hist.el (eshell-hist-initialize): Properly set up history for minibuffer. (eshell-add-command-to-history): Immediately save history. (cherry picked from commit 7e326b915f45346803edb52b5023db9b765ed07a) --- lisp/eshell/em-hist.el | 13 +++++++------ lisp/eshell/eshell.el | 5 +---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index b171a2850ff..2749749bb93 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -294,13 +294,13 @@ Returns nil if INPUT is prepended by blank space, otherwise non-nil." (make-local-variable 'eshell-save-history-index) (setq-local eshell-hist--new-items 0) + (setq-local eshell-history-ring nil) (if (minibuffer-window-active-p (selected-window)) - (setq-local eshell-save-history-on-exit nil) - (setq-local eshell-history-ring nil) + (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)) - - (add-hook 'eshell-exit-hook #'eshell--save-history nil t)) + (eshell-read-history nil t))) (unless eshell-history-ring (setq eshell-history-ring (make-ring eshell-history-size))) @@ -421,7 +421,8 @@ 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)))) + (buffer-substring (minibuffer-prompt-end) (point-max))) + (eshell--save-history)) (defun eshell-add-to-history () "Add last Eshell command to the history ring. diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el index 503f64add41..18e05a371a4 100644 --- a/lisp/eshell/eshell.el +++ b/lisp/eshell/eshell.el @@ -281,10 +281,7 @@ information on Eshell, see Info node `(eshell)Top'." (minibuffer-with-setup-hook (lambda () (eshell-mode) (eshell-command-mode +1)) - (let ((command (read-from-minibuffer prompt))) - (when (eshell-using-module 'eshell-hist) - (eshell-add-input-to-history command)) - command)))) + (read-from-minibuffer prompt)))) ;;;###autoload (defun eshell-command (command &optional to-current-buffer) -- 2.39.2