Go Down

Topic: autoformat strange indets (Read 797 times) previous topic - next topic

Klausj

In case of nested control structures the behavior really looks strange.
The sketch was auto-formatted (IDE 1.8.5).

Code: [Select]

void setup() {
  // of course this code does not
  // make any sense but compiles fine

  // strange auto format behavior:

  // (1) normal:
  while (boo1()) voo1();

  // (2) still normal as expected:
  while (boo1()) if (boo2()) voo1();
    else voo2();

  // (3) same as (2) but surprising:
    while (boo1()) if (boo2()) voo1(); else voo2();

  // (5)  as expected:
  while (boo1()) while (boo2()) voo1();

  // (6)  surprising:
    while (boo1()) do voo1(); while (boo2());

}

void loop() {
  // put your main code here, to run repeatedly:

}

boolean boo1() {}
boolean boo2() {}
void voo1() {}
void voo2() {}


The indents are not as they should be.
Shouldn't it be fixed some time?

el_supremo

#1
May 28, 2018, 05:08 pm Last Edit: May 28, 2018, 05:08 pm by el_supremo
The IDE uses the astyle C formatting program. It is documented here. You can set your own preferences for this program in a file called formatter.conf. The original version of the file is in your arduino installation's .../lib directory. Once you've modified it the way you like, write your version into the same directory as your preferences.txt (look right at the bottom of the File|Preferences dialog for the pathname to this file).
This is my current version of the formatter.conf file:
Code: [Select]
# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style"
# http://astyle.sourceforge.net/astyle.html
#
# If you wish to change them, don't edit this file.
# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE
# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link

mode=c
# I added this
style=kr

# This is standard Arduino IDE
# 2 spaces indentation
indent=spaces=2

# also indent macros
indent-preprocessor

# indent classes, switches (and cases), comments starting at column 1
#indent-classes
#indent-switches
#indent-cases
#indent-col1-comments

# put a space around operators
# I would have kept this except that it also pads
# this: f(1,'c') to this f(1, 'c')
#pad-oper

# put a space after if/for/while
#pad-header

# if you like one-liners, keep them
keep-one-line-statements

#remove-comment-prefix


I don't know if there are options in astyle to modify the behaviour of what you have shown but dig through the docs and you might be able to fix it up to work the way you like.

Pete
Don't send me technical questions via Private Message.

Go Up