Skip to contentSkip to conversation

Query on CodingStyle: indentation

DISCUSSION Kumar amit mehta 3 participants 5 messages Oct 19, 2012 – Oct 22, 2012

lore
Share & tools
lore
#0 lore raw

Hi,

I've a query regarding the coding style for Linux Kernel code. I'm reading the CodingStyle under Documentation and what I've understood is that I shouldn't be using spaces for indentation purposes and should use tabs of width 8 characters. Quoting from the same document:
"Outside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken." However, Is it correct to replace each tab stroke by 8 spaces ? I use vim editor and I've put following under $HOME/.vimrc file:
<snip>
set tabstop=8
set shiftwidth=8
set expandtab
<snip>

In past I've seen that some application have different interpretation of tabs and hence sometimes even If I've done proper indentation using tab, the code appears unindented, and therefore In order to make sure that I'm moving 8 characters upon hitting tab, I've put the above rules under my .vimrc file. Please let me know If I should remove these from my .vimrc file and rely on tab instead.

-Amit

#1 lore raw
Quoted 16 lines · Kumar amit mehta

Hi,

I've a query regarding the coding style for Linux Kernel code. I'm reading the CodingStyle under Documentation and what I've understood is that I shouldn't be using spaces for indentation purposes and should use tabs of width 8 characters. Quoting from the same document:
"Outside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken." However, Is it correct to replace each tab stroke by 8 spaces ? I use vim editor and I've put following under $HOME/.vimrc file:
<snip>
set tabstop=8
set shiftwidth=8
set expandtab
<snip>

Quoted 6 lines

In past I've seen that some application have different interpretation of tabs and hence sometimes even If I've done proper indentation using tab, the code appears unindented, and therefore In order to make sure that I'm moving 8 characters upon hitting tab, I've put the above rules under my .vimrc file. Please let me know If I should remove these from my .vimrc file and rely on tab instead.

No, you should not expand tabs. Tabs in CodingStyle mean _hard_ tabs.

Mine:

<snip>
set tabstop=8
set noexpandtab
set shiftwidth=8
set cinoptions=:0,l1,t0,g0
<snip>

Signature · 3 lines
Regards,
Adam Lee
http://adam8157.info
#2 lore raw
Quoted 26 lines · Adam Lee
Quoted 16 lines · Kumar amit mehta

Hi,

I've a query regarding the coding style for Linux Kernel code. I'm reading the CodingStyle under Documentation and what I've understood is that I shouldn't be using spaces for indentation purposes and should use tabs of width 8 characters. Quoting from the same document:
"Outside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken." However, Is it correct to replace each tab stroke by 8 spaces ? I use vim editor and I've put following under $HOME/.vimrc file:
<snip>
set tabstop=8
set shiftwidth=8
set expandtab
<snip>

Quoted 6 lines

In past I've seen that some application have different interpretation of tabs and hence sometimes even If I've done proper indentation using tab, the code appears unindented, and therefore In order to make sure that I'm moving 8 characters upon hitting tab, I've put the above rules under my .vimrc file. Please let me know If I should remove these from my .vimrc file and rely on tab instead.

No, you should not expand tabs. Tabs in CodingStyle mean _hard_ tabs.

Quoted 9 lines

Mine:

<snip>
set tabstop=8
set noexpandtab
set shiftwidth=8
set cinoptions=:0,l1,t0,g0
<snip>

Thank you Adam for sharing your vim recipe.

#3 lore raw
Quoted 37 lines · Kumar amit mehta
Quoted 26 lines · Adam Lee
Quoted 16 lines · Kumar amit mehta

Hi,

I've a query regarding the coding style for Linux Kernel code. I'm reading the CodingStyle under Documentation and what I've understood is that I shouldn't be using spaces for indentation purposes and should use tabs of width 8 characters. Quoting from the same document:
"Outside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken." However, Is it correct to replace each tab stroke by 8 spaces ? I use vim editor and I've put following under $HOME/.vimrc file:
<snip>
set tabstop=8
set shiftwidth=8
set expandtab
<snip>

Quoted 6 lines

In past I've seen that some application have different interpretation of tabs and hence sometimes even If I've done proper indentation using tab, the code appears unindented, and therefore In order to make sure that I'm moving 8 characters upon hitting tab, I've put the above rules under my .vimrc file. Please let me know If I should remove these from my .vimrc file and rely on tab instead.

No, you should not expand tabs. Tabs in CodingStyle mean _hard_ tabs.

Quoted 9 lines

Mine:

<snip>
set tabstop=8
set noexpandtab
set shiftwidth=8
set cinoptions=:0,l1,t0,g0
<snip>

Quoted 1 line

Thank you Adam for sharing your vim recipe.

I believe you can still use your standard vim recipe, then run checkpatch.pl on your patches to replace spaces with tabs before sending them to upstream.

Someone else who uses that workflow would need to confirm that works well.

Greg

#4 lore raw
Quoted 40 lines · Greg Freemyer
Quoted 37 lines · Kumar amit mehta
Quoted 26 lines · Adam Lee
Quoted 16 lines · Kumar amit mehta

Hi,

I've a query regarding the coding style for Linux Kernel code. I'm reading the CodingStyle under Documentation and what I've understood is that I shouldn't be using spaces for indentation purposes and should use tabs of width 8 characters. Quoting from the same document:
"Outside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken." However, Is it correct to replace each tab stroke by 8 spaces ? I use vim editor and I've put following under $HOME/.vimrc file:
<snip>
set tabstop=8
set shiftwidth=8
set expandtab
<snip>

Quoted 6 lines

In past I've seen that some application have different interpretation of tabs and hence sometimes even If I've done proper indentation using tab, the code appears unindented, and therefore In order to make sure that I'm moving 8 characters upon hitting tab, I've put the above rules under my .vimrc file. Please let me know If I should remove these from my .vimrc file and rely on tab instead.

No, you should not expand tabs. Tabs in CodingStyle mean _hard_ tabs.

Quoted 9 lines

Mine:

<snip>
set tabstop=8
set noexpandtab
set shiftwidth=8
set cinoptions=:0,l1,t0,g0
<snip>

Quoted 1 line

Thank you Adam for sharing your vim recipe.

Quoted 7 lines

I believe you can still use your standard vim recipe, then run checkpatch.pl on your patches to replace spaces with tabs before sending them to upstream.

Someone else who uses that workflow would need to confirm that works well.

Greg

Thank you Greg for reminding about this script(checkpatch.pl). I updated my $HOME/.vimrc file as per Adam's suggestion and generated a patch and then ran this checkpatch.pl script against my patch and It didn't give me any error. So I guess the above vim recipe is fine. I've sent that patch to kernel-janitor group and had kept the maintainer in the CC as well. I haven't got the reply yet, so I don't know if my patch got merged or not.

-Amit