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 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, ...)