I run Emacs in Windows via msys2. If I set my language environment in my .bashrc using export LANG=en_US.UTF-8 I get as my default environment in Emacs utf-8-dos. Is there a need thereafter to set any of the following variables in dot emacs:

(prefer-coding-system 'utf-8-dos)
(set-default-coding-systems 'utf-8)
(setq-default buffer-file-coding-system 'utf-8)
(setq selection-coding-system 'utf-8)

There seems to me to be some confusion around what utf settings need to be made explicit in dot emacs.

1 Answer 1


None of those are necessary as utf-8 is the default for everything. Furthermore, even if you do want to change the defaults, you should not use the code as you pasted it; it is incomplete. It changes some of the coding system settings, but not all of them. You should instead use set-language-environment to set everything at once. See chapter 23.2 Language Environments of the Emacs manual for more information.

(set-language-environment 'utf-8)

But again, even this is unnecessary as utf-8 is the default.

  • 3
    Shouldn't it be (set-language-environment "UTF-8"). Double quotes and upper case? Commented Aug 3, 2023 at 13:36
  • 1
    Yes, technically. However, in practice a symbol will work just as well and the search is not case sensitive.
    – db48x
    Commented Aug 3, 2023 at 16:14

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.