一、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. hdu2058java

    The sum problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. Ⅶ.AngularJS的点点滴滴-- 事件

    事件(和js一样有冒泡和捕获) <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2 ...

  3. linux下安装redis并自启动

    最近需要使用redis作为tomcat集群的session存储介质,因此记录redis的安装步骤.redis是一款高性能的nosql,支持异步将缓存写入到磁盘中,避免宕机的意外情况导致的缓存信息丢失. ...

  4. 【转】char码值对应列表大全

    char("56") A char("97") a [转]char码值对应列表大全 Char("0") 为0的字符Char("1& ...

  5. android使用adb installapk出现can't find **.apk to install

    1. 有时候我们需要在使用ADT命令的adb安卓外部命令的时候出现下面的问题 出现上面的问题,其实是我们的apk方的文件不对,具体是什么问题怎么改路径我就没有深入研究了,.我查阅了好多资料才发现并不是 ...

  6. A题笔记(7)

    No. 1468 已知三角形的三条边求面积:海伦公式 S=√[p(p-a)(p-b)(p-c)]   p=(a+b+c)/2 #include <cmath> cmath 是 c++ 语言 ...

  7. Invalid segment BIN$xxx and dba_recyclebin was empty (回收站空,释放无效的BIN$xx空间)

    近来有套库空间紧张,发现有很大BIN$开头的TABLE partition,index partition 类型的段,查询确认是2个月前删除的对象,手动清空过dba_recyclebin使用purge ...

  8. Java stackoverflow error

    本文想记录一下尝试产生stackoverflow的程序 1 -Xss=1k, 设置stack大小1024个字节,产生515个long,想把stack撑爆. 2 嵌套调用 3 创建大量线程 1 -Xss ...

  9. wel

    欢迎来到mathant.com 这个网站是什么 这个网站是我搭建在阿里云vps上的个人网站.目前的用途是充当个人博客和云存储,当然它的功能不止如此.我会在以后的日子里完善他,希望他能变得更好.目前我在 ...

  10. Android学习2--项目文件列表简单分析

    使用Eclipse创建的默认项目文件列表如下: src:src目录是Android工程的源程序目录,该目录用于存放Java项目的源代码 gen:gen目录存放所有自动生成的文件,在这个目录中最关键的文 ...