Subject: bug#21780: 25.0.50; Saving *Help* results in bad encoding because of curly quotes

From: Drew Adams <[email-masked]>
Date: Thu, 29 Oct 2015 13:53:30 -0700 (PDT)

> It might work as you expect already.  You can try this:
> 
>   . After "C-h f some-function RET", switch to the *Help* buffer and
>     type "C-x RET f utf-8 RET", then save the buffer as in your
>     recipe.
> 
>   . Now visit the file where you saved the *Help* buffer: if the
>     curved quotes display correctly, then "it works for you".

That's exactly what I reported I did.  The result was seeing octal
escapes when I opened the file in a new Emacs session.

Or so I thought.  I just repeated it now with `emacs -Q' and it does
not seem to be a problem if utf-8 is used.

I think now that what I did earlier, when specified utf-8, I was
using my setup.  When I try that again (with my setup), I see the
problem I reported.

Also, with my setup the *Warning* text is different.  Instead of
providing lots of possible encoding choices and using
chinese-iso-8bit as the default (which is what I get with emacs
-Q - why is that, BTW?), it says:

Select one of the safe coding systems listed below,
or cancel the writing with C-g and edit the buffer
   to remove or modify the problematic characters,
or specify any other coding system (and risk losing
   the problematic characters).

  raw-text no-conversion

It was in that context that I anyway tried utf-8 and got the
awful result.  I also tried raw-text, since utf-8 was not in
the prompt (but was apparently accepted, and apparently did
not help).

The full warning is this, when I use my setup (which uses font
"-outline-Lucida Console-normal-normal-normal-mono-14-*-*-*-c-*-iso8859-1"):

These default coding systems were tried to encode text
in the buffer 'throw-isearch-help5.txt':
  (undecided-unix (489 . 8216) (491 . 8217) (499 . 8216) (503 . 8217)
  (577 . 8216) (583 . 8217) (875 . 8216) (892 . 8217) (912 . 8216)
  (931 . 8217) (963 . 8216)) (iso-latin-1-unix (489 . 8216) (491
  . 8217) (499 . 8216) (503 . 8217) (577 . 8216) (583 . 8217) (875
  . 8216) (892 . 8217) (912 . 8216) (931 . 8217) (963 . 8216))
However, each of them encountered characters it couldn't encode:
  undecided-unix cannot encode these: ' ' ' ' ' ' ' ' ' ' ...
  iso-latin-1-unix cannot encode these: ' ' ' ' ' ' ' ' ' ' ...

Click on a character (or switch to this window by 'C-x o'
and select the characters by RET) to jump to the place it appears,
where 'C-u C-x =' will give information about it.

Select one of the safe coding systems listed below,
or cancel the writing with C-g and edit the buffer
   to remove or modify the problematic characters,
or specify any other coding system (and risk losing
   the problematic characters).

  raw-text no-conversion

I got only a #...# file written with utf-8, as the Emacs 25 build
I have crashes all the time, and trying to select the minibuffer
frame after the popped-up *Warning* frame grabs the selection just
crashes Emacs.  And that happens now when I try again, with my setup.

I've attached those files from the first try I made for this,
with my setup.  I see now that the `#...#' one has UTF-8 encoding
and the other, `...' without the #s, has encoding `t' in the mode
line, which I guess means raw text.

To report the problem I then used `emacs -Q', and this time I
tried raw text, and I saw the octal escapes.  So I mistakenly
reported that I saw them after specifying both utf-8 and raw text.

>   . If the curved quotes look like raw bytes or, worse, pairs of
>     non-ASCII characters, you need to visit such file like this:
> 
>       C-x RET c utf-8 RET C-x C-f FILE-NAME RET

Users should not have to do that.  I thought they would, like me
have that annoyance.

> > In Emacs, before saving, the buffer looks fine.
> 
> It looks fine, but the encoding mnemonic on the mode line is not "U"
> (which stands for UTF-8), right?  That is why Emacs asks you for
> encoding: it cannot save these characters using your locale's default
> encoding (which is what the *Help* buffer uses by default).

> Yes, because you probably told Emacs to use raw-text or somesuch, when
> it asked.

See above.

> > Do I need to save the buffer using some other encoding?  If so, which?
> 
> Yes, you could tell it to use UTF-8 when it asked.  (After my change,
> Emacs will do that automatically, no questions asked, when saving
> *Help* buffers with curved quotes.)

Sounds good.

> > Emacs proposed two encodings (one of which was raw text, which I tried;
> > and I tried also utf-8, which I would have thought would show curly
> > quotes OK.
> 
> UTF-8 should have worked.  I wouldn't expect you to see octal escapes
> after saving in UTF-8.

See above for, I think, the explanation of what I did and saw.

Thx.