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