aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/misc/eshell.texi19
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/eshell/em-hist.el16
3 files changed, 33 insertions, 8 deletions
diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi
index e8aa8cdc6a3..99a1491f1c3 100644
--- a/doc/misc/eshell.texi
+++ b/doc/misc/eshell.texi
@@ -1237,11 +1237,20 @@ command containing @code{foo}. The n-th argument of the last command
1237beginning with @code{foo} is accessible by @code{!foo:n}. 1237beginning with @code{foo} is accessible by @code{!foo:n}.
1238 1238
1239@vindex eshell-history-file-name 1239@vindex eshell-history-file-name
1240The history ring is loaded from a file at the start of every session, 1240@vindex eshell-history-append
1241and written back to the file at the end of every session. The file path 1241The history is loaded to the history ring from the file
1242is specified in @code{eshell-history-file-name}. Unlike other shells, 1242@code{eshell-history-file-name} at the start of every session, and
1243such as Bash, Eshell can not be configured to keep a history ring of a 1243saved to that file at the end of every session. The default history
1244different size than that of the history file. 1244saving behavior is to overwrite the history file with the whole
1245history ring of the session. If @code{eshell-history-append} is
1246non-@code{nil}, the history will instead be saved by appending new
1247entries from the session to the history file, which could prevent
1248potential history loss with multiple Eshell sessions. Unlike other
1249shells, such as Bash, Eshell cannot currently be configured to control
1250the size of the history file. In particular, when
1251@code{eshell-history-append} is non-@code{nil}, the size of the file
1252will keep increasing, and the recommended way to truncate the file is
1253to run the @samp{history -w} command in an Eshell session.
1245 1254
1246Since the default buffer navigation and searching key-bindings are 1255Since the default buffer navigation and searching key-bindings are
1247still present in the Eshell buffer, the commands for history 1256still present in the Eshell buffer, the commands for history
diff --git a/etc/NEWS b/etc/NEWS
index c55719416d3..e14ab4aed27 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -617,6 +617,12 @@ calling external rgrep.
617+++ 617+++
618*** If a command exits abnormally, the Eshell prompt now shows its exit code. 618*** If a command exits abnormally, the Eshell prompt now shows its exit code.
619 619
620+++
621*** New user option 'eshell-history-append'.
622If non-nil, each Eshell session will save history by appending new
623entries of that session to the history file rather than overwriting
624the file with the whole history of the session. The default is nil.
625
620** Minibuffer and Completions 626** Minibuffer and Completions
621 627
622*** New commands 'previous-line-completion' and 'next-line-completion'. 628*** New commands 'previous-line-completion' and 'next-line-completion'.
diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el
index cf03f8399a6..79336204847 100644
--- a/lisp/eshell/em-hist.el
+++ b/lisp/eshell/em-hist.el
@@ -116,6 +116,12 @@ If set to t, history will always be saved, silently."
116 (const :tag "Ask" ask) 116 (const :tag "Ask" ask)
117 (const :tag "Always save" t))) 117 (const :tag "Always save" t)))
118 118
119(defcustom eshell-history-append nil
120 "If non-nil, append new entries to the history file when saving history."
121 :type '(choice (const :tag "Overwrite history file" nil)
122 (const :tag "Append new entries to file" t))
123 :version "30.1")
124
119(defcustom eshell-input-filter 'eshell-input-filter-default 125(defcustom eshell-input-filter 'eshell-input-filter-default
120 "Predicate for filtering additions to input history. 126 "Predicate for filtering additions to input history.
121Takes one argument, the input. If non-nil, the input may be saved on 127Takes one argument, the input. If non-nil, the input may be saved on
@@ -294,17 +300,21 @@ Returns nil if INPUT is prepended by blank space, otherwise non-nil."
294 (if eshell-history-file-name 300 (if eshell-history-file-name
295 (eshell-read-history nil t)) 301 (eshell-read-history nil t))
296 302
297 (add-hook 'eshell-exit-hook #'eshell-write-history nil t)) 303 (add-hook 'eshell-exit-hook #'eshell--save-history nil t))
298 304
299 (unless eshell-history-ring 305 (unless eshell-history-ring
300 (setq eshell-history-ring (make-ring eshell-history-size))) 306 (setq eshell-history-ring (make-ring eshell-history-size)))
301 307
302 (add-hook 'eshell-exit-hook #'eshell-write-history nil t) 308 (add-hook 'eshell-exit-hook #'eshell--save-history nil t)
303 309
304 (add-hook 'kill-emacs-query-functions #'eshell-save-some-history) 310 (add-hook 'kill-emacs-query-functions #'eshell-save-some-history)
305 311
306 (add-hook 'eshell-input-filter-functions #'eshell-add-to-history nil t)) 312 (add-hook 'eshell-input-filter-functions #'eshell-add-to-history nil t))
307 313
314(defun eshell--save-history ()
315 "Save the history for current Eshell buffer."
316 (eshell-write-history nil eshell-history-append))
317
308(defun eshell-save-some-history () 318(defun eshell-save-some-history ()
309 "Save the history for any open Eshell buffers." 319 "Save the history for any open Eshell buffers."
310 (dolist (buf (buffer-list)) 320 (dolist (buf (buffer-list))
@@ -318,7 +328,7 @@ Returns nil if INPUT is prepended by blank space, otherwise non-nil."
318 (format-message 328 (format-message
319 "Save input history for Eshell buffer `%s'? " 329 "Save input history for Eshell buffer `%s'? "
320 (buffer-name buf))))) 330 (buffer-name buf)))))
321 (eshell-write-history))))) 331 (eshell--save-history)))))
322 t) 332 t)
323 333
324(defun eshell/history (&rest args) 334(defun eshell/history (&rest args)