Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs 23 on OS X - use multiple instances or emacsclient?

I wonder if anyone has any recommendations as to setup of emacs 23 on OS X. I have been using Linux/Windows for a while and there, I would just open many instances of emacs and they were self-contained - for instance, I could have two separate files in separate frames, each with their own R, Python, and/or shell running. I think this is frowned upon(?) - but it kept the working directory for each script file separate, which I loved.

I understand there is some advantage to setting (server-start) in my .emacs file and calling 'emacsclient' rather than 'Emacs' is now the preferred way(?). I found this thread which facilitates this to occur through an Applescript: Emacs 23, OS X, multi-tty and emacsclient

But I wonder if this the only way to go about it - when I open two emacs instances on OS X it gives me the error:

** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x3803, name = 'org.gnu.Emacs.ServiceProvider'

but opens a new frame allows me to edit files. I understand that for vim on OS X there is something called 'mvim' which allows multiple instances of vim to be launched, but is there something similar for emacs? Sorry for the long-winded question - in summary, I guess these are the questions for which I would like to solicit your expertise:

(1) Is 'emacsclient' the way of the experts, and (2) if not necessarily, is there a way to get multiple instances of emacs 23 (not just frames) running on OS X?

Thanks!

like image 694
hatmatrix Avatar asked Aug 12 '09 00:08

hatmatrix


People also ask

Is Emacs available for Mac?

Emacs can be installed on MacOS using Homebrew. The Emacs for OSX website also provides universal binaries.


3 Answers

Let me answer your questions indirectly.

As you know, emacsclient provides a service, allowing users to open documents from outside Emacs in an existing Emacs. Is this "the way" of the experts? Depends on the expert. I'm a heavy user of Emacs, but never use emacsclient. Why? Because I never leave Emacs in the first place. All the shells I run are inside Emacs (using a home-brewed screen package), I read mail in Emacs, etc. There's never a reason for me to type emacsclient at a command line.

Your usage model seems to be that you prefer having multiple Emacsen running, making it easier to keep track of which processes and files are being used together. And that makes sense. You could do it all in one Emacs if you wish, but it might take some changes in your usage model, or some customizations to help manage multiple interpreters/shells/whatever to your liking.

So, if you like multiple instances of Emacs running, then by all means, continue doing so.

Regarding the second question, it appears as though having (server-start) in your .emacs is causing problems - likely because there's a conflict with two Emacsen trying to use the same port. Check out the documentation for starting the server, and perhaps remove that line from your .emacs, and instead start the server once by using the --daemon command line option.

Then, at the command line, you have the choice of whether you want to start a new emacs (by typing emacs) or connect to the server you started (by typing emacsclient).

like image 145
Trey Jackson Avatar answered Oct 14 '22 04:10

Trey Jackson


If you want multiple instances (and not frames) of emacs use the following at the terminal prompt:

/Applications/Emacs.app/Contents/MacOS/Emacs &

(Generic form for any app) /Path_To_Application.app/Contents/MacOS/Application &
like image 42
spockaroo Avatar answered Oct 14 '22 05:10

spockaroo


Here's a simple shell script that will start a separate instance, raise the Emacs window and give it focus:

#!/bin/bash

/Applications/Emacs.app/Contents/MacOS/Emacs \
    --eval '(select-frame-set-input-focus (nth 0 (frame-list)))' \
    "$@"

Notes:

  • This script makes emacs behave like the emacs on Linux that I'm used to.
  • There is probably a better way than '(nth 0 (frame-list))' to identify the frame to activate, but the above script does the right thing for me.
  • I do not have '(server-start)' in my .emacs file.
like image 4
Alex Tomlinson Avatar answered Oct 14 '22 04:10

Alex Tomlinson