60

I don't find the encoding of current file, how to display it?

emacs

You can see there are some Chinese characters in the file, but I don't know what the encoding it is.

Is there any way to let it always show on the emacs GUI?

1 Answer 1

104

You have several ways to get (and set) the buffer encoding:

  • You can see with the U in the mode-line that your buffer is in "Unicode", if you put the mouse over it, it will show in a tooltip the current buffer encoding.

  • you can also see the current encoding with C-hv buffer-file-coding-system RET

  • you can change the whole buffer encoding for next save with C-xRETf

  • you can also change the detected encoding to force an other one and reload the file with C-xRETr

  • you can set an encoding for the next I/O command only with C-xRETc

  • there are some other possibilities, take a look on C-xRETC-h

Fix and diagnose:

  • Inside a buffer, if you are interested by a single character encoding / details, put the point on a chinese char and C-uC-x= will help. (The same without the C-u shows only a few informations about the character, and the encoding is not part of it.)
  • examine the file by yourself:
    • you can open a text file without any decoding or heuristic with M-xfind-file-literallyRET
    • or you can go closer to the metal (hex editor) with M-xhexl-find-fileRET or for current file M-xhexl-modeRET
  • if the file is a mess with mixed encodings, you can fix portions with M-xrecode-regionRET
2
  • 8
    @BorisStitnicky: you're welcome :o). Emacs is my swiss knife when I must deal with file encodings. The only problem is that it is a long way before being comfortable with it. C-h a helps a lot though.
    – Seki
    May 8, 2012 at 15:33
  • 1
    Thanks. This helped me solve a long-running problem! We could see that some "*" were entered in ascii and others were UTF8, causing errors in some old programs. Life Saver, you are.
    – pauljohn32
    Dec 5, 2016 at 16:48

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.