Home About Now Archive RSS

Rethink about the prefix for my Emacs keymap

I wrote a blog post about binding <menu> as the prefix key to my own Emacs keymap and swapping CapsLock for Menu on GNU/Linux and its closest equivalent, <apps> on Windows. (I have deleted that blog post since I realised doing that was dumb, and I don't want to steer others down that path.) It worked as long as I used Emacs in its GUI on Windows 11 or Wayland. However, when I installed Guix on my laptop and was trying to figure out how to get Sway running on Guix, I naturally used Emacs in the TTY where it works just as well as in a graphical session except some limitations around showing pictures, using multiple faces and keybindings. TTYs and graphical terminals doesn't send through every key to Emacs and one of the many newer keys they don't send to Emacs is <menu>. So I was left with none of my own keybindings. It made me realise that using any special key not usable in a TTY for my own keymap is not very smart.

There is always M-x, so I could do everything I wanted to do, but without using my own keymap. The advantage of having a keymap that works everywhere is that it makes using commonly used functions a lot faster than using M-x. If the keymap isn't available everywhere, the advantage of having a keymap at all is severely limited and you have to think about in which situations it is usable and in which it isn't. Training oneself to remember the keychords through muscle memory also make little sense if it is only available some of the time.

I had a quick think about which possible prefix keys I could use that would work everywhere and in theory, every combo with ctrl or meta is usable except a few that has special meaning in a terminal like C-i and C-m. However, it is important not to remove a keychord I already use a lot for its original functionality to use it as the prefix for my own keymap instead, and I don't want a situation where a keychord both has its own functionality that I sometimes use and also is the prefix key for my keymap. That would be confusing and annoying to work with. I don't use C-z to iconify GUI Emacs or stop TTY Emacs, so I thought it was a keychord I could unbind and then use as my prefix.

Below is the code from my Emacs config for my keymap. It has just a few functions I use often that doesn't have a keybinding by default and a few of my own functions. Using it makes me faster than using M-x.

(global-unset-key (kbd "C-z"))
(define-prefix-command 'emo-map)
(global-set-key (kbd "C-z") 'emo-map)
(define-key emo-map (kbd "a") 'tempo-complete-tag)
(define-key emo-map (kbd "b") 'tempo-backward-mark)
(define-key emo-map (kbd "c") 'org-insert-structure-template)
(define-key emo-map (kbd "d") 'org-display-inline-images)
(define-key emo-map (kbd "e") 'elfeed)
(define-key emo-map (kbd "C-e") 'eshell)
(define-key emo-map (kbd "f") 'tempo-forward-mark)
(define-key emo-map (kbd "h") 'emo-hjemmeside)
(define-key emo-map (kbd "i") 'emo-ispell-toggle)
(define-key emo-map (kbd "l") 'org-toggle-link-display)
(define-key emo-map (kbd "m") 'mu4e)
(define-key emo-map (kbd "o") 'emo-dired-convert-to-org)
(define-key emo-map (kbd "C-s") '(lambda () (interactive) (emo-present 'toggle)))
(define-key emo-map (kbd "s") 'shell)
(define-key emo-map (kbd "t") '(lambda () (interactive) (ansi-term "bash")))
(define-key emo-map (kbd "y") 'emo-systemcrafters)
© Einar Mostad 2010 - 2025. Content is licensed under the terms of CC BY SA except code which is GNU GPL v3 or later.
Made with GNU Emacs, Org-Static-Blog, and Codeberg Pages on GNU/Linux.