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

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 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. – Patrick Ryan Mar 02 '21 at 05: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 02 '21 at 14:03

2 Answers2

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.

db48x
  • 15,741
  • 1
  • 19
  • 23
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.

point618
  • 233
  • 1
  • 8