source insight 代码格式化工具使用

source insight 代码格式化(Astyle)

source insight 代码格式化是通过Astyle实现
Astyle

  1. 下载Astyle

  2. Source Insight 4.0设置Astyle
    在Souce insight上选择Tools->Custom Commands,点击Add,输入Astyle,点击OK。

    在Run中查找Astyle路径:如下"D:\Program Files (x86)\Source Insight 4.0\AStyle\bin\AStyle.exe"在路径后面添加格式化信息,取消Output所有选项,取消Control所有选项。

     --style=ansi -S -N -L -xC80 -z2 --convert-tabs -H -p -U --align-pointer=name --quiet --suffix=none %f
    
  3. Source Insight 4.0设置Astyle菜单
    在Source insight选择Options->Menu Assignments,在Command中选择Astyle,在Menu中选择work,在Menu Contents中选择Toolbars,然后点击Insert,点击OK,完成。

Astyle参数

Astyle提供了很多参数供大家使用,通过配置这些参数,我们可以将文件格式化成我们想要的形式。
使用的是

--style=ansi -S -N -L -xC80 -z2 -H -p -U --align-pointer=name --suffix=none --quiet
配置 含义
-S ”case XXX”需要缩进
-N namespace中的内容缩进
-L 缩进label,让label比当前的内容先前一个缩进距离,而不是通通靠左
-xC80 最长80个字符
-convert-tabs 将tab转换为合适长度的空格
-H 在if for等关键字后面,加一个空格
-p 在操作符两边加空格
-U 去掉()内部不必要的空格
—align-pointer=name 让*更靠近变量名
–suffix=none 不备份原始文件

更多的参数,可以直接在命令行中输入

astyle --help

你可能感兴趣的:(软件工具)