all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how do you strip leading white spaces in c-mode or similar?
@ 2007-07-05  0:34 Johna
  2007-07-05  8:49 ` brianjiang
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Johna @ 2007-07-05  0:34 UTC (permalink / raw)
  To: help-gnu-emacs

Hi, I googled around to no avail.
Basically I am frustrated with the default indentation in c-mode (or
similar modes)
because it inserts unnecessary white space(s) on empty lines.
I want all empty lines to contain nothing but '\n'.
Instead they contain "\n\t" or "\n    ".
The preferred solution that I am looking for is a way to inhibit white
space insertion
on empty lines across all modes that have anything to do with
programming languages.

Example:
------------------------------------
int foo(int x)
{
      int y = x/2;

// the preceding empty line contains superfluous and annoying white
space!
      return y;
}
-------------------------------------

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

* RE: how do you strip leading white spaces in c-mode or similar?
  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
  2 siblings, 0 replies; 11+ messages in thread
From: brianjiang @ 2007-07-05  8:49 UTC (permalink / raw)
  To: help-gnu-emacs

 
Try this:
delete-trailing-whitespace


-----Original Message-----
From: help-gnu-emacs-bounces+brianjiang=gdnt.com.cn@gnu.org [mailto:help-gnu-emacs-bounces+brianjiang=gdnt.com.cn@gnu.org] On Behalf Of Johna
Sent: 2007年7月5日 8:35
To: help-gnu-emacs@gnu.org
Subject: how do you strip leading white spaces in c-mode or similar?

Hi, I googled around to no avail.
Basically I am frustrated with the default indentation in c-mode (or similar modes) because it inserts unnecessary white space(s) on empty lines.
I want all empty lines to contain nothing but '\n'.
Instead they contain "\n\t" or "\n    ".
The preferred solution that I am looking for is a way to inhibit white space insertion on empty lines across all modes that have anything to do with programming languages.

Example:
------------------------------------
int foo(int x)
{
      int y = x/2;

// the preceding empty line contains superfluous and annoying white space!
      return y;
}
-------------------------------------

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: how do you strip leading white spaces in c-mode or similar?
  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
  2 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2007-07-05 13:20 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Johna <nnn4431@mailc.net>
> Newsgroups: gnu.emacs.help
> Date: Wed, 04 Jul 2007 17:34:31 -0700
> 
> Basically I am frustrated with the default indentation in c-mode (or
> similar modes)
> because it inserts unnecessary white space(s) on empty lines.

Not in Emacs, it doesn't.  At least not for me.  That is, when I type
C-j, Emacs does indeed insert indentation, but if I then type another
C-j, the whitespace is removed.

If this does not work for you, please show a sequence of keystrokes
that cause such excess whitespace to appear on empty lines, perhaps
I'm missing something.

> Example:
> ------------------------------------
> int foo(int x)
> {
>       int y = x/2;
> 
> // the preceding empty line contains superfluous and annoying white
> space!

No, it doesn't, at least not in the message you sent.

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

* Re: how do you strip leading white spaces in c-mode or similar?
  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
  2 siblings, 1 reply; 11+ messages in thread
From: Peter Lee @ 2007-07-05 17:48 UTC (permalink / raw)
  To: help-gnu-emacs

>>>> Johna  writes:

    > Basically I am frustrated with the default indentation in c-mode (or
    > similar modes) because it inserts unnecessary white space(s) on empty
    > lines.  I want all empty lines to contain nothing but '\n'.  Instead they
    > contain "\n\t" or "\n ".

If you are only concerned about the extraneous spaces being persisted you could:

insert

(add-hook 'before-save-hook 'delete-trailing-whitespace t t)

into your mode-hook... which will strip them on each save.

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

* Re: how do you strip leading white spaces in c-mode or similar?
  2007-07-05 17:48 ` Peter Lee
@ 2007-07-06  1:29   ` Johna
  2007-07-06 10:35     ` Tassilo Horn
  2007-07-06 12:41     ` Nikolaj Schumacher
  0 siblings, 2 replies; 11+ messages in thread
From: Johna @ 2007-07-06  1:29 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 5, 1:48 pm, Peter Lee <pete.a....@gmail.com> wrote:
> >>>> Johna  writes:
>
>     > Basically I am frustrated with the default indentation in c-mode (or
>     > similar modes) because it inserts unnecessary white space(s) on empty
>     > lines.  I want all empty lines to contain nothing but '\n'.  Instead they
>     > contain "\n\t" or "\n ".
>
> If you are only concerned about the extraneous spaces being persisted you could:
>
> insert
>
> (add-hook 'before-save-hook 'delete-trailing-whitespace t t)
>
> into your mode-hook... which will strip them on each save.

Sorry I am too dumb to do that.
Can you post a more complete example?
I added the above line to the end of my .emacs file, restarted emacs
but it had no effect.

The white space usually is added when I press TAB and then ENTER
for those who wonder where it comes from.

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

* Re: how do you strip leading white spaces in c-mode or similar?
  2007-07-06  1:29   ` Johna
@ 2007-07-06 10:35     ` Tassilo Horn
  2007-07-06 12:32       ` Eli Zaretskii
  2007-07-06 12:41     ` Nikolaj Schumacher
  1 sibling, 1 reply; 11+ messages in thread
From: Tassilo Horn @ 2007-07-06 10:35 UTC (permalink / raw)
  To: help-gnu-emacs

Johna <nnn4431@mailc.net> writes:

Hi Johna,

>> insert
>>
>> (add-hook 'before-save-hook 'delete-trailing-whitespace t t)
>>
>> into your mode-hook... which will strip them on each save.
>
> Sorry I am too dumb to do that.
> Can you post a more complete example?

That is complete.

> I added the above line to the end of my .emacs file, restarted emacs
> but it had no effect.

That's all what is needed. As soon as you save the file, all trailing
whitespaces will be deleted.

> The white space usually is added when I press TAB and then ENTER
> for those who wonder where it comes from.

That's strange, anyway. Here, my emacs (22.1) removes trailing
whitespaces in the current line as soon as I go to the next line...

Bye,
Tassilo
-- 
The  desire  to  be  rewarded  for one's  creativity  does  not  justify
depriving  the world  in  general of  all  or part  of that  creativity.
(Richard M. Stallman)

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

* Re: how do you strip leading white spaces in c-mode or similar?
  2007-07-06 10:35     ` Tassilo Horn
@ 2007-07-06 12:32       ` Eli Zaretskii
  2007-07-06 12:48         ` Nikolaj Schumacher
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2007-07-06 12:32 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Tassilo Horn <tassilo@member.fsf.org>
> Date: Fri, 06 Jul 2007 12:35:12 +0200
> 
> > The white space usually is added when I press TAB and then ENTER
> > for those who wonder where it comes from.
> 
> That's strange, anyway. Here, my emacs (22.1) removes trailing
> whitespaces in the current line as soon as I go to the next line...

It does that for me, too.

Johna, could you please check if the problem goes away in Emacs
invoked with "emacs -Q"?  If it does, then the problem is in some
setting within your .emacs init file.

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

* Re: how do you strip leading white spaces in c-mode or similar?
  2007-07-06  1:29   ` Johna
  2007-07-06 10:35     ` Tassilo Horn
@ 2007-07-06 12:41     ` Nikolaj Schumacher
  1 sibling, 0 replies; 11+ messages in thread
From: Nikolaj Schumacher @ 2007-07-06 12:41 UTC (permalink / raw)
  To: help-gnu-emacs

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

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

* Re: how do you strip leading white spaces in c-mode or similar?
  2007-07-06 12:32       ` Eli Zaretskii
@ 2007-07-06 12:48         ` Nikolaj Schumacher
  2007-07-06 15:52           ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Nikolaj Schumacher @ 2007-07-06 12:48 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Tassilo Horn <tassilo@member.fsf.org>
>> Date: Fri, 06 Jul 2007 12:35:12 +0200
>> 
>> That's strange, anyway. Here, my emacs (22.1) removes trailing
>> whitespaces in the current line as soon as I go to the next line...
>
> It does that for me, too.

`newline' doesn't.  Only `newline-and-indent' does.

regards,
Nikolaj Schumacher

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

* Re: how do you strip leading white spaces in c-mode or similar?
  2007-07-06 12:48         ` Nikolaj Schumacher
@ 2007-07-06 15:52           ` Eli Zaretskii
  2007-07-08  9:16             ` Nikolaj Schumacher
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2007-07-06 15:52 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Nikolaj Schumacher <n_schumacher@web.de>
> Date: Fri, 06 Jul 2007 14:48:38 +0200
> 
> Eli Zaretskii <eliz@gnu.org> wrote:
> 
> >> From: Tassilo Horn <tassilo@member.fsf.org>
> >> Date: Fri, 06 Jul 2007 12:35:12 +0200
> >> 
> >> That's strange, anyway. Here, my emacs (22.1) removes trailing
> >> whitespaces in the current line as soon as I go to the next line...
> >
> > It does that for me, too.
> 
> `newline' doesn't.  Only `newline-and-indent' does.

Why should anyone use `newline' instead of `newline-and-indent'?

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

* Re: how do you strip leading white spaces in c-mode or similar?
  2007-07-06 15:52           ` Eli Zaretskii
@ 2007-07-08  9:16             ` Nikolaj Schumacher
  0 siblings, 0 replies; 11+ messages in thread
From: Nikolaj Schumacher @ 2007-07-08  9:16 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Nikolaj Schumacher <n_schumacher@web.de>
>> Date: Fri, 06 Jul 2007 14:48:38 +0200
>> 
>> Eli Zaretskii <eliz@gnu.org> wrote:
>> 
>> >> From: Tassilo Horn <tassilo@member.fsf.org>
>> >> Date: Fri, 06 Jul 2007 12:35:12 +0200
>> >> 
>> >> That's strange, anyway. Here, my emacs (22.1) removes trailing
>> >> whitespaces in the current line as soon as I go to the next line...
>> >
>> > It does that for me, too.
>> 
>> `newline' doesn't.  Only `newline-and-indent' does.
>
> Why should anyone use `newline' instead of `newline-and-indent'?

I'm not advising anyone on using it, if that's what you mean. :)

It just appeared the OP was using `newline' (isn't it the default?) and
I wanted to clear up the confusion.

regards,
Nikolaj Schumacher

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

end of thread, other threads:[~2007-07-08  9:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.