Emacs: How to define Super & Hyper Keys

Advertise Here

, 2005, …, 2011-06-21

This page shows you how to define SuperHyper keys in emacs. If you are not familiar with the basics of defining keys in emacs, see: Emacs: How to Define Keyboard Shortcuts.

Emacs supports extra modifier keys called Super & Hyper. You can map PC keyboard's Win key or the Menu (aka Apps) key to them, or Apple Keyboard's ⌥ Option key.

The advantage of creating the Super & Hyper in emacs is that you can have more hotkeys. For example, Super for all your personal keybinding, and Hyper for entering math symbols of your choice. (See: Math Symbols in UnicodeHow to Create a APL or Math Symbols Keyboard Layout.)

lisp-machine-keyboard-2-left
Symbolics's lisp machine keyboard PN 365407 Rev C. (Photo by Joey Devilla. Used with permission.)

For those curious, the Super & Hyper are actual keys on lisp machine keyboards. Lisp machine keyboards are popular around late 1980s and is used to develop emacs. For photos of Lisp Machine keyboards, see: Space-cadet Keyboard and Other Lisp Keyboards.

Setting up Super & Hyper

Microsoft Windows

;; setting the PC keyboard's various keys to
;; Super or Hyper, for emacs running on Windows.
(setq w32-pass-lwindow-to-system nil 
      w32-pass-rwindow-to-system nil 
      w32-pass-apps-to-system nil 
      w32-lwindow-modifier 'super ; Left Windows key 
      w32-rwindow-modifier 'super ; Right Windows key 
      w32-apps-modifier 'hyper) ; Menu key

Note: in Microsoft Windows, several keybindings with the Windows key is bound at a low level, and applications do not see them. For example, 【Win+r】 is for launching apps by command name. (See: Windows Logo Key Keyboard Shortcuts.) There's no way around that unless you use other tools such as AutoHotkey. Even so, it may not be possible to disable 【Win+l】 (lock window).

(info "(emacs) Windows Keyboard")

See also: AutoHotkey Basics.

Mac OS X

; setting Super & Hyper keys for the Mac keyboard, for emacs running in OS X
(setq mac-option-modifier 'hyper) ; sets the Option key as Hyper
(setq mac-option-modifier 'super) ; sets the Option key as Super
(setq mac-command-modifier 'meta) ; sets the Command key as Meta
(setq mac-control-modifier 'meta) ; sets the Control key as Meta

See also: How to Swap Control, Caps Lock, Option, Command Keys on OS XCreating Keyboard Layout in Mac OS X.

Linux

On Linuxes, you should define Super & Hyper key in the OS. For example, in Ubuntu 11.04, it's under 〖System▸Preferences▸keyboard〗 then “Layout” tap, “Options…” button.

Defining Super & Hyper Keyboard Shortcuts

The syntax for defining keys with the Super or Hyper modifier keys is the same as Meta and Control. Use “H” for Hyper, “s” for Super. Example:

(global-set-key (kbd "H-b") 'backward-word) ; H is for hyper
(global-set-key (kbd "s-b") 'backward-word) ; lower case “s” is for super

(global-set-key (kbd "M-H-b") 'backward-word) ; Meta+Hyper+b
(global-set-key (kbd "M-s-b") 'backward-word) ; Meta+Super+b

For more examples, see: Emacs: How to Define Keyboard Shortcuts.

Key Ghosting

Be aware that keyboard won't be able to detect certain combination of keys. This is called keyboard ghosting.

For example, on Microsoft Natural Ergonomic 4000 keyboard, the key【Menu+RShift+x】 does not register (but with left Shift it does). Vast majority of keyboards have ghosting problem. For detail, see: Keyboard Ghosting; How Many Keys Your Keyboard Can Take?.

blog comments powered by Disqus