3

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.

3
  • 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.
    – YoungFrog
    Jun 8, 2016 at 19:37
  • 1
    See lists.gnu.org/archive/html/emacs-devel/2018-11/msg00071.html for the likely explanation.
    – phils
    Nov 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.
    – xji
    Nov 7, 2018 at 15:46

2 Answers 2

7

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.

-1
(set-default-coding-systems 'utf-8)
(setq-default buffer-file-coding-system 'utf-8)

check they are in your .emacs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.