7

I want to run the Emacs.app in daemon mode on Mac OS X. I can run emacs in daemon mode via the terminal, but instructions for running the app in a client-server pattern do not work (e.g.: http://overtone.github.io/emacs-live/doc-starting.html, yet /Applications/Emacs.app/Contents/MacOS/bin/emacsclient does not exist) with the latest versions of Emacs.

How can I run Emacs 24.x app on Mac OS X in daemon mode?

My goals are to start the server on start up (which I know how to do), and, when I launch a client, to launch a new frame in the app version of Emacs which is already running.

pwalsh
  • 245
  • 2
  • 6

2 Answers2

1

I've also run into issues trying to run Emacs as a daemon in OS X, so I wrote a "pseudo-daemon" mode that just creates a new hidden GUI frame when you close the last frame. The result is that Emacs just hides in the dock whenever it would normally exit, which provides a surprisingly good approximation of daemon mode while keeping the Dock icon functional. You can get it from MELPA: https://melpa.org/#/mac-pseudo-daemon

Ryan C. Thompson
  • 435
  • 2
  • 10
1

I used https://korewanetadesu.com/emacs-on-os-x.html and it worked fine, but recently I've installed Emacs via 'brew' and it works much better (less hassle and better daemon experience) for the daemon part: http://www.emacswiki.org/emacs/EmacsForMacOS#toc16

Once you install it, it says that get emacs to load on startup, execute:

$ ln -sfv /usr/local/opt/emacs/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.emacs.plist
Galder Zamarreño
  • 1,527
  • 2
  • 12
  • 21
  • I use the homebrew version too. Your answer helps with starting the app in daemon mode, but when I connect with a client, e.g: `emacsclient -c` it creates a new 'instance' of the app in the dock, rather than launching a new window or frame in my current emacs instance. Is that consistent with the behaviour you have? – pwalsh Feb 12 '15 at 15:09
  • I never use `emacsclient`. I launch `emacs` directly and runs fast enough for me. I dunno much about this, but I suspect that those two operations I mentioned above speed up `emacs` loading. When using the "korewanetadesu" suggestions, I found that when I was using `emacsserver`, which created a instance of the app in the doc, it used to hang sometimes. – Galder Zamarreño Feb 13 '15 at 08:58
  • That's great, but the question is clearly about connecting to the app in daemon mode when launching a client. – pwalsh Feb 13 '15 at 19:49
  • There is a package in melpa called osx-pseudo-daemon which might be worth looking at. – Tim X Feb 14 '15 at 08:18
  • @pwalsh To run emacs in daemon mode, the `launchctrl` command above will start an emacs process for you. So to make a new frame you would do: `emacsclient -n -c` The emacs icon will appear in the dock, it will stay in the dock until the process started by launchctrl (emacs -daemon) exits, or is killed. You can also use `emacsclient -t` in a terminal. Both commands connect to the emacs daemon instance if the instance is not running, the commands will throw an error. – xmonk Apr 22 '15 at 11:51
  • @pwalsh One other point make sure you're using `/usr/local/bin/emacsclient` and not `/usr/bin/emacsclient` which is the emacs22 version that comes with OS X. – xmonk Apr 22 '15 at 11:52
  • @xmonk yes you are right, thanks. My question was wrong, in that, being new to emacs, I got confused between buffers and frames. I see that theses instructions do work for frames, as I asked. I'll accept the answer. What I actually want is a new buffer (I'm using full screen mode and a new frame is not very useful with my current workflow of switching buffers). – pwalsh Apr 22 '15 at 12:17
  • The second command is `launchctl`, not `launchctrl`. Please fix. – Mike Apr 19 '17 at 07:31
  • Spelling mistake fixed :) – Galder Zamarreño May 05 '17 at 15:56