Install Emacs on Mac using homebrew

Emacs is one of my favorites editors, but is more simple to install it on other systems like GNU/Linux, here are the step to install Emacs and how to create the Mac OS X client.

Install Emacs with homebrew:

brew install emacs --srgb --with-cocoa --with-d-bus --with-imagemagick

This command is to start the Emacs daemon in every session:

ln -sfv /usr/local/opt/emacs/*.plist ~/Library/LaunchAgents

The command below is for start the daemon without restart:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.emacs.plist

Client

To create the client we need insert the code bellow on Script Editor and save it as Emacs Client.app:

set emacs_path to "/usr/local/Cellar/emacs/24.5/Emacs.app/Contents/MacOS/"
set emacs_client_path to "/usr/local/bin/"

try
	-- we look for <= 2 because Emacs --daemon seems to always have an entry in visibile-frame-list even if there isn't
	set frameVisible to do shell script emacs_client_path & "emacsclient -e '(<= 2 (length (visible-frame-list)))'"
	if frameVisible is not "t" then
		-- there is a not a visible frame, launch one
		do shell script emacs_client_path & "emacsclient -c -n"
	end if
on error
	-- daemon is not running, start the daemon and open a frame
	do shell script emacs_path & "Emacs -nw --daemon"
	do shell script emacs_client_path & "emacsclient -c -n"
end try

-- bring the visible frame to the front
tell application "Emacs" to activate

Save the file in one of these directories:
/Applications, /Users/$USER/Applications

Comments: