timonwong / SublimeAStyleFormatter

SublimeAStyleFormatter is a code formatter/beautifier for Sublime Text 2 & 3. It provides ability to format C/C++/C#/Java files.
MIT License
285 stars 42 forks source link

Multi line statement indentation #66

Open Lahorde opened 8 years ago

Lahorde commented 8 years ago

On sublime 3 I have these user settings :

{
    // Please visit http://astyle.sourceforge.net/astyle.html for more information
    "options_default": {
        // Default bracket style
        // Can be one of "allman", "bsd", "break", "java", "attach", "kr", "k&r",
        // "k/r" "stroustrup", "whitesmith", "banner", "gnu", "linux", "horstmann",
        // "1tbs", "otbs ", "google", "pico", "lisp", "python", "vtk", or null
        // for default.
        "style": null,

        // Tab options
        // "indent": Can be one of "spaces", "tab" "force-tab", "force-tab-x", or null
        // "indent-spaces": Can be either null or numbers
        //
        // While both "indent" or "indent-spaces" are null (default), the indentation options
        // will be retrieved from Sublime Text view settings: `tab_size`, `translate_tabs_to_spaces`:
        //   1. If `translate_tabs_to_spaces` is true, "indent" will be "spaces", otherwise, "tab";
        //   2. "indent-spaces" will equal to `tab_size`.
        "indent": "spaces",
        "indent-spaces": 2,

        // null      - Do nothing
        // "default" - Pad empty lines around header blocks (e.g. 'if',
        //              'for', 'while'...).
        // "all"     - Pad empty lines around header blocks (e.g. 'if',
        //              'for', 'while'...). Treat closing header blocks
        //              (e.g. 'else', 'catch') as stand-alone blocks.
        "break-blocks": "",
        "pad-header": false
    }
}

I would want to format this code :

if(arg_as8_algo->fpRTLSAlgoInit() 
!= 0)
{
log4c_category_log(file_cat,
LOG4C_PRIORITY_ERROR,
"Cannot init nearest tag scenario");
}

To :

  if(arg_as8_algo->fpRTLSAlgoInit() 
    != 0)
  {
    log4c_category_log(file_cat,
      LOG4C_PRIORITY_ERROR,
      "Cannot init nearest tag scenario");
  }

But applying formatter on selection gives :

  if(arg_as8_algo->fpRTLSAlgoInit()
  != 0)
  {
    log4c_category_log(file_cat,
    LOG4C_PRIORITY_ERROR,
    "Cannot init nearest tag scenario");
  }

According to Astyle doc http://astyle.sourceforge.net/astyle.html multi-line statement should be indented. How can a given number of spaces indentation in a multi line statement?

lnksz commented 6 years ago

Hey, you could have a look at max-instatement-indent. If it is less then what you would like to have, then it will not indent.

{
    log4c_category_log(file_cat,
                       LOG4C_PRIORITY_ERROR,
                       "Cannot init nearest tag scenario");
//^^^^^^^^^^^^^^^^^^^^^-This must be less then max-instatement-indent.
}

I set this in my user settings to about max-code-length - 10 chars