From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Florian Lindner Newsgroups: gmane.emacs.help Subject: Re: How to get rid of annoying ^M lineendings Date: Fri, 18 Jul 2014 08:52:15 +0200 Message-ID: References: <227a76ea-99a0-44cd-bb5f-e6c7b328e347@e67g2000hsa.googlegroups.com> <877ieoa5kz.fsf@xsteve.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: ger.gmane.org 1405666392 6853 80.91.229.3 (18 Jul 2014 06:53:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 18 Jul 2014 06:53:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 18 08:53:05 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1X822M-0004wR-RE for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Jul 2014 08:52:58 +0200 Original-Received: from localhost ([::1]:48306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X822M-00032M-Ee for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Jul 2014 02:52:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8226-00032A-6e for help-gnu-emacs@gnu.org; Fri, 18 Jul 2014 02:52:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X821y-00064D-Mm for help-gnu-emacs@gnu.org; Fri, 18 Jul 2014 02:52:42 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:60884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X821y-000641-Fg for help-gnu-emacs@gnu.org; Fri, 18 Jul 2014 02:52:34 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1X821v-0004jk-NX for help-gnu-emacs@gnu.org; Fri, 18 Jul 2014 08:52:31 +0200 Original-Received: from lapsgs09.informatik.uni-stuttgart.de ([129.69.213.139]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Jul 2014 08:52:31 +0200 Original-Received: from mailinglists by lapsgs09.informatik.uni-stuttgart.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Jul 2014 08:52:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 46 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: lapsgs09.informatik.uni-stuttgart.de User-Agent: KNode/4.13.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:98740 Archived-At: 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 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)