Define-keymap

Zachary Kanfer has a useful post for those of you who want to reduce to a bare minimum the amount of code you have to write to configure Emacs. Kanfer was bothered by all the boilerplate you have to enter to make a keymap so he decided to write a couple of functions that simplified the process. While getting ready to publish his code, he discovered define-keymap. It is, strictly speaking, an Emacs 29 functionality but Emacs 28 has the compat-29.el module that backports define-keymap and other functionality to older Emacs versions. The nice thing about it is that it removes all the complexity and boiler plate involved in making a key map. Basically all you do is list the bindings (as text strings) and the corresponding functions. It could hardly be easier.

Personally, I’ve never found the old way of defining keymaps that onerous—although it can be hard to remember the exact spell if you aren’t doing it all the time—so I’m not going to jump into using define-keymap but I could see myself using it if I needed a quick keymap and didn’t want to look up the make-keymap incantation.

If you’re on Emacs 29, Emacs 28, or possibly older versions, invoke describe-function on define-keymap to see all the details. If you’re into simplifying your init.el, take a look at Kanfer’s post to see one way of doing that.

This entry was posted in General and tagged . Bookmark the permalink.