[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How switch from escaped octal character code to escaped HEX?
From: |
Oleksandr Gavenko |
Subject: |
Re: How switch from escaped octal character code to escaped HEX? |
Date: |
Tue, 11 Jan 2011 12:23:38 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 |
On 03.01.2011 6:23, Stefan Monnier wrote:
When Emacs find that byte that does
not correspond to any specific displayable character it display
octal codes instead, like: \276 (and with different color).
This is useful, but I prefer HEX base instead octal.
There is no direct/easy way to do it.
But you can do it by adding the corresponding 128 entries to the
standard-display-table.
E.g.
(setq standard-display-table (make-display-table))
(aset standard-display-table (unibyte-char-to-multibyte 131)
[?\\ ?x ?8 ?3])
(aset standard-display-table (unibyte-char-to-multibyte 132)
[?\\ ?x ?8 ?4])
Should make the bytes 131 and 132 be displayed as \x83 and \x84 rather
than \203 and \204.
Thanks Stefan for tips.
I read docs for 'buffer-display-table'. Here said:
For example, (aset buffer-display-table ?X [?Y]) tells Emacs
to display a capital Y instead of each X character.
So if in one encoding (cp1251) letter - й, in another (row-text) - \351.
I set:
(aset standard-display-table (unibyte-char-to-multibyte ?\xe9) [?\\ ?x
?e ?9])
but in cp1251 it properly displayed like й, in row-text - \xe9. I
afraid that it
in all case must be \xe9, but not. This is nice!
With this behavior I make I wont. Only one problem.
In GUI Emacs octal codes colorized (some thins red color,
C-u C-x = don't give font properties).
New hex values is not colorized. How make this?
PS. To make all 128 chars in hex I wrote:
(setq standard-display-table (make-display-table))
(let ( (i ?\x80) hex hi low )
(while (<= i ?\xff)
(setq hex (format "%x" i))
(setq hi (elt hex 0))
(setq low (elt hex 1))
(aset standard-display-table (unibyte-char-to-multibyte i) (vector
?\\ ?x hi low))
(setq i (+ i 1))
) )
PPS. Noel Evans send to me private mail where hi suggest:
(setq read-quoted-char-radix 16)
I already have this settings a lot of years. It allow you type byte in
hex: C-q 9 9 RET.