astyle(1)
β¨ NAME β¨
Okay so welcome to the astyle(1) user documentation, bestie π β astyle is literally a C syntax indenter and formatter.
π¦ SYNOPSIS π¦
astyle [OPTIONS] [input files]
πΈ DESCRIPTION πΈ
astyle provides a variety of options to apply a consistent coding style to C, C++, Java or Objective-C source code files. Itβs giving βyour code, but make it coordinatedβ π
.
When indenting a specific file, the resulting indented file RETAINS the original file-name. The original pre-indented file is renamed, with a suffix of .orig added to the original filename. No cap.
Wildcards (* and ?) may be used in the filename. A 'recursive' option can process directories recursively. Multiple file extensions may be separated by a comma.
By default, astyle is set up to indent with four spaces per indent, a maximal indentation of 40 spaces inside continuous statements, a minimum indentation of eight spaces inside conditional statements, and NO formatting options. The default vibe is lowkey minimal β¨.
π Brace Style Options π
If no brace style is requested, the opening braces will not be changed and closing braces will be broken from the preceding line.
--style=allmanOR--style=bsdOR--style=breakOR-A1β Allman style formatting/indenting. Broken braces.--style=javaOR--style=attachOR-A2β Java style formatting/indenting. Attached braces.--style=krOR--style=k&rOR--style=k/rOR-A3β Kernighan & Ritchie style formatting/indenting. Linux braces.--style=stroustrupOR-A4β Stroustrup style formatting/indenting. Linux braces, with broken closing headers.--style=whitesmithOR-A5β Whitesmith style formatting/indenting. Broken, indented braces. Indented class blocks and switch blocks.--style=vtkOR-A15β VTK style formatting/indenting. Broken, indented braces except for the opening braces.--style=ratliffOR--style=bannerOR-A6β Ratliff style formatting/indenting. Attached, indented braces.--style=gnuOR-A7β GNU style formatting/indenting. Broken braces, indented blocks.--style=linuxOR--style=knfOR-A8β Linux style formatting/indenting. Linux braces, minimum conditional indent is one-half indent.--style=horstmannOR--style=run-inOR-A9β Horstmann style formatting/indenting. Run-in braces, indented switches.--style=1tbsOR--style=otbsOR-A10β One True Brace Style formatting/indenting. Linux braces, add braces to all conditionals.--style=googleOR-A14β Google style formatting/indenting. Attached braces, indented class modifiers.--style=mozillaOR-A16β Mozilla style formatting/indenting. Linux braces, with broken braces for structs and enums, and attached braces for namespaces.--style=webkitOR-A17β WebKit style formatting/indenting. Linux braces, with attached closing headers.--style=picoOR-A11β Pico style formatting/indenting. Run-in opening braces and attached closing braces. Uses keep one line blocks and keep one line statements.--style=lispOR-A12β Lisp style formatting/indenting. Attached opening braces and attached closing braces. Uses keep one line statements.
π Tab Options π
If no indentation option is set, the default option of 4 spaces per indent will be used.
--indent=spaces=#OR-s#β Indent using # spaces per indent. Not specifying # will result in a default of 4 spaces per indent.--indent=tabOR--indent=tab=#OR-tOR-t#β Indent using tab characters, assuming that each indent is # spaces long. Not specifying # will result in a default assumption of 4 spaces per indent.--indent=force-tab=#OR-T#β Indent using tab characters, assuming that each indent is # spaces long. Force tabs to be used in areas AStyle would prefer to use spaces.--indent=force-tab-x=#OR-xT#β Allows the tab length to be set to a length that is different from the indent length. This may cause the indentation to be a mix of both spaces and tabs. This option sets the tab length.
π«Ά Brace Modify Options π«Ά
--attach-namespacesOR-xnβ Attach braces to a namespace statement.--attach-classesOR-xcβ Attach braces to a class statement.--attach-inlinesOR-xlβ Attach braces to class inline function definitions.--attach-extern-cOR-xkβ Attach braces to an extern "C" statement.--attach-closing-whileOR-xVβ Attach closing while of do-while to the closing brace.
π§ Indentation Options π§
--indent-classesOR-Cβ Indent 'class' blocks so that the entire block is indented.--indent-modifiersOR-xGβ Indent 'class' access modifiers, 'public:', 'protected:' or 'private:', one half indent. The rest of the class is not indented.--indent-switchesOR-Sβ Indent 'switch' blocks, so that the inner 'case XXX:' headers are indented in relation to the switch block.--indent-casesOR-Kβ Indent case blocks from the 'case XXX:' headers. Case statements not enclosed in blocks are NOT indented.--indent-namespacesOR-Nβ Indent the contents of namespace blocks.--indent-after-parensOR-xUβ Indent, instead of align, continuation lines following lines that contain an opening paren '(' or an assignment '='.--indent-continuation=#OR-xt#β Indent continuation lines an additional # indents. The valid values are 0 thru 4 indents. The default value is 1 indent.--indent-labelsOR-Lβ Indent labels so that they appear one indent less than the current indentation level, rather than being flushed completely to the left (which is the default).--indent-preproc-blockOR-xWβ Indent preprocessor blocks at brace level 0. Without this option the preprocessor block is not indented.--indent-preproc-condOR-xwβ Indent preprocessor conditional statements #if/#else/#endif to the same level as the source code.--indent-preproc-defineOR-wβ Indent multi-line preprocessor #define statements.--indent-col1-commentsOR-Yβ Indent line comments that start in column one.--min-conditional-indent=#OR-m#β Indent a minimal # spaces in a continuous conditional belonging to a conditional header. The valid values are: 0 - no minimal indent. 1 - indent at least one additional indent. 2 - indent at least two additional indents. 3 - indent at least one-half an additional indent. The default value is 2, two additional indents.--max-continuation-indent=#OR-M#β Indent a maximal # spaces in a continuation line, relative to the previous line. The minimum and default value is 40.
π Padding Options π
--break-blocksOR-fβ Insert empty lines around unrelated blocks, labels, classes, ...--break-blocks=allOR-Fβ Like--break-blocks, except also insert empty lines around closing headers (e.g. 'else', 'catch', ...).--pad-operOR-pβ Insert space padding around operators.--pad-commaOR-xgβ Insert space padding after commas.--pad-negationβ Insert space padding after negations.--pad-negation=beforeβ Insert space padding also before negations.--pad-parenOR-Pβ Insert space padding around parenthesis on both the outside and the inside.--pad-paren-outOR-dβ Insert space padding around parenthesis on the outside only.--pad-first-paren-outOR-xdβ Insert space padding around first parenthesis in a series on the outside only.--pad-paren-inOR-Dβ Insert space padding around parenthesis on the inside only.--pad-headerOR-Hβ Insert space padding after paren headers (e.g. 'if', 'for'...).--unpad-parenOR-Uβ Remove unnecessary space padding around parenthesis. This can be used in combination with the 'pad' options above.--pad-empty-parenOR-xoβ Apply padding to empty pairs of parentheses; combine with other parenthesis padding options.--pad-bracketsβ Insert space padding around square brackets on both the outside and the inside.--pad-brackets-inβ Insert space padding around square brackets the inside only.--pad-brackets-outβ Insert space padding around square brackets the outside only.--unpad-bracketsβ Remove unnecessary space padding around square brackets.--delete-empty-linesOR-xeβ Delete empty lines within a function or method. It will NOT delete lines added by the break-blocks options.--fill-empty-linesOR-Eβ Fill empty lines with the white space of their previous lines.--align-pointer=typeOR-k1--align-pointer=middleOR-k2--align-pointer=nameOR-k3
Pointer alignment tea β: Attach a pointer or reference operator (*,&, or^) to either the operator type (left), middle, or operator name (right). To align the reference separately use--align-reference.
--align-reference=noneOR-W0--align-reference=typeOR-W1--align-reference=middleOR-W2--align-reference=nameOR-W3
Reference alignment tea β: Attach a reference operator (&) to either the operator type (left), middle, or operator name (right). If not set, follow pointer alignment.
--squeeze-lines=#β Remove superfluous empty lines exceeding the given number.--squeeze-wsβ Remove superfluous whitespace.
β¨ Formatting Options β¨
Okay bestie these are the shape-shifter options β they move braces, break lines, glue types to names, the whole glow-up. Let's go one by one. π
--break-closing-bracesOR-yβ Break braces before closing headers (like'else','catch', ...). Use it with--style=java,--style=kr,--style=stroustrup,--style=linux, or--style=1tbs.--break-elseifsOR-eβ Break'else if()'statements into two different lines. Splitting the couple up, respectfully. π--break-one-line-headersOR-xbβ Break one line headers (e.g.'if','while','else', ...) away from a statement sitting on the same line. Give them their own space, periodt.--add-bracesOR-j--add-braces=nested(experimental) β Add braces to unbraced one line conditional statements.--add-one-line-bracesOR-Jβ Add one line braces to unbraced one line conditional statements.--remove-bracesOR-xjβ Remove braces from a braced one line conditional statements.--break-return-typeOR-xB--break-return-type-declOR-xDβ Break the return type from the function name. These options are for the function definitions and the function declarations.--attach-return-typeOR-xf--attach-return-type-declOR-xhβ Attach the return type to the function name. These options are for the function definitions and the function declarations.--keep-one-line-blocksOR-Oβ Don't break blocks that live completely on one line. Leave them cozy. π«Ά--keep-one-line-statementsOR-oβ Don't break lines that contain multiple statements into multiple single-statement lines.--convert-tabsOR-cβ Convert tabs to the appropriate number of spaces. Tabs found, tabs handled. β¨--close-templatesOR-xyβ Close ending angle brackets on template definitions.--remove-comment-prefixOR-xpβ Remove the leading'*'prefix on multi-line comments and indent the comment text one indent.--max-code-length=#OR-xC#--break-after-logicalOR-xLβmax-code-length=#will break the line if it exceeds more than#characters. The valid values are50thru200. If the line contains logical conditionals they will be placed first on the new line. The optionbreak-after-logicalwill cause the logical conditional to be placed last on the previous line.--mode=cβ Indent a C or C++ source file (this is the default).--mode=javaβ Indent a Java source file.--mode=csβ Indent a C# source file.--mode=objcβ Indent an Objective-C source file.--mode=jsβ Indent a JavaScript source file (experimental).--mode=ghcβ Indent a GHC source file (experimental).--mode=gscβ Indent a GSC source file (experimental).
π Objective-C Options π
Apple-girlie formatting, exclusively for the - and + of it all. π
--pad-method-prefixOR-xQβ Insert space padding after the'-'or'+'Objective-C method prefix.--unpad-method-prefixOR-xRβ Remove all space padding after the'-'or'+'Objective-C method prefix.--pad-return-typeOR-xqβ Insert space padding after the Objective-C return type.--unpad-return-typeOR-xrβ Remove all space padding after the Objective-C return type.--pad-param-typeOR-xSβ Insert space padding after the Objective-C param type.--unpad-param-typeOR-xsβ Remove all space padding after the Objective-C param type.--align-method-colonOR-xMβ Align the colons in an Objective-C method definition. Alignment, but make it method. π--pad-method-colon=noneOR-xP--pad-method-colon=allOR-xP1--pad-method-colon=afterOR-xP2--pad-method-colon=beforeOR-xP3β Add or remove space padding before or after the colons in an Objective-C method call.
π Other Options π
The rest of the toolbox, bestie. Every single one matters, no skips. π
--suffix=####β Append the suffix####instead of'.orig'to original filename.--suffix=noneOR-nβ Do not retain a backup of the original file. Living dangerously, we love that for you. π--recursiveOR-rOR-Rβ Process subdirectories recursively.--dry-runβ Perform a trial run with no changes made to check for formatting. A vibe check before the real thing. β¨--exclude=####β Specify a file or directory####to be excluded from processing.--ignore-exclude-errorsOR-iβ Allow processing to continue if there are errors in theexclude=####options. It will display the unmatched excludes.--ignore-exclude-errors-xOR-xiβ Allow processing to continue if there are errors in theexclude=####options. It will NOT display the unmatched excludes.--errors-to-stdoutOR-Xβ Print errors and help information to standard-output rather than to standard-error.--preserve-dateOR-Zβ Preserve the original file's date and time modified. The time modified will be changed a few micro seconds to force a compile.--verboseOR-vβ Verbose mode. Extra informational messages will be displayed. She talks a lot and we love her. π£οΈ--formattedOR-Qβ Formatted display mode. Display only the files that have been formatted.--quietOR-qβ Quiet mode. Suppress all output except error messages.--lineend=windowsOR-z1--lineend=linuxOR-z2--lineend=macoldOR-z3β Force use of the specified line end style. Valid options arewindows(CRLF),linux(LF), andmacold(CR).
π Command Line Only π
These ones are command-line exclusives β they don't hang out in your option files. Main character behavior only. π
--options=####--options=noneβ Specify a default option file####to read and use. It must contain a file path and a file name.'none'disables the default option file.--project--project=####--project=noneβ Specify a project option file####to read and use. It must contain a file name only, without a directory path. The file should be included in the project top-level directory. The default file name is.astylercor_astylerc.'none'disables the project or environment variable file.--asciiOR-Iβ The displayed output will be ascii characters only.--versionOR-Vβ Print version number.--helpOR-hOR-?β Print this help message.--htmlOR-!β Open the HTML help file"astyle.html"in the default browser. The documentation must be installed in the standard install path.--html=####β Open a HTML help file in the default browser using the file path####. The path may include a directory path and a file name, or a file name only. Paths containing spaces must be enclosed in quotes.--stdin=####β Use the file path####as input to single file formatting. This is a replacement for redirection.--stdout=####β Use the file path####as output from single file formatting. This is a replacement for redirection.
πΈ Option Files πΈ
Artistic Style goes looking for a default option file and/or a project option file, and it does it in this exact order:
- The command line options have precedence.
- The project option file has precedence over the default file
- the file name indicated by the
--project=command line option. - the file named
.astylercor_astylerc. - the file name identified by
ARTISTIC_STYLE_PROJECT_OPTIONS. - the file is disabled by
--project=noneon the command line.
- the file name indicated by the
- The default option file that can be used for all projects.
- the file path indicated by the
--options=command line option. - the file path indicated by
ARTISTIC_STYLE_OPTIONS. - the file named
.astylercin theHOMEdirectory (for Linux). - the file name
astylercin theAPPDATAdirectory (for Windows). - the file is disabled by
--project=noneon the command line.
- the file path indicated by the
Long options within the option files may be written without '--'.
Line-end comments begin with a '#'. π
π¦ Disable Formatting π¦
Sometimes you just need the formatter to not. And that's valid, bestie.
Blocks of code can be disabled with the comment tags *INDENT-OFF* and *INDENT-ON*. It must be contained in a one-line comment.
Padding of operators can be disabled on a single line using the comment tag *NOPAD*. It must be contained in a line-end comment.
Pro tip from the vibes: these tags have to live inside the right kind of comment or they do nothing. Read the line above again, fr fr. π
β Examples β
File conversions, the moment you've been waiting for:
astyle --style=allman /home/project/foo.cpp
astyle --style=allman --recursive /home/project/*.cpp,*.h
astyle --style=allman < OriginalSourceFile > BeautifiedSourceFile
π AUTHORS π
Andre Simon <as@andre-simon.de>
π SEE ALSO π
More information at https://sourceforge.net/p/astyle/.
That's the whole page, bestie β every flag, every default, every little ####, all accounted for. π«Ά This one was written by Andre Simon, dated 2024-06-30, and it's the astyle(1) page. Go forth and format, you absolute icon. Slay. Periodt. πβ¨
π¦ where this page comes from
- ubuntu resolute: astyle 3.6.12-1 Β· MIT
- ubuntu stonking: astyle 3.6.12-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms