1

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?enter image description here

2
  • I figured out that calling delete-trailing-white-space will fix it when I open it. However, I am not sure how to prevent it from happening in the first place. Mar 2, 2021 at 5:08
  • Are you running on Linux/Unix/MacOS or are you running on Windows? What does 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.
    – NickD
    Mar 2, 2021 at 14:03

2 Answers 2

2

^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.

0

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.

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.