Very similar to this question: Copy text as it is rendered by Emacs but what I need is to coy the
^E and so on characters as they are displayed. (Otherwise the text in clipboard gets truncated).
It sounds like you are looking for function
returns the string
(length (text-char-desription ?^M))
^M is the single control character except in
"^M", where it is the two chars
(This is different from what
single-key-description does. For
?^M that returns the string
C-h f text-char-description:
text-char-descriptionis a built-in function in
C source code.
Return a pretty description of file-character
Control characters turn into "^char", etc. This differs from `single-key-description' which turns them into "C-char".
Also, this function recognizes the 2**7 bit as the Meta character, whereas `single-key-description' uses the 2**27 bit for Meta.
See Info node (elisp) Describing Characters for examples.