As it is well known, characters in emacs are indistinguishable from the
integer number representing them, so much so that the form (eq ?A 65)
returns t.
Nevertheless, there are situations in
which one might want to start out with an integer, such as 9, and print
the associated character representation, such as ?\C-i.
For example, when one evaluates an expression such as 9 using the
function eval-last-sexp, the minibuffer shows the result of this
evaluation, among other things, as (#o11, #x9, ?\C-i), indicating that
the number 9 may be alternatively represented as #o11, #x9, ?\C-i.
Specifically I'd like a command, say char-representation-of-number which gives the third representation above, so that
(char-representation-of-number 1) ⇒ "?\C-a"
(char-representation-of-number 9) ⇒ "?\C-i"
(char-representation-of-number 65) ⇒ "?A"
Is there a native command in emacs allowing one to do so?
PS: Note that the command single-key-description (see How to get the string representation of a keymap event?) does approximately what I want, but not quite. For example:
(single-key-description 9) ⇒ "TAB" ;; (I wish this was "?\C-i")
(single-key-description 8) ⇒ "C-h" ;; I wish this was "?\C-h")
(single-key-description 65) ⇒ "A" ;; I wish this was "?A")
In all of these cases, evaluation of the output of single-key-description using eval-last-sexp doesn't give you the input number back.
"?\..."instead of whatsingle-key-descriptiongives you? (This info isn't needed for your question, but are you sure you need the form you request?) – Drew Jun 10 '23 at 23:16"?\C-i"; you instead want some code to give you the character?\C-i, i.e., the number 9. Evaluating the string witheval-last-sexpwon't give you the character. If you want to useeval(-last-sexp)then you need to evaluate the char itself (to give the char itself). – Drew Jun 10 '23 at 23:19