MacOSX 10.11.5 emacs version 24.5.1 brew 0.9.9
I want to have the following behavior in my emacs setup:
- At login, automatically start an emacs server process.
- Running the
/Application/Emacs.appexecutable opens a frame to a running emacs server. If the server is not running, then run it and try again (i.e.
emacsclient -a ''&).
- When executed from the command-line, have this behavior but use the current terminal instance to host the emacs session (i.e.
emacsclient -nw -a ''&).
There are several pages that cover this information, albeit incompletely:
- How can I run Emacs 24.x app on Mac OS X in daemon mode
What I've Tried
- I was able to accomplish (1) by installing the homebrew launch-agent. See
brew info emacsfor more detail.
- Once (1) is running, it was easy enough to get (3) working.
- The problem with the above links was that the my version of
homebrew(0.9.9) doesn't have
emacsclientin a subdirectory of the app bundle. That's not too big of a deal, I was able to locate the correct binary at
/usr/local/Cellar/emacs/24.5/bin/emacsclientand modify the scripts appropriately.
I created an AppleScript app to replace the standard link to the
/Applications. The AppleScript has the following code
tell application "Terminal" try do shell script "/usr/local/bin/emacsclient -c -n -a ''&" tell application "Emacs" to activate on error do shell script "/usr/local/bin/emacsclient -c -n -a ''&" end try end tell
There are two problems here:
tryblock doesn't do anything; it doesn't error out (i.e. throw an exception).
- Even though the shell script command works on the command-line, running it from AppleScript doesn't respawn the server process.
My main problem is the sometimes I accidentally kill the server process. Trying to activate the
Emacs.app GUI frame doesn't work until I manually go to the command line and run
emacsclient -a ''&. At that point I am able to use Emacs from the GUI.
Using the vanilla emacs provided by homebrew, how do I setup a system where activating
Emacs.app restarts the server if it's been terminated? I suspect it has something to do with the way AppleScript sets up its environment to call