A minimal config for Emacs on macOS

This is a somewhat opinionated minimal set of customisations for Emacs when running on macOS that give me a good baseline quality of experience.

Keys

My expectation from a lifetime of keyboards is that the modifier keys are Ctrl, Alt and Meta, in that order, to the left of the spacebar, and Meta, Alt and Ctrl to the right of the spacebar. This means that on a macOS keyboard I need to map Cmd to Meta and Option to Alt.

The only problem is that macOS already uses Option for symbol entry so I want to leave Left Option unchanged and only bind Right Option to Alt.

I've also gradually discovered that Super is often useful in Emacs so I have chosen to bind Right Cmd to Super.

(setopt mac-command-modifier 'meta)
(setopt mac-right-command-modifier 'super)
(setopt mac-option-modifier nil)
(setopt mac-right-option-modifier 'alt)

I have grown used to the macOS keysfor hiding an app with Cmd-h and for window cycling with Cmd-`. Unfortunately Emacs has existing bindings for these keys that prevent this, so I need to set them back to the desired behaviour.

(keymap-set global-map "M-h" 'ns-do-hide-emacs)
(keymap-set global-map "M-`" 'other-frame)

Appearance

Visual appearance is probably the most subjective thing about any configuration. Here I am focused on the basics — a dark theme, provided by tango-dark, with uncluttered UI and maximised editor real-estate.

In my Emacs lifetime, the tool bar is something I have never used and don't give screen space to. The same goes for the scroll bar. The fringe, on the other hand, is genuinely useful and I like to have the left fringe enabled.

(setopt custom-enabled-themes '(tango-dark))
(setopt default-frame-alist '((width . 120) (height . 98) (top . 25)))
(setopt scroll-bar-mode nil)
(setopt tool-bar-mode nil)
(setopt fringe-mode '(nil . 0))
(setopt inhibit-startup-screen t)

With optional clutter removed, my iMac can show a frame that is 120 columns by 98 rows, taking up almost exactly a vertical third of the screen. This lets me have three equally sized frames visible.

three-frames.png
A screen capture of macOS with three equal-sized Emacs frames filling the display.

Modes that improve UX

There are some global minor modes that switch on valuable functionality throughout Emacs.

(column-number-mode t)
(which-key-mode t)
(pixel-scroll-precision-mode t)
(setopt mode-line-collapse-minor-modes t)
  • column-number-mode extends adds the cursor column to the modeline after the cursor line number.
  • which-key-mode displays key bindings that can follow the current partial command. For example, typing C-x 8 will reveal the keys for inserting special characters.
  • pixel-scroll-precision-mode enables smooth scrolling of buffers that contain inline images, instead of treating the whole image as a single scroll line.
ctrl-x-8-keys.png
A screen capture of the Emacs minibuffer displaying all of the C-x 8 key bindings.

Minor modes usually get displayed on the modeline so it's great to be able to hide them and save modeline real-estate for more valuable information. mode-line-collapse-minor-modes is a brand new option that does exactly this.