0

I run Emacs in msys2 on Windows. I have set my system environment to utf-8 using this command in my .bashrc: export LANG=en_US.UTF-8. This has resulted in the coding being set to utf-8-dos without the need to make any changes to my init.el. Does utf-8-dos offer advantages over utf-8-unix if one is running Emacs on Windows in msys2?

3
  • 2
    Instead of asking which is better, ask for advantages of each. Otherwise, the question encourages opinion-based answers.
    – Drew
    Commented Aug 3, 2023 at 14:24
  • 1
    If you don't get the answer you want, just use utf-8.
    – shynur
    Commented Aug 3, 2023 at 18:01
  • Do you mean by setting it explicitly in dot emacs?
    – Edman
    Commented Aug 4, 2023 at 13:17

1 Answer 1

1

The difference between utf-8-unix and utf-8-dos are the characters signaling a newline. In unix this is the line feed or LF character whereas in dos a newline is signaled by a carriage return character or short CR, followed by a line feed. So when editing files in utf-8-unix when you enter a newline the character LF is added to the buffer. In utf-8-dos entering a newline adds the two characters CR LF to the buffer. CR and LF here are just representations of those characters. They are not literally the letters C and R or L and F written out. A table listing the different representations can be found on Wikipedia

Which mode is better for you depends on where else you will be using the files you write. If they are consumed by Windows programs the dos newline encoding will be more compatible. However, I found most other editors on Windows being able to handle unix newline encoding as well. Emacs shows the CR characters as ^M if using utf-8-unix encoding. So if you write these files for a mostly Linux audience maybe consider using the unix style newline encodings for less visual clutter.

If you look at the emacs manual page for coding system basics you can find that there is a third option. Variant coding systems as utf-8-unix and utf-8-dos are so specfiy the newline characters. Base coding systems however, leave the newline characters unspecified and should adapt to the file you are using. In this case that would be just utf-8.

I would use utf-8-dos if you are mostly using these files on Windows and utf-8-unix if you are creating files for a repository that is used by mostly Linux users. In the end I think it does not matter too much which one you choose. Most programs know how to handle both and it is trivial to convert if you ever need to. Specifying a Coding System for File Text in the manual lists the commands you can use for this.

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.