views:

210

answers:

3

My problem stems from Emacs inserting the coding system headers into source files containing non-ascii characters:

# -*- coding: utf-8 -*-

My coworkers do not like these headers being checked into our repositories. I don't want them inserted into my files because Emacs automatically detects that the file should be UTF-8 regardless so there doesn't seem to be any benefit to anyone.

I would like to simply set Emacs to use UTF-8 automatically for all files, yet it seems to disagree with this idea. In an effort to fix this, I've added the following to my .emacs:

(prefer-coding-system 'utf-8)
(setq coding-system-for-read 'utf-8)
(setq coding-system-for-write 'utf-8)

This does not seem to solve my problem. Emacs still inserts the coding-system headers into my files. Anyone have any ideas?

EDIT:

I think this problem is specifically related to ruby-mode. I still can't turn it off though.

+2  A: 

By default, Emacs will not write file variables into your files. You must have asked it to do so somewhere in your .emacs. Try running emacs -q and see if the file variables get inserted.

alephnull
A: 

Hi,

Update: I must admit, that I overlooked your actual question concerning the insertion of the variables, so I only answered the "howto setup UTF-8 part", sorry about this. Concerning your actual question I have nothing to add, normally emacs doesn't do this.

maybe this blog entry helps you. Reading the documentation of coding-system-for-read and coding-system-for-write doesn't suggest that you should use it:

coding-system-for-write is a variable defined in `C source code'.
Its value is nil

Documentation:
Specify the coding system for write operations.
Programs bind this variable with `let', but you should not set it globally.
...
danielpoe
A: 

First, I agree with the the original answer, but I would also add that if I had your issue I would use something like the following:

(defun java-setup ()
  (setq tab-stop-list
        '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92)
        indent-tabs-mode nil
        tab-width 4
    fill-column 96
    buffer-file-coding-system 'utf-8-unix
    c-comment-start-regexp "\\(@\\|/\\(/\\|[*][*]?\\)\\)"))

(add-hook 'java-mode-hook 'java-setup)
pajato0
Isn't most of that extraneous? I think really what you're trying to say is: (defun set-coding-system () (setq buffer-file-coding-system 'utf-8-unix)) (add-hook 'find-file-hook 'set-coding-system) ... Of course, I haven't tried that, but that seems like the important part of what you're saying.
quodlibetor
In a narrow sense, yes you are correct. However, I thought it might be more effective to show the solution (using emacs hook functions to set buffer local variables) with a real world example that might be easy to relate to. Sometimes doing that is effective and helpful, sometimes it adds confusion. But since you raised the issue I'll keep a mind to make it clearer what's extraneous and what's not in future answers. Thanks.
pajato0