From: srihari
Subject: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <54e0b83c.0405070521.7bdf7d14@posting.google.com>
HI guys,
            I am having this problem for a long time. When I open  a
file  in emacs it adds an extra ^M character at the end of each line.
I want to get rid of this. Please tell me a way out.

Thank you

From: Eric Blood
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <c7hcg406h4@news3.newsguy.com>
srihari wrote:
>             I am having this problem for a long time. When I open  a
> file  in emacs it adds an extra ^M character at the end of each line.
> I want to get rid of this. Please tell me a way out.

M-x replace-string
C-q C-m <enter>
<enter>

-- 
eblood
From: Steven M. Haflich
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <kWMmc.6092$f36.1609@newssvr27.news.prodigy.com>
srihari wrote:

>             I am having this problem for a long time. When I open  a
> file  in emacs it adds an extra ^M character at the end of each line.
> I want to get rid of this. Please tell me a way out.

This is not a Lisp question, so it would be better to discuss it on one
of the Emacs lists.

Briefly, Emacs with Mule maintains a notion of what file encoding it
should use for visiting and writing a file.  The file coding embodies
among other things the line-terminator conventions of the file.  Unix,
and Emacs internally, use a single \linefeed.  Windows prefers the two
char \return \linefeed sequence.

Emacs heuristically figures out what encoding to use when it visits a
file, but the heuristic can fail if the file has inconsistent line
terminations.

First execute (apropos "file-coding") and see the documentation on
buffer-file-coding-system, file-coding-system-alist, and some of the
other related variables and functions.  You might decide to convert
the files to some consistent encoding, perhaps deleting all the \return,
with some external program like Unix tr.
From: Jock Cooper
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <m3r7twb1ev.fsf@jcooper02.sagepub.com>
"Steven M. Haflich" <·················@alum.mit.edu> writes:

> srihari wrote:
> 
> >             I am having this problem for a long time. When I open  a
> > file  in emacs it adds an extra ^M character at the end of each line.
> > I want to get rid of this. Please tell me a way out.
> 
> This is not a Lisp question, so it would be better to discuss it on one
> of the Emacs lists.
> 
> Briefly, Emacs with Mule maintains a notion of what file encoding it
> should use for visiting and writing a file.  The file coding embodies
> among other things the line-terminator conventions of the file.  Unix,
> and Emacs internally, use a single \linefeed.  Windows prefers the two
> char \return \linefeed sequence.
> 
> Emacs heuristically figures out what encoding to use when it visits a
> file, but the heuristic can fail if the file has inconsistent line
> terminations.
> 
> First execute (apropos "file-coding") and see the documentation on
> buffer-file-coding-system, file-coding-system-alist, and some of the
> other related variables and functions.  You might decide to convert
> the files to some consistent encoding, perhaps deleting all the \return,
> with some external program like Unix tr.

This is the correct answer.  The file you are editing has CRLF (for
some but not necessarily all lines) but emacs has decided the newline
sequence is just LF.. so any CRs are appearing as normal text.  You
have to find out why this is happening and fix that problem.

However, in the short term you can remove the ^Ms using:

Meta-X replace-string ^Q^M <ret><ret>

(use control-q and control-m, not caret q caret m)

control-Q quotes the carriage return 
From: Gerald Doussot
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <m2y8o3c2mk.fsf@jade.ice.org>
Try the following:

c-x ret f unix ret

Regards,
Gerald.
From: Wade Humeniuk
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <MnOmc.25251$LA4.22485@edtnps84>
srihari wrote:
> HI guys,
>             I am having this problem for a long time. When I open  a
> file  in emacs it adds an extra ^M character at the end of each line.
> I want to get rid of this. Please tell me a way out.
> 
> Thank you

Usually brute force, I use the emacs replace-string? function.
When it prompts for the string to replace I copy and yank the ^M from the buffer
into the mini-buffer prompt and then replace it with the empty string.
There is probably some better emacs way, you should probably ask in
an emacs newsgroup.

Wade
From: Edi Weitz
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <m3fzac43jm.fsf@bird.agharta.de>
On Fri, 07 May 2004 15:59:40 GMT, Wade Humeniuk <········@telus.delete.net> wrote:

> Usually brute force, I use the emacs replace-string? function.  When
> it prompts for the string to replace I copy and yank the ^M from the
> buffer into the mini-buffer prompt

You can type C-q C-m instead.
From: Jeff Sandys
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <409BBCA7.1B915812@juno.com>
This is in my .emacs file, just M-x d2u to the buffer.

;;;---------------------------------------
;;; Delete all the control-M's from windows files
;;;
(defun d2u ()
  (interactive)
  (beginning-of-buffer)
  (while (search-forward "\r" nil t)
    (replace-match "" nil t)))


This is a common problem when using dos/windows files.

Thanks,
Jeff Sandys

srihari wrote:
> 
> HI guys,
>             I am having this problem for a long time. When I open  a
> file  in emacs it adds an extra ^M character at the end of each line.
> I want to get rid of this. Please tell me a way out.
> 
> Thank you
From: Jacek Generowicz
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <tyfzn8kqkrn.fsf@pcepsft001.cern.ch>
···········@yahoo.com (srihari) writes:

> HI guys,
>             I am having this problem for a long time. When I open  a
> file  in emacs it adds an extra ^M character at the end of each line.
> I want to get rid of this. Please tell me a way out.

A few years ago, sharing a filesystem with Windows users somehow made
this happen very regularly to me (whenever the file was modified on
Windoze, it would put back the extra returns). So I wrote the following,
which seemed to sufficient for my needs:


(defun dos-to-unix ()
  "Translate contents of buffer from dos format to unix format
Replace \r\n with \n."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while
	(search-forward "\r\n" () t)
      (replace-match "\n"))
    ()))
From: Thomas A. Russ
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <ymiekpss061.fsf@sevak.isi.edu>
···········@yahoo.com (srihari) writes:

> 
> HI guys,
>             I am having this problem for a long time. When I open  a
> file  in emacs it adds an extra ^M character at the end of each line.

Actually, it isn't adding extra ^M characters.  It is just displaying
the ones that are already there.

> I want to get rid of this. Please tell me a way out.

The other suggestions told you how to modify the file contents to remove
half of the Windows/DOS line ending pair of carriage-return line-feed.
(^M is carriage return).  Emacs, being unix-centric uses only the
line feed (or ^J) as its line terminator.

You can, of course, change the file, but then I suspect that if you want
to use that file with other windows-based programs, they will not
recognize the line breaks.  On the other hand, if you are moving the
files to Unix from a Windows system you may, in fact, want that.  But
you need to be clear about what you are doing.

A more useful thing to do would be to locate one of the emacs libraries
that actually knows how to handle other line ending formats such as DOS
or Macintosh.  Then it will be transformed for display only, but always
written back in the format in question.  Unfortunately, I can't seem to
locate the library that does that for my installed Emacs, but perhaps
someone else can provide a pointer.

> Thank you

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Bruce Hoult
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <bruce-7CAC45.09075111052004@copper.ipg.tsnz.net>
In article <···············@sevak.isi.edu>,
 ···@sevak.isi.edu (Thomas A. Russ) wrote:

> A more useful thing to do would be to locate one of the emacs libraries
> that actually knows how to handle other line ending formats such as DOS
> or Macintosh.  Then it will be transformed for display only, but always
> written back in the format in question.  Unfortunately, I can't seem to
> locate the library that does that for my installed Emacs, but perhaps
> someone else can provide a pointer.

I've always found that emacs does this totally automatically, without 
any external library.  You don't even know unless you notice the (DOS) 
or (Mac) on the left of the status line.

-- Bruce
From: Harald Hanche-Olsen
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <pco3c66kal5.fsf@shuttle.math.ntnu.no>
+ Bruce Hoult <·····@hoult.org>:

| > [...] how to handle other line ending formats such as DOS or
| > Macintosh.
| 
| I've always found that emacs does this totally automatically,
| without any external library.  You don't even know unless you notice
| the (DOS) or (Mac) on the left of the status line.

"Always" is a strong word to use on a newsgroup populated by old
geezers who have used emacs since version 18, if not before.  As far
as I can tell, emacs acquired this functionality with version 20.1 (if
the NEWS file is any indication).

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow
From: Bruce Hoult
Subject: Re: how to remove the adjunct ^M at the end of every line in emacs
Date: 
Message-ID: <bruce-BC3EF1.19134112052004@copper.ipg.tsnz.net>
In article <···············@shuttle.math.ntnu.no>,
 Harald Hanche-Olsen <······@math.ntnu.no> wrote:

> + Bruce Hoult <·····@hoult.org>:
> 
> | > [...] how to handle other line ending formats such as DOS or
> | > Macintosh.
> | 
> | I've always found that emacs does this totally automatically,
> | without any external library.  You don't even know unless you notice
> | the (DOS) or (Mac) on the left of the status line.
> 
> "Always" is a strong word to use on a newsgroup populated by old
> geezers who have used emacs since version 18, if not before.  As far
> as I can tell, emacs acquired this functionality with version 20.1 (if
> the NEWS file is any indication).

My apologies to the geezers.  I seem to recall using emacs 19 way back 
when with files moved cross platform via translation mechanisms such as 
FTP and CVS, but I guess it's only fairly recently that I've been using 
it on a system (OSX) where any random text file could have either Mac or 
Unix line endings.

-- Bruce