I am trying to configure Emacs to save UTF-8 files with a Byte Order Mark. (Yes, I know that the BOM is evil and unnecessary for UTF-8 files. However, Microsoft has decided they know better, so I want to make sure I'm able to save files with BOM.)
However, for some reason my choice of utf-8-with-signature
for buffer-file-coding-system
won't stick when I save the file.
I'm using Emacs 24.5.1 on Windows 10. To reproduce:
emacs -Q
- Open a file (optionally one that already has a BOM).
(setq buffer-file-coding-system 'utf-8-with-signature)
(OrM-x set-buffer-file-coding-system RET utf-8-with-signature RET
.)C-x C-s
C-h v buffer-file-coding-system
. It is now set toutf-8-dos
. I also verified that the existing BOM was removed from the file.
Why is this happening, and how can I fix it?
after-change-major-mode-hook
instead ofhtml-mode-hook
. But I think this is not necessary. From what I read about the problem it is special tohtml-mode-hook
. Note, that it is not limited to Windows. – Tobias Oct 23 '17 at 15:24html-mode
when I ran into this problem; I think it wasweb-mode
and/orcsharp-mode
. – Scott Weldon Oct 23 '17 at 18:02