I'm using Arduino IDE 2.3.2 under Linux Mint. Its 'Auto Format' feature appears twice in the menus (under the Edit and Tools menus), but when I select it, it doesn't wrap lines. In fact, in some cases, it unwraps lines. So I'm wondering whether I have something set up incorrectly.
As a professional software engineer, I'm in the habit of using autoformatting tools, and embracing whatever standards they format to. I might not particularly like the standard, but it helps avoid pointless style arguments, and it means code changes in the repo are more likely substance than style, which makes comparing different versions of code more helpful. Still, I don't think many devs like scrolling horizontally to read code, so wrapping lines to some reasonable length seems a pretty basic autoformatting feature.
Here's an example. I've wrapped the arguments in the function declaration to 80 characters, and also the ternary expression in the last return
statement. But some other lines are much longer:
unsigned long doSomethingUseful(MyMeaningfulStructName maryTheStruct, int foo,
int bar) {
// I'll put the curly brace on a separate line for fun. Oh, and this comment is long.
if (foo > bar)
{
return maryTheStruct.someLongThing;
}
while (unreasonablyLongCriterium && anotherUnreasonablyLongCriterium && yetAnotherUnreasonablyLongCriterium && stillAnotherUnreasonablyLongCriterium && byCrikeyHowManyCriteriaCanAWhileLoopHave) {
Serial.println(F("Surely 197 characters is long enough to wrap it?!"));
}
return globalThingo > CRAZY_CONST ?
maryTheStruct.anotherLongThing * bar - foo : somethingTheCatDraggedIn;
}
Then I pressed Ctrl+T, and the code got changed to this:
unsigned long doSomethingUseful(MyMeaningfulStructName maryTheStruct, int foo,
int bar) {
// I'll put the curly brace on a separate line for fun. Oh, and this comment is long.
if (foo > bar) {
return maryTheStruct.someLongThing;
}
while (unreasonablyLongCriterium && anotherUnreasonablyLongCriterium && yetAnotherUnreasonablyLongCriterium && stillAnotherUnreasonablyLongCriterium && byCrikeyHowManyCriteriaCanAWhileLoopHave) {
Serial.println(F("Surely 197 characters is long enough to wrap it?!"));
}
return globalThingo > CRAZY_CONST ? maryTheStruct.anotherLongThing * bar - foo : somethingTheCatDraggedIn;
}
It's left the function declaration alone and moved the curly brace, but it's made the return
statement a single long line, and it hasn't wrapped anything.
I've seen a lot of posts whingeing about the 80-character line length, so it seems line wrapping does happen for some people, but perhaps only while they're typing it. (I do my coding in a separate editor, and I've been using the IDE just for compiling and autoformatting.)
There don't seem to be a lot of settings in the IDE, but is there one for wrapping or line length that I'm missing?
Thanks,
Mik.