Summary: | app-editors/vim indents a piece of C code improperly | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Luis Fernando Schultz Xavier da Silveira <zahlberer> |
Component: | [OLD] Development | Assignee: | Vim Maintainers <vim> |
Status: | RESOLVED UPSTREAM | ||
Severity: | normal | ||
Priority: | High | ||
Version: | unspecified | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- |
Description
Luis Fernando Schultz Xavier da Silveira
2008-09-07 14:53:30 UTC
Well, to begin with, the ':help C-indenting' vim help page does contain this caveat: Note that 'cindent' indenting does not work for every code scenario. Vim is not a C compiler: it does not recognize all syntax. One requirement is that toplevel functions have a '{' in the first column. Otherwise they are easily confused with declarations. Based on your example (and some other quick testing I did here), it seems that another (unstated) limitation of the cindent feature is that it doesn't recognize a structure initialization if you put the '=' and a cast on the same line. For example, the following blocks do format properly: v = { .x = 2, .y = 4 }; v = (vector) { .x = 2, .y = 4 }; Whereas these do not: v = (vector) { .x = 2, .y = 4 }; v = (vector) { .x = 2, .y = 4 }; v = (struct vector) { .x = 2, .y = 4 }; Now all 3 of these 'failing' cases are indeed valid C code, but after a quick glance through the code, it would be non-trivial to hack the code to recognize this kind of syntax (especially that last case!). So, it's not really a *bug* per se, as Vim freely acknowledges that they can't parse every possible C syntax variation... I'm closing this as UPSTREAM and encouraging you to reporting it upstream, or try fixing it yourself if you're really interested. Please feel free to re-open this bug if you or upstream or someone else ends up adding support for this syntax, and I'll ensure I get the patch in to our ebuild. Thank you for the information. I am not able to make that change myself, but I may talk to some friends who are. Another possibility you *may* be able to do is to use the vim "indent-expression" mechanism to override the existing cindent and fix this case? It's not a facility I'm very familiar with, and doing this may be harder than fixing the code itself, but I thought I'd suggest it just in case it helps somehow. The problem is that I don't understand vim scripting, so I cannot write the indentation code. I can happily live with indenting that case myself as long as I have a tool to fix a whole file. I was thinking of using GNU indent to do that. Thanks for the hint anyway. |