all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ^M characters
@ 2008-10-22 20:29 Corey Foote
  2008-10-22 20:43 ` Parker, Matthew
  0 siblings, 1 reply; 6+ messages in thread
From: Corey Foote @ 2008-10-22 20:29 UTC (permalink / raw
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 450 bytes --]


I copied some text into an email buffer, but
each line ends with a funny colored character that looks like ^M. What are
these characters? How can I remove them without having to manually delete each
one? And how can I insert one myself?
_________________________________________________________________
Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008

[-- Attachment #2: Type: text/html, Size: 697 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: ^M characters
  2008-10-22 20:29 ^M characters Corey Foote
@ 2008-10-22 20:43 ` Parker, Matthew
  0 siblings, 0 replies; 6+ messages in thread
From: Parker, Matthew @ 2008-10-22 20:43 UTC (permalink / raw
  To: Corey Foote, help-gnu-emacs


Control-Q Control-M will create this character, so will Control-Q and RETURN key... 

which you can enter into the buffer to create or into M-x query-replace-regexp to do a search/replace

BTW, control-Q is the quoting command




-----Original Message-----
From: help-gnu-emacs-bounces+mparker=seic.com@gnu.org on behalf of Corey Foote
Sent: Wed 10/22/2008 4:29 PM
To: help-gnu-emacs@gnu.org
Subject: ^M characters
 

I copied some text into an email buffer, but
each line ends with a funny colored character that looks like ^M. What are
these characters? How can I remove them without having to manually delete each
one? And how can I insert one myself?
_________________________________________________________________
Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ^M characters
       [not found] <mailman.1834.1224707393.25473.help-gnu-emacs@gnu.org>
@ 2008-10-22 21:25 ` Xah
  2008-10-22 23:32   ` Mike Treseler
  0 siblings, 1 reply; 6+ messages in thread
From: Xah @ 2008-10-22 21:25 UTC (permalink / raw
  To: help-gnu-emacs

On Oct 22, 1:29 pm, Corey Foote <coreyfo...@hotmail.com> wrote:
> I copied some text into an email buffer, but
> each line ends with a funny colored character that looks like ^M. What are
> 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. “query-replace”), 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 “Alt+x set-buffer-file-coding-system” (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↗
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 “Alt+x eval-region”. 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 “Alt+x eval-region”, then “Alt+x dired”, then
press “m” to mark the files you want, then do “Alt+x dired-dos2unix-
marked-files”.

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ^M characters
  2008-10-22 21:25 ` Xah
@ 2008-10-22 23:32   ` Mike Treseler
  2008-10-23 19:55     ` Mike Treseler
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Treseler @ 2008-10-22 23:32 UTC (permalink / raw
  To: help-gnu-emacs

Xah wrote:

> 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.

When I run across such a text file,
I use hex-mode to see what is going on.
In every case I have seen, the problem
is due to a malformed end-of-line pattern.

Emacs recognizes and hides standard end-of-line patterns
if they are use consistently.

MAC-like  (CR)
DOS-like  (CR+LF)
Unix-like (LF)

Corey's file probably has the end-of-line pattern
CR+CR+LF where the first CR is printed ^M
while the CR+LF is interpreted as a DOS end-of-line and hidden.

In this case I would do

(buffer-to-unix)

to fix up the end-of-lines
and then a query-replace of the ^M characters to nothing.

       -- Mike Treseler

Corey, see also:
http://www.rfc-editor.org/EOLstory.txt
http://en.wikipedia.org/wiki/Newline


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ^M characters
@ 2008-10-23  9:49 roodwriter
  0 siblings, 0 replies; 6+ messages in thread
From: roodwriter @ 2008-10-23  9:49 UTC (permalink / raw
  To: help-gnu-emacs

Corey Foote <coreyfoote@hotmail.com> writes:

> I copied some text into an email buffer, but each line ends with 
a funny
> colored character that looks like ^M. What are these characters? 
How can I
> remove them without having to manually delete each one?  And how 
can I
> insert one myself?
> 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> Stay organized with simple drag and drop from Windows Live 
Hotmail. Try it


I'm lazy. I just copy the ^M and then uses M-x replace-regexp. I 
paste (yank) the ^M into the command, hit <return> twice and let 
it rip. All gone faster than you can read this.

Once upon a time I made a macro that did this, but I rarely get 
Microsoft files anymore. (I use Linux.) They may have started out 
as Microsoft, but e-mail programs seem to convert them better now.

Rod



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ^M characters
  2008-10-22 23:32   ` Mike Treseler
@ 2008-10-23 19:55     ` Mike Treseler
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Treseler @ 2008-10-23 19:55 UTC (permalink / raw
  To: help-gnu-emacs

Mike Treseler wrote:

> (buffer-to-unix)

(defun buffer-to-unix () "Change buffer coding to unix"
  (interactive)
  (set-buffer-file-coding-system 'undecided-unix)
  )


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-10-23 19:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-22 20:29 ^M characters Corey Foote
2008-10-22 20:43 ` Parker, Matthew
     [not found] <mailman.1834.1224707393.25473.help-gnu-emacs@gnu.org>
2008-10-22 21:25 ` Xah
2008-10-22 23:32   ` Mike Treseler
2008-10-23 19:55     ` Mike Treseler
  -- strict thread matches above, loose matches on Subject: below --
2008-10-23  9:49 roodwriter

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.