ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

超好用的代码格式化工具Astyle使用

2021-05-09 11:02:27  阅读:439  来源: 互联网

标签:缩进 格式化 -- 超好 isFoo indent Astyle Foo 大括号


本软件适用于C, C++, C++/CLI, Objective‑C, C#, and Java

一、使用流程

1.安装软件

linux:apt install astyle,重启vscode

windows:下载最新版本,并将exe路径添加至PATH,重启vscode

2.安装vscode插件Astyle

3.配置

使用:设置->拓展->Astyle->在settings.json中编辑(后附具体配置)

配置示意图

"astyle.additional_languages": [
        "c",
        "cpp",
    ],
    "astyle.cmd_options": [
        "--style=allman",
        "--indent=spaces=4",
        "--indent-modifiers",
        "--indent-switches",
        "--indent-cases",
        "--indent-namespaces",
        "--indent-preproc-block",
        "--min-conditional-indent=2",
        "--pad-oper",
        "--pad-header",
        "--unpad-paren",
        "--delete-empty-lines",
        "--align-pointer=name",
        "--align-reference=name",
        "--keep-one-line-statements",
        "--convert-tabs",
        "--close-templates",
        /*"--max-code-length=#", 单行code最大长度
        "--break-after-logical",*/
        "--suffix=none",
        "--lineend=linux",
        "--verbose",
    ],
    "[c]": {
        "editor.defaultFormatter": "chiehyu.vscode-astyle"
    },
    "[cpp]": {
        "editor.defaultFormatter": "chiehyu.vscode-astyle"
    },

(配置参考:RT-thread)

具体配置:

1.大括号选项

--style=allman / --style=bsd / --style=break / -A1 :分离大括号风格

int Foo(bool isBar)

{

    if (isBar)

    {

        bar();

        return 1;

    }

    else

        return 0;

}

--style=java / --style=attach / -A2 :JAVA风格 ——附加大括号

int Foo(bool isBar) {

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

--style=kr / --style=k/r / -A3:Linux风格 —— 开始的大括号与名称空间、类和函数定义分开。其余大括号附加到函数内的所有其他内容,包括数组、结构体、枚举和语句。

int Foo(bool isBar)

{

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

--style=stroustrup / -A4:Stroustrup风格 —— 使用了linux大括号,并将大括号的结束头与结束头分开(例如:break - closing - headers)。开始的大括号只从函数定义中断开。开始的大括号附加到函数中的所有其他内容,包括名称空间、类、数组、结构、枚举和语句。这种样式经常与“attach - closing - while”、tab缩进和5个空格缩进一起使用。

int Foo(bool isBar)

{

    if (isBar) {

        bar();

        return 1;

    }

    else

        return 0;

}

--style=whitesmith / -A5:白铁匠风格 —— 使用破碎的,缩进的括号。Switch块和类块缩进以防止以下case语句和c++类修饰符(public, private, protected)的“挂缩进”。

int Foo(bool isBar)

    {

    if (isBar)

        {

        bar();

        return 1;

        }

    else

        return 0;

    }

--style=ratliff / --style=banner / -A6:Ratliff风格 —— 使用附加的,缩进的括号。Switch块和类块缩进是为了防止下面的case语句和c++类修饰符(public, private, protected)出现“挂缩进”。

int Foo(bool isBar) {

    if (isBar) {

        bar();

        return 1;

        }

    else

        return 0;

    }

--style=gnu / -A7:GNU风格 —— 使用断括号。额外的缩进只被添加到函数内的块中。整个块都是缩进的,而不仅仅是大括号。这种样式经常用于缩进2个空格。

int Foo(bool isBar)

{

    if (isBar)

        {

            bar();

            return 1;

        }

    else

        return 0;

}

--style=linux / --style=knf / -A8:Linux风格 —— 使用Linux大括号。开始的大括号与名称空间、类和函数定义分开。大括号附加到函数内的所有其他内容,包括数组、结构体、枚举和语句。最小的条件缩进是一半缩进。如果您想要不同的最小条件缩进,请使用K&R样式。这种风格最适合大缩进。它经常与缩进8个空格一起使用。也称为内核范式(KNF)风格,这是在Linux BSD内核中使用的风格。

int Foo(bool isBar)

{

        if (isFoo) {

                bar();

                return 1;

        } else

                return 0;

}

--style=horstmann / --style=run-in / -A9:Horstmann风格 —— 使用破括号和插入语句。switch是缩进的,以允许在打开开关块上磨合。这种样式经常使用缩进3个空格。

int Foo(bool isBar)

{   if (isBar)

    {   bar();

        return 1;

    }

    else

        return 0;

}

--style=1tbs / --style=otbs / -A10:One True Brace 风格 —— 使用linux大括号,并将大括号添加到未加大括号的条件语句中。开始的大括号与名称空间、类和函数定义分开。大括号附加到函数内的所有其他内容,包括数组、结构体、枚举和语句。

int Foo(bool isBar)

{

    if (isFoo) {

        bar();

        return 1;

    } else {

        return 0;

    }

}

--style=pico / -A11:Pico风格 —— 使用断开的大括号和带有附加的闭大括号的run-in语句。右大括号附加到代码块的最后一行。开关是缩进的,以允许在打开开关块上磨合。这种风格意味着保持一行块和保持一行语句。如果使用了add-大括号,它们将被添加为一行大括号。这种样式经常用于缩进2个空格。

int Foo(bool isBar)

{   if (isBar)

    {   bar();

        return 1; }

    else

        return 0; }

--style=lisp / --style=python / -A12:Lisp风格 —— 使用附加的开括号和闭括号。右大括号附加到代码块的最后一行。这种风格意味着保持一行语句,而不是保持一行块。此样式不支持单行大括号。如果使用了add-one-line-大括号,它们将被添加为多行大括号。

int Foo(bool isBar) {

    if (isBar) {

        bar()

        return 1; }

    else

        return 0; }

--style=google / -A14: 谷歌风格 —— 使用附加的花括号和缩进的类访问修饰符。有关缩进修饰符格式的示例,请参阅缩进修饰符选项。这实际上不是唯一的大括号风格,而是带有非大括号变体的Java风格。这种样式经常用于缩进2个空格。

int Foo(bool isBar) {

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

--style=vtk / -A15:VTK(可视化工具包)风格 —— 使用破碎、缩进的大括号,除了类、数组、结构、枚举和函数定义的左大括号。Switch块缩进是为了防止下面的case语句出现“挂缩进”。

int Foo(bool isBar)

{

    if (isBar)

        {

        bar();

        return 1;

        }

    else

        return 0;

}

--style=mozilla / -A16:Mozilla风格 —— 使用linux大括号。开始的大括号与类、结构体、枚举和函数定义分开。大括号附加到函数中的所有其他内容,包括名称空间、数组和语句。这种样式经常与缩进2个空格和——break-return-type一起使用。

int Foo(bool isBar)

{

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

 

2.Tab选项

default indent(如果没有设置缩进选项,将使用默认选项4个空格(eg::-s4/--indent=spaces=4)。)

void Foo() {

....if (isBar1

............&& isBar2)    // indent of this line can be changed with min-conditional-indent

........bar();

}

--indent=spaces / --indent=spaces=# / -s#:每缩进使用#空格(eg::-s3/--indent=spaces=3)。#必须在2到20之间。不指定同default indent

void Foo() {

...if (isBar1

.........&& isBar2)    // indent of this line can be changed with min-conditional-indent

......bar();

}

--indent=tab / --indent=tab=# / -t / -t#:使用制表符进行缩进,使用空格进行继续行对齐。这可以确保无论查看器的选项卡大小如何,代码都能正确显示。将每个缩进当作#空格(例如-t6 /——indent=tab=6)。#必须在2到20之间。如果没有设置#,将缩进处理为4个空格。

with indent=tab:

void Foo() {

>   if (isBar1

>   ........&& isBar2)    // indent of this line can be changed with min-conditional-indent

>   >   bar();

}

with style=linux, indent=tab=8:

void Foo()

{

>       if (isBar1

>       ....&& isBar2)    // indent of this line can NOT be changed with style=linux

>       >       bar();

}

--indent=force-tab / --indent=force-tab=# / -T / -T#:如果可能的话,使用所有制表符缩进。如果连续行不是偶数个制表符,将在末尾添加空格。将每个制表符视为#空格(例如-T6 /——indent=force-tab=6)。#必须在2到20之间。如果没有设置#,将制表符视为4个空格。

with indent=force-tab:

void Foo() {

>   if (isBar1

>   >   >   && isBar2)    // indent of this line can be changed with min-conditional-indent

>   >   bar();

}

--indent=force-tab-x / --indent=force-tab-x=# / -xT / -xT#:这个force-tab选项允许将制表符长度设置为与缩进长度不同的长度。这可能会导致缩进同时包含制表符和空格。如果可能的话,制表符将用于缩进。如果不能使用制表符缩进,将使用空格代替。此选项设置制表符长度。将每个制表符视为#空格(例如-xT6 /——indent=force-tab-x=6。#必须在2到20之间。如果没有设置#,将制表符视为8个空格。为了改变缩进长度从默认的4空格选项"indent=force-tab"也必须使用。

with indent=force-tab-x (default tab length of 8 and default indent length of 4):

void Foo() {

....if (isBar1

>       ....&& isBar2)    // indent of this line can be changed with min-conditional-indent

>       bar();

}

 

3.大括号修饰选项

--attach-namespaces / -xn:大括号总是附加在命名空间语句上。

namespace FooName {

...

}

--attach-classes / -xc: 大括号总是附加在类语句上。

class FooClass {

...

};

--attach-inlines / -xl:所有大括号都附加到类和结构的内联方法定义(仅c++)

class FooClass

{

    void Foo() {

    ...

    }

};

--attach-extern-c / -xk:将大括号附加到带大括号的extern "C"语句(仅c++)

#ifdef __cplusplus

extern "C" {

#endif

但是函数定义是按照要求的大括号样式进行格式化的:

extern "C" EXPORT void STDCALL Foo()

{}

--attach-closing-while / -xV:将'do-while'语句的'while'附加到右括号。这优先于大括号样式和break关闭大括号选项。

do

{

    bar();

    ++x;

}

while x == 1;

becomes:

do

{

    bar();

    ++x;

} while x == 1;

 

4.缩进选项

--indent-classes / -C:缩进'class'和'struct'访问修饰符'public:', 'protected:'和'private:'(仅c++)

class Foo

{

public:

    Foo();

    virtual ~Foo();

};

becomes:

class Foo

{

    public:

        Foo();

        virtual ~Foo();

};

--indent-modifiers / -xG:缩进'class '和'struct'访问修饰符'public:', 'protected:'和'private:',缩进一半。如果与缩进类一起使用,这个选项将被忽略。(仅c++)

class Foo

{

public:

    Foo();

    virtual ~Foo();

};

becomes:

class Foo

{

  public:

    Foo();

    virtual ~Foo();

};

--indent-switches / -S:缩进'switch'块,以便'case X:'语句在switch块中缩进。整个case块是缩进的。

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:缩进'case X:'块从'case X:'头。不包含在块中的Case语句不缩进。

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-namespaces / -N:向名称空间块添加额外的缩进

namespace foospace

{

class Foo

{

    public:

        Foo();

        virtual ~Foo();

};

}

becomes:

namespace foospace

{

    class Foo

    {

        public:

            Foo();

            virtual ~Foo();

    };

}

--indent-after-parens / -xU:在包含开头圆括号'('或赋值'='的行后面缩进,包括函数定义、声明和返回语句。

void Foo(bool bar1,

         bool bar2)

{

    isLongFunction(bar1,

                   bar2);



    isLongVariable = foo1

                     || foo2;

}

becomes:

void Foo(bool bar1,

    bool bar2)

{

    isLongFunction(bar1,

        bar2);



    isLongVariable = foo1

        || foo2;

}

--indent-continuation=# / -xt#:设置以开始的圆括号'('或赋值'='结尾的行的延续缩进,包括函数定义和声明。它还将修改前面的缩进后括号选项。#的值表示大量的缩进。有效值是从0到4的整数值。如果不使用该选项,则使用默认值1。

isLongVariable =

    foo1 ||

    foo2;



isLongFunction(

    bar1,

    bar2);

becomes (with indent-continuation=3):

isLongVariable =

            foo1 ||

            foo2;



isLongFunction(

            bar1,

            bar2);

--indent-labels / -L:向标签添加额外的缩进,使它们显示比当前缩进少1个缩进,而不是向左刷新(默认)。

void Foo() {

    while (isFoo) {

        if (isFoo)

            goto error;

        ...

error:

        ...

        }}

becomes (with indented 'error:'):

void Foo() {

    while (isFoo) {

        if (isFoo)

            goto error;

        ...

    error:

        ...

        }

}

--indent-preproc-block / -xW:缩进预处理器块在大括号级别0,并立即在名称空间内。对缩进的内容有限制。方法、类、数组等中的块不会缩进。包含大括号或多行定义语句的块将不会缩进。没有此选项,预处理器块不会缩进。

#ifdef _WIN32

#include <windows.h>

#ifndef NO_EXPORT

#define EXPORT

#endif

#endif

becomes:

#ifdef _WIN32

    #include <windows.h>

    #ifndef NO_EXPORT

        #define EXPORT

    #endif

#endif

--indent-preproc-define / -w:缩进以反斜杠结尾的多行预处理器定义。应该与 --convert-tabs一起使用,以获得正确的结果。做得很好,但不能在模糊预处理定义中执行奇迹。如果没有这个选项,预处理器语句将保持不变。

#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)))

--indent-preproc-cond / -xw:将预处理条件语句缩进到与源代码相同的级别。

        isFoo = true;

#ifdef UNICODE

        text = wideBuff;

#else

        text = buff;

#endif

becomes:

        isFoo = true;

        #ifdef UNICODE

        text = wideBuff;

        #else

        text = buff;

        #endif

--indent-col1-comments / -Y:从第一列开始缩进c++注释。默认情况下,从第一列开始的c++注释被假定为注释输出代码,而不是缩进。此选项将允许注释与代码一起缩进。

void Foo()\n"

{// comment

    if (isFoo)

        bar();

}

becomes:

void Foo()\n"

{

    // comment

    if (isFoo)

        bar();

}

--min-conditional-indent=# / -m#:

设置header由多行组成时添加的最小缩进。这种缩进有助于轻松地将header与后面的命令语句分开。#的值表示缩进的数量,并且是最小值。缩进可能更大,以与前一行的数据对齐。有效值为:

0 - 没有最小缩进。这些行将与前一行上的括号对齐。

1 - 至少缩进一个额外的缩进。

2 - 缩进至少两个额外的缩进。

3 - 至少要增加定单的一半。这用于大缩进(例如8)。

默认值是2,两个额外的缩进。

// default setting makes this non-braced code clear

if (a < b

        || c > d)

    foo++;



// but creates an exaggerated indent in this braced code

if (a < b

        || c > d)

{

    foo++;

}

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

// setting makes this non-braced code less clear

if (a < b

    || c > d)

    foo++;



// but makes this braced code clearer

if (a < b

    || c > d)

{

    foo++;

}

--max-continuation-indent=# / -M#:设置#空格的最大长度以缩进延续行。#表示列的数量,且不能小于40或大于120。如果没有设置,则使用默认值40。此选项将防止延续行向右延伸太远。设置更大的值将允许代码进一步向右扩展。

fooArray[] = { red,

         green,

         blue };



fooFunction(barArg1,

         barArg2,

         barArg3);

becomes (with larger value):

fooArray[] = { red,

               green,

               blue };



fooFunction(barArg1,

            barArg2,

            barArg3);

4.填充选项

--break-blocks / -f:在标题块周围填充空行(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:在标题块周围填充空行(e.g. 'if', 'for', 'while'...).处理关闭头文件块(e.g. 'else', 'catch')作为独立块。

isFoo = true;

if (isFoo) {

    bar();

} else {

    anotherBar();

}

isBar = false;

becomes:

isFoo = true;



if (isFoo) {

    bar();



} else {

    anotherBar();

}



isBar = false;

--pad-oper / -p:在运算符周围插入空格。这也会添加逗号。如果可能的话,行尾注释将保留在原始列中。注意,没有取消垫的选项。一旦被填充,它们就保持填充状态。

if (foo==2)

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

becomes:

if (foo == 2)

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

--pad-comma / -xg:在逗号后插入空格。如果使用pad-oper,则不需要加。行尾注释将保留在原始列中。

if (isFoo(a,b))

    bar(a,b);

becomes:

if (isFoo(a, b))

    bar(a, b);

--pad-paren / -P:在括号的外部和内部都插入空格填充。行尾注释将保留在原始列中。

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

    bar(a, b);

becomes:

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

    bar ( a, b );

--pad-paren-out / -d:只在括号外面插入空格填充。空的括号不会加衬垫。如果可能的话,行尾注释将保留在原始列中。这可以用下面的unpad-paren来删除不需要的空间。

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

    bar(a, b);

becomes:

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

    bar (a, b);

--pad-first-paren-out / -xd:在序列的第一个圆括号周围只在外部插入空格填充。空的括号不会加衬垫。行尾注释将保留在原始列中。可以用unpad-paren删除不需要的空间。如果与pad‑paren或pad‑paren‑out一起使用,该选项将被忽略。

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

    bar(a, b);

becomes:

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

    bar (a, b);

--pad-paren-in / -D:只在里面插入圆括号周围的空格。行尾注释将保留在原始列中。这可以用下面的unpad-paren来删除不需要的空间。

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

    bar(a, b);

becomes:

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

    bar( a, b );

--pad-header / -H:在标题之间插入空格(e.g. 'if', 'for', 'while'...)和下面的括号。行尾注释将保留在原始列中。可以使用unpad-paren删除不需要的空格。

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

    bar(a, b);

becomes:

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

    bar(a, b);

--unpad-paren / -U:在内外两边去掉多余的填充空间。行尾注释将保留在原始列中。

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

    bar ( a, b );

becomes (with no padding option requested):

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

    bar(a, b);

--delete-empty-lines / -xe:删除函数或方法中的空行。函数或方法之外的空行不会被删除。如果与break-blocks或break-blocks=all一起使用,它将删除除由break-blocks选项添加的行之外的所有行。

void Foo()

{



    foo1 = 1;



    foo2 = 2;



}

becomes:

void Foo()

{

    foo1 = 1;

    foo2 = 2;

}

--fill-empty-lines / -E:用前一行的空白填充空行。

--align-pointer=type   / -k1

--align-pointer=middle / -k2

--align-pointer=name   / -k3

将指针或引用操作符(*、&或^)附加到变量类型(左)或变量名称(右),或将其放在类型和名称(中间)之间。如果可能的话,将保留类型和名称之间的空格。这个选项适用于C/ c++、c++ /CLI和c#文件。要单独格式化引用,请使用以下align-reference选项。

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=none   / -W0

--align-reference=type   / -W1

--align-reference=middle / -W2

--align-reference=name   / -W3

该选项将引用与指针分开对齐。指针不会被这个选项改变。如果指针和引用要对齐,请使用前面的对齐指针选项。选项align-reference=none不会改变引用对齐方式。其他选项与对齐指针相同。(仅C/ C++、c++ /CLI和C#文件)。

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;

 

5.格式化选项

--break-closing-braces / -y:当与 --style=java, --style=kr, --style=stroustrup, --style=linux, 或者--style=1tbs同时使用,会打破关闭头文件 (e.g. 'else', 'catch', ...) 。结束标题花括号总是与其他样式一起断开。

void Foo(bool isFoo) {

    if (isFoo) {

        bar();

    } else {

        anotherBar();

    }}

becomes (a broken 'else'):

void Foo(bool isFoo) {

    if (isFoo) {

        bar();

    }

    else {

        anotherBar();

    }

}

--break-elseifs / -e:将"else if"标题组合分隔成单独的行。如果使用keep-one-line语句,则此选项无效,“else if”语句将保持原样。

如果不使用此选项,"else If "标题组合将被放置在单行上。

if (isFoo) {

    bar();

}

else if (isFoo1()) {

    bar1();

}

else if (isFoo2()) {

    bar2;

}

becomes:

if (isFoo) {

    bar();

}

else

    if (isFoo1()) {

        bar1();

    }

    else

        if (isFoo2()) {

            bar2();

        }

--break-one-line-headers / -xb:从位于同一行的语句中断开一行标题(e.g. 'if', 'while', 'else', ...)如果语句用大括号括起来,大括号将根据要求的大括号样式进行格式化。如果使用keep-one-line-statements,则多语句行不会被断开。如果使用keep-one-line-blocks,并且报头包含在块中,则一行块不会被打断。

void Foo(bool isFoo)

{

    if (isFoo1) bar1();



    if (isFoo2) { bar2(); }}

becomes:

void Foo(bool isFoo)

{

    if (isFoo1)

        bar1();



    if (isFoo2) {

        bar2();

    }

}

--add-braces / -j:向不带大括号的单行条件语句添加大括号(例如:“如果”,“对”,“而”……)。大括号将根据要求的大括号样式添加。如果没有要求样式,将附加大括号。如果使用keep-one-line-statements,则不会将大括号添加到多语句行中。如果使用keep-one-line-blocks,则不会将大括号添加到一行块中。如果与--add-one-line-braces一起使用,结果将是一行大括号。

if (isFoo)

    isFoo = false;

becomes:

if (isFoo) {

    isFoo = false;

}

--add-one-line-braces / -J:添加一行大括号到不加大括号的一行条件语句 (e.g. 'if', 'for', 'while'...)。该选项意味--keep-one-line-blocks,并且不会打破一行块。

if (isFoo)

    isFoo = false;

becomes:

if (isFoo)

    { isFoo = false; }

--remove-braces / -xj:从条件语句中删除括号(例如:“如果”,“对”,“而”……)。语句必须是单行上的单个语句。如果还使用--add-braces或--add-one-line-braces,结果将是添加大括号。大括号不会从"One True Brace Style"中删除,--style=1tbs。

if (isFoo)

{

    isFoo = false;

}

becomes:

if (isFoo)

    isFoo = false;

--break-return-type      / -xB

--break-return-type-decl / -xD

从函数名中分离返回类型。这两个选项用于函数定义(-xB)和函数声明或签名(-xD)。如与--attach-return-type一起使用,结果将破坏返回类型。

void Foo(bool isFoo);

becomes:

void

Foo(bool isFoo);

--attach-return-type      / -xf

--attach-return-type-decl / -xh

将返回类型附加到函数名。这两个选项用于函数定义(-xf)和函数声明或签名(-xh)。它们的目的是撤消--break-return-type选项。如果与--break-return-type一起使用,结果将打破返回类型。

void

Foo(bool isFoo);

becomes:

void Foo(bool isFoo);

--keep-one-line-blocks / -O:不要打断一行代码块。

if (isFoo)

{ isFoo = false; cout << isFoo << endl; }

remains unchanged.

--keep-one-line-statements / -o:不要打破复杂语句和驻留在一行中的多个语句。

if (isFoo)

{

    isFoo = false; cout << isFoo << endl;

}

remains unchanged.

--convert-tabs / -c:将Tab转换为行非缩进部分中的空格。插入的空格数将保持制表符的间距。使用每个选项卡的空格的当前设置。如果在更改每个选项卡的空格时使用convert-tabs,可能不会产生预期的结果。制表符不会在引号内替换。

--close-templates / -xy:关闭模板定义结束尖括号之间的空白。

Stack< int, List< int > > stack1;

becomes:

Stack< int, List< int >> stack1;

--remove-comment-prefix / -xp:在以一行开头的多行注释中删除前面的'*'。如果末尾有'*',也会被删除。小于一个缩进的文本缩进为一个缩进。不改变大于一个缩进的文本。一行开头没有'*'的多行注释被缩进为一个缩进,以保持一致性。这可以略微修改注释掉代码块的缩进。包含所有'*'的行保持不变。注释关闭符'*/'将删除额外的空格。

/*

* comment line 1

* comment line 2

*/

becomes:

/*

    comment line 1

    comment line 2

*/

--max-code-length=#   / -xC#

--break-after-logical / -xL

如果代码超过#字符,选项max‑code‑length将断行。有效值为50到200。没有逻辑条件的行会在逻辑条件(||,&&,…)、逗号、圆括号、分号或空格处中断。有些代码不会被破坏,比如注释、引号和数组。如果与keep‑one‑line‑blocks或add-one-line-braces一起使用,block不会被破坏。如果与keep‑one‑line‑statements一起使用,当行超过最大长度时,语句将以分号分隔。如果在最大代码长度内没有可用的断点,则该行将在最大代码长度之后的第一个可用断点处被中断。默认情况下,逻辑条件将放在新行的第一个位置。选项break‑after‑logical将导致逻辑条件被放在前一行的最后。如果没有最大代码长度,这个选项就不起作用。

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();

--mode=c

--mode=cs

--mode=java

缩进一个C类型、c#或Java文件。C类型文件有C、c++、c++ /CLI和Objective-C。该选项通常从每个文件的文件扩展名设置。您可以使用此条目覆盖该设置。它将用于所有文件,而不管文件扩展名是什么。它允许格式化程序识别特定于语言的语法,如c++类、模板和关键字。

 

标签:缩进,格式化,--,超好,isFoo,indent,Astyle,Foo,大括号
来源: https://blog.csdn.net/qq_35358125/article/details/116561762

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有