I have a file which is encoded in utf-8. But for some reason, each time I open it in Emacs, I get no-conversion (nil) encoding, and all the non-ascii characters can't display correctly. If I run revert-buffer-with-coding-system
and choose utf-8 then they are rendered correctly, but even if I edit and save the file this time, the next time I open it, the same problem occurs. I'm not sure what went wrong and what I should do to fix it.
-
Usually happens to me when I have a file with a control character such as NUL. Is it your case? You could maybe bisect the file to see what triggers the raw decoding.– YoungFrogJun 8, 2016 at 19:37
-
1See lists.gnu.org/archive/html/emacs-devel/2018-11/msg00071.html for the likely explanation.– philsNov 7, 2018 at 11:04
-
@phils Thanks for the link. Though I'm still not sure how null bytes got into the files in the first place, if they're indeed the cause. Will pay attention to that in the future.– xjiNov 7, 2018 at 15:46
2 Answers
As mentioned in comments, NUL bytes in the files seem to have caused it, though I have no idea how they got in. The following sed command gets rid of them:
sed -i s/"\x0"// file.org
The next time this file is opened in Emacs, its encoding should be detected correctly.
(set-default-coding-systems 'utf-8)
(setq-default buffer-file-coding-system 'utf-8)
check they are in your .emacs