I want to check if there is a "\r" at the end of a line of a plain text file (compressed as .gz file). I try the whitespace mode, and I don't find ^M shown. Is \r shown as ^M in whitespace mode?

enter image description here

But my python program says something is wrong with the 1 at the end of the second line

line 67, in transform
    vals = [eval(v) for v in line.replace('\n', '').split(',')]
  File "<string>", line 1
SyntaxError: unexpected EOF while parsing

Did I use emacs correctly to show the \r, \n and other characters at the end of each line? Thanks.

2 Answers 2


On the left side of the modeline, you'll see (DOS). This means that Emacs is viewing the buffer as if it had DOS-style line endings. To view the buffer as if it had Unix-style line endings, use the command revert-buffer-with-coding-system (bound to C-x RET r or C-x C-m r), and select something like utf-8-unix. Then the ^M characters will be visible.

Alternatively, if you want to convert the file to Unix-style line endings, use set-buffer-file-coding-system (C-x RET f/C-x C-m f) and choose utf-8-unix, then save the buffer.

From the Emacs manual, 22.6 Recognizing Coding Systems:

Emacs recognizes which kind of end-of-line conversion to use based on the contents of the file: if it sees only carriage-returns, or only carriage-return linefeed sequences, then it chooses the end-of-line conversion accordingly. You can inhibit the automatic use of end-of-line conversion by setting the variable inhibit-eol-conversion to non-nil. If you do that, DOS-style files will be displayed with the ‘^M’ characters visible in the buffer; some people prefer this to the more subtle ‘(DOS)’ end-of-line type indication near the left edge of the mode line (see eol-mnemonic).


  • Thanks. What caused emacs to use DOS instead of UNIX encoding to display the text file by default?
    – Tim
    Commented Apr 27, 2015 at 18:26
  • @Tim It's detected automatically.
    – nanny
    Commented Apr 27, 2015 at 18:29
  • @Tim I added in some info from the Emacs manual about changing this behavior.
    – nanny
    Commented Apr 27, 2015 at 18:39

To visualize newlines in emacs, activate whitespace-newline-mode, a minor mode associated with whitespace-mode.

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.