Short version: Can I make Emacs show \ff
or \xff
instead of \377
?
Long version: Suppose you open a file that is not entirely text and has some binary data (say a PostScript or PDF file). For example, suppose you open GNU Emacs Reference Card (PDF).
Then, for bytes outside the ASCII printable range (32–126),
- Emacs shows the "high" bytes (bytes with value 128 to 255) as octal escape sequences: 128 is shown as
\200
, 129 is shown as\201
, …, 255 is shown as\377
. - Emacs shows the bytes 0 to 31 (other than byte 9 which is shown as a tab not
^I
, and byte 10 which is shown as a newline not^J
) as a caret followed by the character that is 64 ahead: byte 0 is shown as^@
, byte 1 is shown as^A
, …, byte 26 is shown as^Z
, byte 27 is shown as^[
, …, byte 31 is shown as^_
. Also, Emacs shows byte 127 as^?
.
I know that the reason Emacs shows octal is historical: at some point a few decades ago, octal was more commonly in use. (For example, man ascii
starts with octal first, and TeX supports octal escape sequences.) But as octal is less useful than hexadecimal these days (e.g. to compare with the output of hexdump
or Python byte-string representations), I'd like to see hexadecimal escape sequences. How can I change this?
(Note: the octal escape sequences are shown highlighted instead of looking like regular text, and of course it's not possible to step "into" the escape character (i.e. hitting C-f
at the point before \343
takes you to the point after \343
); I'd like to retain this.)