1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Fix and improve behavior of 'eshell/clear'

* lisp/eshell/esh-mode.el (eshell-clear): New function.
(eshell/clear): Fix incorrect behavior, and do the right thing when
'eshell-scroll-show-maximum-output' is nil.
(eshell/clear-scrollback): Call 'eshell/clear'.

* test/lisp/eshell/esh-mode-tests.el
(esh-mode-test/clear/eshell-command)
(esh-mode-test/clear/eshell-command/erase)
(esh-mode-test/clear/emacs-command)
(esh-mode-test/clear/emacs-command/erase): New tests.

* etc/NEWS: Mention the new 'eshell-command' (bug#73722).
This commit is contained in:
Jim Porter 2024-10-10 21:03:45 -07:00
parent 9ff155183c
commit 98e24e369a
3 changed files with 101 additions and 10 deletions

View file

@ -26,6 +26,8 @@
(require 'ert)
(require 'esh-mode)
(require 'eshell)
(require 'em-banner)
(require 'em-prompt)
(require 'eshell-tests-helpers
(expand-file-name "eshell-tests-helpers"
@ -59,4 +61,44 @@
(eshell-match-command-output (format "(format \"hello%c%cp\")" ?\C-h ?\C-h)
"\\`help\n")))
(ert-deftest esh-mode-test/clear/eshell-command ()
"Test that `eshell/clear' works as an Eshell command."
(let ((eshell-banner-message "")
(eshell-prompt-function (lambda () "$ ")))
(with-temp-eshell
(eshell-insert-command "echo hi")
(eshell-insert-command "clear")
(should (string-match "\\`\\$ echo hi\nhi\n\\$ clear\n+\\$ "
(buffer-string))))))
(ert-deftest esh-mode-test/clear/eshell-command/erase ()
"Test that `eshell/clear' can erase the buffer."
(let ((eshell-banner-message "")
(eshell-prompt-function (lambda () "$ ")))
(with-temp-eshell
(eshell-insert-command "echo hi")
(eshell-insert-command "clear t")
(should (string-match "\\`\\$ " (buffer-string))))))
(ert-deftest esh-mode-test/clear/emacs-command ()
"Test that `eshell-clear' works as an interactive Emacs command."
(let ((eshell-banner-message "")
(eshell-prompt-function (lambda () "$ ")))
(with-temp-eshell
(eshell-insert-command "echo hi")
(insert "echo b")
(eshell-clear)
(should (string-match "\\`\\$ echo hi\nhi\n\n+\\$ echo b"
(buffer-string))))))
(ert-deftest esh-mode-test/clear/emacs-command/erase ()
"Test that `eshell-clear' can erase the buffer."
(let ((eshell-banner-message "")
(eshell-prompt-function (lambda () "$ ")))
(with-temp-eshell
(eshell-insert-command "echo hi")
(insert "echo b")
(eshell-clear t)
(should (string-match "\\`\\$ echo b" (buffer-string))))))
;; esh-mode-tests.el ends here