sourceInsight宏命令实现添加注释、切换源文件与头文件、增加函数注释的功能、多行注释#if0..#endif

添加#if 0 .. #endif

可以当做多行注释来用。

macro AddMacroComment()
{
	hwnd=GetCurrentWnd()
	sel=GetWndSel(hwnd)
	lnFirst=GetWndSelLnFirst(hwnd)
	lnLast=GetWndSelLnLast(hwnd)
	hbuf=GetCurrentBuf()
	if (LnFirst == 0) 
	{
	    szIfStart = ""
	} 
    else 
	{
		szIfStart = GetBufLine(hbuf, LnFirst)
	}
	szIfEnd = GetBufLine(hbuf, lnLast)
	if (szIfStart == "#if 0" && szIfEnd =="#endif") 
	{
		DelBufLine(hbuf, lnLast)
		DelBufLine(hbuf, lnFirst)
	} 
	else 
	{
		InsBufLine(hbuf, lnFirst, "#if 0")
		InsBufLine(hbuf, lnLast+2, "#endif")
	}
}

添加头文件

macro AddInclude()
{
	hwnd = GetCurrentWnd()
	lnFirst = GetWndSelLnFirst(hwnd)
	hbuf = GetCurrentBuf()
	InsBufLine(hbuf, lnFirst, "#include \"\"")
	len = strlen("#include \"")
	SetBufIns (hbuf, lnFirst, len)
}

添加单行注释

"/**/"类型的注释,添加完毕后光标自动跳转到"/**/"之间。

macro AddCommit02()
{
	hwnd = GetCurrentWnd()
	lnFirst = GetWndSelLnFirst(hwnd)
	hbuf = GetCurrentBuf()
	sz = GetBufLine(hbuf,lnFirst)
	sz = sz # "/*  */"
	PutBufLine (hbuf, lnFirst, sz)
	len = strlen(sz)
	len = len-strlen(" */")
	SetBufIns (hbuf, lnFirst, len)
}

"//"类型的注释,添加完毕光标自动跳转到"//"之后,支持在代码之后添加注释。

macro AddCommit01()
{
	hwnd = GetCurrentWnd()
	lnFirst = GetWndSelLnFirst(hwnd)
	hbuf = GetCurrentBuf()
	sz = GetBufLine(hbuf,lnFirst)
	sz = sz # "//"
	PutBufLine (hbuf, lnFirst, sz)
	len = strlen(sz)
	SetBufIns (hbuf, lnFirst, len)
}

添加函数注释

//提示框中输入参数个数,产生不同的注释
macro MyCommit()
{
	sz = Ask("Number Of Parameters:")
	if (sz != "")
		AddCommit(sz);
}

//添加注释的宏
macro AddCommit(sz)
{
	num = sz
    num2 = 0

	hwnd = GetCurrentWnd()
	lnLast = GetWndSelLnLast(hwnd)
	
	hbuf = GetCurrentBuf()

	InsBufLine(hbuf, lnLast, "/**")
	
	InsBufLine(hbuf, lnLast+1, "  * \@brief ")

	ln=lnLast+2
	
	while (num > 0) {
		num2 = num2+1
		InsBufLine(hbuf, ln, "  * \@param@num2@ ")
		ln = ln+1
		num = num-1
	}
	InsBufLine(hbuf, ln, "  * \@expl ")
	InsBufLine(hbuf, ln+1, "  * \@return 0:success -1:failure")
	InsBufLine(hbuf, ln+2, "  */")
}

头文件与源文件切换

这里仅实现了头文件的源文件在同一个文件夹下时的切换。

macro switch_cpp_hpp()
{
	hwnd = GetCurrentWnd()
	hCurOpenBuf = GetCurrentBuf()
	if (hCurOpenBuf == 0)
		stop 
	curOpenFileName = GetBufName(hCurOpenBuf)
	curOpenFileNameLen = strlen(curOpenFileName)
 
	// 文件类型临时缓冲区
	strFileExt = NewBuf("strFileExtBuf")
	ClearBuf(strFileExt)
	
	// 头文件类型
	index_hpp_begin = 0 							
	AppendBufLine(strFileExt, ".h")
	AppendBufLine(strFileExt, ".hpp")
	index_hpp_end = GetBufLineCount(strFileExt) 		
	
	// 源文件类型
	index_cpp_begin = index_hpp_end 			
	AppendBufLine(strFileExt, ".c")
	AppendBufLine(strFileExt, ".cpp")
	AppendBufLine(strFileExt, ".cc")
	AppendBufLine(strFileExt, ".cx")
	AppendBufLine(strFileExt, ".cxx")
	index_cpp_end = GetBufLineCount(strFileExt)		
 
	isCppFile = 0 						
	curOpenFileExt = "" 					
	index = index_hpp_begin 
	
	while(index < index_cpp_end)	
	{
		curExt = GetBufLine(strFileExt, index) 
		curExtLen = strlen(curExt) 
		curOpenFileExt = strmid(curOpenFileName, curOpenFileNameLen-curExtLen, curOpenFileNameLen) 		
		
		if(curOpenFileExt == curExt)		
		{
			if (index < index_hpp_end)
				isCppFile = 1 			
			else
				isCppFile = 2 			
			break 
		}
		index = index + 1 
	}
	
	index_replace_begin = index_hpp_begin 
	index_replace_end = index_hpp_end 
	
	if (isCppFile == 1)							
	{
		index_replace_begin = index_cpp_begin 
		index_replace_end = index_cpp_end 
	}
	else if(isCppFile == 2)					
	{
		index_replace_begin = index_hpp_begin 
		index_replace_end = index_hpp_end 
	}
	else							
	{
		index_replace_begin = 9999 					
		index_replace_end = index_replace_begin 	
	}
	
	index = index_replace_begin 
	while(index < index_replace_end)
	{
		destExt = GetBufLine(strFileExt, index) 
		destFileName = strmid(curOpenFileName, 0, curOpenFileNameLen-strlen(curOpenFileExt)) 	// 不包括扩展名,绝对路径
		
		// 尝试当前目标扩展名是否能够打开
		destFilePath = cat(destFileName, destExt)	
		hCurOpenBuf = OpenBuf(destFilePath)
		if(hCurOpenBuf != 0)
		{
			SetCurrentBuf(hCurOpenBuf)
			break 
		}
		index = index + 1 
	}
	CloseBuf(strFileExt)							
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值