unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* configuring coding systems for loading/saving
@ 2010-04-20 14:16 David Madore
  2010-05-06 23:23 ` Kevin Rodgers
  0 siblings, 1 reply; 3+ messages in thread
From: David Madore @ 2010-04-20 14:16 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-05-07  8:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-20 14:16 configuring coding systems for loading/saving David Madore
2010-05-06 23:23 ` Kevin Rodgers
2010-05-07  8:49   ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).