[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 63eb015722: Add option to kill a shell buffer when the process en
From: |
Philip Kaludercic |
Subject: |
master 63eb015722: Add option to kill a shell buffer when the process ends |
Date: |
Fri, 20 May 2022 04:23:03 -0400 (EDT) |
branch: master
commit 63eb0157226ad02eb6aeb9a6ec285502fddc4ddf
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add option to kill a shell buffer when the process ends
* shell.el (shell-kill-buffer-on-quit): Add new option (bug#55426).
(shell): Respect 'shell-kill-buffer-on-quit'.
* NEWS: Mention 'shell-kill-buffer-on-quit'.
---
etc/NEWS | 7 +++++++
lisp/shell.el | 17 +++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 26b9b19952..2314e55164 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1616,6 +1616,13 @@ values passed as a single token, such as '-oVALUE' or
'eshell-eval-using-options' macro. See "Defining new built-in
commands" in the "(eshell) Built-ins" node of the Eshell manual.
+** Shell
+
+---
+*** New user option 'shell-kill-buffer-on-exit'.
+Enabling this will automatically kill a *shell* buffer as soon as the
+shell session terminates.
+
** Calc
+++
diff --git a/lisp/shell.el b/lisp/shell.el
index 47887433d9..4e65fccf9e 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -331,6 +331,12 @@ Useful for shells like zsh that has this feature."
:group 'shell-directories
:version "28.1")
+(defcustom shell-kill-buffer-on-exit nil
+ "Kill a shell buffer after the shell process terminates."
+ :type 'boolean
+ :group 'shell
+ :version "29.1")
+
(defvar shell-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-f" 'shell-forward-command)
@@ -818,6 +824,17 @@ Make the shell buffer the current buffer, and return it.
(with-temp-buffer
(insert-file-contents startfile)
(buffer-string)))))))
+ (when shell-kill-buffer-on-exit
+ (let* ((buffer (current-buffer))
+ (process (get-buffer-process buffer))
+ (sentinel (process-sentinel process)))
+ (set-process-sentinel
+ process
+ (lambda (proc event)
+ (when sentinel
+ (funcall sentinel proc event))
+ (unless (buffer-live-p proc)
+ (kill-buffer buffer))))))
buffer)
;;; Directory tracking
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 63eb015722: Add option to kill a shell buffer when the process ends,
Philip Kaludercic <=