Skip to content

Commit cd81598

Browse files
committed
Add display function
1 parent 288dc02 commit cd81598

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

multi-shell.el

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
;;; Code:
3434

3535
(require 'cl-lib)
36+
(require 'comint)
3637
(require 'shell)
3738
(require 'eshell)
3839

@@ -48,20 +49,26 @@
4849
(const :tag "eshell" eshell))
4950
:group 'multi-shell)
5051

52+
(defcustom multi-shell-display-function #'switch-to-buffer
53+
"Function to display shell buffer."
54+
:type 'function
55+
:group 'multi-shell)
56+
5157
(defvar multi-shell--current-shell-id 0
5258
"Record the shell id.")
5359

54-
(defvar multi-shell--live-shells '()
60+
(defvar multi-shell--live-shells nil
5561
"Record of list of shell that are still alive.")
5662

5763
(defvar multi-shell--prevent-nested-kill nil
5864
"Flag to prevent nested kill buffer command.")
5965

6066
(defun multi-shell--run-shell-procss-by-type ()
6167
"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)))))
6572

6673
(defun multi-shell--form-name (base)
6774
"Form the shell name by BASE."
@@ -89,21 +96,21 @@
8996
(defun multi-shell--get-current-shell-index-by-id (&optional id)
9097
"Return the current shell index by ID."
9198
(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))
94101
(let ((index 0) (break nil) (sp nil) (fn-index -1))
95102
(while (and (< index (length multi-shell--live-shells))
96103
(not break))
97104
(setq sp (nth index multi-shell--live-shells))
98105
(when (= (car sp) id)
99-
(setq fn-index index)
100-
(setq break t))
106+
(setq fn-index index
107+
break t))
101108
(setq index (1+ index)))
102109
fn-index))
103110

104111
(defun multi-shell-select-list ()
105112
"Return the list of shell select."
106-
(let ((fn-lst '()))
113+
(let (fn-lst)
107114
(dolist (sp multi-shell--live-shells)
108115
(push (multi-shell--form-name-by-id (car sp)) fn-lst))
109116
fn-lst))
@@ -176,7 +183,7 @@
176183
(setq sp (nth (multi-shell--get-current-shell-index-by-id) multi-shell--live-shells)))
177184
(when sp
178185
(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)))
180187
(kill-buffer (cdr sp)))
181188
(setq multi-shell--live-shells (remove sp multi-shell--live-shells))
182189
(multi-shell--correct-buffer-name multi-shell--current-shell-id)))
@@ -192,7 +199,8 @@
192199
(with-current-buffer sh-name
193200
(rename-buffer name)
194201
(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)))
196204

197205
(defun multi-shell--kill-buffer (fnc &rest args)
198206
"Advice execute around `kill-buffer' function with FNC and ARGS."

0 commit comments

Comments
 (0)