Astyle使用说明
Astyle是一个开源的代码美化工具,可以用于美化C/C++,C#,JAVA代码等。
1 Linux下安装使用
1.1 安装
http://astyle.sourceforge.net/
解压,编译,安装
1.2 配置代码格式
cat > ~/.astylerc
--style=allman
--indent=tab=8
#--brackets=linux
--brackets=stroustrup
--indent-preprocessor
--indent-col1-comments
--max-instatement-indent=50
--min-conditional-indent=0
--pad-oper
--pad-header
--break-closing-brackets
--align-pointer=type
#--align-pointer=middle
#--align-pointer=name
#--recursive
--lineend=linux
--suffix=~
1.3 使用
astyle *.h *.cpp
2 Windows下结合小乌龟使用
2.1 安装
http://download.csdn.net/detail/rainharder/4464674
下载,解压到任意目录,三个文件:AStyle.exe,astylerc,astyle.js
2.2 配置代码格式
使用下载包的配置,可忽略此步骤
将格式配置保存为astylerc,放到AStyle.exe相同目录
2.3 配置小乌龟
右键->TortoiseSVN->Setting->Hook Scripts->Add:
Hook Type: Pre-Commit Hook
Working Copy Path: 代码目录
Command Line To Execute: WScript "AStyle所在目录\astyle.js”
勾选Waiting for the script to finish
勾选Hide the script while running
点击OK完成配置
每次提交前,会自动调用脚本完成代码格式化。
2.4 问题
1) 提交时报错:没有文件扩展”.js”的脚本引擎。可能是js文件关联问题,如关联了一些编辑器,可以取消文件关联,即双击js能够直接执行脚本。
3 其他集成
网上也有集成到SI,VS,Eclipse,vim,emacs等工具中方法。