Subject: Re: bug#55426: [PATCH] Add option to kill a shell buffer when the process ends

From: Eli Zaretskii <[email-masked]>
Date: Sun, 15 May 2022 11:30:17 +0300

> From: Philip Kaludercic <[email-masked]>
> Date: Sun, 15 May 2022 08:13:49 +0000
> 
> The below patch adds an option that has a *shell* buffer automatically
> killed when a shell process terminates.  I find this useful, because it
> helps to avoid re-activating old shell buffers in the wrong
> `default-directory'.

Thanks, a few comments below.

> +(defcustom shell-kill-buffer-on-quit t

I think a better name is shell-kill-shell-buffer-on-exit.

> +  "Kill shell buffer after the process terminates."

"Kill the shell buffer when the shell process terminates."

> +  (when shell-kill-buffer-on-quit
> +    (let* ((buffer (current-buffer))
> +           (sentinel (process-sentinel (get-buffer-process buffer))))
> +      (set-process-sentinel
> +       (get-buffer-process (current-buffer))
> +       (lambda (proc event)
> +         (unless (buffer-live-p proc)
> +           (kill-buffer buffer))
> +         (when sentinel
> +           (funcall sentinel proc event))))))

Shouldn't we call the previous sentinel before killing the buffer?
That sentinel could not be prepared to the buffer being dead.

Also, can you modify the code to call get-buffer-process only once?

> If this patch is merged, perhaps something similar for term could be
> done too?

I'm not sure, but I don't use term frequently enough for my opinion to
matter.