Is there a builtin command to clear shell while using shell in emacs?
If not, is there an elisp function to achieve the same?
Most of the solutions proposed here will not work in EShell mode!
EShell mode buffer is read only, so kill and erase commands will not work.
To use your ordinary Ctrl-L to clear eshell terminal, add this to your .init file:
(defun eshell-clear-buffer ()
"Clear terminal"
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)
(eshell-send-input)))
(add-hook 'eshell-mode-hook
'(lambda()
(local-set-key (kbd "C-l") 'eshell-clear-buffer)))
Note: To better emulate the standard Ctrl-L, after clearing the buffer, the command will restore the initial prompt.