[Python-Dev] PEP 263 -- Python Source Code Encoding

M.-A. Lemburg mal@lemburg.com
Wed, 27 Feb 2002 10:20:57 +0100


jepler@unpythonic.dhs.org wrote:
> 
> On Tue, Feb 26, 2002 at 08:50:35PM +0100, M.-A. Lemburg wrote:
> > Does anybody know where XEmacs is moving w/r to this ? (and
> > for that matter what about vi, vim, etc. ?)
> 
> I'm working with Vim 6.0, 20001 Sep 14.
> 
> VIM lets you set variables with text similar to
>         vim:KEY=VALUE:KEY=VALUE:....:
> Apparently you would use
>         vim:fileencoding=sjis:
> to select shift-jis encoding.  In the vim style, it seems most common to
> place this at the bottom of a file, but it can be placed at the top too.
> The variable "modelines" controls how many lines at each end of the file is
> inspected, with the default being 5.  It's documented that the form
>         vi:set KEY=VALUE:
> may be compatible with "some versions of Vi" but does not say which.  (I
> can't get this to work)
> 
> You can set a list of encodings to attempt when a file is loaded, which
> defaults to "ucs-bom,utf-8,latin1".  A user who wanted to treate
> non-unicode files as shift-jis by default would
>         :set fileencodings=ucs-bom,utf-8,sjis
> You can also load a particular file with the ++enc parameter:
>         :edit ++enc=koi8-r russian.txt
> (I can get this to work, but I have to do it manually to load anything in
> an odd character set)
> 
> The emacs line is harmless in vim, but doesn't do anything.  It's possible
> that using :autocmd someone could make vim use the emacs line to set
> encoding, but I'm not sure -- setting fileencoding after a file is loaded
> seems to perform a translation from the old characterset to the new.

So if we use the RE "coding[=:]\s*([\w-]+)" on the first line,
we should be able to reach out for the encoding, right ?

This RE would then cover both vim and emacs.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/