Subject: Re: bug#78834: Feature request: make keymapp dereference symbol value slot

From: Daniel Mendler <[email-masked]>
Date: Fri, 20 Jun 2025 00:45:35 +0200

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

>>> It's mostly used in very old code that uses the weird
>>> `define-prefix-command` function, such as the code that sets up some of
>>> the "core" keymaps like `ctl-x-5-prefix` `ESC-prefix` `ctl-x-4-prefix`,
>>> `Control-X-prefix`.
>> I was actually wondering why this was done, if it is just an
>> optimization or if there is some other reason?  I am just curious, I
>> don't really understand the idea behind.
>
> You'd have to ask Richard.  IIUC one of the benefit is that you can
> refer (by name) to a keymap before it's defined.  E.g. you can do
>
>     (global-set-key [?\C-z] 'my-z-keymap)
>
> and then have `my-z-keymap` autoloaded from some library the first time
> you hit `C-z`.  I can't remember the last time I've seen this used
> successfully (I tried to use it a few times, but the keymap always
> ended up being "accidentally" autoloaded much too eagerly).

In a bunch of my packages I use the prefix keymap autoloading
functionality successfully. See for example `cape-prefix-map' or
`osm-prefix-map'. I bind `osm-prefix-map' to `s-m', such that I can
invoke `osm-home' via `s-m h'. I've not observed that osm.el gets loaded
too eagerly.

> Maybe it was done simply because Richard thought of keymaps as kinds of
> commands?

I'd suspect it was done like this because of autoloading.

Daniel