How can I look up what key(s) are bound to a particular definition in a keymap? Basically the converse of lookup-key.

where-is-internal is almost the answer I'm looking for, but it doesn't seem to work in all cases.

(defvar my-map (make-sparse-keymap))
(define-key my-map [1] 'one)
(define-key my-map [2] [two])
(list (where-is-internal 'one my-map)
      (where-is-internal [two] my-map))

Expected result:

(([1]) ([2]))

Actual result (with Emacs 26.3):

(([1]) nil)

It seems that where-is-internal can't find a definition that is a vector. A list works, so it's not because the definition is compared with eq (and checking the source code, it does use Fequal). I guess that a vector is interpreted as an indirect binding of some kind, but passing non-nil values for the noindirect and no-remap parameters ((where-is-internal [two] my-map nil t t)) doesn't help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.