all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: david+news@madore.org (David Madore)
To: help-gnu-emacs@gnu.org
Subject: configuring coding systems for loading/saving
Date: Tue, 20 Apr 2010 14:16:22 +0000 (UTC)	[thread overview]
Message-ID: <hqkcvm$ulj$1@nef.ens.fr> (raw)

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/ )


             reply	other threads:[~2010-04-20 14:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-20 14:16 David Madore [this message]
2010-05-06 23:23 ` configuring coding systems for loading/saving Kevin Rodgers
2010-05-07  8:49   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='hqkcvm$ulj$1@nef.ens.fr' \
    --to=david+news@madore.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.