Don't display ^M characters with emacs [duplicate] Don't display ^M characters with emacs [duplicate] unix unix

Don't display ^M characters with emacs [duplicate]


I use the following function (forgot where I found it):

(defun hide-ctrl-M ()  "Hides the disturbing '^M' showing up in files containing mixed UNIX and DOS line endings."  (interactive)  (setq buffer-display-table (make-display-table))  (aset buffer-display-table ?\^M []))


The GNU Emacs documentation describes how to handle Text Coding using revert-buffer-with-coding-system:

C-x <RET> r coding <RET>Revisit the current file using the coding system coding (revert-buffer-with-coding-system).

In your case if the correct system coding isn't detected automatically you can type:

C-x RET r dos RET

to avoid displaying the ^M characters without actually modifying the file.


At least with emacs 22.3 this seems to be an issue only if your file has a combination of newline styles, say from editing with a "non-enlightened" editor under both windows unix.

If the lines are consistently terminated w/ ^M modern emacs will note at the bottom that it's [dos] mode and not show the ^M. It's then smart enough to place ^M in the file when you save.

If you've got some odd combination you can try running

$ unix2dos FILE

to get to a good state, after which hopefully you can keep it in DOS mode.

I note that my xemacs 21.4 doesn't have this feature, alas.

There's a discussion here:http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/676113e90825d4e7