I like Emacs, I like key bindings. I also like the command line and have a lot of key bindings.
Is it possible to dump Emacs key bindings to standard out so that I can search them with things like grep?
Edit: Ideally the output would "play well with command line tools" and be "machine readable". Something like:
"C-x s" save-buffer fundamental-mode
"C-a" beginning-of-line fundamental-mode
would be nice.
Edit: As people have pointed out the keybindings in emacs vary depending upon current buffer and position. I would like the "current" bindings, where this is defined as the selected buffer in the last selected frame. These can be accessed programmatically from emacsclient: (emacsclient --eval "(buffer-file-name (window-buffer (selected-window)))" | tr -d '"')
"Clues"
To make clear what I already have thought of, and to give interested readers clues.
The following script dumps functions to standard out in a similar way:
https://pastebin.com/wvPJiUwb
It uses "emacsclient -eval" for the purpose.
I am aware that the describe-bindings
function. When I looked at this before the code seemed a little "specific purpose without easy to understand general functions".
I am aware the which-key emacs mode which list key bindings as you type them, so this code might be easy to modify.
This code might be kind of readable.
Alternatives considered
Use emacs self-documentation to find key bindings
I am quite aware of the the ability to search function names and find key bindings associated with functions. The utility is that key bindings represent "functions that I am aware of and have used before".
Also the the prefix keys that I have used for key bindings represent an indexing of some descriptions (these functions are related to such and such)
describe-bindings
is the only way that I'm aware of to get a list of bindings without the need for having to handle all the arcane details of key-maps yourself.$(emacsclient --eval "(buffer-file-name (window-buffer (selected-window)))" | tr -d '"')
output the filename (if any) associated