diff options
| author | Liu Hui | 2023-11-16 11:45:28 +0800 |
|---|---|---|
| committer | Sean Whitton | 2023-12-07 11:32:29 +0000 |
| commit | 3a7abc7e497e77ba9bc5a71f3836636675dffe6b (patch) | |
| tree | 204dc26cab928351231ebcd9e3669a324bdbdbf0 /lisp/eshell | |
| parent | e4e1e268c8e9f7de6fe5d4b05beb595a1781c02c (diff) | |
| download | emacs-3a7abc7e497e77ba9bc5a71f3836636675dffe6b.tar.gz emacs-3a7abc7e497e77ba9bc5a71f3836636675dffe6b.zip | |
Add option eshell-history-append
* lisp/eshell/em-hist.el (eshell-history-append): New option.
(eshell--save-history): New function.
(eshell-hist-initialize):
(eshell-save-some-history): Replace eshell-write-history with
eshell--save-history, which respects the new option.
* doc/misc/eshell.texi (History): Document the change.
* etc/NEWS: Announce the change. (Bug#66700)
Diffstat (limited to 'lisp/eshell')
| -rw-r--r-- | lisp/eshell/em-hist.el | 16 |
1 files changed, 13 insertions, 3 deletions
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. |
| 121 | Takes one argument, the input. If non-nil, the input may be saved on | 127 | Takes 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) |