Perfect macOS Emacs workflow

I recently moved from using vim to emacs courtesy of Spacemacs. IMO, vim keybindings are awesome, and I use them everywhere, in my IDEs, my Browsers, Gmail etc. Spacemacs uses a bunch of preconfigured packages to emulate vim (for the most parts) inside emacs, and it works very well for me. The tag-line describes it very well :

The best editor is neither Emacs nor Vim, it's Emacs and Vim!

This arrangement is perfect for me, since I love the vim key-bindings and I also invested a lot of time, in learning them, and at the same time, I get all the goodies that come with Emacs, proper powerline, tramp, magit, and the best of them all, Org-Mode.

Emacs - A brief introduction!

Emacs is one of the most popular text editors. It has been around since the 1980s and it is still extremely relevant, because it has kept pace with modern software development requirements. There is a saying, that keeps going around :

Emacs, "a great operating system, lacking only a decent editor"

Read more about it here. The spacemacs community is thriving to end the editor war, once and for all :)

MacOS Problems

Installation of Emacs on MacOS can be accomplished in a variety of ways. There is a binary version available here. This has one of the best GUI rendering, but since I mostly don't use any GUI tools (like menubars etc) in Emacs, it wasn't a very compelling option for me. There is another version called Aquamacs, which is more tightly integrated into the MacOS user interface. It also comes bundled with a lot of packages that one might use, and is a good place to get started for beginners. It supports native macOS features and keybindings.

The emacs mac port has some nice features, especially for beginners. It also has slightly nicer GUI rendering, However, at least in my experience:

  • It is significantly slower on first launch for some things (opening files, magit operations, etc).
  • It occasionally starts to exhibit significant input lag and requires a restart.
  • It also seems to crash occasionally.
  • It doesn't allow tty and gui on the same server.

I have personally tested a few versions. However, running the binary version from emacsformacosx take significant time on first launch (~ 10 secs) and when the last window is closed, it kills the server. I want to use a persistent server, so that all my buffers stay in memory when I quit the editor, and all subsequent launches take very less time (<1 secs). This is a total killer for me, since I like to use editors that are snappy!

There is another version that I have used, called emacs-plus, which has significantly better graphic rendering, but it is also a little slower. To install the version run the following commands :

For Emacs Plus

$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus
$ brew linkapps emacs-plus 

For GNU Emacs

$  brew install emacs --with-cocoa --with-librsvg --with-gnutls --with-imagemagick  --with-rsvg
$ brew linkapps emacs
$ brew services start emacs

The last command starts emacs as a service while booting up! This will be useful later. The above method doesn't work with Spotlight, which I absolutely love. I had to create a launcher app, to launch Emacs. I got a shell script from the internet (can't find the source anymore) and have been editing it to work properly. The output is :

Now, to make an app out of this script, I am using another script, called appify :

Save the emacslauncher script, and then, use the appify script to make a MacOS App to launch Emacs.

Spotlight launching Emacs

So, the first launch takes a bit of time (about 13 secs), if the server is not already running :
Emacs Launch Time

However, the subsequent launches are absolutely snappy (~1 sec)! Now, I have the all the goodness of Emacs, along with the speed and keybindings of vim!

Final Launch