Wednesday, September 26, 2018

Emacs on Mac

Until recently, I have been an Aquamacs user on the Mac. However, recently I have been switching back to a more standard Emacs distribution for Mac. After some time of research I ended up with the Emacs Mac Port. This distribution is easily installed and updated through Homebrew, and since I am already using Homebrew for other important software on my Mac (including bsdmake), this was an obvious choice. I use Homebrew to install the Emacs Mac Port from railwaycat with these commands:

  brew tap railwaycat/emacsmacport
  brew install emacs-mac

Later, when I want to update to the latest release, I just do this:

  brew update emacs-mac

Optionally, you can also create a soft-link in the Application directory to be able to access Emacs from there:

  ln -s /usr/local/opt/emacs-mac/Emacs.app /Applications

Tips to run Emacs from command line prompt can be found here.

Since I want to have a more Mac feel to my Emacs on the Mac (used Aquamacs to long, I guess), the final configuration I suggest is to add support for typical Mac key bindings. I use a modified version of this mac-port-keys.el. My remapping of modifiers is changed to the following (use the function modifier key for meta since I need option modifier key for different key modifiers, including typing the Norwegian letters æ, ø and å):

  (when (symbolp 'mac-control-modifier)
  ;; Re-map modifiers
  (setq mac-control-modifier 'control
        ;mac-option-modifier 'meta      ; (AA)
        mac-function-modifier 'meta     ; (AA)
        mac-command-modifier 'super)
  )

On my iMac keyboard, I do not have the function modifier key on a proper location, so I use Karabiner-Elements to map the unused Caps Lock key to the function modifier (the fn-key). I actually do this on all my Macs, since I never use Caps Locks and the meta key is used a lot in Emacs.

And I use Cua-Mode (but I disable the overriding of standard Emacs bindings):

  ;; Cua-mode (AA)
  (cua-mode t)
  (setq cua-enable-cua-keys nil)          ; C-v and M-v to scroll!