If you purely want the human-readable key sequence, the key-description
function is all you need:
(key-description [return 3 16 14 5 return 21 3 46 return 24 98 return])
"<return> C-c C-p C-n C-e <return> C-u C-c . <return> C-x b <return>"
If you want to know the names of the commands which will be executed by that key sequence, you can get those too -- although the commands that a macro will run will, of course, depend on the keymaps that are active in the current buffer, so you can only get the commands which would run for that particular context.
The keyboard macro editor (command edit-kbd-macro
) will show you the commands. Invoke it with: C-xC-ke and then select the macro you want. For a named macro, you would use M-x at that prompt.
For your example:
(fset 'foo [return 3 16 14 5 return 21 3 46 return 24 98 return])
Then, in my current text-mode
buffer:
C-xC-keM-x foo
RET
;; Keyboard Macro Editor. Press C-c C-c to finish; press C-x k RET to cancel.
;; Original keys: RET C-c C-p C-n C-e RET C-u C-c . RET C-x b RET
Command: foo
Key: none
Macro:
RET ;; newline
C-c C-p
C-n ;; next-line
C-e ;; move-end-of-line
RET ;; newline
C-u C-c .
RET ;; newline
C-x b ;; switch-to-buffer
RET ;; newline
Note that edmacro-format-keys
isn't necessarily producing the exact same output as key-description
. Here we see <return>
in the latter, but RET
in the former.
key-description
function, which is really what you wanted (although the macro editor's more detailed output may be preferable in many cases). ā phils Jun 24 '18 at 20:47