Skip to content

Commit 4a1502c

Browse files
committed
Fixed sync with kill buffer command.
1 parent 21a011b commit 4a1502c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

multi-shell.el

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; multi-shell.el --- Managing multiple shell buffers. -*- lexical-binding: t; -*-
1+
;;; multi-shell.el --- Managing multiple shell buffers -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2019 Shen, Jen-Chieh
44
;; Created date 2019-10-28 16:46:14
@@ -7,7 +7,7 @@
77
;; Description: Managing multiple shell buffers.
88
;; Keyword: multiple shell terminal
99
;; Version: 0.0.1
10-
;; Package-Requires: ((emacs "24.3"))
10+
;; Package-Requires: ((emacs "24.4"))
1111
;; URL: https://github.com/jcs090218/multi-shell
1212

1313
;; This file is NOT part of GNU Emacs.
@@ -56,6 +56,9 @@
5656
(defvar multi-shell--live-shells '()
5757
"Record of list of shell that are still alive.")
5858

59+
(defvar multi-shell--prevent-nested-kill nil
60+
"Flag to prevent nested kill buffer command.")
61+
5962

6063
(defun multi-shell--run-shell-procss-by-type ()
6164
"Run the shell process by current type."
@@ -175,9 +178,9 @@
175178
(unless sp
176179
(setq sp (nth (multi-shell--get-current-shell-index-by-id) multi-shell--live-shells)))
177180
(when sp
178-
(with-current-buffer (cdr sp) (erase-buffer))
179-
(kill-process (cdr sp))
180-
(kill-buffer (cdr sp))
181+
(when (buffer-name (cdr sp))
182+
(with-current-buffer (cdr sp) (erase-buffer))
183+
(kill-buffer (cdr sp)))
181184
(setq multi-shell--live-shells (remove sp multi-shell--live-shells))
182185
(multi-shell--correct-buffer-name multi-shell--current-shell-id)))
183186

@@ -195,5 +198,15 @@
195198
(push (cons id (current-buffer)) multi-shell--live-shells))))
196199

197200

201+
(defun multi-shell--kill-buffer (fnc &rest args)
202+
"Advice execute around `kill-buffer' function with FNC and ARGS."
203+
(if (and (string-match-p (multi-shell--prefix-name) (buffer-name))
204+
(not multi-shell--prevent-nested-kill))
205+
(let ((multi-shell--prevent-nested-kill t))
206+
(multi-shell-kill))
207+
(apply fnc args)))
208+
(advice-add 'kill-buffer :around #'multi-shell--kill-buffer)
209+
210+
198211
(provide 'multi-shell)
199212
;;; multi-shell.el ends here

0 commit comments

Comments
 (0)