Auto Format fails on this sketch...

Hi - I have a sketch where Auto Format only works up until a certain line in the sketch.

The last line that works with Auto Format is line 37 in the attached sketch. The line is: static const char AUX_TIMEZONE[] PROGMEM = R"( [taken from the Autoconnect library example].

Can anyone verify this code causes Auto Format to fail on their Arduino IDE as well? I'd like to know if the issue is my IDE setup, or if there's something in this code that Auto Format chokes on...and if so, how to fix it.

Thanks...

    // THIS TOP PART OF THE SKETCH RESPONDS CORRECTLY  TO AUTOFORMAT:
    
    int GPIO_0 = 0;
    int GPIO_1 = 1;
    int GPIO_2 = 2;
    int GPIO_3 = 3;
    int GPIO_4 = 4;
    int GPIO_5 = 5;
    int GPIO_12 = 12;
    int GPIO_13 = 13;
    int GPIO_14 = 14;
    int GPIO_15 = 15;
    int GPIO_16 = 16;
    
    // THIS PART OF THE SKETCH RESPONDS CORRECTLY  TO AUTOFORMAT UNTIL
    // LINE 37 below, THEN AUTOFORMAT STOPS WORKING:
    
    /*  Simple.ino, Example for the AutoConnect library.
    Copyright (c) 2018, Hieromon Ikasamo
    https://github.com/Hieromon/AutoCnnect
    
    Default WiFi PWD: 12345678
    Set in: AutoConnectDefs.h
    */
    
    #if defined(ARDUINO_ARCH_ESP8266)
        #include <ESP8266WiFi.h>
        #include <ESP8266WebServer.h>
    #elif defined(ARDUINO_ARCH_ESP32)
        #include <WiFi.h>
        #include <WebServer.h>
    #endif
    #include   <time.h>
    #include <AutoConnect.h>
    
    static const char AUX_TIMEZONE[] PROGMEM = R"(
    // AUTOFORMAT STOPS WORKING HERE!!!
    {
        "title": "TimeZone",
        "uri": "/timezone",
        "menu": true,
        "element": [
         {
          "name": "caption",
          "type": "ACText",
          "value": "Sets the time zone to get the current local time.",
          "style": "font-family:Arial;font-weight:bold;text-align:center;margin-bottom:10px;color:DarkSlateBlue"
        },
        {
          "name": "timezone",
          "type": "ACSelect",
          "label": "Select TZ name",
          "option": [],
          "selected": 10
        },
        {
          "name": "newline",
          "type": "ACElement",
          "value": "
"
        },
        {
          "name": "start",
          "type": "ACSubmit",
          "value": "OK",
          "uri": "/start"
        }
      ]
    }
    )";
    
    typedef struct {
      const char* zone;
      const char* ntpServer;
      int8_t      tzoff;
    } Timezone_t;
    
    static const Timezone_t TZ[] = {
      { "Europe/London", "europe.pool.ntp.org", 0 },
      { "Europe/Berlin", "europe.pool.ntp.org", 1 },
      { "Europe/Helsinki", "europe.pool.ntp.org", 2 },
      { "Europe/Moscow", "europe.pool.ntp.org", 3 },
      { "Asia/Dubai", "asia.pool.ntp.org", 4 },
      { "Asia/Karachi", "asia.pool.ntp.org", 5 },
      { "Asia/Dhaka", "asia.pool.ntp.org", 6 },
      { "Asia/Jakarta", "asia.pool.ntp.org", 7 },
      { "Asia/Manila", "asia.pool.ntp.org", 8 },
      { "Asia/Tokyo", "asia.pool.ntp.org", 9 },
      { "Australia/Brisbane", "oceania.pool.ntp.org", 10 },
      { "Pacific/Noumea", "oceania.pool.ntp.org", 11 },
      { "Pacific/Auckland", "oceania.pool.ntp.org", 12 },
      { "Atlantic/Azores", "europe.pool.ntp.org", -1 },
      { "America/Noronha", "south-america.pool.ntp.org", -2 },
      { "America/Araguaina", "south-america.pool.ntp.org", -3 },
      { "America/Blanc-Sablon", "north-america.pool.ntp.org", -4},
      { "America/New_York", "north-america.pool.ntp.org", -5 },
      { "America/Chicago", "north-america.pool.ntp.org", -6 },
      { "America/Denver", "north-america.pool.ntp.org", -7 },
      { "America/Los_Angeles", "north-america.pool.ntp.org", -8 },
      { "America/Anchorage", "north-america.pool.ntp.org", -9 },
      { "Pacific/Honolulu", "north-america.pool.ntp.org", -10 },
      { "Pacific/Samoa", "oceania.pool.ntp.org", -11 }
    };
    
    #if defined(ARDUINO_ARCH_ESP8266)
    ESP8266WebServer Server;
    #elif defined(ARDUINO_ARCH_ESP32)
    WebServer Server;
    #endif
    
    AutoConnect       Portal(Server);
    AutoConnectConfig Config;       // Enable autoReconnect supported on v0.9.4
    AutoConnectAux    Timezone;
    
    // AND AUTOFORMAT DOES NOT WORK HERE ANYMORE EITHER!!!
    
    void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }

There appears to be an issue with you passing too many parameters.
"min" expects 2 and you seem to be passing 3 to it.

There also appears to be some declarations missing.

If you got the main code from the internet could you post the link to where you got it please.

Also KUDOS for using code tags !

Bob.

[/quote]

ballscrewbob:
There appears to be an issue with you passing too many parameters.
"min" expects 2 and you seem to be passing 3 to it.

There also appears to be some declarations missing.

If you got the main code from the internet could you post the link to where you got it please.

Also KUDOS for using code tags !

Bob.

Hi Bob - Sorry, I should have made the point that this is not executable code. Well, it compiles, but it has no purpose. It's just some stripped-down code in a test script (derived from a very large script that I didn't want to post because of size).

It's not intended to be examined from a code point of view...I wanted someone to tell me if Auto Format works on the posted script for them. It doesn't for me.

So...if you take a line before line 37 and preface it with 3 or 4 tabs...Auto Format should remove the extra tabs and put it back into correct format. It does so on my system.

But if you take a line AFTER line 37 and preface it with 3 or 4 tabs...Auto Format DOES NOT remove the extra tabs on my system...but I get the result message, "No changes necessary for Auto Format".

Auto Format clearly fails past line 37...at least on MY system...and I don't know why. It might be an Auto Format issue, or it might be a problem with my setup.

Can you (or anyone) paste the code I posted into their Arduino IDE and see if Auto Format works past line 37?

Thanks...

ps. Bob, you asked where the code came from. It's from the example included with the Auto Connect v1.01 library by Hieromon Ikasamo, available from the Arduino IDE Library Manager. But the code itself is beside the point...I'm just curious why Auto Format doesn't work past a certain line in that particular code...

So you are complaining that Auto Format is not touching a string literal?

oqibidipo:
So you are complaining that Auto Format is not touching a string literal?

I'm saying that Auto Format stops working at that line. It does not work on any lines past that line.

Is that how it's supposed to work?

chicoDaMan:
I'm saying that Auto Format stops working at that line. It does not work on any lines past that line.

Works for me (1.8.10 / OS X 10.11.6).

oqibidipo:
Works for me (1.8.10 / OS X 10.11.6).

OK thanks...glad you mentioned OSX, that's what I'm using and should have said so. Seems there's something wrong with my installation. Always best to avoid diving deep into the wrong place.... :wink:

Well, I'm baffled. I re-installed Arduino IDE as a fresh install, new preferences and library files. Everything virgin.

I still find that Auto Format doesn't work after the given line in the sketch I posted.

If I add spaces or lines at the beginning of any line after line 37 and then appy Auto Format, the changed line does not revert to a correctly formatted line.

Since it's been reported back to me that the sketch works on someone else's OSX installation...I grudgingly give up :frowning:

Back to hand-formatting, at least on any sketches that use the Autoconnect routine I posted...

Sigh...

Fixed, but I can't exactly explain why.

Starting from scratch, with a new installation, the line "static const char AUX_TIMEZONE[] PROGMEM = R"( "
continued to stymie Auto Format at that line and for all following lines.

Blindly trying different things, I changed the Auto Format preferences item:

# also indent macros
indent-preprocessor

to:

# also indent macros
indent-preproc-block / -xW

as per astyle suggested preferences (Artistic Style)

Everything started working correctly after that.

Not at all sure why this fixed it, but anyway, thanks oqibidipo for letting me know that the sketch worked ok on your system...