I'm just learning emacs and I'm using spacemacs configuration. I created a .org
file and everything looks normal when I save it, but when I reload it I get a whole bunch of ^M
chars at the end of each line. How do I avoid this?
2 Answers
^M
is the "carriage return" character. DOS and Windows computers use the two-character sequence ^M^N
to mark the end of every line, while Linux uses just ^N
(the "line feed" character).
There are a number of Emacs settings which can control how files are encoded when saving them and when opening them, but by default it simply assumes that files will have the proper line endings for the system you're running. Thus, if you're on Linux then Emacs will assume that files have only ^N
characters at the end of every line, and that ^M
characters have no special meaning.
It sounds like you choose to save the file in a specific encoding, such as utf-8-dos
or us-ascii-dos
, which caused it to use the DOS line endings instead. There are a number of different ways you can get into that state, so I'm not going to try to guess how you did it. If it asked you to choose a coding system when you saved the file, then just don't choose one with -dos
in the name next time.
You probably have a file with mixed DOS/Unix carriage return characters.
If you do C-x-RET f
you can select the coding system you prefer. Then save the file and you should be all set.
C-h C RET RET
say? The most important thing is the first two lines (the coding system for saving this buffer). Please edit your question and add this information to it.