8

Many versions ago, if you opened a dos-line-end file on Linux you would see the extra ^M codes. Now it automatically recognizes the situation and puts "DOS" in the info bar and hides the extra ^Ms.

How can I exit "DOS" mode and switch back to Unix mode? How can I disable the auto-detection and force the files to be opened with Unix line endings and the DOS CR shown as ^M?

agentp
  • 183
  • 6
  • 1
    So that none of us get confused, if the original poster could please verify what `major-mode` and what `minor-modes` are active in the buffer -- i.e., type `M-x describe-mode` and update the question with said information. In addition, please consider including a screen-shot and/or some detailed description as to what is meant by "**hides the extra codes**". At first read, I thought perhaps this has to do with a simple `M-x fundamental-mode` to exit whatever major-mode exists; and, I thought about deleting entry from the `auto-mode-alist` -- but now, I'm thinking just line endings dos/unix? – lawlist Aug 01 '16 at 18:27
  • Are you asking how to return to the buffer `^M` codes when opening dos-line-end file? – Konstantin Morenko Aug 01 '16 at 18:32

2 Answers2

7

From the https://www.emacswiki.org/emacs/EndOfLineTips

You can reopen the file with the correct line ending with a command like M-x revert-buffer-with-coding-system utf-8-dos. If your file is not in Unicode, be sure to specify the correct encoding system instead of utf-8-dos

Dos uses CR+LF end of line, when UNIX uses only LF. CR sometimes looks like ^M. For viewing ^M you must use M-x revert-buffer-with-coding-system utf-8-unix. This will use LF as end of line and indicate CR like ^M instead of Dos which uses CR+LF as end of line.

Disable autodetect: not sure it needs. If you want to convert files into UNIX format, then open DOS file and set line ending with M-x set-buffer-file-coding-system utf-8-unix, this command will convert all CR+LF into LF.

If you can edit the file, you could open file with a certain coding system with -*- coding: utf-8-unix; -*- at the first or second line in the file.

Konstantin Morenko
  • 1,407
  • 9
  • 19
  • `revert-buffer-with-coding-system` is exactly what i was after. I would like to have that applied automatically though. I guess there isn't really a compelling reason for it except that I only occasionally encounter dos files and I was used to that obvious visual cue of all the `^M`'s when I open one. – agentp Aug 01 '16 at 19:59
3

(emacs) Recognize Coding

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

npostavs
  • 9,033
  • 1
  • 21
  • 53