My problem stems from Emacs inserting the coding system headers into source files containing non-ascii characters:
# -*- coding: utf-8 -*-
My c
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.
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
If you put a file with a special name .dir-locals.el in a directory, Emacs will read it when it visits any file in that directory or any of its subdirectories, and apply the settings it specifies to the file's buffer. Emacs searches for .dir-locals.el starting in the directory of the visited file, and moving up the directory tree. (To avoid slowdown, this search is skipped for remote files.)
This works for me:
(setq ruby-insert-encoding-magic-comment nil)
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.
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)
In root of your project create file called .dir-locals.el with content:
((nil . ((buffer-file-coding-system . utf-8))))
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
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.