从EmacsWiki,这个Elisp函数适合我:
(defun clear-shell ()
(interactive)
(let ((old-max comint-buffer-maximum-size))
(setq comint-buffer-maximum-size 0)
(comint-truncate-buffer)
(setq comint-buffer-maximum-size old-max)))
Run Code Online (Sandbox Code Playgroud)
把它放在你的~/.emacs.d/init.el执行中M-x clear-shell,或者将它绑定到你的键中init.el,例如:
(global-set-key (kbd "\C-x c") 'clear-shell)