public
Last active — forked from ambethia/Emacs.md

Setting up Emacs daemon on OS X

  • Download Gist
Emacs.md
Markdown

Setting up Emacs daemon on OS X

Tired of waiting for emacs to start on OS X? This step by step guide will teach you how to install the latest version of emacs and configure it to start in the background (daemon mode) and use emacsclient as your main editor.

Install Cocoa Emacs

Download the latest pretest version of [Emacs for Mac OS X]: http://emacsformacosx.com/builds

Drag the Emacs Application to your Applications folder

Create the daemon application

Open the AppleScript editor and paste the following:

tell application "Terminal"
do shell script "/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
end tell

Save this as an Application called "Emacs Daemon" in your Applications folder

Add as a login item

Goto System Preferences > Accounts

  • With your user name selected, click on the Login Items tab
  • Click on the plus sign
  • Browse to your applications folder and find "Emacs Daemon"
  • Don't worry about the "hide" checkbox, since it the dock icon disappears naturally

Create the client application

Open the AppleScript editor and paste the following:

tell application "Terminal"
try
set frameVisible to do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e '(<= 2 (length (visible-frame-list)))'"
if frameVisible is not "t" then
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end if
on error
do shell script "/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end try
end tell
tell application "Emacs" to activate

Save this as an Application called "Emacs Client" in your Applications folder.

Giving the client application a proper icon

Using the Finder, navigate to your Application folder and right click on your Emacs application (not the client or daemon), and click on Show Package Contents Do the same for the Emacs Client application

Copy the Emacs.icns file from Contents/Resources of the Emacs application to the Contents/Resources of the Emacs Client application Delete applet.icns and rename Emacs.icns to applet.icns in the Emacs Client application.

This is great! There's only one thing I haven't been able to solve so far. When the Emacs daemon starts running it doesn't show up on the dock (which is good). But after I run Emacs Client for the first time, even when I close the last window (or frame) the Emacs icon still shows up on the dock.

Do you know of any way to make the Emacs icon disappear of the dock (and most importantly, the cmd-tab menu) when no GUI client is running?

Cheers.

No, there were a couple of problems I never solved with this. That was one
of them. I also ran into a problem occasionally where things didn't get
cleaned up properly, and I had to manually kill emacs. It was something in
my emacs config that didn't agree with it.

I'm currently not using this solution, and am just manually running emacs
with a call to (server-start) in my init.el. That's been working for me.

On Wed, Mar 28, 2012 at 9:40 PM, Andr Silva <
reply@reply.github.com

wrote:

This is great! There's only one thing I haven't been able to solve so far.
When the Emacs daemon starts running it doesn't show up on the dock (which
is good). But, after the first I run Emacs Client for the first time, even
when I close the last window (or frame) the Emacs icon still shows up on
the dock.

Do you know of any way to make the Emacs icon disappear of the dock (and
most importantly, the cmd-tab menu) when no GUI client is running?

Cheers.


Reply to this email directly or view it on GitHub:
https://gist.github.com/1394910

Do you mind elaborating a bit on your alternative? I'm an emacs newbie and I didn't quite get it. Could you describe the workflow of how you start emacs and emacs clients?

I've added (server-start) to my init.el but after I close the last frame the server does not keep running in the background, the app is simply killed. Also, even if the app isn't killed and the server keeps running in the background, does the Emacs icon still persist in the dock?

On Wed, Mar 28, 2012 at 10:07 PM, Andr Silva <
reply@reply.github.com

wrote:

I've added (server-start) to my init.el but after I close the last frame
the server does not keep running in the background, the app is simply
killed. Also, even if the app isn't killed and the server keeps running in
the background, does the Emacs icon still persist in the dock?

No, this is how I use Emacs now. I just never close down emacs anymore and
keep connecting to the same running session.

Oh okay, got it ;-) Thanks for your help.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.