From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Newsgroups: gmane.emacs.help Subject: Re: ^M characters Date: Wed, 22 Oct 2008 14:25:02 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6f700367-8aa9-4112-bdbb-59ea98f809b5@f37g2000pri.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1224711739 30159 80.91.229.12 (22 Oct 2008 21:42:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Oct 2008 21:42:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 22 23:43:19 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KslU7-0002XI-71 for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Oct 2008 23:43:19 +0200 Original-Received: from localhost ([127.0.0.1]:32970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KslT1-0001Bv-PN for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Oct 2008 17:42:11 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!postnews.google.com!f37g2000pri.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 87 Original-NNTP-Posting-Host: 24.6.185.159 Original-X-Trace: posting.google.com 1224710703 25691 127.0.0.1 (22 Oct 2008 21:25:03 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 22 Oct 2008 21:25:03 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f37g2000pri.googlegroups.com; posting-host=24.6.185.159; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.22, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:163709 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:59050 Archived-At: On Oct 22, 1:29 pm, Corey Foote wrote: > I copied some text into an email buffer, but > each line ends with a funny colored character that looks like ^M. What ar= e > these characters? How can I remove them without having to manually delete= each > one? And how can I insert one myself? ^M is a standard notation for the ascii 13 char named Carriage Return. Today, this notation has fallen out of use, unfamiliar to probably 99% of professional programers. For detail, see: The Confusion of Emacs's Keystroke Representation http://xahlee.org/emacs/keystroke_rep.html When you paste some code involving different EOL char, most editor deal with this by simply converting them to your current EOL. Usually they have a preference setting to indicate whether you want this to happen automatically or literal. I think emacs should also adapt this behavior. To replace these unprintable chars, you can use any of the emacs's find/replace command (e.g. =E2=80=9Cquery-replace=E2=80=9D), and type Ctrl+= q when you want to input unprintable or un-typable chars. Alternatively, you can change the buffer's file encoding. See: Q: How to change file line endings between Mac/Dos/Unix? A: Open the file, then do =E2=80=9CAlt+x set-buffer-file-coding-system=E2= =80=9D (Ctrl- x RET f). Give it a value of mac, dos, unix. Then, when you save the file, it'll be saved with the proper encoding for newlines. Note: Unixes (including Linuxes and Mac OS X) uses LF (ascii 10; line feed) for newline. Mac OS Classic uses CR (ascii 13; carriage return) for newline. (Mac OS X prefers LF but accepts CR too) Windows uses CR followed by LF ("\r\n") for its newline char. See wikipedia newline=E2=86= =97 for detail. To do it batch on a list of files, use the following lisp code: (defun to-unix-eol (fpath) "Change file's line ending to unix convention." (let (mybuffer) (setq mybuffer (find-file fpath)) (set-buffer-file-coding-system 'unix) ; or 'mac or 'dos (save-buffer) (kill-buffer mybuffer) ) ) (mapc 'to-unix-eol (list "~/jane/myfile1" "~/jane/myfile2" "~/jane/myfile3" ; ... ) ) To use the code, first edit the list of files above. Then, select all the code, type =E2=80=9CAlt+x eval-region=E2=80=9D. That's it. If you want the function to work on marked files in dired, then use the following code: (defun dired-2unix-marked-files () "Change to unix line ending for marked (or next arg) files." (interactive) (mapc 'to-unix-eol (dired-get-marked-files)) ) Select the code and do =E2=80=9CAlt+x eval-region=E2=80=9D, then =E2=80=9CA= lt+x dired=E2=80=9D, then press =E2=80=9Cm=E2=80=9D to mark the files you want, then do =E2=80=9CAlt+= x dired-dos2unix- marked-files=E2=80=9D. Xah =E2=88=91 http://xahlee.org/ =E2=98=84