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?
1 Answer
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.
utf-8
.