changeset 43322:80c00f33bf18

(eshell-hist-initialize): When in the minibuffer, use the global value of `eshell-history-ring', and never save it to disk, or ask to save it to disk. This allows users of session.el to control whether its global state should be persisted or not. (eshell-add-command-to-history): Don't write Eshell's history out to disk, let the governing mode control that upon exit. (eshell-add-input-to-history): New function, with most of the code from eshell-add-to-history. (eshell-add-command-to-history): New function, to record in eshell-history the commands run via eshell-command. (eshell-add-to-history): Call eshell-add-command-to-history to do most of the work.
author John Wiegley <johnw@newartisans.com>
date Sat, 16 Feb 2002 07:11:05 +0000
parents 358616bbe6a1
children b38653bd5e04
files lisp/eshell/em-hist.el
diffstat 1 files changed, 41 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/eshell/em-hist.el	Sat Feb 16 07:10:35 2002 +0000
+++ b/lisp/eshell/em-hist.el	Sat Feb 16 07:11:05 2002 +0000
@@ -216,7 +216,8 @@
     (add-hook 'pcomplete-try-first-hook
 	      'eshell-complete-history-reference nil t))
 
-  (if (eshell-using-module 'eshell-rebind)
+  (if (and (eshell-using-module 'eshell-rebind)
+	   (not eshell-non-interactive-p))
       (let ((rebind-alist (symbol-value 'eshell-rebind-keys-alist)))
 	(make-local-variable 'eshell-rebind-keys-alist)
 	(set 'eshell-rebind-keys-alist
@@ -270,9 +271,16 @@
 
   (make-local-variable 'eshell-history-index)
   (make-local-variable 'eshell-save-history-index)
-  (make-local-variable 'eshell-history-ring)
-  (if eshell-history-file-name
-      (eshell-read-history nil t))
+
+  (if (minibuffer-window-active-p (selected-window))
+      (set (make-local-variable 'eshell-ask-to-save-history) nil)
+    (set (make-local-variable 'eshell-history-ring) nil)
+    (if eshell-history-file-name
+	(eshell-read-history nil t))
+
+    (make-local-hook 'eshell-exit-hook)
+    (add-hook 'eshell-exit-hook 'eshell-write-history nil t))
+
   (unless eshell-history-ring
     (setq eshell-history-ring (make-ring eshell-history-size)))
 
@@ -360,22 +368,40 @@
   "Get an input line from the history ring."
   (ring-ref (or ring eshell-history-ring) index))
 
-(defun eshell-add-to-history ()
-  "Add INPUT to the history ring.
-The input is entered into the input history ring, if the value of
+(defun eshell-add-input-to-history (input)
+  "Add the string INPUT to the history ring.
+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))
+  (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))))
+
+(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
+variable `eshell-input-filter' returns non-nil when called on the
+command."
   (when (> (1- eshell-last-input-end) eshell-last-input-start)
     (let ((input (buffer-substring eshell-last-input-start
 				   (1- eshell-last-input-end))))
-      (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))
-      (setq eshell-save-history-index eshell-history-index)
-      (setq eshell-history-index nil))))
+      (eshell-add-input-to-history input))))
 
 (defun eshell-read-history (&optional filename silent)
   "Sets the buffer's `eshell-history-ring' from a history file.