Friday, February 26, 2010

Re: PATCH: 'cindent' is too forgiving for function return type decls

Matt Wozniski wrote:

> In #vim, ShingRay pointed out a bug in cindent, which can be reproduced with:
>
> echo $'void f() {\nif (1)\n;\n}' \
> | vim - -u NONE -N -c 'set ft=c' -c 'norm gg=G'
>
> The above adds an extra 'shiftwidth' to every line. It's caused by
> vim mistakenly deciding that "void f() {" is specifying the function
> return type for the function "if". Since I can't think of a C-like
> language that would allow { or } anywhere in the return type of a
> function, here's a patch that fixes the problem by never considering a
> line containing braces to be return type declaration.
>
> ~Matt
>
> diff -r 903fcd726d90 src/misc1.c
> --- a/src/misc1.c Thu Feb 11 18:54:43 2010 +0100
> +++ b/src/misc1.c Thu Feb 25 01:21:16 2010 -0500
> @@ -7729,9 +7729,12 @@
> * line needs to be indented as a function type spec.
> * Don't do this if the current line looks like a comment
> * or if the current line is terminated, ie. ends in ';'.
> + * It also cannot contain a '{' or a '}'.
> */
> else if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
> && !cin_nocode(theline)
> + && !vim_strchr(theline, '{')
> + && !vim_strchr(theline, '}')
> && !cin_ends_in(theline, (char_u *)":", NULL)
> && !cin_ends_in(theline, (char_u *)",", NULL)
> && cin_isfuncdecl(NULL, cur_curpos.lnum + 1)

Thanks for the fix! Not obvious that this would be the cause of the
problem.

--
GALAHAD turns back. We see from his POV the lovely ZOOT standing by him
smiling enchantingly and a number of equally delectable GIRLIES draped
around in the seductively poulticed room. They look at him smilingly and
wave.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
You received this message from the "vim_use" 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

No comments:

Post a Comment