I usually define new keybindings in emacs using
"C-x (" --> (command kmacro-start-macro)
"C-x )" --> (kmacro-end-macro)
(name-last-kbd-macro)
(insert-kbd-macro)
But the code it generates looks different than the code I read and modify in various major / minor modes and other emacs utilities.
I recently came across this blog post that clears up some of my confusion.
Is there an emacs tool that simplifies keystroke representation ?
Ideally one that translates from ahk keystroke notation to any sane emacs keystroke notation.
Edit: some other reading to clear my confusion:
keybinding guide by Jari Aalto.
The sequence you specify does simplify the keystroke representation. What you’re left with is essentially the set of keystrokes you typed.
It’s already been asked if you can convert an emacs macro into elisp.
Perhaps you’re asking if it could be made more human readable?
If so, then you’re in luck.
You can use the
kbdmacro to convert the printed representation of keystrokes into the equivalent vector of keystrokes.For example, the sequence which results in a
query-replaceof3withtjlooks like: M-% 3 RET tj RET !Well, you can manually set that up with:
And this piece of elisp code should generate the above for you if you have named your macro
'my-hand-crafted-kbd-macro:To get this to happen automatically when you finish a keyboard macro C-x ), you can use this advice: