help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how do you strip leading white spaces in c-mode or similar?


From: Nikolaj Schumacher
Subject: Re: how do you strip leading white spaces in c-mode or similar?
Date: Fri, 06 Jul 2007 14:41:16 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin)

Johna <nnn4431@mailc.net> wrote:

> On Jul 5, 1:48 pm, Peter Lee <pete.a....@gmail.com> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]