all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: How to keep character encoding in text file...
Date: Thu, 05 Mar 2009 14:33:48 +0100	[thread overview]
Message-ID: <7c7i34nlfn.fsf@pbourguignon.anevia.com> (raw)
In-Reply-To: yxOrl.9550$cu3.152@uutiset.elisa.fi

Marko Myllymaki <firstname.lastname@iki.fi> writes:

> I usually work with UTF-8 encoded files and my system is set up for
> UTF-8 (text may be in english, finnish, swedish, german, russian...)
>
> However, sometimes I edit latin1 -encoded files and I would like to
> have the encoding automatically kept that way when saving files. Now
> it seems to change unwantedly to UTF-8 sometimes... I have to use
> iconv command line tool to change this...
>
> So... if I load UTF-8 encoded file, emacs always saves it that way. If
> I open latin1-encoded file, it should keep it in the original
> encoding.

I don't know if there's an easy way to do that.


> Maybe something to put in .emacs to achieve this...

The easiest way is to put a comment on the first two lines containing:

-*- coding:iso-8859-1 -*-


Alternatively, you could put a comment in the last 512 bytes of the file containing:

Local Variables:
codingl iso-8859-1
End:



Otherwise, you may use the file extension, or the file location  (or
really any regexp on the file path) to determine the encoding,
customizing the file-coding-system-alist variable.

(push '("^/some/dir/latin-1-files/.*" iso-8859-1 . iso-8859-1)
       file-coding-system-alist)

(push '("\\.iso-8859-1$" iso-8859-1 . iso-8859-1)
       file-coding-system-alist)

-- 
__Pascal Bourguignon__


  reply	other threads:[~2009-03-05 13:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-05 11:17 How to keep character encoding in text file Marko Myllymaki
2009-03-05 13:33 ` Pascal J. Bourguignon [this message]
2009-03-06  7:54   ` Marko Myllymaki
2009-03-05 18:50 ` Eli Zaretskii
     [not found] ` <mailman.2443.1236279043.31690.help-gnu-emacs@gnu.org>
2009-03-06  7:39   ` Marko Myllymaki
2009-03-06  8:21     ` Pascal J. Bourguignon
2009-03-06  9:44       ` Peter Dyballa
2009-03-06 10:13         ` Nikolaj Schumacher
     [not found]       ` <mailman.2491.1236332716.31690.help-gnu-emacs@gnu.org>
2009-03-06 10:12         ` Pascal J. Bourguignon
2009-03-06 10:57       ` Peter Dyballa
     [not found]       ` <mailman.2504.1236337060.31690.help-gnu-emacs@gnu.org>
2009-03-07  9:05         ` Marko Myllymaki
2009-03-06 10:51     ` 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=7c7i34nlfn.fsf@pbourguignon.anevia.com \
    --to=pjb@informatimago.com \
    --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.