How can I find out what character encoding Emacs employs in saving a text file to disk? And how can I specify this encoding?

Operating system: macOS Sierra, Version 10.12.5
Emacs: GNU Emacs 25.1.1

1 Answer 1


From chapter "Choosing Coding Systems for Output" of emacs manual:

Once Emacs has chosen a coding system for a buffer, it stores that coding system in ‘buffer-file-coding-system’. That makes it the default for operations that write from this buffer into a file, such as ‘save-buffer’ and ‘write-region’. You can specify a different coding system for further file output from the buffer using ‘set-buffer-file-coding-system’

So the encoding is stored in variable buffer-file-coding-system (whose value you can examine with C-h v) and the function set-buffer-file-coding-system can be used to change it. However the function's docstring includes:

If you know exactly what coding system you want to use, just set the variable ‘buffer-file-coding-system’ directly.

So the advantage in using M-x set-buffer-file-coding-system is that you can get completion for possible coding systems, with the TAB key.

Also note that you can get information on a coding system with M-x describe-coding-system (bound to C-h C).

  • Thanks. Examining the value of the variable buffer-file-coding-system with C-h v for the file test.tex yields: "Its value is ‘undecided-unix’ Local in buffer test.tex; global value is utf-8-unix". What does it mean?
    – Evan Aad
    Commented May 28, 2017 at 20:13
  • Also, what are the possible values that can be assigned to buffer-file-coding-system? Is there a list of possible values?
    – Evan Aad
    Commented May 28, 2017 at 20:18
  • 2
    Using M-x set-buffer-file-coding-system you can get completion for possible values, through the TAB key. You can get info on a coding system with C-h C.
    – JeanPierre
    Commented May 28, 2017 at 20:30

Your Answer

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

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