Combining mode and encoding in emacs

  • Thread starter Magnus Lie Hetland
  • Start date
M

Magnus Lie Hetland

If I want to specify both mode and source encoding using the

-*- FOO -*-

syntax in emacs -- how can I do that? Both insist on being on the
second line of the file, yet I have found no way of combining them.
That is, the following doesn't work properly (not in all emaxen, at
least):

#!/usr/bin/env python
# -*- encoding: iso-8859-1 -*-
# -*- python -*-

If I switch the two, Python doesn't get the encoding. (I need to
specify the mode, because the file has a '.cgi' ending.)

Any tips?
 
R

Roy Smith

If I want to specify both mode and source encoding using the

-*- FOO -*-

syntax in emacs -- how can I do that? Both insist on being on the
second line of the file, yet I have found no way of combining them.
That is, the following doesn't work properly (not in all emaxen, at
least):

#!/usr/bin/env python
# -*- encoding: iso-8859-1 -*-
# -*- python -*-

If I switch the two, Python doesn't get the encoding. (I need to
specify the mode, because the file has a '.cgi' ending.)

Any tips?

You can set the mode (and a lot of other things) with a local variable
list on the last page (i.e. after the last form-feed). Put something
like this at the end of your file:

#
# ^L
#

# Local Variables:
# mode:python
# End:








Look up info on "file variables" for more details. The -*- stuff is
just a convenient shorthand for a subset of what you can do with the
more verbose Local Variables syntax.
 
D

David M. Cooke

At said:
If I want to specify both mode and source encoding using the

-*- FOO -*-

syntax in emacs -- how can I do that? Both insist on being on the
second line of the file, yet I have found no way of combining them.
That is, the following doesn't work properly (not in all emaxen, at
least):

#!/usr/bin/env python
# -*- encoding: iso-8859-1 -*-
# -*- python -*-

If I switch the two, Python doesn't get the encoding. (I need to
specify the mode, because the file has a '.cgi' ending.)

#!/usr/bin/env python
# -*- mode: python; encoding: iso-8859-1 -*-

This works for me in GNU emacs 21.3.
 
J

John Lenton

If I want to specify both mode and source encoding using the

-*- FOO -*-

syntax in emacs -- how can I do that? Both insist on being on the
second line of the file, yet I have found no way of combining them.
That is, the following doesn't work properly (not in all emaxen, at
least):

#!/usr/bin/env python
# -*- encoding: iso-8859-1 -*-
# -*- python -*-

If I switch the two, Python doesn't get the encoding. (I need to
specify the mode, because the file has a '.cgi' ending.)

what I do is

# -*- python -*- coding: iso-8859-1 -*-

--
John Lenton ([email protected]) -- Random fortune:
La sociedad moderna olvida que el mundo no es propiedad de una única
generación.
-- Oskar Kokoshka.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBOKPagPqu395ykGsRAsYuAKCljqCmHqJW1vfsCrXtS7vADAn0UACfZoUQ
QVa0hz/bF6+BX6/yhkmt4D0=
=Cwv/
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,205
Messages
2,571,067
Members
47,673
Latest member
MahaliaPal

Latest Threads

Top