|
33 | 33 | ;;; Code: |
34 | 34 |
|
35 | 35 | (require 'cl-lib) |
| 36 | +(require 'comint) |
36 | 37 | (require 'shell) |
37 | 38 | (require 'eshell) |
38 | 39 |
|
|
48 | 49 | (const :tag "eshell" eshell)) |
49 | 50 | :group 'multi-shell) |
50 | 51 |
|
| 52 | +(defcustom multi-shell-display-function #'switch-to-buffer |
| 53 | + "Function to display shell buffer." |
| 54 | + :type 'function |
| 55 | + :group 'multi-shell) |
| 56 | + |
51 | 57 | (defvar multi-shell--current-shell-id 0 |
52 | 58 | "Record the shell id.") |
53 | 59 |
|
54 | | -(defvar multi-shell--live-shells '() |
| 60 | +(defvar multi-shell--live-shells nil |
55 | 61 | "Record of list of shell that are still alive.") |
56 | 62 |
|
57 | 63 | (defvar multi-shell--prevent-nested-kill nil |
58 | 64 | "Flag to prevent nested kill buffer command.") |
59 | 65 |
|
60 | 66 | (defun multi-shell--run-shell-procss-by-type () |
61 | 67 | "Run the shell process by current type." |
62 | | - (cl-case multi-shell-prefer-shell-type |
63 | | - (shell (shell)) |
64 | | - (eshell (eshell)))) |
| 68 | + (save-window-excursion |
| 69 | + (cl-case multi-shell-prefer-shell-type |
| 70 | + (`shell (shell)) |
| 71 | + (`eshell (eshell))))) |
65 | 72 |
|
66 | 73 | (defun multi-shell--form-name (base) |
67 | 74 | "Form the shell name by BASE." |
|
89 | 96 | (defun multi-shell--get-current-shell-index-by-id (&optional id) |
90 | 97 | "Return the current shell index by ID." |
91 | 98 | (unless id |
92 | | - (setq multi-shell--current-shell-id (multi-shell--name-to-id (buffer-name))) |
93 | | - (setq id multi-shell--current-shell-id)) |
| 99 | + (setq multi-shell--current-shell-id (multi-shell--name-to-id (buffer-name)) |
| 100 | + id multi-shell--current-shell-id)) |
94 | 101 | (let ((index 0) (break nil) (sp nil) (fn-index -1)) |
95 | 102 | (while (and (< index (length multi-shell--live-shells)) |
96 | 103 | (not break)) |
97 | 104 | (setq sp (nth index multi-shell--live-shells)) |
98 | 105 | (when (= (car sp) id) |
99 | | - (setq fn-index index) |
100 | | - (setq break t)) |
| 106 | + (setq fn-index index |
| 107 | + break t)) |
101 | 108 | (setq index (1+ index))) |
102 | 109 | fn-index)) |
103 | 110 |
|
104 | 111 | (defun multi-shell-select-list () |
105 | 112 | "Return the list of shell select." |
106 | | - (let ((fn-lst '())) |
| 113 | + (let (fn-lst) |
107 | 114 | (dolist (sp multi-shell--live-shells) |
108 | 115 | (push (multi-shell--form-name-by-id (car sp)) fn-lst)) |
109 | 116 | fn-lst)) |
|
176 | 183 | (setq sp (nth (multi-shell--get-current-shell-index-by-id) multi-shell--live-shells))) |
177 | 184 | (when sp |
178 | 185 | (when (buffer-name (cdr sp)) |
179 | | - (with-current-buffer (cdr sp) (erase-buffer)) |
| 186 | + (with-current-buffer (cdr sp) (comint-kill-region (point-min) (point-max))) |
180 | 187 | (kill-buffer (cdr sp))) |
181 | 188 | (setq multi-shell--live-shells (remove sp multi-shell--live-shells)) |
182 | 189 | (multi-shell--correct-buffer-name multi-shell--current-shell-id))) |
|
192 | 199 | (with-current-buffer sh-name |
193 | 200 | (rename-buffer name) |
194 | 201 | (when truncate-lines (toggle-truncate-lines) (message "")) |
195 | | - (push (cons id (current-buffer)) multi-shell--live-shells)))) |
| 202 | + (push (cons id (current-buffer)) multi-shell--live-shells)) |
| 203 | + (funcall multi-shell-display-function name))) |
196 | 204 |
|
197 | 205 | (defun multi-shell--kill-buffer (fnc &rest args) |
198 | 206 | "Advice execute around `kill-buffer' function with FNC and ARGS." |
|
0 commit comments