8

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

Tim
  • 4,987
  • 7
  • 31
  • 60

1 Answers1

12

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

http://www.gnu.org/software/emacs/manual/html_node/emacs/Recognize-Coding.html

nanny
  • 5,704
  • 18
  • 38