Astyle格式化插件

可以集成到Visual Studio、Eclipse和source insight当中。下面只介绍集成到source insight
下载地址:
https://sourceforge.net/projects/astyle/

1. 添加自定义命令
custom
点击“add”起个名字。“run”命令里添加命令格式,最开始是AStyle.exe路径,后面跟参数
command
2. 添加自定义菜单
menu
左边选中你刚刚添加的命令,右边“menu”选择“view”,点击“insert”插入菜单
view
3. 添加自定义快捷键
key
左边选择你刚刚添加的命令,右边点击“assign new key”并设置快捷键
key
4. astyle常用参数

  • -p:在操作符两边插入空格,如=、+、-等
  • -P:在括号两边插入空格。另,-d只在括号外面插入,-D只在里面插入
  • -U:移除括号两边不必要的空格

5. 举例
说明文档:http://astyle.sourceforge.net/astyle.html

File Type

--mode
--mode=c
--mode=cs
--mode=java

括号方式

--style=ansi
--style=kr 
--style=linux 
--style=gnu
--style=java

Tab Options

--indent=spaces=# / -s#
--indent=tab=# / -t#
--indent=force-tab=# / -T#
--indent=force-tab-x=# / -xT# 

‘if’, ‘for’, 'while’等添加大括号

--add-brackets / -j 
--remove-brackets / -xj

*, &, or ^靠近方式

--align-pointer=type / -k1
--align-pointer=middle / -k2
--align-pointer=name / -k3 

操作符增加空格

--pad-oper / -p

关键字后面增加空格

--pad-header / -H 

‘if’, ‘for’, 'while’等前后增加空行

--break-blocks / -f

删除空行

--delete-empty-lines / -xe

去掉括号两边多余的空格

--unpad-paren / -U 

行结束用什么文件格式

--lineend=windows / -z1
--lineend=linux / -z2
--lineend=macold / -z3

switch case也按照标准缩进

--indent-switches / -S

如果是注释,也进行缩进

--indent-col1-comments / -Y

多行条件语句如何进行缩进,=0表示和(对齐,=1表示缩进一次,=2表示缩进两次,=3缩进一个半

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

将tab转化为对应个数的空格

--convert-tabs / -c

总结出一个,%f表示当前文件

run> astyle --style=ansi --indent=spaces=3 --add-brackets --align-pointer=name --pad-oper --break-blocks --unpad-paren --lineend=linux --indent-switches --min-conditional-indent=0 %f
run> astyle --style=ansi -s4 -j -k3 -p -f -U -z2 -S -Y -m0 %f
包含源代码,需要的可以自行下载。 把astyle.exe 复制到 C:\WINDOWS 目录里,省的指定路径 VC6++ 设置方法 菜单->工具->定制->工具菜单内容->新建菜单,参数如下 命令行:astyle.exe 变量: --style=k&r --brackets=break --indent=spaces --indent-cases --indent-preprocessor --pad-header --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs $(FileName)$(FileExt) 初始目录: $(FileDir) VC2008 外部工具里设置,还可以添加快捷键 命令:astyle.exe 参数: --style=k&r --brackets=break --indent=spaces --indent-cases --indent-preprocessor --pad-header --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs $(ItemFileName)$(ItemExt) 初始目录: $(ItemDir) CodeBlocks 设置差不多,很多绿色版的已经设置好了 AStyle_2.02_windows.zip bin 目录里有官方编译好的 Artistic Style 2.01 Maintained by: Jim Pattee Original Author: Tal Davidson Usage : astyle [options] Source1.cpp Source2.cpp [...] astyle [options] Beautified 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. Wildcards (* and ?) may be used in the filename. A 'recursive' option can process directories recursively. By default, astyle is set up to indent C/C++/C#/Java files, 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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值