Categories


Popular topics

The Astyle reformat option in the "Coding" tab opens the Artistic Style Formatter dialog. Here you can adjust artistic style settings before reformatting / beautifying the active source file according to the parameters you set. The number of indent spaces passed to Artistic Style is based on the Indent spaces value set in Settings » Editor » Word wrap/tab settings (based upon extension of active file). The Reformat button will apply the selected options/settings and reformat and beautify the active source file.

Ultraedit artistic style.png

Indentation

The following indentation options are available:

Control Function
Case indents 'case X:' blocks from the 'case X:' headers. Case statements not enclosed in blocks are NOT indented.


switch (foo)
{
    case 1:
        a += 1;
        break;
    case 2:
    {
        a += 2;
        break;
    }
}


becomes:

switch (foo)
{
    case 1:
        a += 1;
        break;
    case 2:
        {
            a += 2;
            break;
        }
}
Class indents 'class' and 'struct' blocks so that the blocks 'public:', 'protected:' and 'private:' are indented. The struct blocks are indented only if an access modifier is declared somewhere in the struct. The entire block is indented. This option is effective for C++ files only.


class Foo
{
public:
    Foo();
    virtual ~Foo();
};


becomes:

class Foo
{
    public:
        Foo();
        virtual ~Foo();
};
Inline comments indents C++ comments beginning in column one. By default C++ comments beginning in column one are not indented. This option will allow the comments to be indented with the code.


void Foo()
{
// comment
    if (isFoo)
        bar();
}


becomes:

void Foo()
{
    // comment
    if (isFoo)
        bar();
}
Label adds extra indentation to labels so they appear 1 indent less than the current indentation, rather than being flushed to the left (the default).


void Foo() {
    while (isFoo) {
        if (isFoo)
            goto error;
        ...
error:
        ...
    }
}


becomes (with indented 'error:'):

void Foo() {
    while (isFoo) {
        if (isFoo)
            goto error;
        ...
    error:
        ...
    }
}
Namespace adds extra indentation to namespace blocks. This option has no effect on Java files.


namespace foospace
{
class Foo
{
    public:
        Foo();
        virtual ~Foo();
};
}


becomes:

namespace foospace
{
    class Foo
    {
        public:
            Foo();
            virtual ~Foo();
    };
}
Preprocessor indents multi-line preprocessor definitions ending with a backslash. Should be used with Tabs -> Spaces for proper results. Does a pretty good job, but cannot perform miracles in obfuscated preprocessor definitions. Without this option the preprocessor statements remain unchanged.


#define Is_Bar(arg,a,b) \
(Is_Foo((arg), (a)) \
|| Is_Foo((arg), (b)))


becomes:

#define Is_Bar(arg,a,b) \
    (Is_Foo((arg), (a)) \
     || Is_Foo((arg), (b)))
Switch indents 'switch' blocks so that the 'case X:' statements are indented in the switch block. The entire case block is indented.


switch (foo)
{
case 1:
    a += 1;
    break;
case 2:
{
    a += 2;
    break;
}
}


becomes:

switch (foo)
{
    case 1:
        a += 1;
        break;
    case 2:
    {
        a += 2;
        break;
    }
}
Max. instatement indent sets the maximum of # spaces to indent a continuation line. The # indicates a number of columns and must not be greater than 120. If no # is set, the default value of 40 will be used. A maximum of less than two indent lengths will be ignored. This option will prevent continuation lines from extending too far to the right. Setting a larger value will allow the code to be extended further to the right.


fooArray[] = { red,
         green,
         blue };
fooFunction(barArg1,
         barArg2,
         barArg3);


becomes (with larger value):

fooArray[] = { red,
               green,
               blue };
fooFunction(barArg1,
            barArg2,
            barArg3);
Min. conditional indent sets the minimal indent that is added when a header is built of multiple lines. This indent helps to easily separate the header from the command statements that follow. The value indicates a number of indents and is a minimum value. The indent may be greater to align with the data on the previous line.


The valid values are:


  • 0: no minimal indent. The lines will be aligned with the parenthesis on the preceding line.
  • 1: indent at least one additional indent.
  • 2: indent at least two additional indents.
  • 3: indent at least one-half an additional indent. This is intended for large indents (e.g. 8).


The default value is 2, two additional indents.


// default setting makes this non-bracketed code clear
if (a < b
        || c > d)
    foo++;

// but creates an exaggerated indent in this bracketed code
if (a < b
        || c > d)
{
    foo++;
}


becomes (when setting min. conditional indent = 0):

// setting makes this non-bracketed code less clear
if (a < b
    || c > d)
    foo++;

// but makes this bracketed code clearer
if (a < b
    || c > d)
{
    foo++;
}

Style

One of sixteen possible styles may be selected using the Style dropdown ( allman, ansi, bsd, break, java, attach, kr, stroustrup, whitesmith, banner, gnu, linux, hortsmann, otbs, pico, lisp).

default If no bracket style option is set, the opening brackets will not be changed and closing brackets will be broken from the preceding line.
  • allman
  • ansi
  • bsd
  • break

Allman style formatting/indenting uses broken brackets.

int Foo(bool isBar)
{
    if (isBar)
    {
        bar();
        return 1;
    }
    else
        return 0;
}
  • java
  • attach
Java style formatting/indenting uses attached brackets.


int Foo(bool isBar) {
    if (isBar) {
        bar();
        return 1;
    } else
        return 0;
}
kr (Kernighan & Ritchie) Kernighan & Ritchie style formatting/indenting uses linux brackets. Brackets are broken from namespaces, classes, and function definitions. Brackets are attached to statements within a function.


int Foo(bool isBar)
{
    if (isBar) {
        bar();
        return 1;
    } else
        return 0;
}
stroustrup Stroustrup style formatting/indenting uses stroustrup brackets. Brackets are broken from function definitions only. Brackets are attached to namespaces, classes, and statements within a function. This style frequently is used with an indent of 5 spaces.


int Foo(bool isBar)
{
     if (isBar) {
          bar();
          return 1;
     } else
          return 0;
}
whitesmith Whitesmith style formatting/indenting uses broken, indented brackets. Class blocks and switch blocks are indented to prevent a 'hanging indent' with switch statements and C++ class modifiers (public, private, protected).


int Foo(bool isBar)
    {
    if (isBar)
        {
        bar();
        return 1;
        }
    else
        return 0;
    }
banner Banner style formatting/indenting uses attached, indented brackets. Class blocks and switch blocks are indented to prevent a 'hanging indent' with switch statements and C++ class modifiers (public, private, protected).


int Foo(bool isBar) {
    if (isBar) {
        bar();
        return 1;
        }
    else
        return 0;
    }
gnu GNU style formatting/indenting uses broken brackets and indented blocks. This style frequently is used with an indent of 2 spaces.


Extra indentation is added to blocks within a function. The opening bracket for namespaces, classes, and functions is not indented.

int Foo(bool isBar)
{
  if (isBar)
    {
      bar();
      return 1;
    }
  else
    return 0;
}
linux Linux style formatting/indenting uses linux brackets. Brackets are broken from namespace, class, and function definitions. Brackets are attached to statements within a function. Min. conditional indent is one-half indent. If you want a different minimum conditional indent use the K&R style instead. This style works best with a large indent. It frequently is used with an indent of 8 spaces.


Also known as Kernel Normal Form (KNF) style, this is the style used in the Linux kernel.

int Foo(bool isBar)
{
        if (isFoo) {
                bar();
                return 1;
        } else
                return 0;
}
horstmann Horstmann style formatting/indenting uses run-in brackets, brackets are broken and allow run-in statements. Switches are indented to allow a run-in to the opening switch block. This style frequently is used with an indent of 3 spaces.


int Foo(bool isBar)
{  if (isBar)
   {  bar();
      return 1;
   } else
      return 0;
}
otbs "One True Brace Style" formatting/indenting uses linux brackets and adds brackets to unbracketed one line conditional statements. In the following example brackets have been added to the "return 0;" statement. The option add one line brackets can also be used with this style.


int Foo(bool isBar)
{
    if (isFoo) {
        bar();
        return 1;
    } else {
        return 0;
    }
}
pico Pico style formatting/indenting uses run-in brackets, opening brackets are broken and allow run-in statements. The closing bracket is attached to the last line in the block. Switches are indented to allow a run-in to the opening switch block. The style implies keep one line blocks and keep one line statements. This style does not support multiple-line brackets. If add brackets is used they will be added as one line brackets. This style frequently is used with an indent of 2 spaces.


int Foo(bool isBar)
{  if (isBar)
   {  bar();
      return 1; }    
    else
      return 0; }
lisp Lisp style formatting/indenting uses attached brackets, opening brackets are attached at the end of the statement. The closing bracket is attached to the last line in the block. The style implies keep one line statements but NOT keep one line blocks. This style does not support one line brackets. If add one line brackets is used they will be added as multiple-line brackets.


int Foo(bool isBar) {
    if (isBar) {
        bar()
        return 1; }
    else
        return 0; }

Mode

This option is usually set from the file extension for each file. You can override the setting with this entry. It will be used for all files regardless of the file extension. It allows the formatter to identify language specific syntax such as C++ classes, templates, and keywords.

c indents a C or C++ file
cs indents a C# file
java indents a Java file

Options file

An optional default options file may be used to supplement or replace the dialog options. The dialog options have precedence. If there is a conflict between a dialog option and an option in the default options file, the dialog option will be used.

Artistic Style looks for this file in the following locations (in order):

  1. the file indicated by the --options= command line option as used if an options file is set in the dialog;
  2. the file and directory indicated by the environment variable ARTISTIC_STYLE_OPTIONS (if it exists);
  3. the file named .astylerc in the directory pointed to by the HOME environment variable (e.g. "$HOME/.astylerc" on Linux);
  4. the file named astylerc in the directory pointed to by the USERPROFILE environment variable (e.g. "%USERPROFILE%\astylerc" on Windows).

Formatting

The following formatting options are available:

Control Function
Add brackets adds brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while', ...). The statement must be on a single line. The brackets will be added according to the currently requested predefined style or bracket type. If no style or bracket type is requested the brackets will be attached. If add one line brackets is also used the result will be one line brackets.


if (isFoo)
    isFoo = false;


becomes:

if (isFoo) {
    isFoo = false;
}
Add one line brackets adds one line brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while', ...). The statement must be on a single line. The option implies keep one line blocks and will not break the one line blocks.


if (isFoo)
    isFoo = false;


becomes:

if (isFoo)
    { isFoo = false; }
Align pointer attaches a pointer or reference operator (*, &, or ^) to either the variable type (left) or variable name (right), or place it between the type and name (middle). The spacing between the type and name will be preserved, if possible. This option is for C/C++, C++/CLI, and C# files. To format references separately use the following align reference option.


char* foo1;
char & foo2;
String ^s1;


becomes (with align pointer = type):

char* foo1;
char& foo2;
String^ s1;


char* foo1;
char & foo2;
String ^s1;


becomes (with align pointer = middle):

char * foo1;
char & foo2;
String ^ s1;


char* foo1;
char & foo2;
String ^s1;


becomes (with align pointer = name):

char *foo1;
char &foo2;
String ^s1;
Align reference aligns references separate from pointers. Pointers are not changed by this option. If pointers and references are to be aligned the same, use the previous align pointer option. The align reference option with value none will not change the reference alignment. The other options are the same as for align pointer. This option is for C/C++, C++/CLI, and C# files.


char &foo1;


becomes (with align reference = type):

char& foo1;


char& foo2;


becomes (with align reference = middle):

char & foo2;


char& foo3;

becomes (with align reference = name):


char &foo3;
Break after logical The option max. code length will break a line if the code exceeds # characters. The valid values are 50 thru 200. Lines without logical conditionals will break on a logical conditional (|| , &&, ...), comma, parenthesis, semicolon, or space.


Some code will not be broken, such as comments, quotes, and arrays. If used with keep one line blocks or add one line brackets the blocks will NOT be broken. If used with keep one line statements the statements will be broken at a semicolon if the line goes over the maximum length. If there is no available break point within the max code length, the line will be broken at the first available break point after the max code length.


By default logical conditionals will be placed first on the new line. The option break after logical will cause the logical conditionals to be placed last on the previous line. This option has no effect without max. code length.


if (thisVariable1 == thatVariable1 || thisVariable2 == thatVariable2 || thisVariable3 == thatVariable3)
    bar();


becomes:

if (thisVariable1 == thatVariable1
        || thisVariable2 == thatVariable2
        || thisVariable3 == thatVariable3)
    bar();


becomes (with break after logical):

if (thisVariable1 == thatVariable1 ||
        thisVariable2 == thatVariable2 ||
        thisVariable3 == thatVariable3)
    bar();
Break else if() breaks 'else if' header combinations into separate lines. This option has no effect if keep one line statements is used, the 'else if' statements will remain as they are. If this option is NOT used, 'else if' header combinations will be placed on a single line.


if (isFoo) {
    bar();
}
else if (isFoo1()) {
    bar1();
}
else if (isFoo2()) {
    bar2;
}


becomes:

if (isFoo) {
    bar();
}
else
    if (isFoo1()) {
        bar1();
    }
    else
        if (isFoo2()) {
            bar2();
        }
Break blocks The default option pads empty lines around header blocks (e.g. 'if', 'for', 'while', ...).


isFoo = true;
if (isFoo) {
    bar();
} else {
    anotherBar();
}
isBar = false;


becomes:

isFoo = true;

if (isFoo) {
    bar();
} else {
    anotherBar();
}

isBar = false;


The all option pads empty lines around header blocks (e.g. 'if', 'for', 'while', ...). Treat closing header blocks (e.g. 'else', 'catch') as stand-alone blocks.


isFoo = true;
if (isFoo) {
    bar();
} else {
    anotherBar();
}
isBar = false;


becomes:

isFoo = true;

if (isFoo) {
    bar();
    
} else {
    anotherBar();
}

isBar = false;
Close templates closes whitespace in the angle brackets of template definitions. Closing the ending angle brackets is now allowed by the C++11 standard. Be sure your compiler supports this before making the changes.


Stack< int,List< int > > stack1;


becomes:

Stack<int,List<int>> stack1;
Empty lines The delete option deletes empty lines within a function or method. Empty lines outside of functions or methods are NOT deleted. If used with break blocks with default or all it will delete all lines EXCEPT the lines added by the break blocks options.


void Foo()
{

    foo1 = 1;

    foo2 = 2;

}


becomes:

void Foo()
{
    foo1 = 1;
    foo2 = 2;
}

The fill option fills empty lines with the white space of the previous line.

Keep one line blocks will not break one line blocks.


if (isFoo)
{ isFoo = false; cout << isFoo << endl; }


remains unchanged.

Keep one line statements will not break complex statements and multiple statements residing on a single line.


if (isFoo)
{
    isFoo = false; cout << isFoo << endl;
}


remains unchanged.

if (isFoo) DoBar();


remains also unchanged.

Max code length The option max code length will break a line if the code exceeds # characters. The valid values are 50 thru 200. Lines without logical conditionals will break on a logical conditional (||, &&, ...), comma, parenthesis, semicolon, or space.


Some code will not be broken, such as comments, quotes, and arrays. If used with keep one line blocks or add one line brackets the blocks will NOT be broken. If used with keep one line statements the statements will be broken at a semicolon if the line goes over the maximum length. If there is no available break point within the max code length, the line will be broken at the first available break point after the max code length.

Space padding There are several padding options available:


first-paren-out
inserts space padding around the first parenthesis in a series on the outside only. Any end of line comments will remain in the original column, if possible. This can be used with unpad-paren below to remove unwanted spaces. If used with pad-paren or pad-paren-out, this option will be ignored. If used with pad-paren-in, the result will be the same as pad-paren.


if (isFoo((a+2), b))
    bar(a, b);


becomes:

if (isFoo ((a+2), b))
    bar (a, b);

oper
inserts space padding around operators. Any end of line comments will remain in the original column, if possible. Note that there is no option to unpad. Once padded, they stay padded.


if (foo==2)
    a=bar((b-c)*a,d--);


becomes:

if (foo == 2)
     a = bar((b - c) * a, d--);

paren
inserts space padding around parenthesis on both the outside and the inside. Any end of line comments will remain in the original column, if possible.


if (isFoo((a+2), b))
    bar(a, b);


becomes:

if ( isFoo ( ( a+2 ), b ) )
    bar ( a, b );

paren-in
inserts space padding around parenthesis on the inside only. Any end of line comments will remain in the original column, if possible. This can be used with unpad-paren below to remove unwanted spaces.


if (isFoo((a+2), b))
    bar(a, b);


becomes:

if ( isFoo( ( a+2 ), b ) )
    bar( a, b );


paren-out
inserts space padding around parenthesis on the outside only. Any end of line comments will remain in the original column, if possible. This can be used with unpad-paren below to remove unwanted spaces.


if (isFoo((a+2), b))
    bar(a, b);


becomes:

if (isFoo ( (a+2), b) )
    bar (a, b);


header
inserts space padding after parenthesis headers only (e.g. 'if', 'for', 'while', ...). Any end of line comments will remain in the original column, if possible. This can be used with unpad-paren to remove unwanted spaces.


if(isFoo((a+2), b))
    bar(a, b);


becomes:

if (isFoo((a+2), b))
    bar(a, b);


unpad-paren
removes extra space padding around parenthesis on the inside and outside. Any end of line comments will remain in the original column, if possible. This option can be used in combination with the parenthesis padding options paren, paren-out, paren-in, and header above. Only padding that has not been requested by other options will be removed.


For example, if a source has parenthesis padded on both the inside and outside, and you want inside only. You need to use unpad-paren to remove the outside padding, and paren-in to retain the inside padding. Using only paren-in would not remove the outside padding.


if ( isFoo( ( a+2 ), b ) )
    bar ( a, b );


becomes (with no padding option requested):

if(isFoo((a+2), b))
    bar(a, b);
Tabs -> Spaces converts tabs into spaces in the non-indentation part of the line. The number of spaces inserted will maintain the spacing of the tab. The current setting for spaces per tab is used. It may not produce the expected results if this option is used when changing spaces per tab. Tabs are not replaced in quotes.
MediaWiki spam blocked by CleanTalk.