Emacs: unix coding in windows

Sometimes ago I posted how to convert a unix file into a dos one and vice versa. This works great on new empty file but cannot work on a already saved file.

What I noticed is that if you are on a windows box and open a unix encoded file you’ll have a lot of ^M character at the end of the line. In my case some rows had only one ^M other more than three. If you use the method described in my previous post

C-x RET f undecided-dos
C-x C-s
C-x C-c

and then reopen the file, you will notice that the file coding is still unix. I think that is because emacs detect the conding type by the first(s) EOL. So first you have to clear the file, then convert the file coding, save, exit and reopen the file.

First let’s define a macro for cleaning the EOL

C-x (
C-a  C-s C-q 15 RET RET C-b C-k C-n
C-x )

Let’s now try it on a new line

C-x e

if It works (I’ve typed it by memory not tested) let’s do the whole file

C-u 1000 C-e

If there are more lines repeat the command 🙂

Save, exit and reload.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s