|
1 | | -;;; multi-shell.el --- Managing multiple shell buffers. -*- lexical-binding: t; -*- |
| 1 | +;;; multi-shell.el --- Managing multiple shell buffers -*- lexical-binding: t; -*- |
2 | 2 |
|
3 | 3 | ;; Copyright (C) 2019 Shen, Jen-Chieh |
4 | 4 | ;; Created date 2019-10-28 16:46:14 |
|
7 | 7 | ;; Description: Managing multiple shell buffers. |
8 | 8 | ;; Keyword: multiple shell terminal |
9 | 9 | ;; Version: 0.0.1 |
10 | | -;; Package-Requires: ((emacs "24.3")) |
| 10 | +;; Package-Requires: ((emacs "24.4")) |
11 | 11 | ;; URL: https://github.com/jcs090218/multi-shell |
12 | 12 |
|
13 | 13 | ;; This file is NOT part of GNU Emacs. |
|
56 | 56 | (defvar multi-shell--live-shells '() |
57 | 57 | "Record of list of shell that are still alive.") |
58 | 58 |
|
| 59 | +(defvar multi-shell--prevent-nested-kill nil |
| 60 | + "Flag to prevent nested kill buffer command.") |
| 61 | + |
59 | 62 |
|
60 | 63 | (defun multi-shell--run-shell-procss-by-type () |
61 | 64 | "Run the shell process by current type." |
|
175 | 178 | (unless sp |
176 | 179 | (setq sp (nth (multi-shell--get-current-shell-index-by-id) multi-shell--live-shells))) |
177 | 180 | (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))) |
181 | 184 | (setq multi-shell--live-shells (remove sp multi-shell--live-shells)) |
182 | 185 | (multi-shell--correct-buffer-name multi-shell--current-shell-id))) |
183 | 186 |
|
|
195 | 198 | (push (cons id (current-buffer)) multi-shell--live-shells)))) |
196 | 199 |
|
197 | 200 |
|
| 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 | + |
198 | 211 | (provide 'multi-shell) |
199 | 212 | ;;; multi-shell.el ends here |
0 commit comments