I'm writing a config file and I need to define if the process expects a windows format file or a unix format file. I've got a copy of the expected file - is there a way I can check if it uses \n or \r\n without exiting emacs?
A:
Open the file in emacs using find-file-literally. If lines have ^M symbols at the end, it expects a windows format text file.
Chris
2008-10-24 17:30:50
This assumes you're not running on Windows. There, the modeline would be \ for \r\n or (Unix) for \n.
cjm
2008-10-24 18:20:24
Surely the OP wants a programmatic solution and not a visual inspection of the modeline?
Chris Conway
2008-10-24 20:51:27
Nope! wanted a visual one, although the elsip is nice to have.
kanja
2009-03-05 21:50:49
A:
The following Elisp function will return nil
if no "\r\n"
terminators appear in a file (otherwise it returns the point of the first occurrence). You can put it in your .emacs
and call it with M-x check-eol
.
(defun check-eol (FILE)
(interactive "fFile: ")
(set-buffer (generate-new-buffer "*check-eol*"))
(insert-file-contents-literally FILE)
(let ((point (search-forward "\r\n")))
(kill-buffer nil)
point))
Chris Conway
2008-10-24 18:11:14
But modern versions of Emacs convert CRLF to LF when loading (and back when saving), so you won't have any \r characters in your buffer. You need to check the buffer's coding system.
cjm
2008-10-24 18:18:23
A:
If you go in hexl-mode (M-x hexl-mode), you shoul see the line termination bytes.
stephanea
2008-10-24 19:39:23