madreblu
madreblu

Reputation: 393

emacs constantly asking before saving python code with # -*- coding: ASCII -*-

I have a python script that starts with:

#!/usr/bin/env python
# -*- coding: ASCII -*-

and prior to saving, it always splits my window, and asks:

Warning (mule): Invalid coding system `ASCII' is specified for the current buffer/file by the :coding tag. It is highly recommended to fix it before writing to a file.

and I need to say yes, it there a way to disable this ? Sorry for asking but I had no luck on google.

Gabriel

Upvotes: 3

Views: 1806

Answers (2)

cjm
cjm

Reputation: 62109

A solution that doesn't involve changing the script is to tell Emacs what ASCII means as a coding system. (By default, Emacs calls it US-ASCII instead.) Add this to your .emacs file:

(define-coding-system-alias 'ascii 'us-ascii)

Then Emacs should be able to understand # -*- coding: ASCII -*-.

Upvotes: 7

Chris
Chris

Reputation: 46346

The Python Enhancement Proposal (PEP) 263, Defining Python Source Code Encodings, discusses a number of ways of defining the source code encoding. Two particular points are relevant here:

  • Without encoding comment, Python's parser will assume ASCII

    So you don't need this at all in your file. Still, if you do want to be explicit about the file encoding:

  • To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:

    # coding=<encoding name>
    

    (note that the = can be replaced by a :). So you can use # coding: ascii instead of the more verbose # -*- coding: ASCII -*-, as suggested by this answer. This seems to keep emacs happy.

Upvotes: 3

Related Questions