Command to clear shell while using emacs shell

前端 未结 6 1070
梦毁少年i
梦毁少年i 2020-12-23 18:52

Is there a builtin command to clear shell while using shell in emacs?

If not, is there an elisp function to achieve the same?

6条回答
  •  无人及你
    2020-12-23 19:25

    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.

提交回复
热议问题