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#20623: XML and HTML files with encoding/charset="utf-8" declaration loose BOM; Coding system is reset from utf-8-with-signature to utf-8 on save Date: Fri, 22 May 2015 10:11:31 +0300 Message-ID: <83egm95boc.fsf@gnu.org> References: <555E2912.7060509@gmx.net> <83iobl67ao.fsf@gnu.org> <555E44EB.6070604@gmx.net> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1432278745 6959 80.91.229.3 (22 May 2015 07:12:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 22 May 2015 07:12:25 +0000 (UTC) Cc: 20623@debbugs.gnu.org To: Simon Ledergerber Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 22 09:12:11 2015 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 1Yvh7q-0007st-MH for geb-bug-gnu-emacs@m.gmane.org; Fri, 22 May 2015 09:12:10 +0200 Original-Received: from localhost ([::1]:60603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yvh7q-00032w-1y for geb-bug-gnu-emacs@m.gmane.org; Fri, 22 May 2015 03:12:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yvh7m-00031W-W0 for bug-gnu-emacs@gnu.org; Fri, 22 May 2015 03:12:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yvh7i-0003eE-LX for bug-gnu-emacs@gnu.org; Fri, 22 May 2015 03:12:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yvh7i-0003dY-If for bug-gnu-emacs@gnu.org; Fri, 22 May 2015 03:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Yvh7i-0005ZE-4u for bug-gnu-emacs@gnu.org; Fri, 22 May 2015 03:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 May 2015 07:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20623 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20623-submit@debbugs.gnu.org id=B20623.143227870521373 (code B ref 20623); Fri, 22 May 2015 07:12:02 +0000 Original-Received: (at 20623) by debbugs.gnu.org; 22 May 2015 07:11:45 +0000 Original-Received: from localhost ([127.0.0.1]:52534 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yvh7Q-0005Ye-Gq for submit@debbugs.gnu.org; Fri, 22 May 2015 03:11:45 -0400 Original-Received: from mtaout26.012.net.il ([80.179.55.182]:47717) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yvh7M-0005YM-LF for 20623@debbugs.gnu.org; Fri, 22 May 2015 03:11:41 -0400 Original-Received: from conversion-daemon.mtaout26.012.net.il by mtaout26.012.net.il (HyperSendmail v2007.08) id <0NOQ00600P0C5X00@mtaout26.012.net.il> for 20623@debbugs.gnu.org; Fri, 22 May 2015 10:13:18 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout26.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NOQ00O9VPE6ZG70@mtaout26.012.net.il>; Fri, 22 May 2015 10:13:18 +0300 (IDT) In-reply-to: <555E44EB.6070604@gmx.net> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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:103014 Archived-At: [Please don't remove the bug address from the CC list, so that this discussion is recorded in the bug data base.] > Date: Thu, 21 May 2015 22:49:47 +0200 > From: Simon Ledergerber > > From the documentation I understand that utf-8 is without BOM and > utf-8-with-signature is with BOM. Maybe I am wrong and should rather > understand that utf-8 is auto-detect. But then there is something like > utf-8-without-signature missing to specify explicitly that no BOM is > desired. > > In my opinion, it is correct when Emacs prefers utf-8 over > utf-8-with-signature when it opens a file without BOM that can still be > recognized as UTF-8. > > However when a file is opened with a BOM already present, it should > stick to the utf-8-with-signature coding system, because the BOM "EF BB > BF" unambiguously marks the file as UTF-8. (For UTF-16 for example, > there is a different BOM byte pattern. There are other coding systems > which do not have a BOM at all.) What do you mean by "stick to"? When I try visiting an XML file that is encoded with BOM, Emacs decodes the file correctly, and the value of buffer-file-coding-system is utf-8-with-signature. Isn't that what you want? If that's what you want, but it doesn't happen for you, please try in "emacs -Q". It's possible that the default you set: (setq-default buffer-file-coding-system 'utf-8-dos) is the reason for what you see. (I don't understand why you need such a default, and it sounds like a bad idea to me.) > By doing C-x f and then saving it with C-x C-s, I expect to be > able to change the coding system. For example, if I specify utf-8-dos, > the BOM should be removed, if one was present, and CR LF should be > inserted for EOL. On the other side, if I choose > utf-8-with-signature-unix, a BOM should be written and LF be taken for > EOL. (The conversion between DOS and Unix works, just the BOM is the > problem.) > > I have found a link, where this topic was already discussed, but it > didn't help me further: > http://superuser.com/questions/41254/make-emacs-not-remove-the-bom-from-xml-files > > In that post Vebjorn Ljosa asked exactly the question I have. Richard > Hoskins replies with the answer to change the coding system with C-x > r utf-8-with-signature. Unfortunately, it didn't work for me - > after doing a change in the file and saving, it got back to utf-8 > automatically - that's why I have filed the bug. That's not how you force a file to be saved in a specific encoding. You should do this instead: C-x RET c utf-8-with-signature RET C-x C-s The "C-x RET c" prefix forces the next Emacs operation to use the specified encoding. In this case, Emacs will ask for confirmation, because the encoding you specified is different from what the XML comment says.