3 ms·
Kind of strikes me as something the editor could do ad-hoc. Maybe the tab character could return to let programmers tell the editor to align the adjoining lines
by morsch 12y ago
Kind of strikes me as something the editor could do ad-hoc. Maybe the tab character could return to let programmers tell the editor to align the adjoining lines according to the tabs. Would work well at least in your example.
- seanmcdirmid 12y agoElastic tab stops: http://nickgravgaard.com/elastictabstops/ http://nickgravgaard.com/elastictabstops/ You could also pad your spaces in the editor so that they align along a global axis. This does fix your code to a particular editor, however.
- morsch 12y agoExactly what I was thinking of, brilliant!
- robert_tweed 12y agoYeah this is nice. All we need now is for this to be supported in all major text editors and we're set! The only possible issue (not sure how it's handled, can't remember if/how gofmt handles it either) is when sometimes you actually want something to be misaligned because the width is so far out of the norm, e.g: int const1 = 10; // There's lots of space here for a long comment int const2 = 5; // Here too, unless the tabs get moved too far right float const3 = ( const1 * 123.45 ) / MAGIC_CONSTANT; // Not here. Normally when this happens I try to regroup the code so that "plain" constants are together and long formulas are in another group, but sometimes the order is important for some reason or doesn't make logical sense to regroup items, so the formatting has to suffer a bit.
- morsch 12y agoAs long as you rely on the tab character to signal the programmer's intent on inserting an elastic tabstop, that's not an issue. In this case, insert a \t in front of the comments on the first two, but not the third line. All three lines could have \t's in front of the equals character so align on it. The other nice thing is that it degraces quite gracefully in non-supporting editors.