help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to remove strange return-commands ?


From: Richard V. Molen
Subject: Re: How to remove strange return-commands ?
Date: 08 Oct 2002 08:21:18 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

>> I want to get some files from noEmacs-windows-editors into Linux GNU
>> Emacs Editor.
>> 
>> But you cannot work because of "strange" return-commands from windows
>> in these files (->  ^M ).
>> 
>> How it's possible to remove/replace these commands with Emacs or any
>> other tools in Unix-Systems ?
>> (with the Emacs-replace-function you cannot find ^M)

"Bingham, Jay" <Jay.Bingham@hp.com> writes:

> Those are carriage return characters (decimal value 13).  If you
> were searching for an up arrow (shift 6) followed by an M emacs will
> not match that with a carriage return.
> Try this to match them:  C-Q C-M
> This will insert a carriage return character into the search string.

I made a keyboard macro out of this which removes all ^M and saves the file.

;strip MS-DOS carriage return from file thus:
;1. goto top of file, 2. S-M-% C-Q C-M <RET> <RET> ! 3. C-x s
(fset 'stripCR
   [home ?\M-% ?\C-q ?\C-m return return ?! ?\C-x ?\C-s])
(global-set-key [f11] 'stripCR)

> 
> I have seen much discussion on removing these from a buffer.  I am
> certain that there are many packages available to do this.  Since I
> wrote my own function before I discovered emacs packages I have not
> paid much attention to them.  You might want to take a look at the
> packages list at http://www.emacswiki.org/elisp/.  Or you could look
> in the archives of this list.  (My function is not quite ready for
> primetime).
> 

For RedHat & Cygwin the dos2unix utility works nicely.  When uploading bash
scripts (for instance) from an M$ box to a RH Linux box, I run...
     dos2unix -k *.sh
...and that removes the carriage returns from all scripts ending in '.sh'.

Other *nix OSes use something else as I noticed in a post in this
group some time in the past month.

-- 
Richard V. Molen

Warning!!
Signature under construction, safety glasses required.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]