Emacs and kmonad (keyboard manager with multi-tap functionality and s-exps config)

(Date: 15 September 2024)

Summary

KMonad is a free program which can provide advanced keyboard customization, with possibilities useful for Emacs. For example, keys can play multiple roles, making space act like Control, or shift keys producing parens, or double tapping enabling a whole new keyboard layer. The advanced technique of ’home row modifiers’ is also possible.

Introduction

The problem of the most efficient way to bind keys in Emacs depends on each user.

A key idea of Emacs is that instead of the approach that a keystroke directly emits a character, as in most text editors, there is a more general mechanism where a keystroke can trigger a command. Indeed in Emacs the mechanism to generate a character calls calls. self-insert-command.

The subject of the choice of language to implement commands will be covered in a future article.

This problem deciding on bindings is a known important aspect. For example, it was mentioned this year on the emacs-devel list by Eli Zaretskii that for new users, learning to bind keys to commands is important. There are also periodic discussions on emacs-devel on the choice of the default key binding set.

Overview of kmonad

kmonad is under MIT license, a GPL-compatible free software license. This includes installation instructions, configuration, and examples.

Furthermore, the configuration is done in a format which consists of s-expressions. To edit this config file, there is an emacs mode, kbd-mode under GPLv3 license.

There are many resources for the specifics of configuration. For example, here are some use case scenarios in increasing order of potential complexity.

Binding a single key

As a first example, you can rebind the Capslock key to another key such as Control. Another possibility is to rebind it to another Backspace, which is easier to reach. This was done on the Space Cadet, where the key was called ‘Rub-Out’.

Layers

You can implement entire layers. Again the example on the Space Cadet is the Greek/Top layer with the alternative symbol printed on the keycap. Because this can be expressed using the s-exp format, following your keyboard layout, it is easy to create your own.

Multi-Use and Multi-Tap buttons functionality

From kmonad’s documentation:

Multi-Use Buttons are one of the distinguishing features of KMonad. You can have a single button do different things based on whether it is pressed quickly in succession, or pressed once, or held. For example, you can configure the Caps Lock key to act as an Escape button when pressed once and released, a Ctrl modifier when held-down, and a button to jump to a layer when pressed twice quickly in succession. You can make the left and right Shift keys to act like left and right parentheses (like the Space Cadet Shift keys) when tapped once, and regular Shift keys when held down.

Home Row Mods (Advanced)

Home row modifiers are an advanced topic. It is a powerful concept, worth investing the time to practice.

See A guide to Home Row mods

Conclusion

kmonad is a useful keyboard configuration utility for Emacs users.