On Apr 24, 2011, at 5:18 PM, Lech Lorens wrote:
> Vim, when 'cino' is set to "(0,ts", will incorrectly indent
> the following function:
> #v+
> static
> void func(int a
> #if defined(FOO)
> , int b
> , int c
> #endif
> )
> {
> }
> #v-
>
> in the following way:
>
> #v+
> static
> void func(int a
> #if defined(FOO)
> , int b
> , int c
> #endif
> )
> {
> }
> #v-
Let's try to analyze what happened here.
By setting 'ts' you told Vim to indent the return type of the function by a
shiftwidth. In the function above, the return type is "void" and Vim is
indenting exactly as required.
If you use a standard style of writing that function (notice the position of
return type declaration and commas) and leave cinoptions=(0,ts you get:
#v+
static void
func(int a,
#if defined(FOO)
int b,
int c
#endif
)
{
}
#v-
Again, Vim indented the return type as required by a shiftwidth.
Now, if you set cinoptions=(0,t0 you get:
#v+
static void
func(int a,
#if defined(FOO)
int b,
int c
#endif
)
{
}
#v-
So, you get what you want by using the standard C-style.
That's either
static void func(...)
or
static void
func(...)
The BSD kernel is written in the latter style. Some old tools could pick up
function names easier when they started in the first column. Despite the fact
that people rarely use those old tools now it's still a popular style because
it offers a nice readability.
The Linux kernel is written in the former style and a lot of new code is
written in this style. The reason is probably influence of the style of C++,
Java, and similar languages where declaration is on the single line, as well as
the use of syntax highlighting editors where the function name is easily
spotted.
Also, I've never seen commas positioned as they are in your example.
Style rules are simple. Write as you write in English.
Comma is placed next to the word _before_ it, and has a space _after_ it.
> while it should as follows:
>
> #v+
> static
> void func(int a
> #if defined(FOO)
> , int b
> , int c
> #endif
> )
> {
> }
> #v-
>
> The attached patch fixes the problem and adds a test.
IMO, Vim does not need to be patched.
Using a more standard style and/or different cinoptions settings is the way to
go in this case.
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php