From 7f4783ae3b09ec670586adee8bdffd925f550cd9 Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Thu, 23 Jul 2020 19:35:49 -0400 Subject: [shell] Close the buffer upon quitting with C-d. --- lisp/shell.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lisp') diff --git a/lisp/shell.el b/lisp/shell.el index 3d58519..0449be2 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -171,3 +171,20 @@ (bind-key "C-c C-s" 'comint-history-isearch shell-mode-map) (bind-key "C-c C-r" 'comint-history-isearch-backward shell-mode-map) + +;; Close the buffer upon quitting with C-d. + +(defun shell-kill-buffer-on-quit (process event) + "Called when the shell process is stopped. + +Kills the buffer when the shell program quits." + (comint-write-input-ring) + (let ((buf (process-buffer process))) + (when (buffer-live-p buf) + (with-current-buffer buf (kill-buffer))))) + +(defun add-shell-sentinel (&rest args) + (set-process-sentinel (get-buffer-process (current-buffer)) + #'shell-test-sentinel)) + +(add-hook 'shell-mode-hook #'add-shell-sentinel) -- cgit v1.3