Skip to content

Instantly share code, notes, and snippets.

@alexandru
Last active May 14, 2017 22:41
Show Gist options
  • Select an option

  • Save alexandru/9cfe4bf1db629b7a7065146fdeb0e12e to your computer and use it in GitHub Desktop.

Select an option

Save alexandru/9cfe4bf1db629b7a7065146fdeb0e12e to your computer and use it in GitHub Desktop.
Getting emacsclient to work with https://emacsformacosx.com

Getting emacsclient to work on MacOS

  1. Download Emacs from https://emacsformacosx.com or use your favorite distribution, but then make sure to have an EMACSCLIENT path exported
  2. Create ~/bin/emacsclient
  3. Create ~/bin/edit
  4. Make sure ~/bin is on your PATH and has precedence over /usr/bin (otherwise the default MacOS emacsclient will be visible, which you should avoid)
  5. Edit your emacs.el
#!/bin/bash
exec emacsclient -c -n $@
(load "server")
(unless (server-running-p) (server-start))
#!/bin/bash
path="${EMACSCLIENT:-/Applications/Emacs.app/Contents/MacOS/bin/emacsclient}"
if [ ! -f "$(which lsof)" ]; then
osascript -e 'tell application "System Events" to display dialog "Make sure you have `lsof` installed on your system." buttons "OK" default button 1 with title "Unable to locate system utility"' >/dev/null 2>&1 &
exit 1
fi
if [ ! -f "$path" ]; then
osascript -e 'tell application "System Events" to display dialog "Make sure you have Emacs for Mac installed on your system, go to emacsformacosx.com" buttons "OK" default button 1 with title "Unable to locate Emacs"' >/dev/null 2>&1 &
exit 2
fi
socket_file=$(lsof -c Emacs | grep server | tr -s " " | cut -d' ' -f8)
if [[ $socket_file == "" ]]; then
exec "$path" --alternate-editor="" $@
else
exec "$path" -s $socket_file $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment