all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to get rid of annoying ^M lineendings
@ 2008-04-22 13:50 olgo
  2008-04-22 14:13 ` Joost Kremers
  2008-04-23  4:59 ` Eli Zaretskii
  0 siblings, 2 replies; 10+ messages in thread
From: olgo @ 2008-04-22 13:50 UTC (permalink / raw)
  To: help-gnu-emacs

I keep reading solutions to this problem by means of substituting the
line endings with a global replace but this is not what I need.
I need for the files to be kept as they are, with all kinds of line
endings, but I don't want to see it in the editor.

Thus, my question is:
Is there a way to tell emacs not to show the ^M character altogether?

Thanks for any help,
/Ola


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

* Re: How to get rid of annoying ^M lineendings
  2008-04-22 13:50 How to get rid of annoying ^M lineendings olgo
@ 2008-04-22 14:13 ` Joost Kremers
  2008-04-23 16:39   ` Stefan Reichör
  2014-07-18  5:44   ` Michael Heerdegen
  2008-04-23  4:59 ` Eli Zaretskii
  1 sibling, 2 replies; 10+ messages in thread
From: Joost Kremers @ 2008-04-22 14:13 UTC (permalink / raw)
  To: help-gnu-emacs

olgo wrote:
> I keep reading solutions to this problem by means of substituting the
> line endings with a global replace but this is not what I need.
> I need for the files to be kept as they are, with all kinds of line
> endings, but I don't want to see it in the editor.
>
> Thus, my question is:
> Is there a way to tell emacs not to show the ^M character altogether?

IME this is only a problem when line endings in a file are not consistent.
so my advice would be to make sure each file only has one kind of line
ending, then emacs will simply detect the format correctly and will tell
you in the mode line you're editing a DOS file, and won't show the ^M
characters.


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


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

* Re: How to get rid of annoying ^M lineendings
  2008-04-22 13:50 How to get rid of annoying ^M lineendings olgo
  2008-04-22 14:13 ` Joost Kremers
@ 2008-04-23  4:59 ` Eli Zaretskii
  1 sibling, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2008-04-23  4:59 UTC (permalink / raw)
  To: help-gnu-emacs

> From: olgo <Ola.Gook@gmail.com>
> Date: Tue, 22 Apr 2008 06:50:49 -0700 (PDT)
> 
> I keep reading solutions to this problem by means of substituting the
> line endings with a global replace but this is not what I need.
> I need for the files to be kept as they are, with all kinds of line
> endings, but I don't want to see it in the editor.
> 
> Thus, my question is:
> Is there a way to tell emacs not to show the ^M character altogether?

This should happen automatically, unless you have a file with
inconsistent lineendings: some with ^M, others without.  Typing "C-x
RET c dos RET" immediately before "C-x C-f" that you use to visit the
file will cause Emacs to not display any ^M characters, even if the
lineendings are inconsistent, but if you edit that file and save it,
Emacs will add a ^M character to each line when it saves the file,
which might not be what you want in this case.

IOW, Emacs cannot remember whether there should be a ^M character on a
line by line basis, only for the whole file.




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

* Re: How to get rid of annoying ^M lineendings
  2008-04-22 14:13 ` Joost Kremers
@ 2008-04-23 16:39   ` Stefan Reichör
  2008-04-23 18:19     ` Drew Adams
  2014-07-17 20:51     ` scott.althoff
  2014-07-18  5:44   ` Michael Heerdegen
  1 sibling, 2 replies; 10+ messages in thread
From: Stefan Reichör @ 2008-04-23 16:39 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers <joostkremers@yahoo.com> writes:

> olgo wrote:
>> I keep reading solutions to this problem by means of substituting the
>> line endings with a global replace but this is not what I need.
>> I need for the files to be kept as they are, with all kinds of line
>> endings, but I don't want to see it in the editor.
>>
>> Thus, my question is:
>> Is there a way to tell emacs not to show the ^M character altogether?
>
> IME this is only a problem when line endings in a file are not consistent.
> so my advice would be to make sure each file only has one kind of line
> ending, then emacs will simply detect the format correctly and will tell
> you in the mode line you're editing a DOS file, and won't show the ^M
> characters.

I use the following function to remove the trailing ^M from such files:

(defun xsteve-remove-control-M ()
  "Remove ^M at end of line in the whole buffer."
  (interactive)
  (save-match-data
    (save-excursion
      (let ((remove-count 0))
        (goto-char (point-min))
        (while (re-search-forward "
$" (point-max) t)
          (setq remove-count (+ remove-count 1))
          (replace-match "" nil nil))
        (message (format "%d ^M removed from buffer." remove-count))))))


Stefan.
** Posted from http://www.teranews.com **


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

* RE: How to get rid of annoying ^M lineendings
  2008-04-23 16:39   ` Stefan Reichör
@ 2008-04-23 18:19     ` Drew Adams
  2014-07-17 20:51     ` scott.althoff
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2008-04-23 18:19 UTC (permalink / raw)
  To: 'Stefan Reichör', help-gnu-emacs

> I use the following function to remove the trailing ^M from 
> such files:

M-x replace-string RET C-q RET RET RET

or

C-M-% C-q RET RET RET !





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

* Re: How to get rid of annoying ^M lineendings
  2008-04-23 16:39   ` Stefan Reichör
  2008-04-23 18:19     ` Drew Adams
@ 2014-07-17 20:51     ` scott.althoff
  2014-07-17 22:31       ` Emanuel Berg
                         ` (2 more replies)
  1 sibling, 3 replies; 10+ messages in thread
From: scott.althoff @ 2014-07-17 20:51 UTC (permalink / raw)
  To: help-gnu-emacs

Is there a way to execute this every time emacs starts?

On Wednesday, April 23, 2008 11:39:24 AM UTC-5, Stefan Reichör wrote:
> Joost Kremers <joostkremers@yahoo.com> writes:
> 
> > olgo wrote:
> >> I keep reading solutions to this problem by means of substituting the
> >> line endings with a global replace but this is not what I need.
> >> I need for the files to be kept as they are, with all kinds of line
> >> endings, but I don't want to see it in the editor.
> >>
> >> Thus, my question is:
> >> Is there a way to tell emacs not to show the ^M character altogether?
> >
> > IME this is only a problem when line endings in a file are not consistent.
> > so my advice would be to make sure each file only has one kind of line
> > ending, then emacs will simply detect the format correctly and will tell
> > you in the mode line you're editing a DOS file, and won't show the ^M
> > characters.
> 
> I use the following function to remove the trailing ^M from such files:
> 
> (defun xsteve-remove-control-M ()
>   "Remove ^M at end of line in the whole buffer."
>   (interactive)
>   (save-match-data
>     (save-excursion
>       (let ((remove-count 0))
>         (goto-char (point-min))
>         (while (re-search-forward "
> $" (point-max) t)
>           (setq remove-count (+ remove-count 1))
>           (replace-match "" nil nil))
>         (message (format "%d ^M removed from buffer." remove-count))))))
> 
> 
> Stefan.
> ** Posted from http://www.teranews.com **



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

* Re: How to get rid of annoying ^M lineendings
  2014-07-17 20:51     ` scott.althoff
@ 2014-07-17 22:31       ` Emanuel Berg
  2014-07-18  5:53       ` Michael Heerdegen
  2014-07-18  6:52       ` Florian Lindner
  2 siblings, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2014-07-17 22:31 UTC (permalink / raw)
  To: help-gnu-emacs

scott.althoff@gmail.com writes:

> Is there a way to execute this every time emacs starts?

Yes, there are hooks: `emacs-startup-hook' - but isn't
this something that should rather go into
`find-file-hook' or perhaps `before-save-hook'?

Because if you use the Emacs startup hook, won't you
get the same situation whenever you `find-file' or the
like from Emacs, i.e., whenever you don't open files by
means of arguments to the emacs shell command?

Anyway, for example, I have

(untab-all delete-trailing-whitespace)

as `before-save-hook'. You could put a call there to
the function that removes those chars.

Hooks are a often an efficient-but-still poor-man's
solution. If you can do something without using them,
that is often better. In this case I can't tell. But if
there isn't an obvious better way to do it, sure, use
hooks.

-- 
underground experts united


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

* Re: How to get rid of annoying ^M lineendings
  2008-04-22 14:13 ` Joost Kremers
  2008-04-23 16:39   ` Stefan Reichör
@ 2014-07-18  5:44   ` Michael Heerdegen
  1 sibling, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2014-07-18  5:44 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers <joostkremers@yahoo.com> writes:

> IME this is only a problem when line endings in a file are not consistent.
> so my advice would be to make sure each file only has one kind of line
> ending, then emacs will simply detect the format correctly and will tell
> you in the mode line you're editing a DOS file, and won't show the ^M
> characters.

And if Emacs fails to detect the coding correctly:

   (info "(emacs) Specify Coding")


Michael.




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

* Re: How to get rid of annoying ^M lineendings
  2014-07-17 20:51     ` scott.althoff
  2014-07-17 22:31       ` Emanuel Berg
@ 2014-07-18  5:53       ` Michael Heerdegen
  2014-07-18  6:52       ` Florian Lindner
  2 siblings, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2014-07-18  5:53 UTC (permalink / raw)
  To: help-gnu-emacs

scott.althoff@gmail.com writes:

> Is there a way to execute this every time emacs starts?

Why do you want to do this?  Emacs handles different file encodings
automatically (the line end convention is part of the coding system).
Normally you don't need to do such things unless your files are garbled
wrt encoding.

If you always open files with the correct encoding - if Emacs guesses
the wrong encoding, you can force the right one:

   (info "(emacs) Specify Coding")

- then you don't ever need to perform any replacements in your files.


Michael.




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

* Re: How to get rid of annoying ^M lineendings
  2014-07-17 20:51     ` scott.althoff
  2014-07-17 22:31       ` Emanuel Berg
  2014-07-18  5:53       ` Michael Heerdegen
@ 2014-07-18  6:52       ` Florian Lindner
  2 siblings, 0 replies; 10+ messages in thread
From: Florian Lindner @ 2014-07-18  6:52 UTC (permalink / raw)
  To: help-gnu-emacs

scott.althoff@gmail.com wrote:

> Is there a way to execute this every time emacs starts?
> 
> On Wednesday, April 23, 2008 11:39:24 AM UTC-5, Stefan Reichör wrote:
>> Joost Kremers <joostkremers@yahoo.com> writes:
>> 
>> > olgo wrote:
>> >> I keep reading solutions to this problem by means of substituting the
>> >> line endings with a global replace but this is not what I need.
>> >> I need for the files to be kept as they are, with all kinds of line
>> >> endings, but I don't want to see it in the editor.
>> >>
>> >> Thus, my question is:
>> >> Is there a way to tell emacs not to show the ^M character altogether?
>> >
>> > IME this is only a problem when line endings in a file are not
>> > consistent. so my advice would be to make sure each file only has one
>> > kind of line ending, then emacs will simply detect the format correctly
>> > and will tell you in the mode line you're editing a DOS file, and won't
>> > show the ^M characters.
>> 
>> I use the following function to remove the trailing ^M from such files:
>> 
>> (defun xsteve-remove-control-M ()
>>   "Remove ^M at end of line in the whole buffer."
>>   (interactive)
>>   (save-match-data
>>     (save-excursion
>>       (let ((remove-count 0))
>>         (goto-char (point-min))
>>         (while (re-search-forward "
>> $" (point-max) t)
>>           (setq remove-count (+ remove-count 1))
>>           (replace-match "" nil nil))
>>         (message (format "%d ^M removed from buffer." remove-count))))))

For just hiding the ^M I have:

(defun hide-dos-eol ()
  "Do not show ^M in files containing mixed UNIX and DOS line endings."
  (interactive)
  (setq buffer-display-table (make-display-table))
  (aset buffer-display-table ?\^M []))

(add-hook 'prog-mode-hook 'hide-dos-eol)




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

end of thread, other threads:[~2014-07-18  6:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-22 13:50 How to get rid of annoying ^M lineendings olgo
2008-04-22 14:13 ` Joost Kremers
2008-04-23 16:39   ` Stefan Reichör
2008-04-23 18:19     ` Drew Adams
2014-07-17 20:51     ` scott.althoff
2014-07-17 22:31       ` Emanuel Berg
2014-07-18  5:53       ` Michael Heerdegen
2014-07-18  6:52       ` Florian Lindner
2014-07-18  5:44   ` Michael Heerdegen
2008-04-23  4:59 ` Eli Zaretskii

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.