My preferred installation on MacOS:
brew cask install emacs
This installs:
App '/Applications/Emacs.app'.
Binary '/usr/local/bin/emacs'.
Binary '/usr/local/bin/ebrowse'.
Binary '/usr/local/bin/emacsclient'.
Binary '/usr/local/bin/etags'.
GOTCHA: make sure these are on the system path and have priority over the system's Emacs.
Create ~/Library/LaunchAgents/my.emacs.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>my.Emacs</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Emacs.app/Contents/MacOS/emacs</string>
<string>--fg-daemon</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The service can then be loaded via:
launchctl load -w ~/Library/LaunchAgents/my.emacs.plist
Or unloaded via:
launchctl unload -w ~/Library/LaunchAgents/my.emacs.plist
Placed in ~/bin/run-emacsclient
:
#!/usr/bin/env bash
cd ~
if [ -z "$EMACSCLIENT_OPTS" ]; then
EMACSCLIENT_OPTS="-nc -a ''"
fi
if [ $# -eq 0 ]; then
COMMAND='/usr/local/bin/emacsclient '$EMACSCLIENT_OPTS' -e "(if (display-graphic-p) (x-focus-frame nil))"'
else
COMMAND='/usr/local/bin/emacsclient '$EMACSCLIENT_OPTS' "$@"'
fi
if [ -z "$(shopt | grep login_shell)" ]; then
echo "$COMMAND" | exec bash --login -s "$@"
else
eval "exec $COMMAND"
fi
# Default editor
export EDITOR="run-emacsclient -t -a '/usr/local/bin/emacs -nw'"
export VISUAL="$EDITOR"
export ALTERNATE_EDITOR="vim"
# Editor aliases
alias e="EMACSCLIENT_OPTS='-t -a '\''/usr/local/bin/emacs -nw'\''' run-emacsclient"
alias ew="run-emacsclient"
alias notes='run-emacsclient -e "(if (display-graphic-p) (x-focus-frame nil))" -e "(deft)" | grep -v nil'