substitute-command-keys

substitute-command-keys is a built-in function in `C source code'.

(substitute-command-keys STRING)

Substitute key descriptions for command names in STRING.
Each substring of the form \[COMMAND] is replaced by either a
keystroke sequence that invokes COMMAND, or "M-x COMMAND" if COMMAND
is not on any keys.

Each substring of the form \{MAPVAR} is replaced by a summary of
the value of MAPVAR as a keymap. This summary is similar to the one
produced by `describe-bindings'. The summary ends in two newlines
(used by the helper function `help-make-xrefs' to find the end of the
summary).

Each substring of the form \<MAPVAR> specifies the use of MAPVAR
as the keymap for future \[COMMAND] substrings.
\= quotes the following character and is discarded;
thus, \=\= puts \= into the output, and \=\[ puts \[ into the output.

Return the original STRING if no substitutions are made.
Otherwise, return a new string.