Martin Geisler avatar Martin Geisler committed 66b2d23

Use "coding:" instead of "encoding:" to specify file encoding

Using "-*- encoding:utf-8 -*-" doesn't really set the file encoding
for Emacs. It will even prompt the user when opening a compiled file:

The local variables list in foo.mak.py
contains values that may not be safe (*).

Do you want to apply it? You can type
y -- to apply the local variables list.
n -- to ignore the local variables list.

! -- to apply the local variables list, and permanently mark these
values (*) as safe (in the future, they will be set automatically.)

* encoding: utf-8

The problem is that Emacs looks for a file variable named "coding" and
it doesn't know about "encoding":

http://www.gnu.org/software/emacs/manual/html_node/emacs/Specify-Coding.html

This is no doubt why Python recognizes "coding:" by itself:

http://www.python.org/dev/peps/pep-0263/

This change makes the code generator output "# -*- coding:%s -*-" and
updates the documentation and examples to match this style.

Comments (0)

Files changed (5)

doc/build/unicode.rst

 
 .. sourcecode:: python
 
-    # -*- encoding:utf-8 -*-
+    # -*- coding:utf-8 -*-
     from mako.template import Template
 
     t = Template("drôle de petite voix m’a réveillé.", disable_unicode=True, input_encoding='utf-8')
 
 .. sourcecode:: python
 
-    # -*- encoding:utf-8 -*-
+    # -*- coding:utf-8 -*-
     #  ...more generated code ...
 
     def render_body(context,**pageargs):
         # module-level names, python code
         if self.compiler.generate_magic_comment and \
             self.compiler.source_encoding:
-            self.printer.writeline("# -*- encoding:%s -*-" %
+            self.printer.writeline("# -*- coding:%s -*-" %
                                     self.compiler.source_encoding)
 
         if self.compiler.future_imports:

test/templates/chs_unicode.html

-## -*- encoding:utf8 -*-
+## -*- coding:utf8 -*-
 <%
  msg = u'新中国的主席'
 %>

test/templates/chs_unicode_py3k.html

-## -*- encoding:utf8 -*-
+## -*- coding:utf8 -*-
 <%
  msg = '新中国的主席'
 %>

test/templates/chs_utf8.html

-## -*- encoding:utf8 -*-
+## -*- coding:utf8 -*-
 <%
  msg = '新中国的主席'
 %>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.