Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How switch from escaped octal character code to escaped HEX?

33 views
Skip to first unread message

Oleksandr Gavenko

unread,
Dec 28, 2010, 10:39:46 AM12/28/10
to help-gn...@gnu.org
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.

How can I change this behavior.

To hard find right keywords for search in manual and Google ((

Oleksandr Gavenko

unread,
Dec 28, 2010, 10:51:46 AM12/28/10
to help-gn...@gnu.org
This from manual:

As a special case, if the character lies in the range 128 (0200
octal) through 159 (0237 octal), it stands for a "raw" byte that does
not correspond to any specific displayable character. Such a
"character" lies within the `eight-bit-control' character set, and is
displayed as an escaped octal character code. In this case, `C-x ='
shows `part of display ...' instead of `file'.

I want change with behavior from octal to hex.


Stefan Monnier

unread,
Jan 2, 2011, 11:23:38 PM1/2/11
to
>> 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.


Stefan

Deniz Dogan

unread,
Jan 3, 2011, 2:14:19 AM1/3/11
to Stefan Monnier, help-gn...@gnu.org
2011/1/3 Stefan Monnier <mon...@iro.umontreal.ca>:

What is the reasoning behind displaying it in octal rather than
decimal or hexadecimal in the first place? I didn't know people cared
about octals anymore.

--
Deniz Dogan

Deniz Dogan

unread,
Jan 3, 2011, 5:13:48 AM1/3/11
to Stefan Monnier, help-gn...@gnu.org
2011/1/3 Deniz Dogan <deniz.a...@gmail.com>:
> 2011/1/3 Stefan Monnier <mon...@iro.umontreal.ca>:
> What is the reasoning behind displaying it in octal rather than
> decimal or hexadecimal in the first place? I didn't know people cared
> about octals anymore.
>

I read on Wikipedia: "Octal representation of non-ASCII bytes may be
particularly handy with UTF-8, where any start byte has octal value
\3nn and any continuation byte has octal value \2nn."

Is this the reason perhaps?

--
Deniz Dogan

Barry Margolin

unread,
Jan 3, 2011, 8:42:33 AM1/3/11
to
In article <mailman.8.1294038895...@gnu.org>,
Deniz Dogan <deniz.a...@gmail.com> wrote:

> What is the reasoning behind displaying it in octal rather than
> decimal or hexadecimal in the first place? I didn't know people cared
> about octals anymore.

I think it's historical. The original MIT developers tended to use
octal more than hex.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Peter Dyballa

unread,
Jan 3, 2011, 9:37:34 AM1/3/11
to Deniz Dogan, help-gn...@gnu.org, Stefan Monnier

Am 03.01.2011 um 11:13 schrieb Deniz Dogan:

> I read on Wikipedia: "Octal representation of non-ASCII bytes may be
> particularly handy with UTF-8, where any start byte has octal value
> \3nn and any continuation byte has octal value \2nn."
>
> Is this the reason perhaps?

Certainly not! GNU Emacs was octal before someone imagined "Unicode"...

It comes from sparse memory. One byte is two nibbles! (1 € is almost 2
ancient DM.) UNIX file permissions are octal. C is great in shifting
bits around.

--
Greetings

Pete

Almost anything is easier to get into than out of.
– Allen's Law


Stefan Monnier

unread,
Jan 3, 2011, 11:03:48 PM1/3/11
to Deniz Dogan, help-gn...@gnu.org
> What is the reasoning behind displaying it in octal rather than
> decimal or hexadecimal in the first place?

As mentioned by someone else, this goes back to the beginning of Emacs,
so we're talking >20 years ago. IIUC octal was more common back then.

There are still some advantages to using octal: e.g., by using fewer
different chars, there is a higher likelihood that the boundary of the
\NNN sequence will be self obvious: when you see \01234, it's not
obvious that it's \012 followed by 3 and 4, but when you see \012ab the
boundary is self-evident. With hexadecimal, the cases where the
boundary is not self-evident are more common.


Stefan

Oleksandr Gavenko

unread,
Jan 11, 2011, 5:23:38 AM1/11/11
to help-gn...@gnu.org
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.


Stefan Monnier

unread,
Jan 11, 2011, 12:34:28 PM1/11/11
to
> New hex values is not colorized. How make this?

(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 (make-glyph-code ?\\ 'escape-glyph)
(make-glyph-code ?x 'escape-glyph)
(make-glyph-code hi 'escape-glyph)
(make-glyph-code low 'escape-glyph)))
(setq i (+ i 1))))


-- Stefan

Oleksandr Gavenko

unread,
Jan 12, 2011, 4:22:42 AM1/12/11
to help-gn...@gnu.org
Oh! Very thanks!!!!!!!!

glyphs is interesting concept which I don't know.


0 new messages