一、AStyle下载路径

  Astyle为开源项目,支持C/C++和java的代码格式化

  Home Page: http://astyle.sourceforge.net/

  Project Page: http://sourceforge.net/projects/astyle/

  下载最新Windows版本的AStyle,解压到你指定位置,笔者解压到D:\program files下的。

二、Source Insight中安装Astyle工具

  如:增加Astyle命令,格式化C/C++文件

  1. 打开source insight中的一个工程,选择Options--Custom Commands命令

  2. 点击add,添加新的命令Astyle。

  1)ansi C 格式化当前文件的命令为

  其中,Run中输入astyle的命令参数:"D:\program files\AStyle\bin\AStyle.exe" --style=ansi -s4 -S -N -L -m0 -M40 --convert-tabs --suffix=.pre %f

  2)ansi C 格式化某个目录下所有文件的命令为:

  "D:\program files\AStyle\bin\AStyle.exe" Z:\LocalProject\DEZHOU3716/*.c Z:\LocalProject\DEZHOU3716/*.h --style=ansi -s4 -S -N -L -m0 -M40 --recursive --convert-tabs --suffix=.pre %f

3. 添加menu菜单,点击“menu”,选择menu--View,然后INSERT。这样就可以在菜单栏View上多一个命令选项。

4. 添加快捷键,点击"Assigh New Key",输入快捷键:Ctrl+Alt+C。以后格式化C/C++文件,就可以直接使用快捷键了。

同理,新建java格式化命令,Astyle参数为

  C:\AStyle\bin\AStyle.exe --style=java -s4 -S -N -L -m0 -M40 --suffix=none --convert-tabs %f

三、其他常用的参数:

-C

类中public,pretected,private关键字,一个tab的缩进

-S

switch中case关键字,一个tab的缩进

-K

switch中case关键字,无缩进

-N

被namespace包含的block,一个tab的缩进

-w

格式化多行的宏定义

-c

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

--mode=c

格式化的是C/C++的源文件或者头文件(缺省值)

--mode=java

格式化的是JAVA的源文件

--suffix=####

将原始文件保存为“####”后缀,而不是“orig”

--suffix=none

不保存原始文件

--exclude=####

优化时不包含“####”文件或目录

-Z

修改后保持文件的修改时间不变

-X

将错误信息输出到标准输出设备(stdout),而不是标准错误设备(stderr)

-Q

只显示格式化前后发生变化的文件

-q

不输出任何信息

-z1

使用windows版本的回车符(CRLF)

-z2

使用linux版本的回车符(LF)

--help

显示帮助信息

-v

显示版本信息

基于V2.02版本,astyle主要支持的参数有:

Style-格式配置:
最常用的就是ansi或或kr格式,实际上,kr,stroustrup和linux这三种格式是非常接近的了,试了好几个文件,只有非常微小的区别,可以忽略不计。

stype
选项

--style=allman
--style=ansi
--style=bsd
--style=break
-A1

--style=java
--style=attach
-A2

--style=kr
--style=k&r
--style=k/r
-A3

--style=stroustrup
-A4

--style=whitesmith
-A5

--style=banner
-A6

代码风格

int Foo()
{
    if (isBar)
    {
        bar();
        return 1;
    }
    else
    {
        return 0;
    }
}

int Foo() {
    if (isBar) {
        bar();
        return 1;
    } else {
        return 0;
    }
}

int Foo()
{
    if (isBar) {
        bar();
        return 1;
    } else {
        return 0;
    }
}

int Foo()
{
    if (isBar) {
        bar();
        return 1;
    } else {
        return 0;
    }
}

int Foo()
    {
    if (isBar)
        {
        bar();
        return 1;
        }
    else
        {
        return 0;
        }
    }

int Foo() {
    if (isBar) {
        bar();
        return 1;
        }
    else {
        return 0;
        }
    }

stype
选项

--style=gnu
-A7

--style=linux
-A8

--style=horstmann
-A9

--style=1tbs
-A10

--style=pico
-A11

--style=lisp
-A12

代码风格

int Foo()
{
    if (isBar)
        {
            bar();
            return 1;
        }
    else
        {
            return 0;
        }
}

int Foo()
{
    if (isBar) {
        bar();
        return 1;
    } else {
        return 0;
    }
}

int Foo()
{   if (isBar)
    {   bar();
        return 1;
    }
    else
    {   return 0;
    }
}

int Foo()
{
    if (isBar) {
        bar();
        return 1;
    } else {
        return 0;
    }
}

int Foo()
{   if (isBar)
    {   bar();
        return 1; }
    else
        return 0; }

int Foo() {
    if (isBar) {
        bar();
        return 1; }
    else
        return 0; }

参考文档:

1. http://www.cnblogs.com/zhaoshixin/archive/2011/12/02/2272076.html

2. http://astyle.sourceforge.net/astyle.html

AStyle代码格式工具在source insight中的使用的更多相关文章

  1. Source Insight 中使用 AStyle 代码格式工具

    Source Insight 中使用 AStyle 代码格式工具 彭会锋 2015-05-19 23:26:32     Source Insight是较好的代码阅读和编辑工具,不过source in ...

  2. 在source insight中集成astyle

    转自:http://www.cnblogs.com/xuxm2007/archive/2013/04/06/3002390.html 好吧,我有代码格式的强迫症,代码不整齐,我看的都头疼,之前一直喜欢 ...

  3. source insight中的快捷键总结

    1.快捷键 1,Shift+F8高亮显示指定字符. 2,Ctrl+F找出来的结果用F4,F3前进后退查找. 3,Alt+,后退alt+.前进查找关键字. 4,Alt+G或者F5跳转到某个固定的行号. ...

  4. source insight 中tab键的设置

    转:http://xinzero.com/source-insight-code-alignment-ended.html source insight代码对齐Tab键终极版 以前也写过一个sourc ...

  5. Source Insight 中调用Notepad++

    options>custom commands 指令为 "E:\Program Files (x86)\Notepad++\notepad++.exe" %f 其中%f表示S ...

  6. Source Insight 中的 Auto Indenting

    编码过程中,希望输入花括号时能自动对齐,Source Insigth 应如何设置? 先来看一下Source Insight 中的帮助. “ Auto Indenting The auto-indent ...

  7. 代码阅读工具:Source Navigator和Source Insight

    (摘自http://www.cnblogs.com/yc_sunniwell/archive/2010/08/25/1808322.html) 一.Source Insight实用技巧: Source ...

  8. 【FLYabroad 】微软内部代码检查工具 (Microsoft Source Analysis for C#)[转]

    SourceAnalysis (StyleCop)的终极目标是让所有人都能写出优雅和一致的代码,因此这些代码具有很高的可读性. 早就听说了微软内部的静态代码检查和代码强制格式美化工具 StyleCop ...

  9. Source Insight中的多行注释

    转自:http://www.cnblogs.com/dongzhiquan/archive/2013/03/04/2943448.html 我们经常要对一整段代码进行注释,很多代码编辑器都提供了这样的 ...

随机推荐

  1. iOS之ASIHttp简单的网络请求实现

    描述: ASIHttpRequest是应用第三方库的方法,利用代码快,减少代码量,提高效率 准备工作: 一.导入第三方库ASIHttpRequest 二.会报很多的错,原因有两个,一个是要导入Xcod ...

  2. hdu2026.java字符

    首字母变大写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. Android开发之ContentProvider(内容提供者)

    1. ContentProvider简介 当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据.虽然使用其他方法也可以对外共享数据,但数据访问 ...

  4. 版本控制SVN与Eclipse4.4.1集成 ( eclipse svn:E175002错误解决 )

    Eclipse版本--Luna Service Release 1(4.4.1) SVN版本-----1.8.X 系统OS-------ubuntu 14.04 LTS 1.通过地址安装 Help-& ...

  5. java 子类重写父类的方法应注意的问题

    若想实现一个合格重写方法,而不是重载,那么必须同时满足下面的要求! A.重写规则之一:    重写方法不能比被重写方法限制有更严格的访问级别.(但是可以更广泛,比如父类方法是包访问权限,子类的重写方法 ...

  6. delphi 截取指定符号之间的字符串-随机读取

    unit Unit1; interface uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...

  7. window.event对象详细介绍

    1.event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等.event对象只在事件发生的过程中才有效.event的某些属性只对特定的事件有意义.比如,fromEleme ...

  8. OC加强-day01

    #pragma mark - 00 知识回顾 1.@property + 类型 + 属性名 :执行的结果 1>在类的.m里面生成一个_属性名的属性 2>生成 _属性名 这个属性的set/g ...

  9. LLDB中的小技巧

    1.打印视图层次结构 po [self.view recursiveDescription]   2.临时调整界面UI      比如说现在你需要改变一个控件的背景色来更好的查看布局的问题,这是就不需 ...

  10. 如何在swift中实现oc中的分类

    在oc中为了增强已有类的功能,我们经常使用分类.使用分类,我们可以在不破坏原有类的结构的前提下,对原有类进行模块化的扩展. 但是在swift中没有分类这种写法了.相对应的是swift中只有扩展(Ext ...