将com.em添加到source insight 的base工程中 :project->open project->base
分配快捷键给各个宏:Options-> Key Assignment 在Command中输入JM会列出com.em里面的宏函数,逐一分配键值即可
参见https://download.csdn.net/download/u010075040/11292810
com.em内容如下:
// =================================================== 插入描述信息 ===============================================================================================
macro JMInsertHBFileHeader()
{
szMyName = getenv(MYNAME)
if (strlen(szMyName) > 0)
{
sz = " : @szMyName@"
}
else
{
sz = " : null"
}
hwnd = GetCurrentWnd()
lnFirst = 0
hbuf = GetCurrentBuf()
szFileName = GetBufName(hbuf);
n = strlen(szFileName) - 1;
while(n>0)
{
if(szFileName[n] == "\\")
break;
n = n-1;
}
szFileName = strmid(szFileName, n+1, strlen(szFileName));
InsBufLine(hbuf, lnFirst, "/**")
InsBufLine(hbuf, lnFirst+1, " * Copyright(C): ")
InsBufLine(hbuf, lnFirst+2, cat(" * \@file ", szFileName))
InsBufLine(hbuf, lnFirst+3, " * \@brief 简要描述该文件功能 ")
InsBufLine(hbuf, lnFirst+4, " * ")
InsBufLine(hbuf, lnFirst+5, " * ")
InsBufLine(hbuf, lnFirst+6, cat(" * \@author ", sz))
InsBufLine(hbuf, lnFirst+7, " * \@version ")
InsBufLine(hbuf, lnFirst+8, cat(" * \@date ", getDateTime()))
InsBufLine(hbuf, lnFirst+9, " * \@详细描述,简单描述与详细描述之间用一个空行分隔,每一个方面成为一段。 ")
InsBufLine(hbuf, lnFirst+10, " * \@bug ")
InsBufLine(hbuf, lnFirst+11, " * \@warning ")
InsBufLine(hbuf, lnFirst+12, " * ")
InsBufLine(hbuf, lnFirst+13, " */")
}
macro ma_getLeftSpace(stTempStr)
{
sBegSpace ="";
i = 0;
while (i < strlen(strTempStr))
{
if (stTempStr[i] == " ")
{
sBegSpace = cat (sBegSpace, " ")
}
else
{
break;
}
i = i + 1
}
return sBegSpace;
}
macro getDateTime()
{
szTime = GetSysTime(1)
Year = szTime.Year
Month = szTime.Month
Day = szTime.Day
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
return "@Year@-@Month@-@Day@ @Hour@:@Minute@:@Second@"
}
macro ma_IsExist(str, sub_str)
{
len = strlen(str);
sub_len = strlen(sub_str);
i = 0;
while (i <= len - sub_len)
{
if (strmid(str, i, sub_len) == sub_str)
{
return 1;
}
i = i+1;
}
return 0;
}
macro ma_getFuncHead(hbuf, sFuntionname)
{
funhead ="";
lineNum = 0;
while(lineNum < 2)
{
str = getbufline(hbuf, sFunctionname.lnFirst + lineNum);
funhead = cat(temp, str);
lineNum = lineNum +1;
if (!ma_IsExist(str, ")"))
{
continue;
}
else
{
break;
}
}
return funhead;
}
macro ma_insertPara(hbuf, ln, funhead, sBegSpace)
{
len = strlen(funhead);
incLine = 0;
i=0;
while(i < len)
{
if (strmid(funhead, i, i+1) == "(")
{
i=i+1;
break;
}
i=i+1;
}
ret = sBegSpace;
tmp = "";
hasspace = 0;
while(i<len)
{
onechar = strmid(funhead, i, i+1);
if (onechar == "," || onechar == ")" || onechar == "[")
{
if(tmp != "")
{
ret = cat(cat(sBegSpace, " * \@param [in] "),tmp);
InsBufLine(hbuf, ln, ret)
ln = ln +1
incLine = incLine +1
tmp =""
}
}
else if(onechar == "]")
{
tmp = "";
}
else
{
tmp=cat(tmp, onechar);
if(tmp == " ")
{
tmp="";
}
}
i= i+1;
}
return incLine;
}
macro JMInsertHBFunctionHeader()
{
hbuf = GetCurrentBuf();
ln = GetBufLnCur(hbuf);
sFunctionName = GetSymbolLocationFromLn(hbuf, ln);
lnFirst = sFunctionName.lnFirst;
stTempStr = GetBufLine(hbuf, lnFirst);
sBegSpace = ma_GetLeftSpace(stTempStr)
// funhead = ma_getFuncHead(hbuf,sFunctionname);
InsBufLine(hbuf, lnFirst, cat(sBegSpace, "/**"))
n=1
InsBufLine(hbuf, lnFirst+n, cat(cat(cat(cat(sBegSpace, " * \@brief Description "), sFunctionName.Type)," "), sFunctionName.Symbol))
n = n+1;
InsBufLine(hbuf, lnFirst+n, cat(sBegSpace, " * "))
n = n+1;
InsBufLine(hbuf, lnFirst+n, cat(sBegSpace, " * "))
n = n+1;
if (sFunctionname.Type != "Class")
{
incLine = ma_insertPara(hbuf, lnFirst+n, stTempStr, sBegSpace);
n = n + incLine
InsBufLine(hbuf, lnFirst+n, cat(sBegSpace, " * \@return "))
n = n+1;
}
InsBufLine(hbuf, lnFirst+n, cat(sBegSpace, " * \@attention "))
n = n + 1;
InsBufLine(hbuf, lnFirst+n, cat(sBegSpace, " * "))
n = n + 1;
InsBufLine(hbuf, lnFirst+n, cat(sBegSpace, " */"))
}
macro JMInsertFunction()
{
funcStat = Ask("Add function");
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
n = 0;
InsBufLine(hbuf, lnFirst+n, cat(cat("int ", funcStat), "(void)"))
n = n + 1;
InsBufLine(hbuf, lnFirst+n, "{")
n = n + 1;
InsBufLine(hbuf, lnFirst+n, " int ret = 0;")
n = n + 1;
InsBufLine(hbuf, lnFirst+n, "")
n = n + 1;
InsBufLine(hbuf, lnFirst+n, " //TODO add code from here")
n = n + 1;
InsBufLine(hbuf, lnFirst+n, "")
n = n + 1;
InsBufLine(hbuf, lnFirst+n, " return ret;")
n = n + 1;
InsBufLine(hbuf, lnFirst+n, "}")
}
// =================================================== 插入描述信息 ===============================================================================================
// =================================================== 注释与条件编译 ===============================================================================================
// 多行注释
macro JMMultiLineComment()
{
hwnd = GetCurrentWnd()
selection = GetWndSel(hwnd)
LnFirst =GetWndSelLnFirst(hwnd) //取首行行号
LnLast =GetWndSelLnLast(hwnd) //取末行行号
hbuf = GetCurrentBuf()
if(GetBufLine(hbuf, 0) =="//magic-number:tph85666031"){
stop
}
Ln = Lnfirst
buf = GetBufLine(hbuf, Ln)
len = strlen(buf)
while(Ln <= Lnlast) {
buf = GetBufLine(hbuf, Ln) //取Ln对应的行
if(buf ==""){ //跳过空行
Ln = Ln + 1
continue
}
if(StrMid(buf, 0, 1) == "/"){ //需要取消注释,防止只有单字符的行
if(StrMid(buf, 1, 2) == "/"){
PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))
}
}
if(StrMid(buf,0,1) !="/"){ //需要添加注释
PutBufLine(hbuf, Ln, Cat("//", buf))
}
Ln = Ln + 1
}
SetWndSel(hwnd, selection)
}
// 将一行中鼠标选中部分注释掉:
macro JMCommentSelStr()
{
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)
str = GetBufSelText(hbuf)
str = cat("/*",str)
str = cat(str,"*/")
SetBufSelText (hbuf, str)
}
// 编译条件宏
macro JMIfdefin0()
{
hwnd = GetCurrentWnd();
sel = GetWndSel ( hwnd );
lnFirst = GetWndSelLnFirst ( hwnd );
lnLast = GetWndSelLnLast ( hwnd );
hbuf = GetCurrentBuf();
if ( LnFirst == 0 )
{
szIfStart = "";
}
else
{
szIfStart = GetBufLine ( hbuf, LnFirst - 1 );
}
szIfEnd = GetBufLine ( hbuf, lnLast + 1 );
if ( szIfStart == "#if 0" && szIfEnd == "#endif" )
{
DelBufLine ( hbuf, lnLast + 1 );
DelBufLine ( hbuf, lnFirst - 1 );
//sel.lnFirst = sel.lnFirst + 1;
//sel.lnLast = sel.lnLast + 1;
}
else
{
InsBufLine ( hbuf, lnFirst, "#if 0" );
InsBufLine ( hbuf, lnLast + 2, "#endif" );
sel.lnFirst = sel.lnFirst + 1;
sel.lnLast = sel.lnLast + 1;
}
SetWndSel ( hwnd, sel );
}
// =================================================== 注释与条件编译 ===============================================================================================