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.
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:
You can also use directory local variables to set up the variables: http://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
I had this problem today. For me, the problem was that I copied and pasted some TODO text from an email. When I removed that text, [ # -- coding: utf-8 -- ] was no longer inserted by emacs.
This works for me:
As suggested here
I believe you're correct that it only happens in ruby-mode. It seems ruby-mode is trying to be helpful by adding the line, which makes Ruby detect the source file encoding automatically.
In root of your project create file called .dir-locals.el with content:
It will apply this coding to any mode and file. You may see more info here https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
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
andcoding-system-for-write
doesn't suggest that you should use it: