November 28, 2006

Newbie Emacs tip: In a text file, the end of a line is stored in one of three ways, depending on the environment in which the file was created. Windows continues to use the old DOS-style of ending lines with two bytes: a carriage return (CR, ASCII 13) and a linefeed (LF, ASCII 10). Unix environments use just a linefeed, and older Macs used to use just the carriage return. Emacs helpfully tries to detect which style a file is using automatically, and preserve the style unless told to do otherwise. If the current buffer uses the DOS-style, "(DOS)" appears in the Emacs modeline.

To change the end-of-line encoding style for a buffer from DOS to Unix, type C-x <RET> f unix <RET>. If you save the buffer to a file (C-x C-s), the file will use Unix-style end-of-line encoding.