您的位置:首页 > 编程语言 > Python开发

source insight使用技巧-宏,颜色.tom

2012-04-24 15:24 507 查看
 

 

 参考:http://blog.sina.com.cn/s/blog_56ccf4fb0100c4yp.html

4、SI中的自动对齐设置:

    在C程序里, 如果遇到行末没有分号的语句,如IF, WHILE, SWITCH等, 写到该行末按回车,则新行自动相对上一行缩进两列。

    Option->Document option下的Auto Indient中Auto Indient Type有三种类型 None,Simple,Smart。个人推荐选用Simple类型。
7、恢复ctrl+a的全选功能

    通过关键词save 找到save all,更改为ctrl+shift+a,通过关键词select找到select all,更改为ctrl +a

8:在Source Insight中添加自定义功能的步骤如下:

1.Source Insight中,Options->Custom Commands...->Add...,New Command name 随便写,我的是"Edit with Vim"

2.Run中写入: "C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f

意思是在当前已经打开的gvim窗口里面打开当前的文件,并且跳转到指定行

%l为当前的行号,%f为文件名

使用 --remote-silent 的作用是,如果已经打开了对应文件,就不会打开第二次,而是在已经打开的文件里跳转到对应行

3.还是同一个对话框里面,选择Keys->Assign New Key...->按F12,如果你已经将F12设置给其他命令,选择其他的按键就行了

下面是一些常用自定义功能:( CUSTOM COMMANDS )

以下几个自定义命令我把他们关联到了菜单。
自定义的菜单名
功能
Run编辑框内容
Explore File
打开资源管理器并选中当前文件
ShellExecute open explorer /e,/select,%f
Edit with UE
在ultriEdit中编辑
"C:\Program Files\UltraEdit-32/uedit32" %f
Edit with VIM
在vim中编辑并定位到当前行
"C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f
AStyle_C
格式化当前文件(后面章节会介绍)
"C:\AStyle\bin\AStyle.exe" --options="C:\AStyle\bin\c.opt" %f
Trim Whitespace
删除整个文件每行行末尾的空白字符
这个是从Edit: Trim Whitespace从加进来的,是SI自带的功能,只是没有放到菜单上来而已。
关于这些%f、%l等参数什么意思,这是SI的通配符,可以搜索下SI帮助文档“Command Line Substitutions”章节,里

查看log

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:log /path:%f /notempfile /closeonend

diff

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:diff /path:%f /notempfile /closeonend

取得锁定(check out)

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:lock /path:%f /notempfile /closeonend

提交(check in)

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:%f /notempfile /closeonend
提交所有(check in)

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:*.* /notempfile /closeonend

更新(update)

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:%f /notempfile /closeonend

更新整个目录(update all)

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:*.* /notempfile /closeonend

取消锁定(undo check out)

"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:revert /path:%f /notempfile /closeonend

在ultriEdit中编辑

"C:\Program Files\UltraEdit-32/uedit32" %f

在vim中编辑并定位到当前行

"C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f

汇总其他小技巧:

让{ 和 } 不缩进:

Options->Document Options->Auto Indent->Indent Open Brace/Indent Close Brace

hao space: SourceInsight 小技巧

1、按住"ctrl", 再用鼠标指向某个变量,点击一下,就能进入这个变量的定义。

2、今天把一个用sourceinsight排版整齐的C文件,偶然用VC打开一看,全乱了。研究了半天,发现SI对每个字符的宽度不太一致。

    请教同事发现选上"view --> draft view", 就可以让每个字符的宽度一致了。快捷键是 "Alt + F12

Source Insight是阅读和编写代码的好东东,基本上也算得上是经典之作了,虽然还有一点点小bug,不过对于我们这些C程序员来说可是一旦拥有别无所求。下列小技巧是在工作中同事整理总结的,对提高工作效率多少有点帮助,其中有些是对应于SVN的,没有使用SVN做版本管理的人就不要白费力气了。

ShellExecute open explorer /e,/select,%f
X:\Progra~1\TortoiseSVN\bin\TortoiseProc.exe /command:log /path:% /notempfile /closeonend

 X:\Progra~1\TortoiseSVN\bin\TortoiseProc.exe /command:diff /path:% /notempfile /closeonend

怎么添加makefile文件

Options -> Document Options... Alt-T    -> 点击Document Type的下拉框,然后选择Make File,在右边的File Filter中,在原先的*.mak后面加上一个分号,即多个不同过滤

规则以分号间隔开,再加上*makefile,变成 *.mak;*makefile,并且选中Include when adding to projects,这样,以后再新建工程的时候,就可以识别makefile或Makefile了(

好像此处Source Insight并不区分大小写)。

 Source Insight常用的快捷键:

    Ctrl+= :Jump to definition

    Ctrl+/ :Look up reference

    F3 : search backward

    F4 : search forward

    F5: go to Line

    F7 :Look up symbols

    F8 :Look up local symbols

    F9 :Ident left

    F10 :Ident right

    Alt+, :Jump backword

    Alt+. : Jump forward

    Shift+F3 : search the word under cusor backward

    Shift+F4 : search the word under cusor forward

    F12 : incremental search

    Shift+Ctrl+f: search in project

    shift+F8 : hilight word

 

颜色

source insight是一个出色的程序编辑器和代码浏览器,利用好它会给编写和阅读源代码带来极大的方便。想要配置好source insight可不是一件轻松的事,我比较喜欢深色背景有利于保护眼睛,但同时也必须更改代码颜色来匹配背景色,source insight的很多窗口、选项都可以指定字体、颜色,实在让人犯晕!最麻烦的是源码窗口的配置了,这里简单提一下,source insight的最终配色是由Style Properties决定的(右键菜单-->Style Properties)



左边一栏是风格名,选中的是当前光标下的风格名,这些风格之间是有继承关系的,可以看到有很多=号,这代表继承了父风格(Parent Style),pick则是让你单独设置,最右边还可以导入、导出、添加风格等。所有风格最终由Default Text继承而来的,Font Name是灰的,它由Document Options(Alt+T)中的当前文档类型 Screen Fonts决定的(所以不同的文件类型,如C,Python,Java它们的字体可以不同的)。Background是由Options-->Preferences-->Colors中的Window
Background决定的,其实Default Text的背景就是源码窗口的背景。Foreground也一样,pick了它等于设置了Options-->Preferences-->Colors中的Default Text。我也晕了,汗……

正是这些风格让source insight五彩缤纷:



还要提一句,sourceinsight中还有一个Draft View(Alt+F12),在这个模式中会忽略Style Properties中字体部分设置,统一改用Draft View(见左边栏)中设置的字体。我制作了一个背景为深黑色,字体为Fixdays的配置文件(包含其它设置)让大家下载:http://download.csdn.net/source/2480193

 

罗嗦了半天,WRK还没说呢,关于如何使用请看中文官网的文章 。source insight分析完WRK后大家肯定会发现连IRP、DEVICE_OBJECT这样的结构都没法解析,其实罪魁祸首就是那些函数宏,比如_IRP前面的DECLSPEC_ALIGN(),如果用我前面的配置文件调过颜色的话一眼就可以看出,source
insight把它当成了Declare Function了,这些宏大多起修饰作用并无实质影响,但一样的宏在MS的代码中数不胜数(如非vc6的crt,头文件,连printf都解析不来)。可以看看这个帖子http://topic.csdn.net/u/20100613/16/b32fc799-c7f2-4648-9d91-cc933f9ffeb8.html
,我一开始以为是BUG,但source insight提供了解决方案,那就是Token Macro。Token Macro就是source insight的预处理器,它可以像C预处理器那样展开宏,正是为了对抗那些混淆source insight的宏而设计的。Token Macro是一个以.tom结尾的文件,对C/C++来说是C.tom,只要把它放在source insight创建工程的目录下,就可以立马起作用(不用重新parse一遍,不过有些时候还是parse一遍好),它会跟程序目录下的全局C.tom结合去展开宏。Token
Macro编写非常简单,跟#define语法差不多(但没它强大)。大家看看我针对WRK做的C.tom就明白了,由于大多数函数宏只起修饰作用不会影响代码的解析,所以我把大多数宏做成了空宏。

下载:http://download.csdn.net/source/2480426

 

Token Macro Syntax
A token macro file consists of token macros, one per line. The format of a token macro is:
macroname <no text here means macro is a no-op>
macroname substituted text here
macroname(parameter list) substituted text with
parameter names
macroname(parameter) text##parameter // concatenates
text
; comments begin with a semicolon

Some examples of token macros:
MyStructure(sname) struct sname
NoOperation
BuildName(name1, name2) name1##name2

另外条件编译也是一个可能让source insight分析出错的地方,默认它会分析所有的条件分支。但碰到这样的情形就糟糕了:

[cpp]
view plaincopyprint?

void MyFunc  
#ifdef XYZ  
    (int param1, int param2)  
#else
  
    (long param1, long param2)  
#endif
  
{  
    …  
}  
void DoThing(  
    int param1,  
#ifdef ABC  
    int param2)  
#else
  
    int param2, param3)  
#endif  

[cpp]
view plaincopyprint?

typedef   
NTSTATUS (*WMIENTRY)(  
……);//NTSTATUS无法解析  
typedef NTSTATUS  
(*WMIENTRY)(  
……);//NTSTATUS可以解析  

typedef
NTSTATUS (*WMIENTRY)(
……);//NTSTATUS无法解析
typedef NTSTATUS
(*WMIENTRY)(
……);//NTSTATUS可以解析


还有typedef定义函数指针类型时,函数的参数也都是不染色!这个问题似乎没有什么解决方法,用Custom Parsing也无济于事。

 

还有一种情况会让source insight解析出错,比如IopfCompleteRequest、NtQueryEaFile函数,在函数名和{之间有一段多行宏,这样source insight就解析的有问题了。这应该是个BUG,不知道大家有什么解决办法,我迫不得已只好挪动一下宏的位置!

 

现在几乎所有的问题都解决了,代码中都染上颜色了吧,呵呵……



 



 



 



 

Token Macro Files
The token macros are listed in a file with a .tom extension. The globaltoken macro file resides in the Source Insight program
directory. The project-specifictoken macro file, if any, is stored in project’s data directory. The projecttoken macro file is combined
with the global file, with the projectmacros taking precedence.
Token Macro Syntax
A token macro file consists oftoken macros, one per line. The format of atoken
macro is:
macroname <no text here means macro is a no-op>
macroname substituted text here
macroname(parameter list) substituted text with
parameter names
macroname(parameter) text##parameter // concatenates
text
; comments begin with a semicolon

Some examples of
token macros:
MyStructure(sname) struct sname
NoOperation
BuildName(name1, name2) name1##name2

Each built-in language parser has a corresponding
token macro file. The name of the
token macro file for each language is summarized below:

Table 4.2:
Token Macro Files for Different Languages


Language

File Name

C and C++

C.tom – a default copy ships with Source Insight.

HTML

Html.tom

Java

Java.tom

Resource Files

Rc.tom

x86 Assembly Language

X86.tom

Perl

Perl.tom

EditingToken Macros
If you want to change the
token macros, simply open the
token macro file, make your changes, and save the file. Source Insight will recognize that thetoken macros have changed for the appropriate language. Open files are automatically re-parsed.
When you edit a
token macro file, you must save it to disk before Source Insight will re-parse your open files. However, Source Insight will not automatically re-parse your whole project. You should make all your changes to thetoken
macro file first, then use the Rebuild Project command to re-parse your whole project. Until your project is re-parsed, the symbol information stored in Source Insight’s symbol database will not reflect the changes you made to yourtoken
macros.
Project SpecificToken Macros
Each project can have its own set of
token macro files. Source Insight does not create them automatically, but you can yourself. A projecttoken macro file is saved in the project's data directory. When Source Insight parses a
source file, it combines the projecttoken macros with the global set saved in the Source Insight program directory. The projecttoken macros
take precedence over the global ones. By adding project specifictoken macros, you can tailor thetoken macro expansion for each project
individually.
 实例:

static __attribute__((unused)) char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];

static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,

      ulong base_addr)

{

加载了C.tom后就可以显示下面的函数了,

C.tom内容如下

__attribute__(unused)

 

__initdata
__init
__init
__initdata
__initconst
__exitdata
__exit_call
__ref
__refdata
__refconst
__init_refok
__initdata_refok
__exit_refok
__exitused
__exitused
__exit
__devinit
__devinitdata
__devinitconst
__devexit
__devexitdata
__devexitconst
__cpuinit
__cpuinitdata
__cpuinitconst
__cpuexit
__cpuexitdata
__cpuexitconst
__meminit
__meminitdata
__meminitconst
__memexit
__memexitdata
__memexitconst
__HEAD
__INIT
__FINIT
__INITDATA
__INITRODATA
__FINITDATA
__DEVINIT
__DEVINITDATA
__DEVINITRODATA
__CPUINIT
__CPUINITDATA
__CPUINITRODATA
__MEMINIT
__MEMINITDATA
__MEMINITRODATA
__REF
__REFDATA
__REFCONST
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息