Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I can M-x eshell to open the first eshell instance but future invocations just focus the first instance.
You can do this:
`C-u M-x eshell`
This will create *eshell*
, *eshell*<2>
, and so on.
My preferred approach is to create named shells:
(defun make-shell (name)
"Create a shell buffer named NAME."
(interactive "sName: ")
(setq name (concat "$" name))
(eshell)
(rename-buffer name))
is the gist. Then M-x make-shell name
will create the desired shell.
The docstring for eshell states that "A nonnumeric prefix arg means to create a new session." I typed M-- M-x eshell over and over, and each time it opened a new eshell buffer.
C-u M-x eshell works great, but I prefer named shells - make-shell approach, is useful when switching buffers
Invoking GNU Screen is another option for those using ansi-term
Mybe, the following solution is better. Because the eshell buffer is determined by the value of eshell-buffer-name. You need not to rename the buffer.
(defun buffer-exists (bufname)
(not (eq nil (get-buffer bufname))))
(defun make-shell (name)
"Create a shell buffer named NAME."
(interactive "sName: ")
(if (buffer-exists "*eshell*")
(setq eshell-buffer-name name)
(message "eshell doesnot exists, use the default name: *eshell*"))
(eshell))
Expanding on make-eshell, this creates an eshell appending the next counter, so it's like eshell1, eshell2, etc.:
(lexical-let ((count 1))
(defun make-eshell-next-number ()
(interactive)
(eshell)
(rename-buffer (concat "*eshell" (number-to-string count) "*"))
(setq count (1+ count))))
Here is my implementation of new eshell buffer / instance.
(defun eshell-new-buffer (args)
"Create a new eshell buffer."
(interactive "P")
(eshell "new")
)
(global-set-key (kbd "C-c e e") 'eshell)
(global-set-key (kbd "C-c e n") 'eshell-new-buffer)
© 2022 - 2024 — McMap. All rights reserved.