From 4c868dbad546b604076ab7c33839b4d3b5919f32 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 10 Oct 2024 21:03:45 -0700 Subject: [PATCH] Fix error when calling "clear" in Eshell. * lisp/eshell/esh-mode.el (eshell/clear): Fix error, and improve handling for using as an interactive Emacs command. * test/lisp/eshell/esh-mode-tests.el (esh-mode-test/clear/eshell-command, esh-mode-test/clear/emacs-command): New tests. --- lisp/eshell/esh-mode.el | 7 +++++-- test/lisp/eshell/esh-mode-tests.el | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 34ce82cfbc4..78e43e84173 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -869,8 +869,11 @@ eshell/clear (if scrollback (eshell/clear-scrollback) (let ((eshell-input-filter-functions nil)) - (insert (make-string (window-size) ?\n)) - (eshell-send-input)))) + (eshell-interactive-print (make-string (window-size) ?\n)) + (when (and (null eshell-current-handles) + (eshell-using-module 'eshell-prompt)) + (declare-function eshell-emit-prompt "em-prompt" ()) + (eshell-emit-prompt))))) (defun eshell/clear-scrollback () "Clear the scrollback content of the eshell window." diff --git a/test/lisp/eshell/esh-mode-tests.el b/test/lisp/eshell/esh-mode-tests.el index 306e11ce445..896931c47f6 100644 --- a/test/lisp/eshell/esh-mode-tests.el +++ b/test/lisp/eshell/esh-mode-tests.el @@ -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,25 @@ esh-mode-test/handle-control-codes/backspace (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/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)))))) + ;; esh-mode-tests.el ends here -- 2.25.1