0

Is there a way in emacs (I'm using version 27.2 currently) to get a listing of all the key mappings that are active in the current buffer as well as the name of the mapped function? I also want the name of the key map itself, since more than one key map might be in use.

Unless I am misunderstanding something, the (current-active-maps) function doesn't return the name of the keymap nor the name of the function, but rather, just an unnamed reference to the keymap and an unnamed representation of the function.

In other words, instead of the standard (current-active-maps) output, I want a list that might look something like this ...

(
  ( 'ctl-x-map "\C-c" 'save-buffers-kill-emacs )
  ;; ... hundreds of other similar entries ...
)

The format of the list could differ slightly. All I care about is that the name of the keymap, the keystrokes, and the name of the mapped function are all shown.

2
  • You will want to read the describe-bindings function and the functions it calls. You can run it with C-h b. It displays the information you’re after to a buffer, but you could write similar code to collect the information into a list instead. Note that there are some complications you might not have thought about yet: keymaps are often nested, forming a tree, and the key binding is not always a named function. Sometimes it is another key, or a keyboard macro, or a closure or lambda, etc.
    – db48x
    Dec 29, 2021 at 0:18
  • @db48x: That shows currently active keyboard key bindings (but not menu bindings). But it does not list the active maps by their variable names.
    – Drew
    Dec 29, 2021 at 2:24

1 Answer 1

2

As a comment by @db48x mentions, C-h b shows currently active keyboard key bindings - the keys and the commands they are bound to (what you called "mapped functions"). (That includes mouse-button/wheel key bindings, but not menu key bindings.)

But C-h b does not list the active keymaps by the names of variables that are bound to them.

More importantly, there is not necessarily any keymap variable for some of the keymaps binding keys that are available. Using a variable whose value is a keymap is just one possibility. For example, minor modes' mappings are registered through minor-mode-map-alist which associates mode names with keymap objects, without involving keymap names. There is a convention that the keymap object is in a variable whose name is the mode name plus -map, but this is just a convention, not an obligation.

To me, this sounds like it might be an X-Y question. Why do you think you need keymap variables instead of the actual keymaps? What is that you want to do with the info you seek? Is there a question behind your question? If so, please post that (separately).

1
  • Actually, describe-bindings gives me most of what I want, and I have accepted this answer. The reason I wanted the variables which hold the keymaps is so that I can know which keymaps to modify when I want to change some mappings. But I can work around that. Thank you for enlightening me about describe-bindings.
    – HippoMan
    Dec 30, 2021 at 6:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.