Astyle代码格式化(C、C++等代码)插件嵌入source insight应用

Astyle代码格式化(C、C++等代码)插件嵌入source insight应用

astyle代码格式化工具,可以对C/C++等代码按照自己制定的格式进行格式化。本文简要总结将astyle外挂到source insight中的用法。步骤如下:
1、下载astyle工具包,在网站http://astyle.sourceforge.net下载;
2、将astyle解压,如解压到D:\lb\(根据自己需求放置目录);
3、在source insight菜单栏里,option-custom commands选择“Add”,在弹出对话框中Conmand写入命令名称;在“run”中添加相应的命令;如图:
Astyle代码格式化(C、C++等代码)插件嵌入source insight应用
4、选择“Keys”,在弹出对话框的command框的列表中找到自定义的命令名称并选中,选中“Assign New Key”,设置该命令的快捷键,然后“OK”完成设置。如图
Astyle代码格式化(C、C++等代码)插件嵌入source insight应用
5、astyle参数说明详见http://astyle.sourceforge.net/astyle.html。
简单例子,验证astyle格式化效果:
1、格式化当前文件,在需要格式化的代码目录下,运行命令行,命令 :“D:\lb\AStyle\bin\Astyle.exe” --style=ansi -s4 -S -N -L -m0 -M40 --convert-tabs --suffix=.pre %f
2、格式化某个目录下所有文件的命令为:“D:\lb\AStyle\bin\Astyle.exe” filepath/**.c filepath/*.h --style=ansi -s4 -S -N -L -m0 -M40 --recursive --convert-tabs --suffix=.pre %f