3. Basics I
▶ I use the string representation. link
▶ Modifiers: C control, M meta, S shift,
▶ Additional Modifiers (GUI only): A alt, s super, H hyper
▶ macOS configuration example
(when (eq system-type ’darwin)
;; Mac-only
;; http://www.emacswiki.org/emacs/MetaKeyProblems#toc15
;; http://ergoemacs.org/emacs/emacs_hyper_super_keys.html
(setq mac-command-modifier ’meta) ; left command
(setq mac-option-modifier ’alt) ; left option
(setq mac-right-command-modifier ’super) ; right command
(setq mac-right-option-modifier ’hyper)) ; right option
▶ Examples
3 / 11
4. Basics II
"C-n" ; control and n
"C-x C-f" ; control and x, then f while keeping Control down
"C-M-s" ; control, meta, and s
"s-s" ; super and s
▶ "If the binding of a key sequence is a keymap, we call the key sequence a
prefix key." link
▶ For example, C-x is a prefix that is bound to ctl-x-map. link
▶ "Otherwise, we call it a complete key." link A complete key sequence calls a
command (interactive function).
▶ "Each keymap is a list whose car is the symbol keymap. The remaining
elements of the list define the key bindings of the keymap." link A keymap
can be examined in ielm. A typical element is a pair of an ascii code (M-x
man RET ascii RET link) and command name.
4 / 11
5. Basics III
my-key-map ; =>
(keymap
(103 . my-magit-status)
(46 . highlight-symbol)
(122 . helm-for-files)
(114 . reveal-in-osx-finder)
(115 . shell)
(118 . revert-buffer)
(111 . just-one-space)
(108 . my-recenter-top)
(104 . help-command)
(97 . auto-revert-mode)
(107 . kill-this-buffer))
▶ Multiple keymaps are active. In descending order of priority, they are minor
mode keymaps, local keymaps (typically major mode keymaps), and global
keymaps. link
5 / 11
6. Basics IV
▶ To invoke alt, super, or hyper in the terminal. C-x @ can be used. For
example, C-x @ h is similar to pressing down the hyper key. link I
simplified these as follows.
(bind-key "C-c a" ’event-apply-alt-modifier function-key-map)
(bind-key "C-c s" ’event-apply-super-modifier function-key-map)
(bind-key "C-c h" ’event-apply-hyper-modifier function-key-map)
6 / 11
7. bind-key I
▶ "A simple way to manage personal keybindings" link
;; Macro Signature
(bind-key KEY-NAME COMMAND &optional KEYMAP PREDICATE)
;; Examples
(bind-key "A-k" ’kill-this-buffer)
(bind-key "k" ’kill-this-buffer my-key-map)
▶ bind-key* creates a global binding that overrides all minor mode
bindings.
▶ Unbinding is done with unbind-key.
(unbind-key "C-c x" some-other-mode-map)
▶ The bind-keys (plural) can be use to add multiple bindings to a keymap.
7 / 11
8. bind-key II
(bind-keys :map dired-mode-map
("o" . dired-omit-mode)
("a" . some-custom-dired-function))
▶ A never-shadowed personal map can be created like this.
(bind-keys* :prefix-map my-key-map
:prefix "C-c m")
▶ M-x describe-personal-keybindings shows personal bindings. I
am experiencing a funny error with my-key-map.
▶ bind-key is more typically used in the context of use-package.
8 / 11
10. which-key I
▶ "Emacs package that displays available keybindings in popup" link
▶ Waiting after a prefix key will show the contents of the corresponding
keymap.
▶ M-x which-key-show-major-mode may also be useful.
(use-package which-key
:config
(setq which-key-lighter "")
(setq which-key-idle-delay 1.0)
;; Type: minibuffer, side-window, frame, and custom.
(setq which-key-popup-type ’side-window)
(setq which-key-side-window-location ’left)
(setq which-key-side-window-max-height 0.5)
(setq which-key-side-window-max-width 0.5)
(which-key-mode 1))
10 / 11
11. free-keys I
▶ "Show free keybindings for modkeys or prefixes" link
;;; free-keys.el
;; https://github.com/Fuco1/free-keys
;; http://emacs.stackexchange.com/questions/964/show-unbound-keys
;; Use this to see what remaining keys are available.
;; Use bind-key.el describe-personal-keybindings for used keys.
(use-package free-keys
:commands (free-keys)
;;
:config
;; List of modifiers that can be used in front of keys.
(setq free-keys-modifiers ’(""
"C" "A" "M" "s" "H"
"C-M" "A-C" "C-s" "A-M")))
11 / 11