Multiple Emacs instances in OSX
March 18, 2011
Here is a very simple tip that has been really useful to me over the last few months.
The way I work in Emacs is by opening lots and lots of files and then quickly selecting the buffer I want with ido-mode.
However, this breaks down if I have more than one project loaded in my Emacs session. For example, when working on Rails projects, I want to be able to find the routes.rb file with just a few keystrokes. To avoid restarting Emacs whenever I switch project, I need multiple instances running simultaneously, which is not “supported” in OSX (or rather, it’s just not the OSX way).
To workaround this, I use a really simple hack: Copying Emacs
So to create Emacs2 and Emacs3 in addition to just Emacs, do
cp -r /Applications/Emacs.app /Applications/Emacs2.app cp -r /Applications/Emacs.app /Applications/Emacs3.app
That’s it! Now you can fire up three Emacs instances at the same time. Next step will be to replace the icons of the clones to make it easier to spot them when switching applications.
[EDIT]
As discussed in the comments below, I can just start new instances with “open -n -a Emacs.app”. Thanks tali713 for bringing this to my attention!
June 9, 2011 at 7:59 pm
why not just use uniquify? (http://www.gnu.org/software/libtool/manual/emacs/Uniquify.html)
June 9, 2011 at 8:35 pm
I am, but especially in Rails projects, this breaks down pretty quickly.
Say I want to find the file index.html.haml. It could be in any of lots of view folders, and uniquify is nice for identifying the right one. But if I mix several projects, it would become pretty painful for me to pick the right view folder.
Thanks for the suggestion though.
June 9, 2011 at 10:05 pm
What’s wrong with the standard command from terminal: “open -a -n ” you could even write a short applescript program to automate the task. Simple, built in, no wasted duplications.
June 9, 2011 at 10:18 pm
Brilliant! Nothing is wrong with using open, I just hadn’t noticed the “-n” switch, so thanks for pointing that out
As you suggest, I can use Applescript to automate this. In fact, it’s a one-liner in AppleScript editor:
do shell script “open -n -a Emacs.app”
After saving this script as /Applications/NewEmacs.app, I can easily launch new Emacs instances from Spotlight.
Thanks!