2009-01-10

Creating multiple shells in Emacs

Sometimes you want to have more than one shell going in Emacs. If you have tried that you know it does not work like you would have expected - you end up in the current shell buffer instead of getting a new one. So I created this small hack:


(defun new-shell (name)
"Start a shell with name NAME, or a generated name if empty.
Returns the name of the new shell."
(interactive "sName: ")
(let ((shell-name
(if (not (string= "" name))
(concat "*shell*<" name ">")
(generate-new-buffer-name "*shell*"))))
(shell shell-name)
shell-name))


It prompts for a name for a new shell buffer. If none is given it will generate one for you. Naming shell buffers can be useful when you are doing a certain kind of work in a certain buffer and want to switch to that buffer easily using parts of the name.

Enjoy!
Post a Comment