GNU bug report logs - #78834
Feature request: make keymapp dereference symbol value slot

Previous Next

Package: emacs;

Reported by: arthur miller <arthur.miller <at> live.com>

Date: Wed, 18 Jun 2025 22:34:01 UTC

Severity: wishlist

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: arthur miller <arthur.miller <at> live.com>
Cc: 78834 <at> debbugs.gnu.org
Subject: bug#78834: Feature request: make keymapp dereference symbol value slot
Date: Thu, 19 Jun 2025 11:18:47 -0400
> because one is fbound and the other is not. The background for this is
> that I want to collect all loaded keymaps in the system:
>
> (defun collect-keymaps ()
>   (cl-loop for k being the symbol when (keymapp k) collect k))

The fix here is to always check the `(symbol-value k)` never `k`.
IOW think of it "I'm looking for all the loaded strings" except that
you're looking for keymaps instead of strings.  You wouldn't do
`(stringp k)` but `(stringp (symbol-value k))`, right?

It is rue that keymaps (contrary to strings) can *also* be represented
by symbols (where it works much like it does for functions).  I don't
know why this was done, but I consider as an historical accident and
don't recommend making use of that "feature".

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`.

> As a suggestion, the attached patch dereferences symbol value slots
> as well.

It's simpler to fix *your* code rather than the rest of the world's.  🙂

> If it is not a wrong thing to do for some reason I am not aware
> of, I would like to suggest it as a "fix" or a "feature request",
> whichever is best describing the issue.

It would break existing uses when the symbol has both
a `symbol-function` value and a `symbol-value` value.  We could consider
adding it as a fallback (i.e. use the `symbol-value` slot only *after*
checking the `symbol-function` slot), but that would be
a somewhat weird/unreliable feature, so we'd need a compelling use-case
(the only advantage I can see of using `symbol-value` over
`symbol-function` is that it can be made buffer-local, so you could
e.g. make a keymap whose parent changes dynamically depending on the
current-buffer, but I don't know what would be the corresponding
"compelling use-case").


        Stefan





This bug report was last modified 13 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.