Source Insight 作为一款优秀的代码浏览和编辑器应用十分广泛,对于一些重复使用的功能,我们可以定义相关的宏来提高开发效率。
1:宏的编写
Source Insight Help文档中Macro Language Guide一节详细的介绍了宏的编写,结构和C语言相似,通过阅读文档,相信就可以编写出各种功能强大的宏。这里我编写了一个简单的添加函数注释的宏。
macro GetCommentsTime() { var year var month var day var commTime var sysTime sysTime = GetSysTime(1) year = sysTime.Year month = sysTime.month day = sysTime.day commTime = "@year@-@month@-@day@" return commTime } macro GetCommentsPos() { var funPos var fun fun = GetCurSymbol() funPos = GetSymbolLine(fun) return funPos } macro GetFunDescribe() { str = Ask ("请输入函数描述!") return str } macro GetAuthor() { author = GetEnv (author_name) if(nil == author) { str = Ask ("请输入作者名!") PutEnv (author_name, str) } author = GetEnv (author_name) return author } macro insertComment() { var comments var hBuff var line var fun fun = GetCurSymbol() hBuff = GetCurrentBuf() line = GetCommentsPos() InsBufLine(hBuff, line, "/**********************************") comments = "函 数 名:" comments = cat(comments,fun) InsBufLine(hBuff, line+1, comments) comments = "描 述:" des = GetFunDescribe() comments = cat(comments,des) InsBufLine(hBuff, line+2, comments) comments = "作 者:" author = GetAuthor() comments = cat(comments,author) InsBufLine(hBuff, line+3, comments) comments = "创 建 日 期:" time = GetCommentsTime() comments = cat(comments,time) InsBufLine(hBuff, line+4, comments) InsBufLine(hBuff, line+5, "**********************************/") SaveBuf(hBuff) }
2:宏调试
在编写一个宏函数的时候我们希望随时可以调试相关信息,可以通过“Inline Macro”来实现,通过stop命令我们可以控制宏执行的结束位置,为了实时查看返回信息,我们可以通过msg这个函数来查看返回信息。
macro GetCommentsPos() { var funPos var fun fun = GetCurSymbol() funPos = GetSymbolLine(fun) msg(funPos) stop return funPos }
然后我们调用下“Run Macro command”这个命令就可以执行该宏了。
3:添加脚本到工程
脚本编写完毕后,我们以.em后缀来保存。我们可以把脚本加入到我们的工程中,然后同步一下。也可以把脚本放入Source Insight\Projects\Base目录中(任何工程都可以使用)。然后我们就可以看到我们定义的宏已经出现在命令列表中了。对于常用的宏都可以映射为快捷键值。
4:宏运行
在需要添加注释的函数中运行一下宏,我们就可以把函数注释头添加进去了,十分方便。
/**********************************
函 数 名:getDigits
描 述:*****
作 者:chencheng
创 建 日 期:2012-7-22
**********************************/
static int getDigits(const char *zDate, ...)
转载请注明原始出处:http://www.cnblogs.com/chencheng/archive/2012/07/22/2603619.html