2006-03-20 11:32:35

by Li Yang

[permalink] [raw]
Subject: Lindent and coding style

There is a lindent script in linux kernel source. It breaks long lines, but uses space instead of tab as indentation. However, the codingstyle document also from the kernel source indicates no space is allowed for indentation. Is there a fix for this problem? Or the result from lindent(space indentation) is actually allowed in kernel source? Thanks.

--
Leo Li
Freescale Semiconductor

[email protected]


2006-03-20 14:29:58

by Alan

[permalink] [raw]
Subject: Re: Lindent and coding style

On Llu, 2006-03-20 at 19:32 +0800, Li Yang-r58472 wrote:
> There is a lindent script in linux kernel source. It breaks long
> lines, but uses space instead of tab as indentation. However, the
> codingstyle document also from the kernel source indicates no space is
> allowed for indentation. Is there a fix for this problem? Or the
> result from lindent(space indentation) is actually allowed in kernel
> source? Thanks.
>

It should produce suitable output. Do you have examples of where it
produces space indentation and you expect tabs ?

2006-03-20 14:50:43

by Jiri Slaby

[permalink] [raw]
Subject: Re: Lindent and coding style

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alan Cox napsal(a):
> On Llu, 2006-03-20 at 19:32 +0800, Li Yang-r58472 wrote:
>> There is a lindent script in linux kernel source. It breaks long
>> lines, but uses space instead of tab as indentation. However, the
>> codingstyle document also from the kernel source indicates no space is
>> allowed for indentation. Is there a fix for this problem? Or the
>> result from lindent(space indentation) is actually allowed in kernel
>> source? Thanks.
>>
>
> It should produce suitable output. Do you have examples of where it
> produces space indentation and you expect tabs ?
As far as I know, it produces:
<tab> if (very long condition &&
<tab> ssss2nd condition)...
where ssss are four spaces. Maybe this is considered as well formed at all, but
I indent 3 tabs in this case.

regards,
- --
Jiri Slaby http://www.fi.muni.cz/~xslaby
\_.-^-._ [email protected] _.-^-._/
B67499670407CE62ACC8 22A032CC55C339D47A7E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFEHsFXMsxVwznUen4RAsGBAJ9wP+y7teZrFQNeNnBDIx0lSfBP+QCguLwx
IAvBdGnkp8Y/Ft9yOH7m3js=
=4zgg
-----END PGP SIGNATURE-----

2006-03-20 16:12:58

by Xavier Bestel

[permalink] [raw]
Subject: Re: Lindent and coding style

On Mon, 2006-03-20 at 15:51, Jiri Slaby wrote:
> > It should produce suitable output. Do you have examples of where it
> > produces space indentation and you expect tabs ?
> As far as I know, it produces:
> <tab> if (very long condition &&
> <tab> ssss2nd condition)...
> where ssss are four spaces. Maybe this is considered as well formed at all, but
> I indent 3 tabs in this case.

Does that mean your tabs are 2-chars wide ? I think Linus stated that
tabs should be 8-chars wide, that should be somewhere in the
CodingStyle.

Xav


2006-03-20 16:20:18

by Jiri Slaby

[permalink] [raw]
Subject: Re: Lindent and coding style

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xavier Bestel napsal(a):
> On Mon, 2006-03-20 at 15:51, Jiri Slaby wrote:
>>> It should produce suitable output. Do you have examples of where it
>>> produces space indentation and you expect tabs ?
>> As far as I know, it produces:
>> <tab> if (very long condition &&
>> <tab> ssss2nd condition)...
>> where ssss are four spaces. Maybe this is considered as well formed at all, but
>> I indent 3 tabs in this case.
>
> Does that mean your tabs are 2-chars wide ? I think Linus stated that
> tabs should be 8-chars wide, that should be somewhere in the
> CodingStyle.
Nope, you maybe misunderstood me. Tab is 8 chars wide, but lindent do 4 spaces
on line after `if' if the condition continues on the next line. Then, I wrote I
do 2 tabs (16 chars) instead of 4-lindent spaces.

regards,
- --
Jiri Slaby http://www.fi.muni.cz/~xslaby
\_.-^-._ [email protected] _.-^-._/
B67499670407CE62ACC8 22A032CC55C339D47A7E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFEHtZWMsxVwznUen4RAv5gAJ9Q14Us1CCO3k+FoNWWgfDNYRzY4gCgt7jg
HKphoxhtCeUYU/l2mNg4TIY=
=P1Gq
-----END PGP SIGNATURE-----

2006-03-20 16:28:29

by Xavier Bestel

[permalink] [raw]
Subject: Re: Lindent and coding style

On Mon, 2006-03-20 at 17:21, Jiri Slaby wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Xavier Bestel napsal(a):
> > On Mon, 2006-03-20 at 15:51, Jiri Slaby wrote:
> >>> It should produce suitable output. Do you have examples of where it
> >>> produces space indentation and you expect tabs ?
> >> As far as I know, it produces:
> >> <tab> if (very long condition &&
> >> <tab> ssss2nd condition)...
> >> where ssss are four spaces. Maybe this is considered as well formed at all, but
> >> I indent 3 tabs in this case.
> >
> > Does that mean your tabs are 2-chars wide ? I think Linus stated that
> > tabs should be 8-chars wide, that should be somewhere in the
> > CodingStyle.
> Nope, you maybe misunderstood me. Tab is 8 chars wide, but lindent do 4 spaces
> on line after `if' if the condition continues on the next line. Then, I wrote I
> do 2 tabs (16 chars) instead of 4-lindent spaces.

My bad. I thought your 3 tabs were equivalent to 1 tab + 4 spaces.



2006-03-21 02:56:09

by Li Yang

[permalink] [raw]
Subject: RE: Lindent and coding style

> From: Alan Cox [mailto:[email protected]]
> Sent: Monday, March 20, 2006 10:37 PM
> To: Li Yang-r58472
> Cc: [email protected]
> Subject: Re: Lindent and coding style
>
> On Llu, 2006-03-20 at 19:32 +0800, Li Yang-r58472 wrote:
> > There is a lindent script in linux kernel source. It breaks long
> > lines, but uses space instead of tab as indentation. However, the
> > codingstyle document also from the kernel source indicates no space is
> > allowed for indentation. Is there a fix for this problem? Or the
> > result from lindent(space indentation) is actually allowed in kernel
> > source? Thanks.
> >
>
> It should produce suitable output. Do you have examples of where it
> produces space indentation and you expect tabs ?
As Jiri has said, it produces code like
<tab> if (very long condition &&
<tab> ssss2nd condition)...
The indent command will align the second line at the next character of the left parentheses it belongs to. In my opinion, this approach makes code more readable. However, it does not comply with the coding style of kernel.

2006-03-21 02:58:36

by Li Yang

[permalink] [raw]
Subject: RE: Lindent and coding style

> From: Alan Cox [mailto:[email protected]]
> Sent: Monday, March 20, 2006 10:37 PM
> To: Li Yang-r58472
> Cc: [email protected]
> Subject: Re: Lindent and coding style
>
> On Llu, 2006-03-20 at 19:32 +0800, Li Yang-r58472 wrote:
> > There is a lindent script in linux kernel source. It breaks long
> > lines, but uses space instead of tab as indentation. However, the
> > codingstyle document also from the kernel source indicates no space is
> > allowed for indentation. Is there a fix for this problem? Or the
> > result from lindent(space indentation) is actually allowed in kernel
> > source? Thanks.
> >
>
> It should produce suitable output. Do you have examples of where it
> produces space indentation and you expect tabs ?
One more thing to add, my indent is GNU indent 2.2.9 coming with Redhat 9.0. Does it matter?

2006-03-21 10:15:19

by Alan

[permalink] [raw]
Subject: RE: Lindent and coding style

On Maw, 2006-03-21 at 10:55 +0800, Li Yang-r58472 wrote:
> > It should produce suitable output. Do you have examples of where it
> > produces space indentation and you expect tabs ?
> As Jiri has said, it produces code like
> <tab> if (very long condition &&
> <tab> ssss2nd condition)...
> The indent command will align the second line at the next character of the left parentheses it belongs to. In my opinion, this approach makes code more readable. However, it does not comply with the coding style of kernel.

Lots of the kernel uses exactly that format (probably because of indent)
so I wouldn't worry personally. The CodingStyle document is a guide not
a formal specification.