From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#22436: read-coding-system uses wrong default when called from write-file Date: Sat, 23 Jan 2016 13:31:59 +0200 Message-ID: <83h9i45y6o.fsf@gnu.org> References: <83zivx5mwu.fsf@gnu.org> <83vb6k6dqi.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1453548742 22096 80.91.229.3 (23 Jan 2016 11:32:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Jan 2016 11:32:22 +0000 (UTC) Cc: 22436@debbugs.gnu.org To: Richard Copley Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 23 12:32:11 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aMwQM-00047b-Nx for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Jan 2016 12:32:10 +0100 Original-Received: from localhost ([::1]:56894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMwQM-00010l-6f for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Jan 2016 06:32:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMwQH-00010Z-VX for bug-gnu-emacs@gnu.org; Sat, 23 Jan 2016 06:32:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMwQE-0003zn-P7 for bug-gnu-emacs@gnu.org; Sat, 23 Jan 2016 06:32:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41900) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMwQE-0003zj-LY for bug-gnu-emacs@gnu.org; Sat, 23 Jan 2016 06:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aMwQE-0006i9-ES for bug-gnu-emacs@gnu.org; Sat, 23 Jan 2016 06:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Jan 2016 11:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22436 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22436-submit@debbugs.gnu.org id=B22436.145354871125781 (code B ref 22436); Sat, 23 Jan 2016 11:32:02 +0000 Original-Received: (at 22436) by debbugs.gnu.org; 23 Jan 2016 11:31:51 +0000 Original-Received: from localhost ([127.0.0.1]:58353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aMwQ3-0006hk-HX for submit@debbugs.gnu.org; Sat, 23 Jan 2016 06:31:51 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42850) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aMwQ1-0006hY-6B for 22436@debbugs.gnu.org; Sat, 23 Jan 2016 06:31:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMwPs-0003vl-GH for 22436@debbugs.gnu.org; Sat, 23 Jan 2016 06:31:43 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:46906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMwPs-0003vh-Ct; Sat, 23 Jan 2016 06:31:40 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2141 helo=HOME-C4E4A596F7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1aMwPr-0005to-Pw; Sat, 23 Jan 2016 06:31:40 -0500 In-reply-to: (message from Richard Copley on Sat, 23 Jan 2016 09:45:39 +0000) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:111883 Archived-At: > From: Richard Copley > Date: Sat, 23 Jan 2016 09:45:39 +0000 > Cc: 22436@debbugs.gnu.org > > > An encoding can be considered "wrong" if it fails to encode a > > character. AFAICS, chinese-iso-8bit does succeed in encoding it, so > > the above definition of "wrong" doesn't fit. > > It encodes the character to #xa1 #xae . When I open the file that is > decoded as "¡®", without asking any questions. Isn't that what you > saw? Are you going to tell me that's right too? Emacs never asks questions when decoding text, only when encoding it. When it visits a file, it guesses the encoding as best it can, and that's what you see. If you type "C-x RET c chinese-iso-8bit RET C-x C-f FILE RET", do you see that character correctly decoded and correctly displayed? > > In addition, there should be a *Warning* buffer displayed where you > > have a long list of encodings Emacs knows about that can encode this > > character; chinese-iso-8bit is just one of them, but the text there > > tells you to select any one of them. Do you see that buffer > > displayed? > > Yes, but chinese-iso-8bit is not on the list. It is: that's the first one in the list, gb2312. It's an alias for chinese-iso-8bit, which is the formal name. > > Given all this information, please do tell why you think what Emacs > > did was wrong, > > Do you seriously think it's the right thing to do? That's the last thing > I expected. I don't know how to respond. > > > and what did you think Emacs should have done instead. > > I think Emacs should pick something less surprising and unhelpful, > like utf-8. Unless it gets some hint from the locale or from customizations, Emacs does not prefer any encoding to any other encoding. GB2312 is a very reasonable choice in some locales, and might be what you want. How is Emacs to know, if your locale is US English? All it knows is that your default encoding cannot be used. What Emacs did here is produce a list of all the encodings that can encode that character, sorted them according what it knows about your preferences (which is nothing in this case), and then picked up the first encoding in the resulting list. And that's what you see. UTF-8 is also in the list, but it comes later. If you want Emacs to prefer UTF-8, you can have that. Just type M-x prefer-coding-system RET utf-8 RET That's it, Emacs will from now on use UTF-8 whenever it can without asking. If you repeat your recipe after setting that preference, it will silently encode the buffer/region with UTF-8, no questions asked. You can have this customization in your ~/.emacs file, of course, if you want it permanent.