(Created page with "Category:Coding tab The '''Astyle reformat''' option in the "Coding" tab opens the '''Artistic Style Formatter''' dialog. Here you can adjust artistic style settings befor...") |
|||
Line 1: | Line 1: | ||
[[Category:Coding tab]] | [[Category:Coding tab]] | ||
− | 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: | + | 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|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. | The '''Reformat''' button will apply the selected options/settings and reformat and beautify the active source file. | ||
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.
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; } }
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(); };
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(); }
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: ... } }
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(); }; }
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)))
#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; } }
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);
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.
// 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++; }
// 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++; } |
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 style formatting/indenting uses broken brackets. |
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; } |
|
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.
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.
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; } |
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 |
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):
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;
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;
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;
char* foo1; char& foo2; String^ s1;
char* foo1; char & foo2; String ^s1;
char * foo1; char & foo2; String ^ s1;
char* foo1; char & foo2; String ^s1;
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;
char& foo1;
char& foo2;
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.
if (thisVariable1 == thatVariable1 || thisVariable2 == thatVariable2 || thisVariable3 == thatVariable3) bar();
if (thisVariable1 == thatVariable1 || thisVariable2 == thatVariable2 || thisVariable3 == thatVariable3) bar();
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; }
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;
isFoo = true; if (isFoo) { bar(); } else { anotherBar(); } isBar = false;
isFoo = true; if (isFoo) { bar(); } else { anotherBar(); } isBar = false;
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;
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; }
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; }
|
Keep one line statements | will not break complex statements and multiple statements residing on a single line.
if (isFoo) { isFoo = false; cout << isFoo << endl; }
if (isFoo) DoBar();
|
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.
|
Space padding | There are several padding options available:
if (isFoo((a+2), b)) bar(a, b);
if (isFoo ((a+2), b)) bar (a, b); oper
if (foo==2) a=bar((b-c)*a,d--);
if (foo == 2) a = bar((b - c) * a, d--); paren
if (isFoo((a+2), b)) bar(a, b);
if ( isFoo ( ( a+2 ), b ) ) bar ( a, b ); paren-in
if (isFoo((a+2), b)) bar(a, b);
if ( isFoo( ( a+2 ), b ) ) bar( a, b );
if (isFoo((a+2), b)) bar(a, b);
if (isFoo ( (a+2), b) ) bar (a, b);
if(isFoo((a+2), b)) bar(a, b);
if (isFoo((a+2), b)) bar(a, b);
if ( isFoo( ( a+2 ), b ) ) bar ( a, b );
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. |