Source Insight常用快捷键及注释快捷键设置
- 格式:doc
- 大小:63.00 KB
- 文档页数:5
[完整版]Source_Insight教程及技巧Source Insight使⽤简单说明Source Insight是⼀个功能⼗分强⼤、使⽤也很⽅便的程序编辑器。
它内置对C/C++、Java 甚⾄x86汇编语⾔程序的解析,在你编程时提供有⽤的函数、宏、参数等提⽰,因⽽,Source Insight正在国际、国内众多的IT公司使⽤。
Source Insight功能强⼤,它的窗⼝、菜单初⼀看来似乎很多,所以刚刚开始使⽤Source Insight的朋友往往觉得很⿇烦。
这⾥本⼈结合⾃⼰的使⽤经验,简单说说Source Insight的使⽤。
(本⽂以McuSystem为例,Source Insight 以3.0版本为例。
其他版本的Source Insight ⼤同⼩异)和众多程序编辑环境⼀样,Source Insight中也有Project。
建⽴⼯程的⽅法很简单:1.打开Source Insight,选择Project菜单->New Project;2.在出现的对话框中选择并选择存放⼯程⽂件的⽂件夹,输⼊⼯程名(⽐如McuSystem),点击“保存”;3.⼜出现⼀个对话框,在Configuration部分可以选择这个⼯程使⽤全局配置⽂件还是⾃⼰单独的配置⽂件,这个⽆所谓,(不过最好选择单独的配置⽂件),再点击“OK”;4.再次出现⼀个对话框,这是选择⽂件添加到Project中,通过左边的树状图找到你想添加的⽂件,点击Add就可以了(如图1)。
你可以将不通路径下的⽂件添加到同⼀个⼯程中,⽽不⽤拷贝源⽂件。
选择完后点击Close;图1这样⼯程就建⽴好了,⽂件列表就出现在Project Window中(如果Project Window被关闭了,可以选中View菜单->Project Window)。
点击Project Window中任意⼀个⽂件,⽂件的内容出现在中央的编辑区了。
(如图2)图2如果⼯程已经建⽴好了,想要打开、关闭、删除⼯程,直接点击Project菜单下相应的选项就可以了,这⾥就不多说了。
sourceinsight4用法SourceInsight是一款用于软件开发的集成开发环境(IDE),它主要用于代码浏览、编辑和导航等操作。
下面是一些SourceInsight的用法:1. 导入项目:打开SourceInsight后,可以选择“导入”或者“新建”项目,将你的代码文件导入到SourceInsight中。
2. 代码浏览:在SourceInsight的主界面,可以通过左侧的目录树来浏览和查看代码文件。
选中文件后,可以在右侧的编辑器中查看和编辑代码。
3. 代码导航:SourceInsight提供了多种导航功能,可以快速定位和跳转到代码中的特定位置。
例如,可以使用“跳转到定义”功能来查看变量或函数的定义位置。
4. 代码搜索:可以使用SourceInsight的搜索功能来查找特定的代码片段。
可以使用快捷键Ctrl+F来启动搜索功能,并输入你要查找的关键字。
5. 代码补全:SourceInsight具有代码补全功能,可以根据已输入的代码自动补全代码片段。
可以使用快捷键Ctrl+空格来触发代码补全。
6. 代码格式化:SourceInsight支持代码的格式化和美化,可以让代码更加清晰易读。
可以使用快捷键Ctrl+K+F来快速格式化选定的代码。
7. 代码调试:SourceInsight支持代码调试,可以在调试过程中查看变量、执行跟踪等操作。
可以使用快捷键F5来启动调试功能。
8. 插件扩展:SourceInsight支持通过插件来扩展功能。
可以根据自己的需要安装、配置和使用各种插件。
需要注意的是,以上是一些常见的用法,实际使用中可能会有一些差异和个性化的配置。
你可以根据自己的需求和习惯来使用和配置SourceInsight。
sourceinsight的使⽤⽅法逆天整理A. why SI: 为什么要⽤Source Insight呢?因为她⽐完整的IDE要更快啊,⽐⼀般的编辑器便捷啊!她有逆天的查看定义,查看调⽤,查看引⽤功能以及⽅便的Context Window上下⽂显⽰,像这样的东西⾮常有利于查看⼤量代码! 那么问题来了——⽐如我现在随便找了⼀份源码,我该要怎么阅读呢?很简单,SI可以极其⽅便地将⼀个源码⽬录变成source insight⼯程,然后直接操作——来天吞天,来地含地:新建⼯程——>命名⼯程——>设置源码⽬录——>好了,去阅读吧。
那么⼜有⼀个问题,⽐如⽼⼦要设置字体背景之类的东西哩?呵呵,Options->Preferences…⾥⾯的内容能让你晚上做梦都笑醒了。
所以说到这⾥,SI的强⼤之处在于:速度快,阅读⽅便,设置⽅便。
当然这只是⼀⼩部分,她还有强⼤的⾃定义指令的功能,这个还在学习,放下不表。
但是,就这些基本的功能就已经能⽀持我很好的⼯作了啊!B. SI Project初体验与窗⼝布局介绍: 新建⼯程之后是add and remove files这个窗⼝,⼀般add tree就把⽂件夹⾥的所有⽂件都加载进这个⼯程了。
那么Load完成之后呢?close对话框就可以了啊。
close之前有个神奇的地⽅向⼤家介绍下——SI可以加不同路径的代码进⼊你的⼯程,嘿嘿嘿。
完成之后,Project Window就出现在右边了,点击其中任意⼀个⽂件,内容就显⽰在中央编辑区域了。
左边是Symbol Window,可以快速定位函数、变量定义等。
下⾯是Context Window,显⽰有⽤的上下⽂相关信息。
可以通过View菜单调出或者关闭各种窗⼝。
⽐如Relative Window可以显⽰出⽅法中调⽤的⽅法。
以下是source insight标准⼯作界⾯,从左到右从上到下分别是Symbol window /编辑区 / Project window / Relative window / Context window. 这样的布局是⾮常⽅便的,⼤家就按照这样布局就⾏。
作为一个开放源代码的操作系统,Linux附带的源代码库使得广大爱好者有了一个广泛学习、深入钻研的机会,特别是 Linux内核的组织极为复杂,同时,又不能像windows平台的程序一样,可以使用集成开发环境通过察看变量和函数,甚至设置断点、单步运行、调试等手段来弄清楚整个程序的组织结构,使得Linux内核源代码的阅读变得尤为困难。
当然Linux下的vim和emacs编辑程序并不是没有提供变量、函数搜索,彩色显示程序语句等功能。
它们的功能是非常强大的。
比如,vim和emacs就各自内嵌了一个标记程序,分别叫做ctag 和etag,通过配置这两个程序,也可以实现功能强大的函数变量搜索功能,但是由于其配置复杂,linux附带的有关资料也不是很详细,而且,即使建立好标记库,要实现代码彩色显示功能,仍然需要进一步的配置(在另一片文章,我将会讲述如何配置这些功能),同时,对于大多数爱好者来说,可能还不能熟练使用vim和 emacs那些功能比较强大的命令和快捷键。
为了方便的学习Linux源程序,我们不妨回到我们熟悉的window环境下,也算是“师以长夷以制夷”吧。
但是在Window平台上,使用一些常见的集成开发环境,效果也不是很理想,比如难以将所有的文件加进去,查找速度缓慢,对于非Windows 平台的函数不能彩色显示。
于是笔者通过在互联网上搜索,终于找到了一个强大的源代码编辑器,它的卓越性能使得学习Linux内核源代码的难度大大降低,这便是Source Insight3.0,它是一个Windows平台下的共享软件,由于Source Insight是一个Windows平台的应用软件,所以首先要通过相应手段把Linux系统上的程序源代码弄到Windows平台下,这一点可以通过在 linux平台上将/usr/src目录下的文件拷贝到Windows平台的分区上,或者从网上光盘直接拷贝文件到Windows平台的分区来实现。
source insight的简单操作Source Insight是一款功能强大的源代码阅读器和编辑器,它能够帮助程序开发人员更加高效地阅读、浏览和编辑源代码。
本文将介绍Source Insight的一些简单操作,以帮助读者快速上手使用这款工具。
一、安装和启动我们需要下载并安装Source Insight软件。
安装完成后,双击桌面上的快捷方式或在开始菜单中找到Source Insight并点击打开。
这样就成功启动了Source Insight。
二、打开源代码文件在Source Insight的菜单栏中,点击“文件”-“打开”选项,选择要打开的源代码文件,然后点击“打开”按钮。
Source Insight 支持多种编程语言的源代码文件,比如C、C++、Java等。
三、浏览源代码Source Insight的界面分为多个窗口,包括文件视图、函数视图、符号视图等。
通过点击不同的选项卡,可以在不同的视图之间切换。
在文件视图中,可以浏览源代码文件的内容,并进行查找、替换等操作。
四、导航代码Source Insight提供了一系列导航功能,帮助开发人员快速定位代码的位置。
比如,可以使用“Go To”菜单中的选项,跳转到光标所在函数的定义处或者跳转到光标所在的变量的声明处。
五、代码补全Source Insight还提供了代码补全功能,可以根据已有的代码上下文,自动补全代码。
在输入代码时,按下“Tab”键或者使用快捷键“Ctrl+Space”,Source Insight会自动弹出代码补全列表,选择对应的代码即可。
六、代码分析Source Insight可以对源代码进行静态分析,帮助开发人员发现潜在的问题或者改进的空间。
比如,可以通过右键点击函数名,选择“Analyze”选项,Source Insight会分析该函数的调用关系并给出相应的提示。
七、书签功能Source Insight的书签功能可以帮助开发人员快速定位到重要的代码位置。
sourceinsight 书签用法-回复关于SourceInsight的书签用法,下面将逐步回答并提供一篇1500-2000字的文章。
第一步:什么是SourceInsight?SourceInsight是一款被广泛使用的源代码阅读器和编辑器,主要用于开发人员在各种编程语言中快速浏览和编辑代码。
它提供了一系列功能,如代码导航、符号查找、语法高亮和自动完成等,使开发人员更加高效和便捷地开发和维护代码。
第二步:SourceInsight的书签功能是什么?SourceInsight的书签功能允许开发人员在源代码文件中设置书签,并随时跳转到这些书签位置,方便快速定位和导航。
第三步:如何设置和管理书签?1. 首先,在SourceInsight中打开要设置书签的源代码文件。
2. 使用鼠标选中要设置书签的行或者位置。
3. 右键单击选中的行或位置,选择"Set Bookmark",或者使用快捷键Ctrl+F2来设置书签。
4. 设置成功后,选中的行或位置会显示一个小蓝色方框,表示该位置已设置了书签。
第四步:如何跳转到书签位置?1. 首先,在SourceInsight中打开设置了书签的源代码文件。
2. 使用鼠标或键盘定位到左侧的书签窗口。
如果书签窗口不可见,可以通过菜单栏的"View" -> "Bookmark Window"来打开。
3. 在书签窗口中,可以看到所有设置了书签的位置列表。
4. 单击书签列表中的任意一项,SourceInsight会自动跳转到对应的书签位置。
第五步:如何管理和删除书签?1. 在书签窗口中,可以对书签进行管理和删除。
2. 选择要删除的书签项,右键单击,选择"Clear Selected Bookmark",或者使用快捷键Shift+F2来删除选中的书签。
3. 如果要删除所有的书签,可以选择"Clear All Bookmarks",或者使用快捷键Ctrl+Shift+F2来删除所有的书签。
Source_Insight3.5简明使⽤教程Source Insight 3.5使⽤教程⼀、建⽴⼯程:1.在桌⾯上新建⼀个保存⼯程⽂件的⽂件夹,⽂件夹取名为project,如图1所⽰。
(当然您可以在你任何路径下建⽴⽂件夹,⽂件夹的名称也可随意取。
)2.将要加⼊⼯程中的源⽂件(*.h,*.c等),都拷贝到建⽴的project⽂件夹中。
图13.打开Source Insight 3.5软件进⼊图2界⾯。
图2/doc/b8e3bb1b86c24028915f804d2b160b4e767f81d9.html 4.点击菜单“Porject→New Project”进⼊图 3图35.图3中弹出的New Project对话框内,修改您要建⽴的⼯程名称,在此我们改成test;再点击Browse选择您要保存的路径,在本例我们选择第1步中建⽴的project ⽂件夹,即桌⾯\project。
如图4:/doc/b8e3bb1b86c24028915f804d2b160b4e767f81d9.html6.点击图4中的New Project的“OK”按纽后进⼊新⼯程设置如图5所⽰界⾯,在此我们按图5中的选择进⾏设置后,点击“OK”确定,进⼊图6所⽰界⾯。
图57.在图6中,我们要选择要加⼊⼯程中的源⽂件。
在“Add and Remove Project Files”对话框中的“Files Name”栏⽬下点击选中任⼀你想加⼊到⼯程中的⽂件,⽐如:I2C.C ⽂件,再点击右侧的“ADD”按纽即可将I2C.C⽂件加⼊⼯程,如图7和8所⽰。
/doc/b8e3bb1b86c24028915f804d2b160b4e767f81d9.html图7/doc/b8e3bb1b86c24028915f804d2b160b4e767f81d9.html8.如果Directory栏下的“project“⽂件夹中所有的⽂件都需要加⼊⼯程,那么,只需要点击右侧的“ADD All”按纽即可将所有⽂件加⼊⼯程。
Source insight 宏的使用作者:颜庆打开source insight 的base工程(菜单Project -> Open Project),其中一个文件叫utils.em ,在这个文件里添加你自己的宏,然后在菜单option/key assignments中给相应的宏分配快捷键,就可以使用source insight 宏了。
下面是一些具体的宏的介绍。
autoexpand把下面的代码拷贝到source insight的base工程中的utils.em文件中,然后在你自己的工程中,打开option/key assignments, 为autoexpand 这个宏分配快捷键,这里用的是ctrl + 1使用:在source insight 中先键入一个关键字,比如for,然后按下你的快捷键,宏就会帮你展开相应的代码,如下图所示,这时你可以通过F3, F4跳到下一个“###”insheaderdef这个source insight宏可以自动给头文件加上头文件宏,它会自动获取文件名,自动添加与文件名对应的宏。
执行insheaderdef宏之前代码如下执行insheaderdef宏之后代码如下InsertIfdef这个source insight宏可以自动给一段选中的代码加上宏开关执行InsertIfdef宏之前选中若干行代码执行InsertIfdef宏之后会有提示框让你输入宏,我们输入AEE_SIMULA TOR然后回车,代码如下:MakeCode2Comments把选中的代码前面加双斜杠“//”执行宏之后:MakeComments2Code与上面一个宏的作用刚好相反NeateanVarDeclaration整理变量声明,让变量对齐,先选中若干行:执行之后:注意:这个宏默认地通过空格作为分隔符来对齐每一部分;另外,你要保证你的source insight 使用的字体是等宽字体Courier New,才能让字符对齐修改字体方法:options -> Document options -> Screen Fontsinsfunheader这个宏可以给函数自动加函数头注释先让光标停留在某个函数体内:执行宏,会弹出输入框,让你输入函数描述:点OK之后:/*附上宏定义文件*//* t357.em - a small collection of useful editing macros *//****************************************************************************** * InsFileHeader -- insert the information of file** modification history* --------------------* 01a, 23mar2003, added DESCRIPTION by t357* 01a, 05mar2003, t357 written* --------------------******************************************************************************/ /*-------------------------------------------------------------------------I N S E R T H E A D E RInserts a comment header block at the top of the current function.This actually works on any type of symbol, not just functions.To use this, define an environment variable "szMyName" and set itto your email name. eg. set szMyName=raygr-------------------------------------------------------------------------*/macro InsFileHeader(){/*######################################################################################################################### Set szMyName variable to your name ############### for example szMyName = "t357" ##########################################################################################################################*/szMyName = ""// Get current timeszTime = GetSysTime(1)Day = szTime.DayMonth = szTime.MonthYear = szTime.Yearif (Day < 10)szDay = "0@Day@"elseszDay = DayszMonth = NumToName(Month)hBuf = GetCurrentBuf()szpathName = GetBufName(hBuf)szfileName = GetFileName(szpathName)nlength = StrLen(szfileName)szInf = Ask("Enter the information of file:")szDescription = Ask("Enter the description of file:")hbuf = GetCurrentBuf()// begin assembling the title stringInsBufLine(hbuf, 0,"/******************************************************************************") InsBufLine(hbuf, 1, " * @szfileName@ - @szInf@")InsBufLine(hbuf, 2, " * ")InsBufLine(hbuf, 3, " * Copyright 1998-2003 Guangzhou Gaoke Communication Technology Co.,Ltd.")InsBufLine(hbuf, 4, " * ")InsBufLine(hbuf, 5, " * DESCRIPTION: - ")InsBufLine(hbuf, 6, " * @szDescription@")InsBufLine(hbuf, 7, " * modification history")InsBufLine(hbuf, 8, " * --------------------")InsBufLine(hbuf, 9, " * 01a, @szDay@@szMonth@@Year@, @szMyName@ written") InsBufLine(hbuf, 10, " * --------------------")InsBufLine(hbuf, 11, "******************************************************************************/")// put the insertion point inside the header commentSetBufIns(hbuf, 1, nlength + strlen(szInf) + 8)}/****************************************************************************** * InsFunHeader -- insert function's information** modification history* --------------------* 01a, 23mar2003, added DESCRIPTION by t357* 01a, 05mar2003, t357 written* --------------------******************************************************************************/ macro InsFunHeader(){// Get the owner's name from the environment variable: szMyName.// If the variable doesn't exist, then the owner field is skipped./*######################################################################################################################### Set szMyName variable to your name ############### for example szMyName = "t357" ##########################################################################################################################*/szMyName = ""// Get a handle to the current file buffer and the name// and location of the current symbol where the cursor is.hbuf = GetCurrentBuf()szFunc = GetCurSymbol()ln = GetSymbolLine(szFunc)// Get current timeszTime = GetSysTime(1)Day = szTime.DayMonth = szTime.MonthYear = szTime.Yearif (Day < 10)szDay = "0@Day@"elseszDay = DayszMonth = NumToName(Month)szInf = Ask("Enter the information of function:")szDescription = Ask("Enter the description of function:")// begin assembling the title stringsz ="/******************************************************************************" InsBufLine(hbuf, ln, sz)InsBufLine(hbuf, ln + 1, " * @szFunc@ - @szInf@")InsBufLine(hbuf, ln + 2, " * DESCRIPTION: - ")InsBufLine(hbuf, ln + 3, " * @szDescription@ ")// remove by t357. CutWord(szDescription)InsBufLine(hbuf, ln + 4, " * Input: ")InsBufLine(hbuf, ln + 5, " * Output: ")InsBufLine(hbuf, ln + 6, " * Returns: ")InsBufLine(hbuf, ln + 7, " * ")InsBufLine(hbuf, ln + 8, " * modification history")InsBufLine(hbuf, ln + 9, " * --------------------")InsBufLine(hbuf, ln + 10, " * 01a, @szDay@@szMonth@@Year@, @szMyName@ written") InsBufLine(hbuf, ln + 11, " * --------------------")InsBufLine(hbuf, ln + 12, "******************************************************************************/")// put the insertion point inside the header commentSetBufIns(hbuf, ln + 1, strlen(szFunc) + strlen(szInf) + 8)}/****************************************************************************** * NumToName -- change the month number to name** modification history* --------------------* 01a, 05mar2003, t357 written* --------------------******************************************************************************/ macro NumToName(Month){if (Month == 1)return "jan"if (Month == 2)return "feb"if (Month == 3)return "mar"if (Month == 4)return "apr"if (Month == 5)return "may"if (Month == 6)return "jun"if (Month == 7)return "jul"if (Month == 8)return "aug"if (Month == 9)return "sep"if (Month == 10)return "oct"if (Month == 11)return "nov"if (Month == 12)return "dec"}/****************************************************************************** * CutWord -- auto newline** modification history* --------------------* 01a, 24mar2003, t357 fix some bug* 01a, 05mar2003, t357 written* --------------------******************************************************************************/ macro CutWord(ncurLine, szInf){LENGTH = 63nlength = StrLen(szInf)i = 0 /* loop control */begin = 0 /* first character's index of current line */pre = 0 /* preceding word's index */hbuf = GetCurrentBuf()// nline = GetBufLnCur()while (i < nlength){/* remove by t357nrow = 0sz = ""while (nrow < 80){if (nlength < 0)breaksz = Cat(sz, szInf[nrow])nrow = nrow + 1nlength = nlength - 1}InsBufLine(hbuf, nline, sz)szInf = szInf[nrow]}*/c = szInf[i]if (" " == @c@ && (i - b < LENGTH)){pre = i}else if (" " == @c@){szOutput = ""k = begin /* loop control */while (k < pre){szOutput = Cat(szOutput, szInf[k]) k = k + 1}InsBufLine(hbuf, ncurLine, sz)ncurLine = ncurLine + 1begin = pre}i = i + 1}if (h != i - 1){szOutput = ""k = begin /* loop control */while (k < pre){szOutput = Cat(szOutput, szInf[k])k = k + 1}InsBufLine(hbuf, ncurLine, sz)ncurLine = ncurLine + 1}}/****************************************************************************** * GetFileName -- get the filename only from the path** modification history* --------------------* 01a, 05mar2003, t357 written* --------------------******************************************************************************/ macro GetFileName(pathName){nlength = strlen(pathName)i = nlength - 1name = ""while (i + 1){ch = pathName[i]if ("\\" == "@ch@")breaki = i - 1}i = i + 1while (i < nlength){name = cat(name, pathName[i])i = i + 1}return name}/****************************************************************************** * ReturnTrueOrFalse -- Inserts "Returns True or False" at the current line** modification history* --------------------* 01a, 05mar2003, t357 written* --------------------******************************************************************************/ macro ReturnTrueOrFalse(){szReturns = "return True if successful or False if errors."hbuf = GetCurrentBuf()ln = GetBufLnCur(hbuf)szCurLine = GetBufLine(hbuf, ln)DelBufLine(hbuf, ln)InsBufLine(hbuf, ln, "@szCurLine@@szReturns@")SetBufIns(hbuf, ln, StrLen(szReturns) + StrLen(szCurLine) + 3)}/****************************************************************************** * InsHeaderDef -- Inserts the header define in the headerfile** modification history* --------------------* 01a, 05mar2003, t357 written* --------------------******************************************************************************/ macro InsHeaderDef(){hBuf = GetCurrentBuf()szpathName = GetBufName(hBuf)szfileName = GetFileName(szpathName)szfileName = toupper(szfileName)nlength = StrLen(szfileName)i = 0 /* loop control */szdefineName = ""while (i < nlength){if (szfileName[i] == ".")szdefineName = Cat(szdefineName, "_")elseszdefineName = Cat(szdefineName, szfileName[i])i = i + 1}szdefineName = Cat("_", szdefineName)IfdefineSz(szdefineName)}/****************************************************************************** * PrintDate - print date on where the cursor point to* DESCRIPTION: -** Input:* Output:* Returns:** modification history* --------------------* 01a, 23mar2003, t357 written* --------------------******************************************************************************/ macro PrintDate(){szTime = GetSysTime(1)Day = szTime.DayMonth = szTime.MonthYear = szTime.Yearif (Day < 10)szDay = "0@Day@"elseszDay = DayszMonth = NumToName(Month)hbuf = GetCurrentBuf()ln = GetBufLnCur(hbuf)szCurLine = GetBufLine(hbuf, ln)DelBufLine(hbuf, ln)InsBufLine(hbuf, ln, "@szCurLine@ @szDay@@szMonth@@Year@")SetBufIns(hbuf, ln, StrLen(szCurLine) + 10)}// Ask user for ifdef condition and wrap it around current// selection.// 28mar2003, modified by t357.// 26mar2003, modified by t357.macro InsIfdef(){sz = Ask("Enter ifdef condition:")if (sz != ""){// IfdefSz(sz);hwnd = GetCurrentWnd()sel = GetWndSel(hwnd)hbuf = GetWndBuf(hwnd)// get line the selection (insertion point) is onszLine = GetBufLine(hbuf, sel.lnFirst - 1);chTab = CharFromAscii(9)// prepare a new indented blank line to be inserted.// keep white space on left and add a tab to indent.// this preserves the indentation level.i = 0 /* loop control */ich = ""while (szLine[i] == " " || szLine[i] == chTab){ich = Cat(ich, szLine[i])i = i + 1}InsBufLine(hbuf, sel.lnFirst, "")InsBufLine(hbuf, sel.lnFirst + 1, "@ich@#ifdef @sz@")InsBufLine(hbuf, sel.lnFirst + 2, "@ich@" # chTab)InsBufLine(hbuf, sel.lnFirst + 3, "@ich@#endif /* @sz@ */")SetBufIns(hbuf, sel.lnFirst + 2, StrLen(ich) + StrLen(chTab))}}// Wrap ifdeinef <sz> .. endif around the current selectionmacro IfdefineSz(sz){hwnd = GetCurrentWnd()lnFirst = GetWndSelLnFirst(hwnd)lnLast = GetWndSelLnLast(hwnd)hbuf = GetCurrentBuf()InsBufLine(hbuf, lnFirst, "#ifndef @sz@")InsBufLine(hbuf, lnFirst + 1, "#define @sz@")InsBufLine(hbuf, lnLast + 3, "#endif /* @sz@ */")SetBufIns(hbuf, lnFirst + 2, 0)}/* A U T O E X P A N D *//*------------------------------------------------------------------------- Automatically expands C statements like if, for, while, switch, etc..To use this macro,1. Add this file to your project or your Base project.2. Run the Options->Key Assignments command and assign aconvenient keystroke to the "AutoExpand" command.3. After typing a keyword, press the AutoExpand keystroke to have thestatement expanded. The expanded statement will contain a ### stringwhich represents a field where you are supposed to type more.The ### string is also loaded in to the search pattern so you canuse "Search Forward" to select the next ### field.For example:1. you type "for" + AutoExpand key2. this is inserted:for (###; ###; ###){###}3. and the first ### field is selected.-------------------------------------------------------------------------*//****************************************************************************** * AutoExpand - Automatically expands C statements** DESCRIPTION: - Automatically expands C statements like if, for, while,* switch, etc..** Input:* Output:* Returns:** modification history* --------------------* 01a, 27mar2003, t357 modified* --------------------******************************************************************************/ macro AutoExpand(){// get window, sel, and buffer handleshwnd = GetCurrentWnd()if (hwnd == 0)stopsel = GetWndSel(hwnd)if (sel.ichFirst == 0)stophbuf = GetWndBuf(hwnd)// get line the selection (insertion point) is onszLine = GetBufLine(hbuf, sel.lnFirst);// parse word just to the left of the insertion pointwordinfo = GetWordLeftOfIch(sel.ichFirst, szLine)ln = sel.lnFirst;chTab = CharFromAscii(9)// prepare a new indented blank line to be inserted.// keep white space on left and add a tab to indent.// this preserves the indentation level.ich = 0while (szLine[ich] == ' ' || szLine[ich] == chTab){ich = ich + 1}szLine = strmid(szLine, 0, ich)sel.lnFirst = sel.lnLastsel.ichFirst = wordinfo.ichsel.ichLim = wordinfo.ich// expand szWord keyword...if (wordinfo.szWord == "if" ||wordinfo.szWord == "while" ||wordinfo.szWord == "elseif"){SetBufSelText(hbuf, " (###)")InsBufLine(hbuf, ln + 1, "@szLine@" # "{");InsBufLine(hbuf, ln + 2, "@szLine@" # chTab);InsBufLine(hbuf, ln + 3, "@szLine@" # "}");}else if (wordinfo.szWord == "for"){SetBufSelText(hbuf, " (###)")InsBufLine(hbuf, ln + 1, "@szLine@" # "{");InsBufLine(hbuf, ln + 2, "@szLine@" # chTab);InsBufLine(hbuf, ln + 3, "@szLine@" # "}");}else if (wordinfo.szWord == "switch"){SetBufSelText(hbuf, " (###)")InsBufLine(hbuf, ln + 1, "@szLine@" # "{")InsBufLine(hbuf, ln + 2, "@szLine@" # "case ")InsBufLine(hbuf, ln + 3, "@szLine@" # chTab)InsBufLine(hbuf, ln + 4, "@szLine@" # chTab # "break;") InsBufLine(hbuf, ln + 5, "@szLine@" # "default:")InsBufLine(hbuf, ln + 6, "@szLine@" # chTab)InsBufLine(hbuf, ln + 7, "@szLine@" # "}")}else if (wordinfo.szWord == "do"){InsBufLine(hbuf, ln + 1, "@szLine@" # "{")InsBufLine(hbuf, ln + 2, "@szLine@" # chTab);InsBufLine(hbuf, ln + 3, "@szLine@" # "} while ();")}else if (wordinfo.szWord == "case"){SetBufSelText(hbuf, " ###")InsBufLine(hbuf, ln + 1, "@szLine@" # chTab)InsBufLine(hbuf, ln + 2, "@szLine@" # chTab # "break;")}elsestopSetWndSel(hwnd, sel)LoadSearchPattern("###", true, false, false);Search_Forward}/* G E T W O R D L E F T O F I C H *//*------------------------------------------------------------------------- Given an index to a character (ich) and a string (sz),return a "wordinfo" record variable that describes thetext word just to the left of the ich.Output:wordinfo.szWord = the word stringwordinfo.ich = the first ich of the wordwordinfo.ichLim = the limit ich of the word-------------------------------------------------------------------------*/ macro GetWordLeftOfIch(ich, sz){wordinfo = "" // create a "wordinfo" structurechTab = CharFromAscii(9)// scan backwords over white space, if anyich = ich - 1;if (ich >= 0)while (sz[ich] == " " || sz[ich] == chTab){ich = ich - 1;if (ich < 0)break;}// scan backwords to start of wordichLim = ich + 1;asciiA = AsciiFromChar("A")asciiZ = AsciiFromChar("Z")while (ich >= 0){ch = toupper(sz[ich])asciiCh = AsciiFromChar(ch)if ((asciiCh < asciiA || asciiCh > asciiZ) && !IsNumber(ch)) break // stop at first non-identifier characterich = ich - 1;}ich = ich + 1wordinfo.szWord = strmid(sz, ich, ichLim)wordinfo.ich = ichwordinfo.ichLim = ichLim;return wordinfo}。
Source Insight常用快捷键及注释快捷键设置
(/tlaff/article/details/6536610)
在使用SI过程中,我根据自己的使用习惯修改了它的默认快捷键,并且在配置文件中添加了一些人性化功能,下面一一介绍:
修改快捷键:Options->Key Assignments...
1.main window:Esc
2.Hight light:Middle Mouse
3.Go Back:Alt+z
4.Go Forward:Alt+x
5.Caller:Alt+c
6.Reference:Alt+r
7.Previous Link:Alt+a 8.Next Link:Alt+s
9.First Link:Alt+d
10.Go Line:Alt+g 11.Select Line:Alt+l
12.Symbol Win:Alt+q 13.Activate SW:Alt+w
14.Projcet Win:Alt+[ 15.Activate PW:Alt+]
16.Contex Win:Alt+,17.Activate CW:Alt+.
18.Relation Win:Alt+;19.Activate RW:Alt+'
20.Select All:Ctrl+a 21.Save All:Ctrl+Shift+a
22.Browse Project Symbols:Alt+b
添加一些配置文件宏,比如:注释掉代码:单行注释、多行注释,将选中内容注释掉;在一行代码的前、后添加注释性文字等。
打开Projcet->Open project,选择base,可以看到utils.em文件,将下列宏添加到该文件中,并在其他工程里加入该文件,
在上面介绍的快捷键添加方式里找到该宏并自定义快捷键。
单行、多行注释:
[plain]view plaincopyprint?
1. m acro MultiLineComment()
2. {
3. hwnd = GetCurrentWnd()
4. selection = GetWndSel(hwnd)
5. LnFirst = GetWndSelLnFirst(hwnd) //取首行行号
6. LnLast = GetWndSelLnLast(hwnd) //取末行行号
7. hbuf = GetCurrentBuf()
8.
9. if(GetBufLine(hbuf, 0) == "//magic-number:tph85666031"){
10. stop
11. }
12.
13. Ln = Lnfirst
14. buf = GetBufLine(hbuf, Ln)
15. len = strlen(buf)
16.
17. while(Ln <= Lnlast) {
18. buf = GetBufLine(hbuf, Ln) //取Ln对应的行
19. if(buf == ""){ //跳过空行
20. Ln = Ln + 1
21. continue
22. }
23.
24. if(StrMid(buf, 0, 1) == "/") { //需要取消注释,防止只有单字符的行
25. if(StrMid(buf, 1, 2) == "/"){
26. PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))
27. }
28. }
29.
30. if(StrMid(buf,0,1) != "/"){ //需要添加注释
32. }
33. Ln = Ln + 1
34. }
35.
36. SetWndSel(hwnd, selection)
37. }
将上面的代码保存到utils.em文件,打开source insight,将该文件添加到工程中,然后在Options->Key Assignments中你就可以看到这个宏了,宏的名字是MultiLineComments,
然后我们为它分配快捷键“Ctrl + /”,然后就可以了。
这是一份添加“#ifdef 0”和“#endif”的宏代码,定义快捷键为Ctrl+#:
[plain]view plaincopyprint?
1. m acro AddMacroComment()
2. {
3. hwnd=GetCurrentWnd()
4. sel=GetWndSel(hwnd)
5. lnFirst=GetWndSelLnFirst(hwnd)
6. lnLast=GetWndSelLnLast(hwnd)
7. hbuf=GetCurrentBuf()
8.
9. if(LnFirst == 0) {
10. szIfStart = ""
11. }else{
12. szIfStart = GetBufLine(hbuf, LnFirst-1)
13. }
14. szIfEnd = GetBufLine(hbuf, lnLast+1)
15. if(szIfStart == "#if 0" && szIfEnd == "#endif") {
16. DelBufLine(hbuf, lnLast+1)
17. DelBufLine(hbuf, lnFirst-1)
18. sel.lnFirst = sel.lnFirst – 1
19. sel.lnLast = sel.lnLast – 1
20. }else{
22. InsBufLine(hbuf, lnLast+2, "#endif")
23. sel.lnFirst = sel.lnFirst + 1
24. sel.lnLast = sel.lnLast + 1
25. }
26.
27. SetWndSel( hwnd, sel )
28. }
这份宏的代码可以把光标所在的行注释掉,定义快捷键为Ctrl+*:[plain]view plaincopyprint?
1. m acro CommentSingleLine()
2. {
3. hbuf = GetCurrentBuf()
4. ln = GetBufLnCur(hbuf)
5. str = GetBufLine (hbuf, ln)
6. str = cat("/*",str)
7. str = cat(str,"*/")
8. PutBufLine (hbuf, ln, str)
9. }
将一行中鼠标选中部分注释掉,定义快捷键为Ctrl+shift+*:[plain]view plaincopyprint?
1. m acro CommentSelStr()
2. {
3. hbuf = GetCurrentBuf()
4. ln = GetBufLnCur(hbuf)
5. str = GetBufSelText(hbuf)
6. str = cat("/*",str)
7. str = cat(str,"*/")
8. SetBufSelText (hbuf, str)
9. }
在一行代码前添加注释性文字,定义快捷键为Alt+/:在一行代码前添加注释性文字,定义快捷键为Alt+\:。