From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: How to keep character encoding in text file... Date: Thu, 05 Mar 2009 14:33:48 +0100 Organization: Anevia SAS Message-ID: <7c7i34nlfn.fsf@pbourguignon.anevia.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1236261105 1548 80.91.229.12 (5 Mar 2009 13:51:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Mar 2009 13:51:45 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 05 14:53:02 2009 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.50) id 1LfE0S-0001RG-Pz for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 14:53:01 +0100 Original-Received: from localhost ([127.0.0.1]:35512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfDz7-0001k0-H0 for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 08:51:37 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!cleanfeed3-b.proxad.net!nnrp19-1.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:MWI5NjUyOWYxYmRkYTFjZTBiMGJiZjQyN2U2OWU2ZDhhYWU5NDBkZg== Original-Lines: 44 Original-NNTP-Posting-Date: 05 Mar 2009 14:33:48 MET Original-NNTP-Posting-Host: 88.170.236.224 Original-X-Trace: 1236260028 news-2.free.fr 23743 88.170.236.224:54089 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:167323 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:62620 Archived-At: Marko Myllymaki 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__