在Source Insight 4.0中,有代码格式化工具:
当你打开某个源文件后,可以对当前文件进行格式修改:
有ANSI、GNU、K&R三种编码风格可以选择。
也可以自己进行设置:
同时,这个代码格式设置还支持导入导出,使用XML文件。
另外在帮助文档里,可以搜到相关的使用说明。
相关说明
1,这里支持的文件类型是C/C++, C#, Java,这些使用类似花括号的语法。
2,你可以将修改后的设置保存成自己的编码格式。
3,如果选择一段代码,则只对选中代码进行格式化。如果不选择代码仅保留一个插入符,则对当前文件进行格式化。
相关设置
Layout and Flow
Control Statements - if, while, for, etc. |
Control statements sart a new line |
yes |
Blank line before control statement |
yes | |
Blank line after control statements |
yes | |
Keep else-if on same line |
yes | |
Force single line bodies onto next line |
yes | |
Add braces around single statement bodies |
no | |
Space after keywords: if, while, for, etc. |
yes | |
Brace style |
Open { brace on new line |
no |
Indent the open { brace |
no | |
Indent the close { brace |
no | |
Extra indent of statements inside braces |
no | |
Outermost braces at column 1 |
yes | |
Keep } else on same line |
no | |
Indentation |
Convert spaces to tabs |
no |
Indent width |
4 | |
Indentation for Goto labels |
At leftmost column |
yes |
Blank line above labels |
yes |
Classes and Comments
Classes and Structs |
Indent members |
yes |
Blank line above public/private labels |
yes | |
Blank line below public/private labels |
yes | |
Align field members at column |
16 | |
Align bit-field sizes at column |
32 | |
Indentation for Member Access Specifiers( private/public/etc) |
One indent level less than other declarations |
yes |
Comments |
Preserve blank lines in comments |
yes |
Blank line above comment blocks |
yes | |
Preserve text formatting in lines that contain only comments |
yes | |
Align right-hand comments at column |
60 | |
Other |
Indent namespace contents |
no |
Spacing
Line Width |
Wrap lines at column |
120 |
Preprocessor Macros(#defines) |
Align macro names at column |
8 |
Align macro values at column |
40 | |
Align macro continuation(\) at column |
80 | |
Line Spacing |
Preserve blank lines in source |
no |
Blank lines between functions. |
2 | |
White space |
Space between function name and parenthese |
no |
Space between function parameters |
yes | |
Spaces around operators |
yes | |
Spaces inside prentheses like ‘( this )’ |
no | |
Remove extra white space at end of lines |
yes | |
Align variables at column: |
16 | |
Align assignments at column: |
20 |
布局和控制流
控制语句 |
控制语句新起一行 |
yes |
控制语句前空一行 |
yes | |
控制语句后空一行 |
yes | |
else if 语句在同一行 |
yes | |
执行语句只有一条时单起一行 |
yes | |
执行语句只有一条时是否加大括号 |
no | |
if, while, for和后面括号间是否加空格 |
yes | |
空格风格 |
开括号新起一行 |
no |
开括号缩进 |
no | |
关括号缩进 |
no | |
括号内语句缩进 |
no | |
最外层括号都在第一列 |
yes | |
} else放在同一行 |
no | |
缩进 |
将空格转换为Tab键 |
no |
缩进宽度 |
4 | |
Goto语句的标签 |
在最左侧 |
yes |
标签前空一行 |
yes |
类和注释
类和结构体 |
类成员缩进 |
yes |
public等访问控制符前加空行 |
yes | |
public等访问控制符后加空行 |
yes | |
成员变量名对齐的列 |
16 | |
位域成员变量对齐的列 |
32 | |
访问控制符的缩进 |
比其他声明缩进一级 |
yes |
注释 |
保留注释中的空行 |
yes |
注释块前加空行 |
yes | |
保留注释中的原本格式 |
yes | |
右侧行尾注释对齐的列 |
60 | |
其他 |
名称空间的内容缩进 |
no |
空白
每行宽度 |
在哪一列换行 |
120 |
预处理 |
预处理名字对齐的列 |
8 |
预处理的值对齐的列 |
40 | |
预处理行连接符对齐的列 |
80 | |
空行 |
是否保留源码中多余的空行 |
no |
两个函数之间的空行个数 |
2 | |
空格 |
函数名和后面括号之间是否加空格 |
no |
函数参数间的空格 |
yes | |
二元操作符两侧是否有空格 |
yes | |
括号内部是否加空格,比如( this ) |
no | |
删除行尾多余的空格 |
yes | |
变量声明时,变量名对齐的列 |
16 | |
变量赋值符号对齐的列 |
20 |
有个缺点是,不能对文件进行批量修改,凑活用了。