8

I run emacs in two ways: One as a Mac OS X executable, built from source, and the other as a Linux executable using the Lucid toolkit, in daemon mode, connected to using a graphical emacscient using XQuartz on my mac laptop.

My base configuration is currently Emacs Prelude, and it defines a set of key chords that use a Super key, in addition to some Meta and Ctrl chords. However, I cannot figure out how to send a Super chord at all. This is true both on my OSX build and on my emacsclient/XQuartz setup. Command sends Meta, Option just sends literal keys (in the OSX way, it emits a subset of the extended Unicode space) and obviously Shift and Ctrl do their usual thing.

So, how do I send super-prefixed key chords to my Emacs?

4 Answers 4

7

You can apply a super modifier with C-x @ s. So to type Super+z, you woule press C-x @ s z. If you find the C-x @ s combo too cumbersome, then you can bind it to something easier to type. Here is an example of binding it to C-]:

;; Turn `C-]' into a sticky "super" modifier.
(define-key local-function-key-map [?\C-\]] 'event-apply-super-modifier)
;; Move the global binding for C-] to C-s-]
(define-key global-map [?\C-\s-\]] (lookup-key global-map [?\C-\]] t))
(define-key global-map [?\C-\]] nil)

Since C-] is most likely already bound to something (abort-recursive-edit by default), I also move whatever is bound to C-] in the global map to C-s-]. You can then invoke abort-recursive-edit when needed by typing C-] twice.

5

You might want to have a look at the various ns-*-modifier, like ns-alternate-modifier (for Option) or ns-command-modifier (for Command). They allow to map the native OSX keys to arbitrary modifiers. Note that there exists a ns-function-modifier which is quite handy for laptops.

That should solve the native OSX Emacs part.

As for XQuartz, without testing at all, I would assume that you might get away with some xmodmap invocation, along the line of xmodmap -e 'add Mod2 = Super_L Super_R'

1

After a bit of digging, I located this page by Xah Lee.

The cause of your problem is that your keyboard settings in OSX are not set for any key to send Super. In order to send Super, you need to change that. The document linked above has directions for doing so.

1
  • Please include a summary of what to do, as such a link may break. Oct 13, 2019 at 14:46
1

This page tells you what to do. The following is the summary of what to do:

Create Super and Hyper Keys on MacOS

;; set keys for Apple keyboard, for emacs in OS X
(setq mac-command-modifier 'meta) ; make cmd key do Meta
(setq mac-option-modifier 'super) ; make opt key do Super
(setq mac-control-modifier 'control) ; make Control key do Control
(setq ns-function-modifier 'hyper)  ; make Fn key do Hyper

Note: if you set ⌘ command or Fn key, some of their Mac function remains. For example, ⌘ command+Tab still do switch app, and Fn key can still be used as the modifier for multimedia keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.