help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getting out of raw-text encoding


From: David Madore
Subject: getting out of raw-text encoding
Date: 10 May 2003 15:21:08 GMT

Hi!

This is with (FSF) Emacs 21.2, compiled with LEIM.  (Though I suppose
the actual Emacs version makes little difference.)

Suppose I have a file which is *mostly* encoded in the iso-8859-1
character set.  However, it has a few occasional characters that are
not iso-8859-1.  For example, it might be actually in the windows-1252
character set (that closely resembles iso-8859-1 but adds 32 extra
characters, with codes from 128 through 159).  A sample could be
produced with

perl -e 'for ($i=32;$i<256;$i++) { print chr($i); } print "\n";' >file

for instance.

When I open the file with Emacs, it quite rightfully detects that it
is not iso-8859-1, and switches to raw-text encoding (non-ASCII
characters are represented by escape sequences).  Now suppose I don't
like that.

I can force the file to be reinterpreted as iso-8859-1 by killing the
buffer and reopening it with C-x RET c iso-8859-1 as prefix.
Basically this does what I want, but suppose I wish to do it without
closing and reopening the file (there may be reasons for this, e.g.,
if the buffer is actually not a file I opened but something that was
produced by an Emacs submodule, like Gnus in attempting to reply to a
news post with a bad encoding).

So what I wish is, to change every raw-text octet value that makes
sense as an iso-8859-1 character by that corresponding character.  I
hope I'm using the correct terminology here.

First of all, doing C-x RET c iso-8859-1 M-x revert-buffer does not
work (it does not do anything, in fact, apparently).  Nor do I
understand why.  But even if it did, it still wouldn't be what I like,
because it would force the buffer to have an associated file.

Usually, when I need to reinterpret using the <bar> encoding a file
that has been read using the <foo> encoding by mistake (typical
example would be when <bar>=utf-8 and <foo>=iso-8859-1) I can do this:
C-x h M-x encode-coding-region <foo> M-x decode-coding-region <bar>
which works by first forcing the buffer back to the octets that encode
it in the <foo> encoding, and then decoding these octets using the
<bar> encoding.  However, when <foo> is raw-text, this does not
function as I expect it (maybe I'm being entirely naive there?), for
the encode-coding-region command does not do anything, and the
decode-coding-region merely adds more junk in front of my escaped
characters.

So, basically, how do I get out of raw-text without killing the
buffer?

Incidentally, is there an implementation of the windows-1252 character
encoding in Emacs somewhere (one that would map iso-8859-1 characters
to iso-8859-1 characters, and all others to the corresponding Unicode
codepoints)?  That would be useful in interacting with these annoying
systems that insist on pretending that windows-1252 "is" iso-8859-1.

Many thanks to those who can Enlighten me in this matter!

-- 
     David A. Madore
    (david.madore@ens.fr,
     http://www.eleves.ens.fr:8080/home/madore/ )


reply via email to

[Prev in Thread] Current Thread [Next in Thread]