Subject: bug#58507: Emacs does not preserve the coding system

From: Eli Zaretskii <[email-masked]>
Date: Mon, 24 Oct 2022 15:45:07 +0300

> From: Juhana Sadeharju <[email-masked]>
> Date: Mon, 24 Oct 2022 03:22:44 +0300
> Cc: [email-masked]
> 
> First I create a new file with c-x c-f. By default, it has coding system iso-latin-9-dos.
> 
> I change the coding system to utf-8 via the buffer's bottombar. Char "0" changes to "U".
> 
> Then I write "äöäöäö" and quit emacs.
> 
> When I rerun the emacs and open the text, the "öä" looks wrong and coding system is back at iso-latin-9-dos.
> 
> I use Total Commander's View to verify the file is ok. The file goes wrong only if I now save the buffer.

This is expected: the short file that you created can be interpreted
both as UTF-8 and as ISO-8859-9.  When there is ambiguity in detection
of the encoding, Emacs prefers the locale-dependent defaults, which in
your case are ISO-8859-9.

> What helps is c-x ret r which asks the coding system -- I type utf-8.
> 
> Also helps when I add ";;; -*- coding: utf-8-dos; -*-" to the top of file. I will use this method as solution, but this
> is too advanced for regular users -- please check what is the problem.

These are indeed two ways of telling Emacs to visit the file as
encoded in UTF-8.