(Screencast) The Best Emacs Modifier Key Setup for OS X

Here is an easy way to use both Emacs and OS X modifier keys when you are inside Emacs:

Toggle the right-option and function key to switch between using them inside Emacs and using them for OS X.

Addendum: <2016-06-08 Wed 08:22>

I used Karabiner to make ENTER send LEFT CONTROL when chorded. I used OS X to make CAPS LOCK be CONTROL. I didn’t change OPTION and COMMAND. I made this change because Emacs couldn’t ignore the key-event when it was coming from Karabiner.

Here is the code:

(help/on-osx
 (setq mac-control-modifier 'control)
 (setq mac-right-control-modifier 'left)
 (setq mac-command-modifier 'meta)
 (setq mac-right-command-modifier 'left)
 (setq mac-option-modifier 'super)
 (setq mac-right-option-modifier 'left)
 (setq mac-function-modifier 'hyper)
 (defun help/toggle-mac-right-option-modifier ()
   "Toggle between passing option modifier either to Emacs or OS X."
   (interactive)
   (let ((old-ropt mac-right-option-modifier))
     (setq mac-right-option-modifier
           (if (eq mac-right-option-modifier 'left)
               'none
             'left))
     (message "Toggled `mac-right-option-modifier' from %s to %s."
              old-ropt
              mac-right-option-modifier)))
 (defun help/toggle-mac-function-modifier ()
   "Toggle between passing function modifier either to Emacs or OS X."
   (interactive)
   (let ((old-func mac-function-modifier))
     (setq mac-function-modifier
           (if (eq mac-function-modifier 'hyper)
               'none
             'hyper))
     (message "Toggled `mac-function-modifier' from %s to %s."
              old-func
              mac-function-modifier))))

4 thoughts on “(Screencast) The Best Emacs Modifier Key Setup for OS X”

  1. Interesting approach. I’ve just moved to OSX for my personal laptop and struggled with M-x until swapping command and option keys in the operating system setup. Also I’ve yet to use hydra but that’s on my list. In the video, what do you use to provide completions in the minibuffer – it doesn’t look like helm or ido. Icicles?
    Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *