Source Insight 宏-单行注释

 

   以前用VS2005或是VS2008写代码,习惯了它的注释功能,使用Source Insight后发现没有提供相应的功能,只能自己写宏来实现,下面就是插入单行注释的宏脚本。

   功能:对选中的内容进行单行注释(//)

   使用:将下面宏脚本写到Source Insight的utils.em文件(Source Insight\Projects\Base下)或是新建一个*.em文件,并加入到Base项目中,通过Key Assignments指定快捷键或是Menu Assignments指定菜单项。

 

  目的:宏的编写纯粹是为了开发的便利,多行注释(/**/)宏,后续会继续做出来。

 

  写的比较乱,但是功能很好用,希望对大家有用,欢迎大家拍!

    

// 插入单行注释
macro Comments_UnComments()
{
	hwnd = GetCurrentWnd()
	hbuf = GetCurrentBuf()
	if(hbuf ==0)
		stop 
		
	// debugBuf只是为了调试
	// debugBuf = NewBuf("debugBuf") 
	// ClearBuf(debugBuf) 

	lnSelFirst = GetWndSelLnFirst(hwnd)		// 获得选中内容的第一行
	lnSelLast = GetWndSelLnLast(hwnd) 		// 获得选中内容的最后一行
		
	const_space = " "			// 空格
	const_comments = "//" 		// 单行注释符号
	isCancelComments = 0 
	
	// 跳过开始的空行,否则下面报错
	line_index = lnSelFirst 
	orig_text = GetBufLine(hbuf, line_index)	// 获得第一行的text
	while(strlen(orig_text) == 0)
	{
		line_index = line_index + 1
		orig_text = GetBufLine(hbuf, line_index)	// 获得第一行的text
	}
	
	// 根据第一行选中文本,确定是“注释”,还是“取消注释”
	// 判断是否以“//”开始,如果是则认为是“取消注释”,首先需要去掉空格
	subIndex = 0 		
	while(strmid(orig_text, subIndex, subIndex+1) == const_space) 
			subIndex = subIndex + 1 
	
	if (strmid(orig_text, subIndex, subIndex+2) == const_comments)	// 以“//”开头,取消注释
	{
		isCancelComments = 1 
	}

	// 遍历所有选中的行
	// line_index = lnSelFirst 	// 前面已经跳过开头的空行
	while(line_index <= lnSelLast)
	{
		orig_text = GetBufLine(hbuf, line_index)	// 获得以前的text
		if (strlen(orig_text) > 0)					// 如果是空行,则跳过
		{
			dest_text = "" 
			if(isCancelComments == 1)					// 取消注释
			{
				// 查找注释符“//”
				subIndex = 0 		
				while(strmid(orig_text, subIndex, subIndex+1) == const_space) 
						subIndex = subIndex + 1 
				
				if (strmid(orig_text, subIndex, subIndex+2) == const_comments)	// 以“//”开头,取消注释
				{
					dest_text = strmid(orig_text, subIndex+2, strlen(orig_text)) 
				}
			}
			else
			{
				dest_text = cat("//", orig_text) 			// 添加注释字符 “//”
			}

			PutBufLine (hbuf, line_index, dest_text)  	// 替换以前的text
		}
		
		line_index = line_index + 1  
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值