3 ms·
For what it's worth, Vim handles it just fine.
by andkerosine 13y ago
For what it's worth, Vim handles it just fine.
- calebegg 13y agoWhat? Not for me, not with cindent on. It indents each if statement by one level, just like it "should". How would it somehow know to not indent them?
- Someone 13y agoAn auto-indenter could easily detect the idiom if hit backspace after the auto-indent it produced after the first 'if'. Once you have your two ifs at the same indent, the indenter can use that info to keep them at the same indentation level. It could even assume you mean (a&&b) vs (!a&&!b) and not the three-way (a&&b), (a&&!b), (!a) when you follow it with an else block (I think that would be the best heuristic) Implementing this will get a bit hairy, but if you are writing an auto-indenter for C, you should be used to that. So, all you would have to do is hit one extra backspace to signal your intent. Alternatively, one could type if(a) if(b) { To signal that one wants if(a) if(b) { Same number of keystrokes, and, IMO, that space is slightly easier to type than the return it replaces.
- jamesaguilar 13y agoNone of the existing auto formatters that I'm aware of do this.
- calebegg 13y agoThat's all good and well, but vim does not do this and, more generally, does not support this style, which is what I was saying.