From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: david+news@madore.org (David Madore) Newsgroups: gmane.emacs.help Subject: configuring coding systems for loading/saving Date: Tue, 20 Apr 2010 14:16:22 +0000 (UTC) Organization: Ecole Normale Superieure, Paris Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1273062346 18413 80.91.229.12 (5 May 2010 12:25:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 5 May 2010 12:25:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 05 14:25:45 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9dfc-0005xt-Fb for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 14:25:44 +0200 Original-Received: from localhost ([127.0.0.1]:49096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9dfb-0003CB-KQ for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 08:25:43 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!jussieu.fr!ens.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-NNTP-Posting-Host: quatramaran.ens.fr Original-X-Trace: nef.ens.fr 1271772982 31411 129.199.129.64 (20 Apr 2010 14:16:22 GMT) Original-X-Complaints-To: abuse@ens.fr Original-NNTP-Posting-Date: Tue, 20 Apr 2010 14:16:22 +0000 (UTC) X-Newsreader: Flrn (0.9.1 - 05/04) X-Start-Date: 20 Apr 2010 13:58:07 GMT Original-Xref: usenet.stanford.edu gnu.emacs.help:177800 X-Mailman-Approved-At: Tue, 04 May 2010 16:55:22 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73419 Archived-At: Hi, I'm trying to configure the way Emacs tries various encoding systems when loading and saving a file, and I find myself unable to do what I want. Basically, the problem I have is that if I load a pure ASCII file, insert a non-ASCII Unicode character in it, and then save it, Emacs saves it in UTF-8 without asking for any kind of confirmation. Generally speaking, that's not what I want: if the file was pure ASCII to start with, I probably want it to stay that way, so I'd like Emacs to ask for confirmation before trying any other encoding. I tried doing (prefer-coding-system 'us-ascii), but this messes up with the way encoding is detected on loading (which was fine with me by default): e.g., if I load an ISO-8859-1 encoded file that encoding is not correctly detected if I do (prefer-coding-system 'us-ascii) whereas it is if I don't. I also tried this: (setq select-safe-coding-system-accept-default-p '(lambda (coding) (string= coding buffer-file-coding-system))) which I think should do more or less what I want (accept an encoding as safe only if it matches exactly the buffer-file-coding-system), but it fails for a stupid reason: coding is typically something like "iso-8859-1" whereas buffer-file-coding-system is typically something like "iso-8859-1-unix" - and I don't know how to test more intelligently than with string-equal. Also, I'm afraid overriding select-safe-coding-system-accept-default-p could have unpleasant effects (e.g., if some Emacs application wishes to suggest that the previously chosen file encoding is inadequate). Any other ideas? Ideally, I'd like Emacs to behave as follows: * when loading a file in the absence of an explicit encoding argument, try the following encodings: us-ascii (always first), then whatever encodings are preferred by the locale (e.g., iso-8859-2 if I happen to have an iso-8859-2 locale), then utf-8, and lastly iso-8859-1 (in that order); * when saving the file in the absence of an explicit encoding argument, always try to save it in the buffer's file coding system, and ask for user input if this fails. (In that way, loading an ASCII file and adding a non-ASCII character to it will cause for confirmation when saving.) Is this achievable? If not, what is the closest I can do? Many thanks for any help, -- David A. Madore ( http://www.madore.org/~david/ )