Emacs on MacOS Catalina 10.15 in 2̶0̶1̶9̶ 2020

Enjoy the power of Emacs on those fruit-branded computers

Simon Holzman
6 min readNov 2, 2019
Photo by me. Nothing to do with Catalina, Emacs, or Apple: it’s made by design, like they do.

I have always been an Emacs lover for the sake of simplicity. With MacOS Catalina update, it is a headache as usual to getting Emacs to work seamlessly with the terminal or iTerm2, or the Finder. One can be a GTD-nerd, a writer of any kind, or just working with plain text files, and loads of information; everyone deserves the right to use free software, even if Emacs is not embed with the last version of MacOS Catalina.

If you haven’t installed Emacs yet, I would recommend you to do it right now thru your favorite shell.

brew cask install emacs

I won’t demonstrate why Emacs is awesome. It goes without speaking. You can download it from emacsformacosx.com as well if you are more comfortable with GUI package installers.

Emacs can be invoked from the command line (emacs) and the Finder (/Applications/Emacs.app). Do not forget to fix its permissions in the panel System Preferences > Security and Privacy > Privacy or Emacs won’t be able to access your hard drive.

Enable ruby as well located in /usr/bin/ruby. After hitting the + button, press ⌘-⇧-G to open /usr/bin . Ruby is hiding in there.

For a nice user experience (aka UX) on MacOS, I can’t stress enough to install Castlemacs. It is lightweight. MacOS keybindings are nicely integrated with Emacs’. I can use the ⌘ key for Command and Super. All of my mac and emacs keybindings are working together like a charm. None is missing.

Note: On the first run, dired gives me an error ls does not support --dired; see `dired-use-ls-dired' for more details. Insert (setq dired-use-ls-dired nil) into your custom.el file.

The problem

Buggy behavior: Emacs starts a new instance (and process) every time I am trying to open a doc either from the command line or the Finder. I don’t really care about that… I am more cringing about the time it is taking to boot on my shiny 2017 Macbook Pro, like… 5 seconds? Way too long for me. Textmate opens instantly (Finder or CLI). So I have this piece of code from the 60’s which is Emacs, flavored with a lightweight layer on top, taking a $4K Macintosh laptop five long seconds at startup? I can’t live with it, can’t sleep with it. It is pinching a painful nerve of injustice: am I going to pour my money into subscription software to manage my tasks, my calendar, my projects, my journals, my bills, my reports… my life? Not today.

I want Emacs to boot in a blitz on MacOS Catalina so do I need a daemon? brew services start emacs is broken. emacs --daemon command does not seem to help. Google is my friend, like Stackoverflow, though I could not find any cure for my pain.

The solution

I am mainly using the CLI on iTerm2. I don’t really need an .app file to double click on, or to spotlight. I am blessed to have a smart son able to speak bash fluently. He wrote me a beautiful piece of shell that does the job, all credits to him. The poetry has been commented for you to understand the true meaning of it. We want to start a server, if it is not already started. Then open our document in a new buffer.

To use your script everywhere on your CLI, you will need to add it to your bin folder. I would recommend you to store your home-made or internet-from executables into a separate bin folder, like I did. Create a bin folder in your Users/username/ home folder. Add it to your PATH in your .zshrc or .profile or .bash or .whatever. Here is the line from my .zshrc file as an example:

export PATH=”/usr/local/sbin:/Users/simon/bin:$PATH”

Create a new file with the code below. Save it to you bin folder. Let’s call the file em .

#!/bin/bash
# Note: X windows are referred as frames, since for emacs a window is a split of a frame. This script is called em.
# The help part.
# If I type in help, or -h... I get something at least.
if [ “$1” == “help” ] || [ “$1” == “ — help” ] || [ “$1” == “-h” ]; then
echo “A dumb script to deal with Emacs Client Frame”
echo “Open a file in the existing frame or create a frame if none”
echo “If multiple frames are open, the file will be opened in the last focused frame”
echo “”
echo “usage: em <name of file> [w]”
echo “ — \”w\” forces the creation of a frame even if there is already one”
exit
fi
# Now the meat part.# We use the command emacsclient. Get the state of the emacsclient, ‘nil’ if no frame is opened and ‘t’ if a is frame is opened
state=”$(emacsclient -qn -e “(if (> (length (frame-list)) 1) ‘t)”)”
# If the server is off OR if there is no frame already opened OR if we explicitly ask for a frame using the suffix “w”
if [ “$state” == “” ] || [ “$state” == “nil” ] || [ “$2” == “w” ] ; then
# Create a frame and open the file within it
emacsclient -a ‘’ -cqn $1
else
# Open the file in the existing frame
emacsclient -qn $1
fi

Don’t forget to chmod +x em to make it executable.

From the command line type in em yourfile and add thew suffix (without any dash) to open a new frame (X Window). The files you will open/create in your term from that on will show up as a new buffer in the last focused frame (X Window). Thus you have absolute control over frame opening without hassle.

Just remember that …

  • C-x C-c kills the frame. The server remains active in the background.
  • ⌘-Q kills the server. Useful if you need to test a config.

Hope you are enjoying blazing fast Emacs take-offs. There must be the possibility of building an .app executable from the script. I am adding it to my list. I haven’t found any clean and simple option yet. Should you have the answer, I would be glad to hear from you.

[EDIT Jan. 7, 2020] Heads up!

The solution proposed in this article solved my cask-installed emacs.app wacky behavior. Thank you Chris Farber for your post.

[EDIT Jan. 16, 2020] Finally it works like before

I ended up building Emacs 28.0 by myself from source. Just do a quick

git clone -b master git://git.sv.gnu.org/emacs.git

Enter the emacs directory and run make install. Emacs.app will be in ./nextstep/. Move it to /Applications/.

My bash config file has an alias to call it, as before

alias emacs=”open /Applications/Emacs.app $1"

I can enjoy it now from the Finder as well as the CLI. Neat. Moving to 2020 was tougher than it thought, interesting still. Currently getting a

Package cl is deprecated

warning on startup. Can’t get rid of it. Okay, it’s no big deal. I’ll investigate later, and will report in another post. Startup time is now 2.3 s, which is acceptable, even if I quit & restart only once in a while. Keep your Emacs source folder at hand and do a git pull from your term when you feel like checking for update.

— END

--

--