Multiple Emacs Shells

Sometimes instead of running several sessions of SSH’s or putty’s, I run Emacs with multiple shells– this cuts down on the number of windows I have to deal with.

To run a shell in Emacs, you invoke the Lisp function “shell” via meta-x shell. This creates a buffer called *shell*. Running it the second time though doesn’t create a 2nd shell buffer as you might expect, instead it brings you back to the original shell buffer. The trick is to rename the original buffer to avoid name collision. The quickest way to do this is via “rename-uniquely" function via meta-x rename-uniquely. It renames the buffer to a similar but unique name like "*shell*<2>“. Now if you start another shell.

The better behavior is for Emacs to automatically create new buffer with unique name. Perhaps there’s a hook to configure this that somebody can point me to.

5 comments so far

You should check out screen util http://www.bangmoney.org/presentations/screen.html

ML
July 22nd, 2008 at 9:47 am

I installed a package “fshell” to solve the same need of renaming a shell. It allows you to use the universal argument (ie “C-u 2″ “M-x fshell”, will create a shell(2))
It’s slightly faster in my opinion, I’m always trying to speed things up in emacs, cause I work with a ssh-tunneled emacs and the latency is a limiting factor.

regards.

ignacio
August 14th, 2008 at 7:56 am

Thanks guys, I’ll check out both fshell & screen.

rex
August 14th, 2008 at 9:10 am

hey Rex,
on how to speed up the opening of extra shells using fshell, I just came out with this simple lisp for my .emacs:

(defalias ‘forth
(read-kbd-macro “C-4 M-x fshell RET”))
(global-set-key [C-f4] ‘forth)

(defalias ‘fifth
(read-kbd-macro “C-5 M-x fshell RET”))
(global-set-key [C-f5] ‘fifth)

… and so on

For me it’s easier to use the direct shortcut “C-f4″ than to input the argument 4 (C-u 4) and then type M-x fshell

Just wanted to share that little tip!

ignacio
August 23rd, 2008 at 4:34 pm

Thanks Ignacio, I’ll definitely give fshell a gander!

rex
September 2nd, 2008 at 3:42 pm

Leave a Comment

Name (required)

Mail (will not be published) (required)

Website

Comment