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 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

转载于:https://www.cnblogs.com/chencheng/archive/2012/07/22/2603619.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值