Source Insight宏说话实践

名人名言:真理不一定都是顺耳的。——谚语 

Source Insight 作为一款优良的代码浏览和编辑器应用十分广泛,对于一些反复应用的功能,我们可以定义相干的宏来进步开辟效力。


1:宏的编写


Source Insight Help文档中Macro Language Guide一节具体的介绍了宏的编写,布局和C说话类似,经由过程浏览文档,信赖就可以编写出各类功能强大的宏。这里我编写了一个简单的添加函数注释的宏。


 


View Code 

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 Comment()
{
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, ...)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章