style=allman style=java style=k&r style=stroustrup style=whitesmith style=banner style=gnu style=linux style=horstmann
default indent indent=spaces indent=tab indent=force‑tab default brackets brackets=break brackets=attach brackets=linux brackets=stroustrup brackets=horstmann
indent‑classes indent‑switches indent‑cases indent‑brackets indent‑blocks indent‑namespaces indent‑labels indent‑preprocessor max‑instatement‑indent min‑conditional‑indent
break‑blocks break‑blocks=all pad‑oper pad‑paren pad‑paren‑out pad‑paren‑in pad‑header unpad‑paren delete‑empty‑lines fill‑empty‑lines
break‑closing‑brackets break‑elseifs keep‑one‑line‑blocks keep‑one‑line‑statements align‑pointer convert‑tabs mode=c mode=java mode=cs
suffix suffix=none options options=none recursive exclude errors‑to‑stdout verbose formatted quiet version help
Line endings in the formatted file will be the same as the input file. If there are mixed line endings the most frequent occurrence will be used.
Artistic Style will determine the file type from the file extension. The extension ".java"
indicates a Java file, and ".cs" indicates a C# file. Everything else is a C or C++ file. If
you are using a non-standard file extension for Java or C#, use one of the --mode=
options.
Artistic Style can process directories recursively. Wildcards (such as "*.cpp" or "*.c??") are processed internally. If a shell is used it should pass the wildcards to Artistic Style instead of resolving them first. For Linux use double quotes around paths whose filename contains wildcards. For Windows use double quotes around paths whose filename contains spaces. The "Other Options" section contains information on recursive processing.
When a file is formatted, the newly indented file retains the original file name. A copy of the original file is created with a .orig
appended to the original file name. (This can be set to a
different string by the option --suffix=
, or suppressed altogether by the options
-n
or --suffix=none
). Thus, after indenting
SourceFile.cpp
the indented file will be named
SourceFile.cpp
, while the original pre-indented file will be renamed to
SourceFile.cpp.orig
.
Artistic Style can format standard class library statements such as wxWidgets, QT, Open GL, and MFC. It can usually format embedded assembler language. There are occasional problems with assembler since it can vary in syntax depending on the platform.
Embedded statements that are multiple-line and are NOT in a C type format, such as SQL or Python, are
usually mal-formatted. (a C type format has blocks enclosed
by brackets and statements terminated by a semi-colon). Macros defining functions
may cause the following code to be mal-formatted because the macro is missing the
brackets and semi-colons from the definition.
If you have source code with these types of statements, exclude them with the --exclude=
statement described in the "Other Options" section.
If you have never used Artistic Style there are a couple of ways to start. One is to run it with no options at all. This will format the file with 4 spaces per indent and will leave the brackets unchanged. Another is to use one of the predefined styles described in the "Predefined Style Options" section. Select one with a bracket formatting style you like. Once you are familiar with the options you can customize the format to your personal preference.
Artistic style is a console program that receives information from the command line. The format of the command line is:
astyle [options] SourceFile1 SourceFile2 SourceFile3 [ . . . ]
The block parens [ ] indicate that more than one option or more than one filename can be entered. They are NOT actually included in the command. For the options format see the following Options section.
Example to format a single file:
astyle --style=allman /home/user/project/foo.cpp
Example to format all .cpp and .h files recursively:
astyle --style=allman --recursive /home/user/project/*.cpp /home/user/project/*.h
Or to format the file with a different name:
astyle [options] < OriginalSourceFile > BeautifiedSourceFile
The < and > characters are used to redirect the files into standard input (cin) and out of standard output (cout) - don't forget them! With this option only one file at a time can be formatted. Wildcards are not recoginzed, there are no console messages, and a backup is not created.
Not specifying any option will result in 4 spaces per indent, no change in bracket placement, and no formatting changes.
Options may be written in two different ways.
These options start with '--', and must be written
one at a time.
(Example: '--brackets=attach --indent=spaces=4
')
These options start with a single '-', and may be
concatenated together.
(Example: '-bps4
' is the same as writing '-b -p -s4
'.)
A default options file may be used to set your favorite source style options.
Example of a default options file:
# this line is a comment --brackets=attach # this is a line-end comment # long options can be written without the preceding '--' indent-switches # cannot do this on the command line # short options must have the preceding '-' -t -p # short options can be concatenated together -M65Ucv
Predefined Style options define the style by setting other options. The style options always override any individual option settings. You will always get the requested style regardless of other defined options.
The predefined style options always set the options brackets=###, indent‑blocks, and indent‑brackets. These options can NOT be changed with the individual option settings.
Some styles use the default setting for spaces per indent and some use a different setting. You may use any of the indent= options with any style. The indent options that do not set the spaces per indent (indent=spaces, indent=tab, or indent=force‑tab) will use the default spaces per tab setting for the style. The indent options that set the spaces per indent (indent=spaces=#, indent=tab=#, or indent=force‑tab=#) will use the specified spaces per tab setting instead of the default for the style. For the options that set the spaces per indent see the following style descriptions.
All other options are available to customize the style. By default, none of the styles indent namespaces. This can be changed with the indent‑namespaces option.
--style=allman / --style=ansi / --style=bsd / -A1
Allman style formatting/indenting uses broken brackets.
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; }
--style=java / -A2
/ --style=kr (depreciated)
Java style formatting/indenting uses attached brackets.
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; }
--style=k&r / --style=k/r / -A3
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.
Using the k&r option may cause problems because of the &. This can be resolved by enclosing the k&r in quotes (e.g. ‑‑style="k&r") or by using the alternate ‑‑style=k/r.
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; }
--style=stroustrup / -A4
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. Indentation is 5 spaces.
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; }
--style=whitesmith / -A5
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; }
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; }
--style=gnu / -A7
GNU style formatting/indenting uses broken brackets and indented blocks. Indentation
is 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; }
--style=linux / -A8
Linux style formatting/indenting uses linux style brackets. Brackets are broken from namespace, class,
and function definitions. Brackets are attached to statements within a function. Indentation is 8 spaces.
Also known as Kernel Normal Form (KNF) style, this is the style used in the Linux kernel.
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; }
--style=horstmann / -A9
Horstmann style formatting/indenting uses horstmann style brackets. Brackets are
broken with run-in statements. Switches are indented. Indentation is 3 spaces.
int Foo(bool isBar) { if (isBar) { bar(); return 1; } else return 0; }
default indent option
If no indentation option is set, the default option of 4 spaces will be
used (e.g. -s4
--indent=spaces=4
).
--indent=spaces /
--indent=spaces=# / -s#
Indent using # spaces per indent (e.g.
-s6
--indent=spaces=6
). # must be between 2 and 20. Not specifying
# will result in a default of 4
spaces per indent.
--indent=tab /
--indent=tab=# / -t /
-t#
Indent using tab characters. Treat each tab as #
spaces (e.g. -t6
/
--indent=tab=6
). # must be between 2 and 20.
If no # is set, treats tabs as 4 spaces.
--indent=force-tab / --indent=force-tab=# /
-T / -T#
/ --force-indent=tab=#
(depreciated)
Indent using tab characters. Treat each tab as #
spaces (e.g. -T6
/
--indent=force-tab=6
).
Uses tabs as indents where
‑‑indent=tab
prefers to use spaces, such as inside multi-line statements.
# must be between 2 and 20. If no # is set, treats tabs as 4 spaces.
default brackets option
If no brackets option is set, the brackets will not be changed.
--brackets=break / -b
Break brackets from their pre-block statements ( e.g. ANSI C / C++ style ).
void Foo(bool isFoo) { if (isFoo) { bar(); } else { anotherBar(); } }
--brackets=attach / -a
Attach brackets to their pre-block statements ( e.g. Java / K&R style ).
void Foo(bool isFoo) { if (isFoo) { bar(); } else { anotherBar(); } }
--brackets=linux / -l
Break brackets from namespace, class, and function definitions, but attach brackets to statements within a function.
With C++ files brackets are attached for function definitions within a class (inline class functions). The brackets are also attached for arrays, structs, enums, and other top level objects that are not classes or functions. This option is effective for C/C++ files only.
void Foo(bool isFoo) { if (isFoo) { bar(); } else { anotherBar; } }
--brackets=stroustrup / -u
Break brackets from function definitions only. Attach brackets to namespaces, classes, and statements within a function.
With C++ files brackets are attached for function definitions within a class (inline class functions). The brackets are also attached for arrays, structs, enums, and other top level objects that are not classes or functions. This option is effective for C/C++ files only.
void Foo(bool isFoo) { if (isFoo) { bar(); } else { anotherBar; } }
--brackets=horstmann / -g
Break brackets from their pre-block statements but allow run-in statements on the
same line as an opening bracket. Cannot use --indent-brackets with this option.
void Foo(bool isFoo) { if (isFoo()) { bar1(); bar2(); } else { anotherBar(); } }
--indent-classes / -C
Indent 'class
' and 'struct
' blocks so that the blocks
'public:
', 'protected:
' and 'private:
' are indented.
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(); };
--indent-switches / -S
Indent '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; } }
--indent-cases / -K
Indent '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; } }
--indent-brackets / -B
Add extra indentation to brackets. This is the option used for Whitesmith and Banner style
formatting/indenting. If both ‑‑indent‑brackets and ‑‑indent‑blocks are used the result
will be ‑‑indent‑blocks. This option will
be ignored if used with a predefined style.
if (isFoo) { bar(); } else anotherBar();
becomes:
if (isFoo) { bar(); } else anotherBar();
--indent-blocks / -G
Add extra indentation to blocks within a function. The opening bracket for namespaces, classes, and
functions is not indented. This is the option used for GNU style formatting/indenting. This option will be ignored if used with a predefined
style.
if (isFoo) { bar(); } else anotherBar();
becomes:
if (isFoo) { bar(); } else anotherBar();
--indent-namespaces / -N
Add 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(); }; }
--indent-labels / -L
Add 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: ... } }
--indent-preprocessor / -w
Indent multi-line preprocessor definitions ending with a backslash. Should be used with
--convert-tabs for proper results. Does a pretty good job,
but can not 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)))
--max-instatement-indent=# / -M#
Indent a maximum of # spaces in a continuous
statement, relative to the previous line (e.g.
‑‑max‑instatement‑indent=40).
# must be less than 80. If no
# is set, the default value of 40
will be used. A maximum of less than two indent lengths will be ignored.
fooArray[] = { red, green, blue }; fooFunction(barArg1, barArg2, barArg3);
becomes (with larger value):
fooArray[] = { red, green, blue }; fooFunction(barArg1, barArg2, barArg3);
--min-conditional-indent=# / -m#
Set the minimal indent that is added when a header is built of multiple-lines. This indent
makes helps to easily separate the header from the command statements that follow. The
value for # must be less than 40. The default
setting for this option is twice the current indent (e.g.
--min-conditional-indent=8).
// 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++; }
--break-blocks / -f
Pad 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;
--break-blocks=all / -F
Pad 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;
--pad-oper / -p
/ --pad=oper (depreciated)
Insert space padding around operators. Operators inside block parens [] are
not padded. 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--);
--pad-paren / -P
/ --pad=paren (depreciated)
Insert 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, b)) bar(a, b);
becomes:
if ( isFoo ( a, b ) ) bar ( a, b );
--pad-paren-out / -d
/ --pad=paren-out (depreciated)
Insert 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, b)) bar(a, b);
becomes:
if (isFoo (a, b) ) bar (a, b);
--pad-paren-in / -D
/ --pad=paren-in (depreciated)
Insert 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, b)) bar(a, b);
becomes:
if ( isFoo( a, b ) ) bar( a, b );
--pad-header / -H
Insert space padding after paren 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, b)) bar(a, b);
becomes:
if (isFoo(a, b)) bar(a, b);
--unpad-paren / -U
/ --unpad=paren (depreciated)
Remove 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 paren padding options pad‑paren
, pad‑paren‑out
,
pad‑paren‑in
, and pad‑header
above.
Only padding that has not been requested by other options will be removed.
For example, if a source has parens padded on both the inside and outside, and you want
inside only. You need to use unpad-paren
to remove the outside padding, and
pad‑paren‑in
to retain the inside padding. Using only
pad‑paren‑in
would not remove the outside padding.
if ( isFoo( a, b ) ) bar ( a, b );
becomes (with no padding option requested):
if (isFoo(a, b)) bar(a, b);
--delete-empty-lines / -x
Delete empty lines within a function or method. Empty lines outside of functions or methods are NOT
deleted. If used with break-blocks or break-blocks=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; }
--fill-empty-lines / -E
Fill empty lines with the white space of the previous line.
--break-closing-brackets /
-y
/ --brackets=break-closing (depreciated)
When used with --brackets=attach, --brackets=linux, or --brackets=stroustrup,
this breaks closing headers (e.g.
'else', 'catch', ...) from their immediately preceding closing brackets. Closing header brackets are always
broken with broken brackets,
horstmann brackets, indented blocks, and indented brackets.
void Foo(bool isFoo) { if (isFoo) { bar(); } else { anotherBar(); } }
becomes (with a broken 'else'):
void Foo(bool isFoo) { if (isFoo) { bar(); } else { anotherBar(); } }
--break-elseifs / -e
Break "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(); }
--keep-one-line-blocks / -O
/ --one-line=keep-blocks (depreciated)
Don't break one-line blocks.
if (isFoo) { isFoo = false; cout << isFoo << endl; }
remains unchanged.
--keep-one-line-statements /
-o
/ --one-line=keep-statements (depreciated)
Don't break complex statements and multiple statements residing on a single line.
if (isFoo) { isFoo = false; cout << isFoo << endl; }
remains unchanged.
if (isFoo) DoBar();
remains unchanged.
--convert-tabs / -c
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 convert-tabs is used
when changing spaces per tab. Tabs are not replaced in quotes.
--align-pointer=type / -k1
--align-pointer=middle / -k2
--align-pointer=name / -k3
Attach a pointer or reference operator (* or &) to either the variable type
(left) or variable name (right), or place it between the type and name. The spacing between the type and name will be preserved,
if possible. This option is effective for C/C++ files only.
char *foo1;
becomes (with align-pointer=type):
char* foo1;
char* foo2;
becomes (with align-pointer=middle):
char * foo2;
char& foo3;
becomes (with align-pointer=name):
char &foo3;
--mode=c
Indent a C or C++ file. The 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.
--mode=java
Indent a Java file. The 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 Java
class's keywords.
--mode=cs
Indent a C sharp file. The 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
sharp classes and keywords.
--suffix=####
Append the suffix #### instead of '.orig' to original filename
(e.g. --suffix=.bak
). If this is to be a file
extension, the dot '.' must be included. Otherwise the suffix will be appended to the
current file extension.
--suffix=none / -n
Do not retain a backup of the original file. The original file is purged after it is
formatted.
--options=####
Specify an options file #### to read and use.
--options=none
Disable the default options file. Only the command-line parameters will be used.
--recursive / -r / -R
For each directory in the command line, process all subdirectories recursively. When using
the recursive option the file name statement should contain a wildcard. Linux users should
place the filepath and name in double quotes so the shell will not resolve the wildcards
(e.g. "$HOME/src/*.cpp"). Windows users should place the filepath and name in double quotes
if the path or name contains spaces.
--exclude=####
Specify a file or sub directory #### to be excluded from
processing.
Excludes are matched from the end of the filepath. An exclude option of "templates" will exclude ALL directories named "templates". An exclude option of "cpp/templates" will exclude ALL "cpp/templates" directories. You may proceed backwards in the directory tree to exclude only the required directories.
Specific files may be excluded in the same manner. An exclude option of "default.cpp" will exclude ALL files named "default.cpp". An exclude option of "python/default.cpp" will exclude ALL files named "default.cpp" contained in a "python" subdirectory. You may proceed backwards in the directory tree to exclude only the required files.
Wildcards are NOT allowed. There may be more than one exclude statement. The filepath and name may be placed in double quotes (e.g. ‑‑exclude="foo bar.cpp").
--errors-to-stdout / -X
Print errors to standard-output rather than to standard-error.
This option should be helpful for systems/shells that do not have this option, such as in
Windows95.
--verbose / -v
Verbose display mode. Display optional information, such as release number and statistical
data.
--formatted / -Q
Formatted files display mode. Display only the files that have been formatted. Do not display
files that are unchanged.
--quiet / -q
Quiet display mode. Suppress all output except error messages.
--version / -V
Print version number and quit. The short option must be by itself, it cannot be
concatenated with other options.
--help / -h / -?
Print a help message and quit. The short option must be by itself, it cannot be
concatenated with other options.
![]() ![]() |
ENJOY !!! |