Emacs 中 shell 结束之后,自动关闭 shell buffer

每当我在 M-x shell 启动shell ,然后执行 exit 退出 shell 之后,buffer 并不自动关 闭,很不爽, 下面的指令,可以让其自动关闭。

(add-hook 'shell-mode-hook 'wcy-shell-mode-hook-func)
(defun wcy-shell-mode-hook-func  ()
  (set-process-sentinel (get-buffer-process (current-buffer))
                            #'wcy-shell-mode-kill-buffer-on-exit)
      )
(defun wcy-shell-mode-kill-buffer-on-exit (process state)
  (message "%s" state)
  (if (or
       (string-match "exited abnormally with code.*" state)
       (string-match "finished" state))
      (kill-buffer (current-buffer))))