Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am wondering if there is a way to temporarily not display the ^M characters in a file. I don't want to remove them I just want to not display them.

Cheers,

like image 939
Chmouel Boudjnah Avatar asked Jun 15 '10 20:06

Chmouel Boudjnah


2 Answers

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 []))
like image 121
Otto Pichlhoefer Avatar answered Oct 09 '22 02:10

Otto Pichlhoefer


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.

like image 21
aculich Avatar answered Oct 09 '22 02:10

aculich