top | item 5764877

(no title)

andkerosine | 12 years ago

For what it's worth, Vim handles it just fine.

discuss

order

calebegg|12 years ago

What? 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|12 years ago

An 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.