Re:Ifs and &&s and Plan 9's Source Code
by calebegg on Friday May 24, 2013 @04:36PM
(#5765069)
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?
[ Parent
| on HN ]
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.
Re:Ifs and &&s and Plan 9's Source Code
by jamesaguilar on Friday May 24, 2013 @05:16PM
(#5765223)
None of the existing auto formatters that I'm aware of do this.