From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: how do you strip leading white spaces in c-mode or similar? Date: Fri, 06 Jul 2007 14:41:16 +0200 Message-ID: References: <1183595671.444536.287460@r34g2000hsd.googlegroups.com> <1183685346.183441.17470@n60g2000hse.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1183725695 28987 80.91.229.12 (6 Jul 2007 12:41:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 6 Jul 2007 12:41:35 +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 06 14:41:34 2007 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 1I6n7r-0001Qs-TY for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Jul 2007 14:41:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I6n7r-0006K1-DL for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Jul 2007 08:41:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I6n7c-0006Jj-VM for help-gnu-emacs@gnu.org; Fri, 06 Jul 2007 08:41:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I6n7a-0006JJ-O2 for help-gnu-emacs@gnu.org; Fri, 06 Jul 2007 08:41:15 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I6n7a-0006JG-Kq for help-gnu-emacs@gnu.org; Fri, 06 Jul 2007 08:41:14 -0400 Original-Received: from fmmailgate01.web.de ([217.72.192.221]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I6n7a-0003zq-7y for help-gnu-emacs@gnu.org; Fri, 06 Jul 2007 08:41:14 -0400 Original-Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate01.web.de (Postfix) with ESMTP id DEB048D46AE8 for ; Fri, 6 Jul 2007 14:41:12 +0200 (CEST) Original-Received: from [89.59.167.203] (helo=wednesday) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.108 #197) id 1I6n7Y-0004hQ-00 for help-gnu-emacs@gnu.org; Fri, 06 Jul 2007 14:41:12 +0200 In-Reply-To: <1183685346.183441.17470@n60g2000hse.googlegroups.com> (Johna's message of "Thu\, 05 Jul 2007 18\:29\:06 -0700") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin) X-Sender: n_schumacher@web.de X-Provags-ID: V01U2FsdGVkX1/E5Y8FDse2Wi4vs4Zeua0bQXluUWX/30wCTuKH GTblQXpxfm1igi0G6HJpsWbmjZlP1bQXh6CgCYBooxpAnEaFAw tWvS2zlBpJPmvPkHRq8A== X-detected-kernel: Linux 2.4-2.6 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:45506 Archived-At: Johna wrote: > On Jul 5, 1:48 pm, Peter Lee wrote: >> >>>> Johna writes: >> >> If you are only concerned about the extraneous spaces being persisted >> you could: >> >> (add-hook 'before-save-hook 'delete-trailing-whitespace t t) I used to do that. But just editing parts of a file and saving has a global effect, which seems like a bad thing for version-controlled files. It would be best to have a way to just prevent creating these accidental spaces. In fact newline-and-indent is smart enough to prevent them, when being used repeatedly. Most stray spaces thus appear after when moving the point after newline-and-indent ... Its easy enough to remove the spaces, if the next command moves the point away without further editing. But unfortunately this breaks some navigational commands (like search). I'm still looking for a good solution ... > Can you post a more complete example? for C dialects: (add-hook 'c-mode-common-hook (lambda () (add-hook 'before-save-hook 'delete-trailing-whitespace t t))) for all files (use with caution!): (add-hook 'before-save-hook 'delete-trailing-whitespace t) You might also be interested in `whitespace-global-mode'. > The white space usually is added when I press TAB and then ENTER > for those who wonder where it comes from. Why do you do that then? :) regards, Nikolaj Schumacher