all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nikolaj Schumacher <n_schumacher@web.de>
To: help-gnu-emacs@gnu.org
Subject: Re: how do you strip leading white spaces in c-mode or similar?
Date: Fri, 06 Jul 2007 14:41:16 +0200	[thread overview]
Message-ID: <m2lkdthfgz.fsf@nschum.de> (raw)
In-Reply-To: <1183685346.183441.17470@n60g2000hse.googlegroups.com> (Johna's message of "Thu\, 05 Jul 2007 18\:29\:06 -0700")

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

      parent reply	other threads:[~2007-07-06 12:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-05  0:34 how do you strip leading white spaces in c-mode or similar? Johna
2007-07-05  8:49 ` brianjiang
2007-07-05 13:20 ` Eli Zaretskii
2007-07-05 17:48 ` Peter Lee
2007-07-06  1:29   ` Johna
2007-07-06 10:35     ` Tassilo Horn
2007-07-06 12:32       ` Eli Zaretskii
2007-07-06 12:48         ` Nikolaj Schumacher
2007-07-06 15:52           ` Eli Zaretskii
2007-07-08  9:16             ` Nikolaj Schumacher
2007-07-06 12:41     ` Nikolaj Schumacher [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2lkdthfgz.fsf@nschum.de \
    --to=n_schumacher@web.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.