source insigt 添加常用宏

将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 );
}

// ===================================================    注释与条件编译         ===============================================================================================
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值